use of org.hl7.fhir.dstu3.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) {
result.setOptions(new Reference());
if (vs.getExpansion() == null) {
result.getOptions().setReference(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.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.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.dstu3.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.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method selectTypes.
private void selectTypes(StructureDefinition profile, QuestionnaireItemComponent sub, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> source, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> dest) {
List<QuestionnaireResponse.QuestionnaireResponseItemComponent> temp = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
temp.add(g);
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) source.remove(g);
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) {
// it should be empty
assert (g.getItem().size() == 0);
QuestionnaireResponse.QuestionnaireResponseItemComponent q = g.addItem();
q.setLinkId(g.getLinkId() + "._type");
q.setText("type");
Coding cc = new Coding();
QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
a.setValue(cc);
if (t.getCode().equals("Reference") && t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
cc.setCode(t.getProfile().get(0).getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = null;
if (t.hasProfile())
ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
if (ps != null) {
cc.setCode(t.getProfile().get(0).getValue());
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
cc.setCode(t.getCode());
cc.setSystem("http://hl7.org/fhir/data-types");
}
}
// 1st: create the subgroup
QuestionnaireResponse.QuestionnaireResponseItemComponent subg = a.addItem();
dest.add(subg);
subg.setLinkId(sub.getLinkId());
subg.setText(sub.getText());
subg.setUserData("object", g.getUserData("object"));
}
}
use of org.hl7.fhir.dstu3.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.getComments() != null) {
Questionnaire.QuestionnaireItemComponent display = new Questionnaire.QuestionnaireItemComponent();
display.setType(QuestionnaireItemType.DISPLAY);
display.setText(element.getComments());
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.dstu2016may.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
buildQuestion(childGroup, profile, child, child.getPath(), nResponse);
}
}
}
use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderForm.
public boolean renderForm(XhtmlNode x, Questionnaire q) throws UnsupportedEncodingException, IOException {
boolean hasExt = false;
XhtmlNode d = x.div();
boolean hasPrefix = false;
for (QuestionnaireItemComponent c : q.getItem()) {
hasPrefix = hasPrefix || doesItemHavePrefix(c);
}
int i = 1;
for (QuestionnaireItemComponent c : q.getItem()) {
hasExt = renderFormItem(d, q, c, hasPrefix ? null : Integer.toString(i), 0) || hasExt;
i++;
}
return hasExt;
}
Aggregations