Search in sources :

Example 16 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.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.r4b.model.Questionnaire.QuestionnaireItemComponent)

Example 17 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent 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 18 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method selectTypes.

private void selectTypes(StructureDefinition profile, QuestionnaireItemComponent sub, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> source, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> dest) throws FHIRFormatError {
    List<QuestionnaireResponse.QuestionnaireResponseItemComponent> temp = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
        temp.add(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) source.remove(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) {
        // it should be empty
        assert (g.getItem().size() == 0);
        QuestionnaireResponse.QuestionnaireResponseItemComponent q = g.addItem();
        q.setLinkId(g.getLinkId() + "._type");
        q.setText("type");
        Coding cc = new Coding();
        QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
        a.setValue(cc);
        if (t.getCode().equals("Reference") && t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
            cc.setCode(t.getTargetProfile().substring(40));
            cc.setSystem("http://hl7.org/fhir/resource-types");
        } else {
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasTargetProfile())
                ps = pu.getProfile(profile, t.getTargetProfile());
            else if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile());
            if (ps != null) {
                cc.setCode(t.getProfile());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        // 1st: create the subgroup
        QuestionnaireResponse.QuestionnaireResponseItemComponent subg = a.addItem();
        dest.add(subg);
        subg.setLinkId(sub.getLinkId());
        subg.setText(sub.getText());
        subg.setUserData("object", g.getUserData("object"));
    }
}
Also used : QuestionnaireResponseItemAnswerComponent(org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Coding(org.hl7.fhir.dstu3.model.Coding) ProfileUtilities(org.hl7.fhir.dstu3.conformance.ProfileUtilities) Element(org.hl7.fhir.dstu3.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse)

Example 19 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderOptions.

private void renderOptions(List<QuestionnaireItemComponent> items, XhtmlNode x) {
    for (QuestionnaireItemComponent i : items) {
        renderItemOptions(x, i);
        renderOptions(i.getItem(), x);
    }
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)

Example 20 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent 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)

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