Search in sources :

Example 1 with QuestionComponent

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

the class QuestionnaireBuilder method addTimingQuestions.

private void addTimingQuestions(GroupComponent group, ElementDefinition element, String path, List<QuestionnaireResponse.GroupComponent> answerGroups) throws FHIRException {
    ToolingExtensions.addType(group, "Schedule");
    addQuestion(group, AnswerFormat.STRING, path, "text", "text:", answerGroups);
    addQuestion(group, AnswerFormat.DATETIME, path, "date", "date:", answerGroups);
    QuestionComponent q = addQuestion(group, AnswerFormat.REFERENCE, path, "author", "author:", answerGroups);
    ToolingExtensions.addReference(q, "/Patient?");
    ToolingExtensions.addReference(q, "/Practitioner?");
    ToolingExtensions.addReference(q, "/RelatedPerson?");
}
Also used : QuestionComponent(org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent)

Example 2 with QuestionComponent

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

the class QuestionnaireBuilder method addQuestion.

private QuestionComponent addQuestion(GroupComponent group, AnswerFormat af, String path, String id, String name, List<QuestionnaireResponse.GroupComponent> answerGroups, ValueSet vs) throws FHIRException {
    QuestionComponent result = group.addQuestion();
    if (vs != null) {
        result.setOptions(new Reference());
        if (vs.getExpansion() == null) {
            result.getOptions().setReference(vs.getUrl());
            ToolingExtensions.addFilterOnly(result.getOptions(), true);
        } else {
            if (Utilities.noString(vs.getId())) {
                vs.setId(nextId("vs"));
                questionnaire.getContained().add(vs);
                vsCache.put(vs.getUrl(), vs.getId());
                vs.setText(null);
                vs.setCodeSystem(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.GroupComponent ag : answerGroups) {
            List<Base> children = new ArrayList<Base>();
            QuestionnaireResponse.QuestionComponent 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.addQuestion();
                        aq.setLinkId(result.getLinkId());
                        aq.setText(result.getText());
                    }
                    aq.addAnswer().setValue(convertType(child, af, vs, result.getLinkId()));
                }
            }
        }
    }
    return result;
}
Also used : Enumeration(org.hl7.fhir.dstu2.model.Enumeration) StringType(org.hl7.fhir.dstu2.model.StringType) QuestionComponent(org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent) Reference(org.hl7.fhir.dstu2.model.Reference) Element(org.hl7.fhir.dstu2.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse) Base(org.hl7.fhir.dstu2.model.Base)

Example 3 with QuestionComponent

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

the class QuestionnaireBuilder method addReferenceQuestions.

// Special Types ---------------------------------------------------------------
private void addReferenceQuestions(GroupComponent group, ElementDefinition element, String path, String profileURL, List<QuestionnaireResponse.GroupComponent> answerGroups) throws FHIRException {
    // var
    // rn : String;
    // i : integer;
    // q : TFhirQuestionnaireGroupQuestion;
    ToolingExtensions.addType(group, "Reference");
    QuestionComponent q = addQuestion(group, AnswerFormat.REFERENCE, path, "value", group.getText(), answerGroups);
    group.setText(null);
    String rn = null;
    if (profileURL != null && profileURL.startsWith("http://hl7.org/fhir/StructureDefinition/"))
        rn = profileURL.substring(40);
    else
        rn = "Any";
    if (rn.equals("Any"))
        ToolingExtensions.addReference(q, "/_search?subject=$subj&patient=$subj&encounter=$encounter");
    else
        ToolingExtensions.addReference(q, "/" + rn + "?subject=$subj&patient=$subj&encounter=$encounter");
    for (QuestionnaireResponse.GroupComponent ag : answerGroups) ag.setText(null);
}
Also used : QuestionComponent(org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent) QuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse)

Aggregations

QuestionComponent (org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent)3 QuestionnaireResponse (org.hl7.fhir.dstu2.model.QuestionnaireResponse)2 ArrayList (java.util.ArrayList)1 Base (org.hl7.fhir.dstu2.model.Base)1 Element (org.hl7.fhir.dstu2.model.Element)1 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)1 Reference (org.hl7.fhir.dstu2.model.Reference)1 StringType (org.hl7.fhir.dstu2.model.StringType)1