use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method buildGroup.
private void buildGroup(QuestionnaireItemComponent group, StructureDefinition profile, ElementDefinition element, List<ElementDefinition> parents, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> 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.setText(element.getShort());
if (element.getComment() != null) {
Questionnaire.QuestionnaireItemComponent display = new Questionnaire.QuestionnaireItemComponent();
display.setType(QuestionnaireItemType.DISPLAY);
display.setText(element.getComment());
group.addItem(display);
}
group.setType(QuestionnaireItemType.GROUP);
ToolingExtensions.addFlyOver(group, element.getDefinition());
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 (org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) {
ag.setLinkId(group.getLinkId());
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);
QuestionnaireItemComponent childGroup = group.addItem();
childGroup.setType(QuestionnaireItemType.GROUP);
List<QuestionnaireResponse.QuestionnaireResponseItemComponent> nResponse = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
processExisting(child.getPath(), answerGroups, nResponse);
// it will have children of its own
if (child.getType().isEmpty() || isAbstractType(child.getType()))
buildGroup(childGroup, profile, child, nparents, nResponse);
else if (isInlineDataType(child.getType()))
// todo: get the right children for this one...
buildGroup(childGroup, profile, child, nparents, nResponse);
else
buildQuestion(childGroup, profile, child, child.getPath(), nResponse);
}
}
}
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 addQuestion.
private QuestionnaireItemComponent addQuestion(QuestionnaireItemComponent group, QuestionnaireItemType af, String path, String id, String name, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, ValueSet vs) throws FHIRException {
QuestionnaireItemComponent result = group.addItem();
if (vs != null) {
if (vs.getExpansion() == null) {
result.setAnswerValueSet(vs.getUrl());
ToolingExtensions.addControl(result, "lookup");
} else {
if (Utilities.noString(vs.getId())) {
vs.setId(nextId("vs"));
questionnaire.getContained().add(vs);
vsCache.put(vs.getUrl(), vs.getId());
vs.setText(null);
vs.setCompose(null);
vs.getContact().clear();
vs.setPublisherElement(null);
vs.setCopyrightElement(null);
}
result.setAnswerValueSet("#" + 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.QuestionnaireResponseItemComponent ag : answerGroups) {
List<Base> children = new ArrayList<Base>();
QuestionnaireResponse.QuestionnaireResponseItemComponent 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.addItem();
aq.setLinkId(result.getLinkId());
aq.setText(result.getText());
}
aq.addAnswer().setValue(convertType(child, af, vs, result.getLinkId()));
}
}
}
}
return result;
}
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, List<CanonicalType> 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);
CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
for (UriType u : profileURL) if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
rn.append(u.getValue().substring(40));
if (rn.length() == 0)
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
else {
ToolingExtensions.addAllowedResource(q, rn.toString());
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
}
for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
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