Search in sources :

Example 6 with GroupComponent

use of org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method buildQuestion.

private void buildQuestion(GroupComponent group, StructureDefinition profile, ElementDefinition element, String path, List<QuestionnaireResponse.GroupComponent> 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);
    group.setRepeats(!element.getMax().equals('1'));
    for (QuestionnaireResponse.GroupComponent ag : answerGroups) {
        ag.setLinkId(group.getLinkId());
        ag.setTitle(group.getTitle());
        ag.setText(group.getText());
    }
    if (!Utilities.noString(element.getComments()))
        ToolingExtensions.addFlyOver(group, element.getDefinition() + " " + element.getComments());
    else
        ToolingExtensions.addFlyOver(group, element.getDefinition());
    if (element.getType().size() > 1 || element.getType().get(0).getCode().equals("*")) {
        List<TypeRefComponent> types = expandTypeList(element.getType());
        Questionnaire.QuestionComponent q = addQuestion(group, AnswerFormat.CHOICE, element.getPath(), "_type", "type", null, makeTypeList(profile, types, element.getPath()));
        for (TypeRefComponent t : types) {
            Questionnaire.GroupComponent sub = q.addGroup();
            sub.setLinkId(element.getPath() + "._" + t.getUserData("text"));
            sub.setText((String) t.getUserData("text"));
            // always optional, never repeats
            List<QuestionnaireResponse.GroupComponent> selected = new ArrayList<QuestionnaireResponse.GroupComponent>();
            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.dstu2.model.Questionnaire) GroupComponent(org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent) GroupComponent(org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent) TypeRefComponent(org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse) QuestionComponent(org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent)

Example 7 with GroupComponent

use of org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method selectTypes.

private void selectTypes(StructureDefinition profile, GroupComponent sub, TypeRefComponent t, List<QuestionnaireResponse.GroupComponent> source, List<QuestionnaireResponse.GroupComponent> dest) {
    List<QuestionnaireResponse.GroupComponent> temp = new ArrayList<QuestionnaireResponse.GroupComponent>();
    for (QuestionnaireResponse.GroupComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
        temp.add(g);
    for (QuestionnaireResponse.GroupComponent g : temp) source.remove(g);
    for (QuestionnaireResponse.GroupComponent g : temp) {
        // it should be empty
        assert (g.getQuestion().size() == 0);
        QuestionnaireResponse.QuestionComponent q = g.addQuestion();
        q.setLinkId(g.getLinkId() + "._type");
        q.setText("type");
        Coding cc = new Coding();
        QuestionAnswerComponent a = q.addAnswer();
        a.setValue(cc);
        if (t.getCode().equals("Reference") && t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
            cc.setCode(t.getProfile().get(0).getValue().substring(40));
            cc.setSystem("http://hl7.org/fhir/resource-types");
        } else {
            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.getCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        // 1st: create the subgroup
        QuestionnaireResponse.GroupComponent subg = a.addGroup();
        dest.add(subg);
        subg.setLinkId(sub.getLinkId());
        subg.setText(sub.getText());
        subg.setUserData("object", g.getUserData("object"));
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) GroupComponent(org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent) QuestionAnswerComponent(org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent) Coding(org.hl7.fhir.dstu2.model.Coding) Element(org.hl7.fhir.dstu2.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse)

Aggregations

QuestionnaireResponse (org.hl7.fhir.dstu2.model.QuestionnaireResponse)6 ArrayList (java.util.ArrayList)4 QuestionComponent (org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent)4 GroupComponent (org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent)3 Element (org.hl7.fhir.dstu2.model.Element)2 Base (org.hl7.fhir.dstu2.model.Base)1 Coding (org.hl7.fhir.dstu2.model.Coding)1 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)1 TypeRefComponent (org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent)1 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)1 Questionnaire (org.hl7.fhir.dstu2.model.Questionnaire)1 QuestionAnswerComponent (org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent)1 Reference (org.hl7.fhir.dstu2.model.Reference)1 StringType (org.hl7.fhir.dstu2.model.StringType)1 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)1 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)1