Search in sources :

Example 1 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class EnableWhenEvaluator method evaluateCondition.

protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) {
    List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition);
    QuestionnaireItemOperator operator = enableCondition.getOperator();
    if (operator == QuestionnaireItemOperator.EXISTS) {
        DataType answer = enableCondition.getAnswer();
        if (!(answer instanceof BooleanType)) {
            throw new UnprocessableEntityException("Exists-operator requires answerBoolean");
        }
        return new EnableWhenResult(((BooleanType) answer).booleanValue() != answerItems.isEmpty(), enableCondition);
    }
    boolean result = false;
    for (Element answer : answerItems) {
        result = result || evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator());
    }
    return new EnableWhenResult(result, enableCondition);
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) Element(org.hl7.fhir.r5.elementmodel.Element) BooleanType(org.hl7.fhir.r5.model.BooleanType) QuestionnaireItemOperator(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemOperator) DataType(org.hl7.fhir.r5.model.DataType)

Example 2 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderDefinition.

private boolean renderDefinition(XhtmlNode tbl, Questionnaire q, QuestionnaireItemComponent qi, 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("item." + qi.getLinkId());
    for (QuestionnaireItemComponent p : parents) {
        td.ah("#item." + p.getLinkId()).img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
        td.tx(" > ");
    }
    td.img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
    td.tx(" Item ");
    td.b().tx(qi.getLinkId());
    // general information
    defn(tbl, "Link Id", qi.getLinkId());
    defn(tbl, "Prefix", qi.getPrefix());
    defn(tbl, "Text", qi.getText());
    defn(tbl, "Type", qi.getType().getDisplay());
    defn(tbl, "Required", qi.getRequired(), true);
    defn(tbl, "Repeats", qi.getRepeats(), true);
    defn(tbl, "Read Only", qi.getReadOnly(), false);
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
        defn(tbl, "Subject", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject", "This element changes who the subject of the question is", null);
    }
    // content control
    defn(tbl, "Max Length", qi.getMaxLength());
    if (qi.hasAnswerValueSet()) {
        defn(tbl, "Value Set", qi.getDefinition(), context.getWorker().fetchResource(ValueSet.class, qi.getAnswerValueSet()));
    }
    if (qi.hasAnswerOption()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx("Allowed Answers");
        XhtmlNode ul = tr.td().ul();
        for (QuestionnaireItemAnswerOptionComponent ans : qi.getAnswerOption()) {
            XhtmlNode li = ul.li();
            render(li, ans.getValue());
            if (ans.getInitialSelected()) {
                li.tx(" (initially selected)");
            }
        }
    }
    if (qi.hasInitial()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Initial Answer", qi.getInitial().size()));
        if (qi.getInitial().size() == 1) {
            render(tr.td(), qi.getInitialFirstRep().getValue());
        } else {
            XhtmlNode ul = tr.td().ul();
            for (QuestionnaireItemInitialComponent ans : qi.getInitial()) {
                XhtmlNode li = ul.li();
                render(li, ans.getValue());
            }
        }
    }
    // appearance
    if (qi.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
        XhtmlNode tr = tbl.tr();
        tr.td().ah("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").tx("Display Category");
        render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValue());
    }
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
        defn(tbl, "Hidden Item", "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory", "This item is a hidden question", null);
    }
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
        defn(tbl, "Hidden Item", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay", "This item is optional to display", null);
    }
    // formal definitions
    if (qi.hasDefinition()) {
        genDefinitionLink(defn(tbl, "Definition"), qi);
    }
    if (qi.hasCode()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Code", qi.getCode().size()));
        XhtmlNode ul = tr.td().ul();
        for (Coding c : qi.getCode()) {
            renderCodingWithDetails(ul.li(), c);
        }
    }
    if (qi.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
        XhtmlNode tr = tbl.tr();
        tr.td().ah("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").tx("Observation Link Period");
        render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").getValue());
    }
    // dynamic management
    if (qi.hasEnableWhen()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx("Enable When");
        td = tr.td();
        if (qi.getEnableWhen().size() == 1) {
            renderEnableWhen(td, qi.getEnableWhen().get(0));
        } else {
            td.tx(qi.getEnableBehavior().getDisplay() + " are true:");
            XhtmlNode ul = td.ul();
            for (QuestionnaireItemEnableWhenComponent ew : qi.getEnableWhen()) {
                renderEnableWhen(ul.li(), ew);
            }
        }
    }
    // other stuff
    List<QuestionnaireItemComponent> curr = new ArrayList<>();
    curr.addAll(parents);
    curr.add(qi);
    for (QuestionnaireItemComponent qic : qi.getItem()) {
        ext = renderDefinition(tbl, q, qic, curr) || ext;
    }
    return ext;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent) QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Coding(org.hl7.fhir.r4b.model.Coding) QuestionnaireItemInitialComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemInitialComponent) ArrayList(java.util.ArrayList) QuestionnaireItemEnableWhenComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent) ValueSet(org.hl7.fhir.r4b.model.ValueSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 3 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderTreeItem.

private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, Questionnaire q, QuestionnaireItemComponent i, boolean hasFlags) throws IOException {
    Row r = gen.new Row();
    rows.add(r);
    boolean hasExt = false;
    r.setIcon("icon-q-" + i.getType().toCode().toLowerCase() + ".png", i.getType().getDisplay());
    r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget() + "#item." + i.getLinkId(), i.getLinkId(), null, null));
    String txt = (i.hasPrefix() ? i.getPrefix() + ". " : "") + i.getText();
    r.getCells().add(gen.new Cell(null, null, txt, null, null));
    r.getCells().add(gen.new Cell(null, null, (i.getRequired() ? "1" : "0") + ".." + (i.getRepeats() ? "*" : "1"), null, null));
    if (i.getTypeElement().hasExtension(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL)) {
        String t = i.getTypeElement().getExtensionString(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL);
        r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + t, t, null, null));
    } else {
        r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + i.getType().toCode(), i.getType().toCode(), null, null));
    }
    if (hasFlags) {
        // flags:
        Cell flags = gen.new Cell();
        r.getCells().add(flags);
        if (i.getReadOnly()) {
            flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecificationLink(), "questionnaire-definitions.html#Questionnaire.item.readOnly"), null, "Is Readonly").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-readonly.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-isSubject.html"), null, "Can change the subject of the questionnaire").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-subject.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
            flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-hidden.html"), null, "Is a hidden item").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-hidden.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-optionalDisplay.html"), null, "Is optional to display").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-optional.png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-observationLinkPeriod"), null, "Is linked to an observation").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-observation.png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation")) {
            String code = ToolingExtensions.readStringExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation");
            flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-choiceorientation.html"), null, "Orientation: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
            CodeableConcept cc = i.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValueCodeableConcept();
            String code = cc.getCode("http://hl7.org/fhir/questionnaire-display-category");
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-displayCategory"), null, "Category: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
        }
    }
    Cell defn = gen.new Cell();
    r.getCells().add(defn);
    if (i.hasMaxLength()) {
        defn.getPieces().add(gen.new Piece(null, "Max Length: ", null));
        defn.getPieces().add(gen.new Piece(null, Integer.toString(i.getMaxLength()), null));
    }
    if (i.hasDefinition()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Definition: ", null));
        genDefinitionLink(gen, i, defn);
    }
    if (i.hasEnableWhen()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        Piece p = gen.new Piece(null, "Enable When: ", null);
        defn.getPieces().add(p);
        if (i.getEnableWhen().size() == 0) {
            XhtmlNode x = new XhtmlNode(NodeType.Element, "span");
            p.getChildren().add(x);
            renderEnableWhen(x, i.getEnableWhenFirstRep());
        } else {
            XhtmlNode x = new XhtmlNode(NodeType.Element, "ul");
            p.getChildren().add(x);
            for (QuestionnaireItemEnableWhenComponent qi : i.getEnableWhen()) {
                renderEnableWhen(x.li(), qi);
            }
        }
    }
    if (i.hasAnswerValueSet()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Value Set: ", null));
        if (!Utilities.noString(i.getAnswerValueSet()) && i.getAnswerValueSet().startsWith("#")) {
            ValueSet vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1));
            if (vs == null) {
                defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
            } else {
                defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
            }
        } else {
            ValueSet vs = context.getWorker().fetchResource(ValueSet.class, i.getAnswerValueSet());
            if (vs == null || !vs.hasUserData("path")) {
                defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
            } else {
                defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
            }
        }
    }
    if (i.hasAnswerOption()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Options: ", null));
        if (context.getDefinitionsTarget() == null) {
            // if we don't have a definitions target, we'll add them below.
            defn.getPieces().add(gen.new Piece("#opt-item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
        } else {
            defn.getPieces().add(gen.new Piece(context.getDefinitionsTarget() + "#item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
        }
    }
    if (i.hasInitial()) {
        for (QuestionnaireItemInitialComponent v : i.getInitial()) {
            if (!defn.getPieces().isEmpty())
                defn.addPiece(gen.new Piece("br"));
            defn.getPieces().add(gen.new Piece(null, "Initial Value: ", null));
            defn.getPieces().add(gen.new Piece(null, v.getValue().fhirType(), null));
            defn.getPieces().add(gen.new Piece(null, " = ", null));
            if (v.getValue().isPrimitive()) {
                defn.getPieces().add(gen.new Piece(null, v.getValue().primitiveValue(), null));
            } else {
                renderCoding(gen, defn.getPieces(), v.getValueCoding());
            }
        }
    }
    if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Expressions: ", null));
        Piece p = gen.new Piece("ul");
        defn.getPieces().add(p);
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
            addExpression(p, e.getValueExpression(), "Initial Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression")) {
            addExpression(p, e.getValueExpression(), "Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext")) {
            addExpression(p, e.getValueExpression(), "Item Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression")) {
            addExpression(p, e.getValueExpression(), "Enable When", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression")) {
            addExpression(p, e.getValueExpression(), "Calculated Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression")) {
            addExpression(p, e.getValueExpression(), "Candidates", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression");
        }
    }
    for (QuestionnaireItemComponent c : i.getItem()) {
        hasExt = renderTreeItem(gen, r.getSubRows(), q, c, hasFlags) || hasExt;
    }
    return hasExt;
}
Also used : Extension(org.hl7.fhir.r4b.model.Extension) QuestionnaireItemComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) QuestionnaireItemInitialComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemInitialComponent) QuestionnaireItemEnableWhenComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ValueSet(org.hl7.fhir.r4b.model.ValueSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept)

Example 4 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderTreeItem.

private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, Questionnaire q, QuestionnaireItemComponent i, boolean hasFlags) throws IOException {
    Row r = gen.new Row();
    rows.add(r);
    boolean hasExt = false;
    r.setIcon("icon-q-" + i.getType().toCode().toLowerCase() + ".png", i.getType().getDisplay());
    Cell c1 = gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget() + "#item." + i.getLinkId(), i.getLinkId(), null, null);
    c1.setId("item." + i.getLinkId());
    r.getCells().add(c1);
    String txt = (i.hasPrefix() ? i.getPrefix() + ". " : "") + i.getText();
    r.getCells().add(gen.new Cell(null, null, txt, null, null));
    r.getCells().add(gen.new Cell(null, null, (i.getRequired() ? "1" : "0") + ".." + (i.getRepeats() ? "*" : "1"), null, null));
    if (i.getTypeElement().hasExtension(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL)) {
        String t = i.getTypeElement().getExtensionString(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL);
        r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + t, t, null, null));
    } else {
        r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + i.getType().toCode(), i.getType().toCode(), null, null));
    }
    if (hasFlags) {
        // flags:
        Cell flags = gen.new Cell();
        r.getCells().add(flags);
        if (i.getReadOnly()) {
            flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecificationLink(), "questionnaire-definitions.html#Questionnaire.item.readOnly"), null, "Is Readonly").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-readonly.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-isSubject.html"), null, "Can change the subject of the questionnaire").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-subject.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
            flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-hidden.html"), null, "Is a hidden item").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-hidden.png"))));
        }
        if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-optionalDisplay.html"), null, "Is optional to display").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-optional.png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-observationLinkPeriod"), null, "Is linked to an observation").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-observation.png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation")) {
            String code = ToolingExtensions.readStringExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation");
            flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-choiceorientation.html"), null, "Orientation: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
        }
        if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
            CodeableConcept cc = i.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValueCodeableConcept();
            String code = cc.getCode("http://hl7.org/fhir/questionnaire-display-category");
            flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-displayCategory"), null, "Category: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
        }
    }
    Cell defn = gen.new Cell();
    r.getCells().add(defn);
    if (i.hasMaxLength()) {
        defn.getPieces().add(gen.new Piece(null, "Max Length: ", null));
        defn.getPieces().add(gen.new Piece(null, Integer.toString(i.getMaxLength()), null));
    }
    if (i.hasDefinition()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Definition: ", null));
        genDefinitionLink(gen, i, defn);
    }
    if (i.hasEnableWhen()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        Piece p = gen.new Piece(null, "Enable When: ", null);
        defn.getPieces().add(p);
        if (i.getEnableWhen().size() == 1) {
            XhtmlNode x = new XhtmlNode(NodeType.Element, "span");
            p.getChildren().add(x);
            renderEnableWhen(x, i.getEnableWhenFirstRep());
        } else {
            XhtmlNode x = new XhtmlNode(NodeType.Element, "ul");
            p.getChildren().add(x);
            for (QuestionnaireItemEnableWhenComponent qi : i.getEnableWhen()) {
                renderEnableWhen(x.li(), qi);
            }
        }
    }
    if (i.hasAnswerValueSet()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Value Set: ", null));
        if (!Utilities.noString(i.getAnswerValueSet()) && i.getAnswerValueSet().startsWith("#")) {
            ValueSet vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1));
            if (vs == null) {
                defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
            } else {
                defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
            }
        } else {
            ValueSet vs = context.getWorker().fetchResource(ValueSet.class, i.getAnswerValueSet());
            if (vs == null || !vs.hasUserData("path")) {
                defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
            } else {
                defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
            }
        }
    }
    if (i.hasAnswerOption()) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Options: ", null));
        if (context.getDefinitionsTarget() == null) {
            // if we don't have a definitions target, we'll add them below.
            defn.getPieces().add(gen.new Piece("#opt-item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
        } else {
            defn.getPieces().add(gen.new Piece(context.getDefinitionsTarget() + "#item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
        }
    }
    if (i.hasInitial()) {
        for (QuestionnaireItemInitialComponent v : i.getInitial()) {
            if (!defn.getPieces().isEmpty())
                defn.addPiece(gen.new Piece("br"));
            defn.getPieces().add(gen.new Piece(null, "Initial Value: ", null));
            defn.getPieces().add(gen.new Piece(null, v.getValue().fhirType(), null));
            defn.getPieces().add(gen.new Piece(null, " = ", null));
            if (v.getValue().isPrimitive()) {
                defn.getPieces().add(gen.new Piece(null, v.getValue().primitiveValue(), null));
            } else {
                renderCoding(gen, defn.getPieces(), v.getValueCoding());
            }
        }
    }
    if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
        if (!defn.getPieces().isEmpty())
            defn.addPiece(gen.new Piece("br"));
        defn.getPieces().add(gen.new Piece(null, "Expressions: ", null));
        Piece p = gen.new Piece("ul");
        defn.getPieces().add(p);
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
            addExpression(p, e.getValueExpression(), "Initial Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression")) {
            addExpression(p, e.getValueExpression(), "Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext")) {
            addExpression(p, e.getValueExpression(), "Item Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression")) {
            addExpression(p, e.getValueExpression(), "Enable When", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression")) {
            addExpression(p, e.getValueExpression(), "Calculated Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression");
        }
        for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression")) {
            addExpression(p, e.getValueExpression(), "Candidates", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression");
        }
    }
    for (QuestionnaireItemComponent c : i.getItem()) {
        hasExt = renderTreeItem(gen, r.getSubRows(), q, c, hasFlags) || hasExt;
    }
    return hasExt;
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) QuestionnaireItemInitialComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent) QuestionnaireItemEnableWhenComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ValueSet(org.hl7.fhir.r5.model.ValueSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 5 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderDefinition.

private boolean renderDefinition(XhtmlNode tbl, Questionnaire q, QuestionnaireItemComponent qi, 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("item." + qi.getLinkId());
    for (QuestionnaireItemComponent p : parents) {
        td.ah("#item." + p.getLinkId()).img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
        td.tx(" > ");
    }
    td.img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
    td.tx(" Item ");
    td.b().tx(qi.getLinkId());
    // general information
    defn(tbl, "Link Id", qi.getLinkId());
    defn(tbl, "Prefix", qi.getPrefix());
    defn(tbl, "Text", qi.getText());
    defn(tbl, "Type", qi.getType().getDisplay());
    defn(tbl, "Required", qi.getRequired(), true);
    defn(tbl, "Repeats", qi.getRepeats(), true);
    defn(tbl, "Read Only", qi.getReadOnly(), false);
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
        defn(tbl, "Subject", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject", "This element changes who the subject of the question is", null);
    }
    // content control
    defn(tbl, "Max Length", qi.getMaxLength());
    if (qi.hasAnswerValueSet()) {
        defn(tbl, "Value Set", qi.getDefinition(), context.getWorker().fetchResource(ValueSet.class, qi.getAnswerValueSet()));
    }
    if (qi.hasAnswerOption()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx("Allowed Answers");
        XhtmlNode ul = tr.td().ul();
        for (QuestionnaireItemAnswerOptionComponent ans : qi.getAnswerOption()) {
            XhtmlNode li = ul.li();
            render(li, ans.getValue());
            if (ans.getInitialSelected()) {
                li.tx(" (initially selected)");
            }
        }
    }
    if (qi.hasInitial()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Initial Answer", qi.getInitial().size()));
        if (qi.getInitial().size() == 1) {
            render(tr.td(), qi.getInitialFirstRep().getValue());
        } else {
            XhtmlNode ul = tr.td().ul();
            for (QuestionnaireItemInitialComponent ans : qi.getInitial()) {
                XhtmlNode li = ul.li();
                render(li, ans.getValue());
            }
        }
    }
    // appearance
    if (qi.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
        XhtmlNode tr = tbl.tr();
        tr.td().ah("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").tx("Display Category");
        render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValue());
    }
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
        defn(tbl, "Hidden Item", "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory", "This item is a hidden question", null);
    }
    if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
        defn(tbl, "Hidden Item", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay", "This item is optional to display", null);
    }
    // formal definitions
    if (qi.hasDefinition()) {
        genDefinitionLink(defn(tbl, "Definition"), qi);
    }
    if (qi.hasCode()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Code", qi.getCode().size()));
        XhtmlNode ul = tr.td().ul();
        for (Coding c : qi.getCode()) {
            renderCodingWithDetails(ul.li(), c);
        }
    }
    if (qi.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
        XhtmlNode tr = tbl.tr();
        tr.td().ah("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").tx("Observation Link Period");
        render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").getValue());
    }
    // dynamic management
    if (qi.hasEnableWhen()) {
        XhtmlNode tr = tbl.tr();
        tr.td().tx("Enable When");
        td = tr.td();
        if (qi.getEnableWhen().size() == 1) {
            renderEnableWhen(td, qi.getEnableWhen().get(0));
        } else {
            td.tx(qi.getEnableBehavior().getDisplay() + " are true:");
            XhtmlNode ul = td.ul();
            for (QuestionnaireItemEnableWhenComponent ew : qi.getEnableWhen()) {
                renderEnableWhen(ul.li(), ew);
            }
        }
    }
    // other stuff
    List<QuestionnaireItemComponent> curr = new ArrayList<>();
    curr.addAll(parents);
    curr.add(qi);
    for (QuestionnaireItemComponent qic : qi.getItem()) {
        ext = renderDefinition(tbl, q, qic, curr) || ext;
    }
    return ext;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Coding(org.hl7.fhir.r5.model.Coding) QuestionnaireItemInitialComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent) ArrayList(java.util.ArrayList) QuestionnaireItemEnableWhenComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 ArrayList (java.util.ArrayList)3 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent)3 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)2 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent)2 QuestionnaireItemInitialComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemInitialComponent)2 ValueSet (org.hl7.fhir.r4b.model.ValueSet)2 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)2 QuestionnaireItemInitialComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent)2 ValueSet (org.hl7.fhir.r5.model.ValueSet)2 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)2 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)2 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)2 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 CodeableConcept (org.hl7.fhir.r4b.model.CodeableConcept)1 Coding (org.hl7.fhir.r4b.model.Coding)1 Extension (org.hl7.fhir.r4b.model.Extension)1 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)1 Element (org.hl7.fhir.r5.elementmodel.Element)1 BooleanType (org.hl7.fhir.r5.model.BooleanType)1