Search in sources :

Example 31 with QuestionnaireItemComponent

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

the class QuestionnaireValidator method checkIntegerOption.

private void checkIntegerOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueInteger");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<IntegerType> list = new ArrayList<IntegerType>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                list.add(components.getValueIntegerType());
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSINTEGER);
        } else {
            boolean found = false;
            for (IntegerType item : list) {
                if (item.getValue() == Integer.parseInt(v.primitiveValue())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOINTEGER, v.primitiveValue());
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_INTNOOPTIONS);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 32 with QuestionnaireItemComponent

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

the class QuestionnaireValidator method validateAnswerCode.

private void validateAnswerCode(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean theOpenChoice) {
    Element v = answer.getNamedChild("valueCoding");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0)
        checkCodingOption(errors, answer, stack, qSrc, qItem, theOpenChoice);
    else // validateAnswerCode(errors, v, stack, qItem.getOption());
    if (qItem.hasAnswerValueSet())
        validateAnswerCode(errors, v, stack, qSrc, qItem.getAnswerValueSet(), theOpenChoice);
    else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONS);
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack)

Example 33 with QuestionnaireItemComponent

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

the class QuestionnaireValidator method checkTimeOption.

private void checkTimeOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueTime");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<TimeType> list = new ArrayList<TimeType>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                list.add(components.getValueTimeType());
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSTIME);
        } else {
            boolean found = false;
            for (TimeType item : list) {
                if (item.getValue().equals(v.primitiveValue())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTIME, v.primitiveValue());
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_TIMENOOPTIONS);
}
Also used : QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.r5.model.TimeType)

Example 34 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.r4.model.ValueSet) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 35 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, List<ElementDefinition> parents) 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).getWorkingCode().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, parents);
        }
    } 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, parents);
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)

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