use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent 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;
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method checkStringOption.
private void checkStringOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
Element v = answer.getNamedChild("valueString");
NodeStack ns = stack.push(v, -1, null, null);
if (qItem.getAnswerOption().size() > 0) {
List<StringType> list = new ArrayList<StringType>();
for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
try {
if (components.getValue() != null) {
list.add(components.getValueStringType());
}
} catch (FHIRException e) {
// If it's the wrong type, just keep going
}
}
if (!openChoice) {
if (list.isEmpty()) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSSTRING);
} else {
boolean found = false;
for (StringType item : list) {
if (item.getValue().equals((v.primitiveValue()))) {
found = true;
break;
}
}
if (!found) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOSTRING, v.primitiveValue());
}
}
}
} else {
hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_STRINGNOOPTIONS);
}
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method checkDateOption.
private void checkDateOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
Element v = answer.getNamedChild("valueDate");
NodeStack ns = stack.push(v, -1, null, null);
if (qItem.getAnswerOption().size() > 0) {
List<DateType> list = new ArrayList<DateType>();
for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
try {
list.add(components.getValueDateType());
} catch (FHIRException e) {
// If it's the wrong type, just keep going
}
}
if (list.isEmpty() && !openChoice) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSDATE);
} else {
boolean found = false;
for (DateType item : list) {
if (item.getValue().equals(v.primitiveValue())) {
found = true;
break;
}
}
if (!found) {
rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NODATE, v.primitiveValue());
}
}
} else
hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_DATENOOPTIONS);
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.
the class Questionnaire10_50 method convertQuestionnaireQuestionComponent.
public static org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent convertQuestionnaireQuestionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent tgt = new org.hl7.fhir.dstu2.model.Questionnaire.QuestionComponent();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
if (src.hasLinkIdElement())
tgt.setLinkIdElement(String10_50.convertString(src.getLinkIdElement()));
for (org.hl7.fhir.r5.model.Coding t : src.getCode()) tgt.addConcept(Coding10_50.convertCoding(t));
if (src.hasTextElement())
tgt.setTextElement(String10_50.convertString(src.getTextElement()));
if (src.hasType())
tgt.setTypeElement(convertQuestionnaireItemType(src.getTypeElement(), src.getAnswerConstraint()));
if (src.hasRequiredElement())
tgt.setRequiredElement(Boolean10_50.convertBoolean(src.getRequiredElement()));
if (src.hasRepeatsElement())
tgt.setRepeatsElement(Boolean10_50.convertBoolean(src.getRepeatsElement()));
if (src.hasAnswerValueSetElement())
tgt.setOptions(Reference10_50.convertCanonicalToReference(src.getAnswerValueSetElement()));
for (QuestionnaireItemAnswerOptionComponent t : src.getAnswerOption()) if (t.hasValueCoding())
try {
tgt.addOption(Coding10_50.convertCoding(t.getValueCoding()));
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e);
}
for (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent t : src.getItem()) tgt.addGroup(convertQuestionnaireGroupComponent(t));
return tgt;
}
use of org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderItemOptions.
public void renderItemOptions(XhtmlNode x, QuestionnaireItemComponent i) {
if (i.hasAnswerOption()) {
boolean useSelect = false;
for (QuestionnaireItemAnswerOptionComponent opt : i.getAnswerOption()) {
useSelect = useSelect || opt.getInitialSelected();
}
x.an("opt-item." + i.getLinkId());
x.para().b().tx("Answer options for " + i.getLinkId());
XhtmlNode ul = x.ul();
for (QuestionnaireItemAnswerOptionComponent opt : i.getAnswerOption()) {
XhtmlNode li = ul.li();
li.style("font-size: 11px");
if (useSelect) {
if (opt.getInitialSelected()) {
li.img("icon-selected.png");
} else {
li.img("icon-not-selected.png");
}
}
if (opt.getValue().isPrimitive()) {
li.tx(opt.getValue().primitiveValue());
} else if (opt.getValue() instanceof Coding) {
Coding c = (Coding) opt.getValue();
String link = c.hasSystem() ? context.getWorker().getLinkForUrl(context.getSpecificationLink(), c.getSystem()) : null;
if (link == null) {
li.tx(c.getSystem() + "#" + c.getCode());
} else {
li.ah(link).tx(describeSystem(c.getSystem()));
li.tx(": " + c.getCode());
}
if (c.hasDisplay()) {
li.tx(" (\"" + c.getDisplay() + "\")");
}
} else {
li.tx("??");
}
}
}
}
Aggregations