use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class ToolingExtensions method addFlyOver.
// public static boolean hasDeprecated(Element c) {
// return findBooleanExtension(c, EXT_DEPRECATED);
// }
public static void addFlyOver(QuestionnaireItemComponent item, String text, String linkId) {
if (!StringUtils.isBlank(text)) {
QuestionnaireItemComponent display = item.addItem();
display.setType(QuestionnaireItemType.DISPLAY);
display.setText(text);
display.setLinkId(linkId);
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.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class EnableWhenEvaluator method evaluateCondition.
protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) {
List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition);
QuestionnaireItemOperator operator = enableCondition.getOperator();
if (operator == QuestionnaireItemOperator.EXISTS) {
DataType answer = enableCondition.getAnswer();
if (!(answer instanceof BooleanType)) {
throw new UnprocessableEntityException("Exists-operator requires answerBoolean");
}
return new EnableWhenResult(((BooleanType) answer).booleanValue() != answerItems.isEmpty(), enableCondition);
}
boolean result = false;
for (Element answer : answerItems) {
result = result || evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator());
}
return new EnableWhenResult(result, enableCondition);
}
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) 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.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderOptions.
private void renderOptions(List<QuestionnaireItemComponent> items, XhtmlNode x) {
for (QuestionnaireItemComponent i : items) {
renderItemOptions(x, i);
renderOptions(i.getItem(), x);
}
}
use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderDefinition.
private boolean renderDefinition(XhtmlNode tbl, Questionnaire q, QuestionnaireItemComponent qi, List<QuestionnaireItemComponent> parents) throws IOException {
boolean ext = false;
XhtmlNode td = tbl.tr().td("structure").colspan("2").span(null, null).attribute("class", "self-link-parent");
td.an("item." + qi.getLinkId());
for (QuestionnaireItemComponent p : parents) {
td.ah("#item." + p.getLinkId()).img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
td.tx(" > ");
}
td.img(Utilities.path(context.getLocalPrefix(), "icon_q_item.png"));
td.tx(" Item ");
td.b().tx(qi.getLinkId());
// general information
defn(tbl, "Link Id", qi.getLinkId());
defn(tbl, "Prefix", qi.getPrefix());
defn(tbl, "Text", qi.getText());
defn(tbl, "Type", qi.getType().getDisplay());
defn(tbl, "Required", qi.getRequired(), true);
defn(tbl, "Repeats", qi.getRepeats(), true);
defn(tbl, "Read Only", qi.getReadOnly(), false);
if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
defn(tbl, "Subject", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject", "This element changes who the subject of the question is", null);
}
// content control
defn(tbl, "Max Length", qi.getMaxLength());
if (qi.hasAnswerValueSet()) {
defn(tbl, "Value Set", qi.getDefinition(), context.getWorker().fetchResource(ValueSet.class, qi.getAnswerValueSet()));
}
if (qi.hasAnswerOption()) {
XhtmlNode tr = tbl.tr();
tr.td().tx("Allowed Answers");
XhtmlNode ul = tr.td().ul();
for (QuestionnaireItemAnswerOptionComponent ans : qi.getAnswerOption()) {
XhtmlNode li = ul.li();
render(li, ans.getValue());
if (ans.getInitialSelected()) {
li.tx(" (initially selected)");
}
}
}
if (qi.hasInitial()) {
XhtmlNode tr = tbl.tr();
tr.td().tx(Utilities.pluralize("Initial Answer", qi.getInitial().size()));
if (qi.getInitial().size() == 1) {
render(tr.td(), qi.getInitialFirstRep().getValue());
} else {
XhtmlNode ul = tr.td().ul();
for (QuestionnaireItemInitialComponent ans : qi.getInitial()) {
XhtmlNode li = ul.li();
render(li, ans.getValue());
}
}
}
// appearance
if (qi.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
XhtmlNode tr = tbl.tr();
tr.td().ah("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").tx("Display Category");
render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValue());
}
if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
defn(tbl, "Hidden Item", "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory", "This item is a hidden question", null);
}
if (ToolingExtensions.readBoolExtension(qi, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
defn(tbl, "Hidden Item", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay", "This item is optional to display", null);
}
// formal definitions
if (qi.hasDefinition()) {
genDefinitionLink(defn(tbl, "Definition"), qi);
}
if (qi.hasCode()) {
XhtmlNode tr = tbl.tr();
tr.td().tx(Utilities.pluralize("Code", qi.getCode().size()));
XhtmlNode ul = tr.td().ul();
for (Coding c : qi.getCode()) {
renderCodingWithDetails(ul.li(), c);
}
}
if (qi.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
XhtmlNode tr = tbl.tr();
tr.td().ah("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").tx("Observation Link Period");
render(tr.td(), qi.getExtensionByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod").getValue());
}
// dynamic management
if (qi.hasEnableWhen()) {
XhtmlNode tr = tbl.tr();
tr.td().tx("Enable When");
td = tr.td();
if (qi.getEnableWhen().size() == 1) {
renderEnableWhen(td, qi.getEnableWhen().get(0));
} else {
td.tx(qi.getEnableBehavior().getDisplay() + " are true:");
XhtmlNode ul = td.ul();
for (QuestionnaireItemEnableWhenComponent ew : qi.getEnableWhen()) {
renderEnableWhen(ul.li(), ew);
}
}
}
// other stuff
List<QuestionnaireItemComponent> curr = new ArrayList<>();
curr.addAll(parents);
curr.add(qi);
for (QuestionnaireItemComponent qic : qi.getItem()) {
ext = renderDefinition(tbl, q, qic, curr) || ext;
}
return ext;
}
Aggregations