use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireMapper method getItem.
private QuestionnaireItemComponent getItem(Question question, String caseId) {
if (question != null) {
List<QuestionnaireItemOptionComponent> questionnaireItemOptionComponentList = new ArrayList<>();
QuestionnaireItemComponent item = new QuestionnaireItemComponent();
item.setLinkId(caseId);
item.setPrefix(getPrefix(question));
item.setType(Questionnaire.QuestionnaireItemType.CHOICE);
item.setRequired(true);
item.setRepeats(false);
if (question.getQuestionText() != null) {
item.setText(question.getQuestionText());
} else {
item.setText(NOT_APPLICABLE);
}
if (question.getAnswers() != null) {
if (question.getAnswers().sizeOfAnswerArray() > 0) {
for (Answer answer : question.getAnswers().getAnswerArray()) {
QuestionnaireItemOptionComponent optionComponent = new QuestionnaireItemOptionComponent();
StringType answerStringType = new StringType();
answerStringType.setValueAsString(String.format("%s, Selected: %s", answer.getText(), answer.getSelected()));
optionComponent.setValue(answerStringType);
questionnaireItemOptionComponentList.add(optionComponent);
}
}
}
item.setOption(questionnaireItemOptionComponentList);
return item;
}
return null;
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method addTimingQuestions.
private void addTimingQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
ToolingExtensions.addFhirType(group, "Schedule");
addQuestion(group, QuestionnaireItemType.STRING, path, "text", "text:", answerGroups);
addQuestion(group, QuestionnaireItemType.DATETIME, path, "date", "date:", answerGroups);
QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, path, "author", "author:", answerGroups);
ToolingExtensions.addAllowedResource(q, "Patient");
ToolingExtensions.addAllowedResource(q, "Practitioner");
ToolingExtensions.addAllowedResource(q, "RelatedPerson");
}
use of org.hl7.fhir.r5.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) 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.getComments()))
ToolingExtensions.addFlyOver(group, element.getDefinition() + " " + element.getComments());
else
ToolingExtensions.addFlyOver(group, element.getDefinition());
if (element.getType().size() > 1 || element.getType().get(0).getCode().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);
}
} 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);
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class ToolingExtensions method addFlyOver.
public static void addFlyOver(QuestionnaireItemComponent item, String text) {
if (!StringUtils.isBlank(text)) {
QuestionnaireItemComponent display = item.addItem();
display.setType(QuestionnaireItemType.DISPLAY);
display.setText(text);
display.getExtension().add(Factory.newExtension(EXT_CONTROL, Factory.newCodeableConcept("flyover", "http://hl7.org/fhir/questionnaire-item-control", "Fly-over"), true));
}
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method addReferenceQuestions.
// Special Types ---------------------------------------------------------------
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, String profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
// var
// rn : String;
// i : integer;
// q : TFhirQuestionnaireGroupQuestion;
ToolingExtensions.addFhirType(group, "Reference");
QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.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.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
else {
ToolingExtensions.addAllowedResource(q, rn);
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
}
for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
Aggregations