use of org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireResponseMapper method getItem.
private QuestionnaireResponseItemComponent getItem(Question question) {
QuestionnaireResponseItemComponent item = new QuestionnaireResponseItemComponent();
QuestionnaireResponseItemAnswerComponent answer = new QuestionnaireResponseItemAnswerComponent();
StringType correctAnswerText = new StringType();
if (StringUtils.isBlank(question.getQuestionId())) {
item.setLinkId(NOT_APPLICABLE);
} else {
item.setLinkId(question.getQuestionId());
}
item.setText(question.getQuestionText());
for (Answer singleAnswer : question.getAnswers().getAnswerArray()) {
if (singleAnswer.getSelected() && !singleAnswer.getText().isBlank()) {
correctAnswerText.setValueAsString(singleAnswer.getText());
}
}
answer.setValue(correctAnswerText);
item.addAnswer(answer);
return item;
}
use of org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent 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) throws FHIRFormatError {
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");
QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
if (t.hasTarget()) {
for (UriType u : t.getTargetProfile()) {
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
Coding cc = new Coding();
a.setValue(cc);
cc.setCode(u.getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
}
}
} else {
Coding cc = new Coding();
a.setValue(cc);
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.getWorkingCode());
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.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent 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) throws FHIRFormatError {
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.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
cc.setCode(t.getTargetProfile().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = null;
if (t.hasTargetProfile())
ps = pu.getProfile(profile, t.getTargetProfile());
else if (t.hasProfile())
ps = pu.getProfile(profile, t.getProfile());
if (ps != null) {
cc.setCode(t.getProfile());
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.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent 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) throws FHIRFormatError {
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");
QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
if (t.hasTarget()) {
for (UriType u : t.getTargetProfile()) {
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
Coding cc = new Coding();
a.setValue(cc);
cc.setCode(u.getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
}
}
} else {
Coding cc = new Coding();
a.setValue(cc);
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.getWorkingCode());
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.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireResponseRenderer method renderTreeItem.
private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, QuestionnaireResponse q, QuestionnaireResponseItemComponent i) throws IOException {
Row r = gen.new Row();
rows.add(r);
boolean hasExt = false;
boolean hasItem = i.hasItem();
for (QuestionnaireResponseItemAnswerComponent a : i.getAnswer()) {
hasItem = a.hasItem();
}
if (hasItem) {
r.setIcon("icon-q-group.png", "Group");
} else {
r.setIcon("icon-q-string.png", "Item");
}
r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget() + "#item." + i.getLinkId(), i.getLinkId(), null, null));
r.getCells().add(gen.new Cell(null, null, i.getText(), null, null));
r.getCells().add(gen.new Cell(null, null, null, null, null));
r.getCells().add(gen.new Cell(null, null, null, null, null));
return hasExt;
}
Aggregations