Search in sources :

Example 6 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, String path, String id, String name, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, ValueSet vs) throws FHIRException {
    QuestionnaireItemComponent result = group.addItem();
    if (vs != null) {
        result.setOptions(new Reference());
        if (vs.getExpansion() == null) {
            result.getOptions().setReference(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.getOptions().setReference("#" + vs.getId());
        }
    }
    result.setLinkId(path + '.' + id);
    result.setText(name);
    result.setType(af);
    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.dstu3.model.Questionnaire.QuestionnaireItemComponent) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) Element(org.hl7.fhir.dstu3.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse) Base(org.hl7.fhir.dstu3.model.Base)

Example 7 with QuestionnaireItemComponent

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

the class QuestionnaireBuilder method addCodeQuestions.

private void addCodeQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
    ToolingExtensions.addFhirType(group, "code");
    ValueSet vs = resolveValueSet(null, element.hasBinding() ? element.getBinding() : null);
    addQuestion(group, QuestionnaireItemType.CHOICE, path, "value", unCamelCase(tail(element.getPath())), answerGroups, vs);
    group.setText(null);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse)

Example 8 with QuestionnaireItemComponent

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

the class QuestionnaireBuilder method addTimingQuestions.

private void addTimingQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
    ToolingExtensions.addFhirType(group, "Schedule");
    addQuestion(group, QuestionnaireItemType.STRING, path, "text", "text:", answerGroups);
    addQuestion(group, QuestionnaireItemType.DATETIME, path, "date", "date:", answerGroups);
    QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, path, "author", "author:", answerGroups);
    ToolingExtensions.addAllowedResource(q, "Patient");
    ToolingExtensions.addAllowedResource(q, "Practitioner");
    ToolingExtensions.addAllowedResource(q, "RelatedPerson");
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent)

Example 9 with QuestionnaireItemComponent

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

the class QuestionnaireBuilder method buildQuestion.

private void buildQuestion(QuestionnaireItemComponent group, StructureDefinition profile, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
    group.setLinkId(path);
    // in this context, we don't have any concepts to mark...
    // prefix with name?
    group.setText(element.getShort());
    group.setRequired(element.getMin() > 0);
    if (element.getMin() > 0)
        ToolingExtensions.addMin(group, element.getMin());
    group.setRepeats(!element.getMax().equals('1'));
    if (!element.getMax().equals("*"))
        ToolingExtensions.addMax(group, Integer.parseInt(element.getMax()));
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) {
        ag.setLinkId(group.getLinkId());
        ag.setText(group.getText());
    }
    if (!Utilities.noString(element.getComment()))
        ToolingExtensions.addFlyOver(group, element.getDefinition() + " " + element.getComment());
    else
        ToolingExtensions.addFlyOver(group, element.getDefinition());
    if (element.getType().size() > 1 || element.getType().get(0).getCode().equals("*")) {
        List<TypeRefComponent> types = expandTypeList(element.getType());
        Questionnaire.QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.CHOICE, element.getPath(), "_type", "type", null, makeTypeList(profile, types, element.getPath()));
        for (TypeRefComponent t : types) {
            Questionnaire.QuestionnaireItemComponent sub = q.addItem();
            sub.setType(QuestionnaireItemType.GROUP);
            sub.setLinkId(element.getPath() + "._" + t.getUserData("text"));
            sub.setText((String) t.getUserData("text"));
            // always optional, never repeats
            List<QuestionnaireResponse.QuestionnaireResponseItemComponent> selected = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
            selectTypes(profile, sub, t, answerGroups, selected);
            processDataType(profile, sub, element, element.getPath() + "._" + t.getUserData("text"), t, selected);
        }
    } else
        // now we have to build the question panel for each different data type
        processDataType(profile, group, element, element.getPath(), element.getType().get(0), answerGroups);
}
Also used : Questionnaire(org.hl7.fhir.dstu3.model.Questionnaire) TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse) QuestionnaireItemComponent(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent)

Example 10 with QuestionnaireItemComponent

use of org.hl7.fhir.r4.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");
        QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
        if (t.hasTarget()) {
            for (UriType u : t.getTargetProfile()) {
                if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                    Coding cc = new Coding();
                    a.setValue(cc);
                    cc.setCode(u.getValue().substring(40));
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                }
            }
        } else {
            Coding cc = new Coding();
            a.setValue(cc);
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
            if (ps != null) {
                cc.setCode(t.getProfile().get(0).getValue());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getWorkingCode());
                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.r4b.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) Coding(org.hl7.fhir.r4b.model.Coding) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) Element(org.hl7.fhir.r4b.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4b.model.QuestionnaireResponse) UriType(org.hl7.fhir.r4b.model.UriType)

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