use of org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionAnswerComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method selectTypes.
private void selectTypes(StructureDefinition profile, GroupComponent sub, TypeRefComponent t, List<QuestionnaireResponse.GroupComponent> source, List<QuestionnaireResponse.GroupComponent> dest) {
List<QuestionnaireResponse.GroupComponent> temp = new ArrayList<QuestionnaireResponse.GroupComponent>();
for (QuestionnaireResponse.GroupComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
temp.add(g);
for (QuestionnaireResponse.GroupComponent g : temp) source.remove(g);
for (QuestionnaireResponse.GroupComponent g : temp) {
// it should be empty
assert (g.getQuestion().size() == 0);
QuestionnaireResponse.QuestionComponent q = g.addQuestion();
q.setLinkId(g.getLinkId() + "._type");
q.setText("type");
Coding cc = new Coding();
QuestionAnswerComponent 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.GroupComponent subg = a.addGroup();
dest.add(subg);
subg.setLinkId(sub.getLinkId());
subg.setText(sub.getText());
subg.setUserData("object", g.getUserData("object"));
}
}
Aggregations