Search in sources :

Example 1 with QuestionAnswerComponent

use of org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent 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

ArrayList (java.util.ArrayList)1 Coding (org.hl7.fhir.dstu2.model.Coding)1 Element (org.hl7.fhir.dstu2.model.Element)1 GroupComponent (org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent)1 QuestionnaireResponse (org.hl7.fhir.dstu2.model.QuestionnaireResponse)1 QuestionAnswerComponent (org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent)1 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)1