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