use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method addQuestion.
private QuestionnaireItemComponent addQuestion(QuestionnaireItemComponent group, QuestionnaireItemType af, QuestionnaireAnswerConstraint constraint, String path, String id, String name, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, ValueSet vs) throws FHIRException {
QuestionnaireItemComponent result = group.addItem();
if (vs != null) {
if (vs.getExpansion() == null) {
result.setAnswerValueSet(vs.getUrl());
ToolingExtensions.addControl(result, "lookup");
} else {
if (Utilities.noString(vs.getId())) {
vs.setId(nextId("vs"));
questionnaire.getContained().add(vs);
vsCache.put(vs.getUrl(), vs.getId());
vs.setText(null);
vs.setCompose(null);
vs.getContact().clear();
vs.setPublisherElement(null);
vs.setCopyrightElement(null);
}
result.setAnswerValueSet("#" + vs.getId());
}
}
result.setLinkId(path + '.' + id);
result.setText(name);
result.setType(af);
result.setAnswerConstraint(constraint);
result.setRequired(false);
result.setRepeats(false);
if (id.endsWith("/1"))
id = id.substring(0, id.length() - 2);
if (answerGroups != null) {
for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) {
List<Base> children = new ArrayList<Base>();
QuestionnaireResponse.QuestionnaireResponseItemComponent aq = null;
Element obj = (Element) ag.getUserData("object");
if (isPrimitive((TypeRefComponent) obj))
children.add(obj);
else if (obj instanceof Enumeration) {
String value = ((Enumeration) obj).toString();
children.add(new StringType(value));
} else
children = obj.listChildrenByName(id);
for (Base child : children) {
if (child != null) {
if (aq == null) {
aq = ag.addItem();
aq.setLinkId(result.getLinkId());
aq.setText(result.getText());
}
aq.addAnswer().setValue(convertType(child, af, vs, result.getLinkId()));
}
}
}
}
return result;
}
use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class ToolingExtensions method addFlyOver.
// public static boolean hasDeprecated(Element c) {
// return findBooleanExtension(c, EXT_DEPRECATED);
// }
public static void addFlyOver(QuestionnaireItemComponent item, String text, String linkId) {
if (!StringUtils.isBlank(text)) {
QuestionnaireItemComponent display = item.addItem();
display.setType(QuestionnaireItemType.DISPLAY);
display.setText(text);
display.setLinkId(linkId);
display.getExtension().add(Factory.newExtension(EXT_CONTROL, Factory.newCodeableConcept("flyover", "http://hl7.org/fhir/questionnaire-item-control", "Fly-over"), true));
}
}
use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderItemOptions.
public void renderItemOptions(XhtmlNode x, QuestionnaireItemComponent i) {
if (i.hasAnswerOption()) {
boolean useSelect = false;
for (QuestionnaireItemAnswerOptionComponent opt : i.getAnswerOption()) {
useSelect = useSelect || opt.getInitialSelected();
}
x.an("opt-item." + i.getLinkId());
x.para().b().tx("Answer options for " + i.getLinkId());
XhtmlNode ul = x.ul();
for (QuestionnaireItemAnswerOptionComponent opt : i.getAnswerOption()) {
XhtmlNode li = ul.li();
li.style("font-size: 11px");
if (useSelect) {
if (opt.getInitialSelected()) {
li.img("icon-selected.png");
} else {
li.img("icon-not-selected.png");
}
}
if (opt.getValue().isPrimitive()) {
li.tx(opt.getValue().primitiveValue());
} else if (opt.getValue() instanceof Coding) {
Coding c = (Coding) opt.getValue();
String link = c.hasSystem() ? context.getWorker().getLinkForUrl(context.getSpecificationLink(), c.getSystem()) : null;
if (link == null) {
li.tx(c.getSystem() + "#" + c.getCode());
} else {
li.ah(link).tx(describeSystem(c.getSystem()));
li.tx(": " + c.getCode());
}
if (c.hasDisplay()) {
li.tx(" (\"" + c.getDisplay() + "\")");
}
} else {
li.tx("??");
}
}
}
}
use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderRootDefinition.
private boolean renderRootDefinition(XhtmlNode tbl, Questionnaire q, List<QuestionnaireItemComponent> parents) throws IOException {
boolean ext = false;
XhtmlNode td = tbl.tr().td("structure").colspan("2").span(null, null).attribute("class", "self-link-parent");
td.an(q.getId());
td.img(Utilities.path(context.getLocalPrefix(), "icon_q_root.gif"));
td.tx(" Questionnaire ");
td.b().tx(q.getId());
// general information
defn(tbl, "URL", q.getUrl());
defn(tbl, "Version", q.getVersion());
defn(tbl, "Name", q.getName());
defn(tbl, "Title", q.getTitle());
if (q.hasDerivedFrom()) {
td = defn(tbl, "Derived From");
boolean first = true;
for (CanonicalType c : q.getDerivedFrom()) {
if (first)
first = false;
else
td.tx(", ");
// todo: make these a reference
td.tx(c.asStringValue());
}
}
defn(tbl, "Status", q.getStatus().getDisplay());
defn(tbl, "Experimental", q.getExperimental());
defn(tbl, "Publication Date", q.getDateElement().primitiveValue());
defn(tbl, "Approval Date", q.getApprovalDateElement().primitiveValue());
defn(tbl, "Last Review Date", q.getLastReviewDateElement().primitiveValue());
if (q.hasEffectivePeriod()) {
renderPeriod(defn(tbl, "Effective Period"), q.getEffectivePeriod());
}
if (q.hasSubjectType()) {
td = defn(tbl, "Subject Type");
boolean first = true;
for (CodeType c : q.getSubjectType()) {
if (first)
first = false;
else
td.tx(", ");
td.tx(c.asStringValue());
}
}
defn(tbl, "Description", q.getDescription());
defn(tbl, "Purpose", q.getPurpose());
defn(tbl, "Copyright", q.getCopyright());
if (q.hasCode()) {
td = defn(tbl, Utilities.pluralize("Code", q.getCode().size()));
boolean first = true;
for (Coding c : q.getCode()) {
if (first)
first = false;
else
td.tx(", ");
renderCodingWithDetails(td, c);
}
}
return false;
}
use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method listOptions.
private void listOptions(Questionnaire q, QuestionnaireItemComponent i, XhtmlNode select) {
if (i.hasAnswerValueSet()) {
ValueSet vs = null;
if (!Utilities.noString(i.getAnswerValueSet()) && i.getAnswerValueSet().startsWith("#")) {
vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1));
if (vs != null && !vs.hasUrl()) {
vs = vs.copy();
vs.setUrl(q.getUrl() + "--" + q.getContained(i.getAnswerValueSet().substring(1)));
}
} else {
vs = context.getContext().fetchResource(ValueSet.class, i.getAnswerValueSet());
}
if (vs != null) {
ValueSetExpansionOutcome exp = context.getContext().expandVS(vs, true, false);
if (exp.getValueset() != null) {
for (ValueSetExpansionContainsComponent cc : exp.getValueset().getExpansion().getContains()) {
select.option(cc.getCode(), cc.hasDisplay() ? cc.getDisplay() : cc.getCode(), false);
}
return;
}
}
} else if (i.hasAnswerOption()) {
renderItemOptions(select, i);
}
select.option("a", "??", false);
}
Aggregations