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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations