Search in sources :

Example 1 with QuestionnaireItemAnswerOptionComponent

use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.

the class Questionnaire10_40 method convertQuestionnaireQuestionComponent.

public static org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent convertQuestionnaireQuestionComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent tgt = new org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent();
    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
    if (src.hasLinkIdElement())
        tgt.setLinkIdElement(String10_40.convertString(src.getLinkIdElement()));
    for (org.hl7.fhir.r4.model.Coding t : src.getCode()) tgt.addConcept(Coding10_40.convertCoding(t));
    if (src.hasTextElement())
        tgt.setTextElement(String10_40.convertString(src.getTextElement()));
    if (src.hasType())
        tgt.setTypeElement(convertQuestionnaireItemType(src.getTypeElement()));
    if (src.hasRequiredElement())
        tgt.setRequiredElement(Boolean10_40.convertBoolean(src.getRequiredElement()));
    if (src.hasRepeatsElement())
        tgt.setRepeatsElement(Boolean10_40.convertBoolean(src.getRepeatsElement()));
    if (src.hasAnswerValueSetElement())
        tgt.setOptions(Canonical10_40.convertCanonicalToReference(src.getAnswerValueSetElement()));
    for (QuestionnaireItemAnswerOptionComponent t : src.getAnswerOption()) if (t.hasValueCoding())
        try {
            tgt.addOption(Coding10_40.convertCoding(t.getValueCoding()));
        } catch (org.hl7.fhir.exceptions.FHIRException e) {
            throw new FHIRException(e);
        }
    for (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent t : src.getItem()) tgt.addGroup(convertQuestionnaireGroupComponent(t));
    return tgt;
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with QuestionnaireItemAnswerOptionComponent

use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent 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 QuestionnaireItemAnswerOptionComponent

use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireValidator method checkCodingOption.

private void checkCodingOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueCoding");
    String system = v.getNamedChildValue("system");
    String code = v.getNamedChildValue("code");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<Coding> list = new ArrayList<Coding>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                if (components.getValue() != null) {
                    list.add(components.getValueCoding());
                }
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSCODING);
        } else {
            boolean found = false;
            for (Coding item : list) {
                if (ObjectUtil.equals(item.getSystem(), system) && ObjectUtil.equals(item.getCode(), code)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOCODING, system, code);
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_CODINGNOOPTIONS);
}
Also used : QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Coding(org.hl7.fhir.r5.model.Coding) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with QuestionnaireItemAnswerOptionComponent

use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireValidator method checkIntegerOption.

private void checkIntegerOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueInteger");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<IntegerType> list = new ArrayList<IntegerType>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                list.add(components.getValueIntegerType());
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSINTEGER);
        } else {
            boolean found = false;
            for (IntegerType item : list) {
                if (item.getValue() == Integer.parseInt(v.primitiveValue())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOINTEGER, v.primitiveValue());
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_INTNOOPTIONS);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with QuestionnaireItemAnswerOptionComponent

use of org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireValidator method checkTimeOption.

private void checkTimeOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueTime");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<TimeType> list = new ArrayList<TimeType>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                list.add(components.getValueTimeType());
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSTIME);
        } else {
            boolean found = false;
            for (TimeType item : list) {
                if (item.getValue().equals(v.primitiveValue())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTIME, v.primitiveValue());
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_TIMENOOPTIONS);
}
Also used : QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.r5.model.TimeType)

Aggregations

QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)8 ArrayList (java.util.ArrayList)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 Element (org.hl7.fhir.r5.elementmodel.Element)5 NodeStack (org.hl7.fhir.validation.instance.utils.NodeStack)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 Coding (org.hl7.fhir.r5.model.Coding)3 Coding (org.hl7.fhir.r4b.model.Coding)2 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)2 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)1 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)1 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent)1 QuestionnaireItemInitialComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemInitialComponent)1 ValueSet (org.hl7.fhir.r4b.model.ValueSet)1 DateType (org.hl7.fhir.r5.model.DateType)1 IntegerType (org.hl7.fhir.r5.model.IntegerType)1 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)1 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent)1 QuestionnaireItemInitialComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent)1 StringType (org.hl7.fhir.r5.model.StringType)1