Search in sources :

Example 1 with GroupComponent

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

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

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

the class QuestionnaireBuilder method buildGroup.

private void buildGroup(GroupComponent group, StructureDefinition profile, ElementDefinition element, List<ElementDefinition> parents, List<QuestionnaireResponse.GroupComponent> answerGroups) throws FHIRException {
    // todo: this will be wrong when we start slicing
    group.setLinkId(element.getPath());
    // todo - may need to prepend the name tail...
    group.setTitle(element.getShort());
    group.setText(element.getComments());
    ToolingExtensions.addFlyOver(group, element.getDefinition());
    group.setRequired(element.getMin() > 0);
    group.setRepeats(!element.getMax().equals("1"));
    for (org.hl7.fhir.dstu2.model.QuestionnaireResponse.GroupComponent ag : answerGroups) {
        ag.setLinkId(group.getLinkId());
        ag.setTitle(group.getTitle());
        ag.setText(group.getText());
    }
    // now, we iterate the children
    List<ElementDefinition> list = ProfileUtilities.getChildList(profile, element);
    for (ElementDefinition child : list) {
        if (!isExempt(element, child) && !parents.contains(child)) {
            List<ElementDefinition> nparents = new ArrayList<ElementDefinition>();
            nparents.addAll(parents);
            nparents.add(child);
            GroupComponent childGroup = group.addGroup();
            List<QuestionnaireResponse.GroupComponent> nResponse = new ArrayList<QuestionnaireResponse.GroupComponent>();
            processExisting(child.getPath(), answerGroups, nResponse);
            // it will have children of it's own
            if (child.getType().isEmpty() || isAbstractType(child.getType()))
                buildGroup(childGroup, profile, child, nparents, nResponse);
            else
                buildQuestion(childGroup, profile, child, child.getPath(), nResponse);
        }
    }
}
Also used : GroupComponent(org.hl7.fhir.dstu2.model.Questionnaire.GroupComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) QuestionnaireResponse(org.hl7.fhir.dstu2.model.QuestionnaireResponse)

Example 4 with GroupComponent

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

the class QuestionnaireBuilder method addCodeQuestions.

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

Example 5 with GroupComponent

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

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