Search in sources :

Example 66 with QuestionnaireItemComponent

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;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) Enumeration(org.hl7.fhir.r5.model.Enumeration) StringType(org.hl7.fhir.r5.model.StringType) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r5.model.QuestionnaireResponse) Base(org.hl7.fhir.r5.model.Base)

Example 67 with QuestionnaireItemComponent

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));
    }
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)

Example 68 with QuestionnaireItemComponent

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("??");
            }
        }
    }
}
Also used : QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Coding(org.hl7.fhir.r5.model.Coding) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 69 with QuestionnaireItemComponent

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;
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) CodeType(org.hl7.fhir.r5.model.CodeType) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 70 with QuestionnaireItemComponent

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);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

ArrayList (java.util.ArrayList)32 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)16 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)15 QuestionnaireItemComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)11 Element (org.hl7.fhir.r5.elementmodel.Element)9 NodeStack (org.hl7.fhir.validation.instance.utils.NodeStack)9 QuestionnaireItemComponent (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent)7 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)7 QuestionnaireResponse (org.hl7.fhir.r4b.model.QuestionnaireResponse)7 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)7 QuestionnaireResponse (org.hl7.fhir.r5.model.QuestionnaireResponse)7 QuestionnaireItemComponent (org.hl7.fhir.dstu2016may.model.Questionnaire.QuestionnaireItemComponent)6 ValueSet (org.hl7.fhir.r4b.model.ValueSet)6 ValueSet (org.hl7.fhir.r5.model.ValueSet)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)6 QuestionnaireResponse (org.hl7.fhir.dstu2016may.model.QuestionnaireResponse)5 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5