From 786aa001c53329f8c352d08c5df2c706f296e022 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 22 May 2020 08:17:36 +1000 Subject: [PATCH] fix misleading error message + uppate for new release of tests --- .../fhir/r5/context/BaseWorkerContext.java | 2 +- .../r5/renderers/QuestionnaireRenderer.java | 95 +++++++++++++++++++ .../fhir/r5/test/utils/TestingUtilities.java | 2 + .../fhir/utilities/i18n/I18nConstants.java | 2 +- .../hl7/fhir/utilities/xhtml/XhtmlNode.java | 30 ++++++ .../src/main/resources/Messages.properties | 2 +- .../instance/InstanceValidator.java | 2 +- pom.xml | 2 +- 8 files changed, 132 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index a0b9d7154..29e141bd9 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -532,7 +532,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte return new ValueSetExpansionOutcome(vs.copy()); } if (!vs.hasUrl()) - throw new Error(formatMessage(I18nConstants.NO_VALUE_SET)); + throw new Error(formatMessage(I18nConstants.NO_VALUE_SET_IN_URL)); CacheToken cacheToken = txCache.generateExpandToken(vs, heirarchical); ValueSetExpansionOutcome res; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireRenderer.java index 79ad3373b..d5c62a8c9 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireRenderer.java @@ -3,6 +3,7 @@ package org.hl7.fhir.r5.renderers; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.List; +import java.util.UUID; import org.hl7.fhir.r5.model.CodeableConcept; import org.hl7.fhir.r5.model.DomainResource; @@ -10,9 +11,11 @@ import org.hl7.fhir.r5.model.Expression; import org.hl7.fhir.r5.model.Extension; import org.hl7.fhir.r5.model.Questionnaire; import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent; import org.hl7.fhir.r5.renderers.utils.RenderingContext; +import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome; import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator; @@ -258,7 +261,73 @@ public class QuestionnaireRenderer extends TerminologyRenderer { p.tx(": "); } p.span(null, "linkId: "+i.getLinkId()).tx(i.getText()); + if (i.getRequired()) { + p.span("color: red", "Mandatory").tx(" *"); + } + XhtmlNode input = null; + switch (i.getType()) { + case STRING: + p.tx(" "); + input = p.input(i.getLinkId(), "text", i.getType().getDisplay(), 60); + break; + case ATTACHMENT: + break; + case BOOLEAN: + p.tx(" "); + input = p.input(i.getLinkId(), "checkbox", i.getType().getDisplay(), 1); + break; + case CHOICE: + input = p.select(i.getLinkId()); + listOptions(q, i, input); + break; + case DATE: + p.tx(" "); + input = p.input(i.getLinkId(), "date", i.getType().getDisplay(), 10); + break; + case DATETIME: + p.tx(" "); + input = p.input(i.getLinkId(), "datetime-local", i.getType().getDisplay(), 25); + break; + case DECIMAL: + p.tx(" "); + input = p.input(i.getLinkId(), "number", i.getType().getDisplay(), 15); + break; + case DISPLAY: + break; + case GROUP: + break; + case INTEGER: + p.tx(" "); + input = p.input(i.getLinkId(), "number", i.getType().getDisplay(), 10); + break; + case OPENCHOICE: + break; + case QUANTITY: + p.tx(" "); + input = p.input(i.getLinkId(), "number", "value", 15); + p.tx(" "); + input = p.input(i.getLinkId(), "unit", "unit", 10); + break; + case QUESTION: + break; + case REFERENCE: + break; + case TEXT: + break; + case TIME: + break; + case URL: + break; + default: + break; + } + if (input != null) { + if (i.getReadOnly()) { + input.attribute("readonly", "1"); + } + + } int t = 1; for (QuestionnaireItemComponent c : i.getItem()) { hasExt = renderFormItem(d, q, c, pfx == null ? null : pfx+"."+Integer.toString(t), false) || hasExt; @@ -267,6 +336,32 @@ public class QuestionnaireRenderer extends TerminologyRenderer { return hasExt; } + private void listOptions(Questionnaire q, QuestionnaireItemComponent i, XhtmlNode select) { + if (i.hasAnswerValueSet()) { + ValueSet vs = null; + if (i.getAnswerValueSet().startsWith("#")) { + vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1)).copy(); + if (vs != null && !vs.hasUrl()) { + vs.setUrl("urn:uuid:"+UUID.randomUUID().toString().toLowerCase()); + } + } else { + vs = context.getContext().fetchResource(ValueSet.class, i.getAnswerValueSet()); + } + if (vs != null) { + ValueSetExpansionOutcome exp = context.getContext().expandVS(vs, true, false); + if (exp.getValueset() != null) { + for (ValueSetExpansionContainsComponent cc : exp.getValueset().getExpansion().getContains()) { + select.option(cc.getCode(), cc.hasDisplay() ? cc.getDisplay() : cc.getCode(), false); + } + return; + } + } + } else if (i.hasAnswerOption()) { + + } + select.option("a", "??", false); + } + public String display(DomainResource dr) throws UnsupportedEncodingException, IOException { return display((Questionnaire) dr); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java index eaab972b4..4ab0bb891 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java @@ -19,6 +19,7 @@ import org.fhir.ucum.UcumEssenceService; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.model.Parameters; +import org.hl7.fhir.r5.terminologies.TerminologyClientR5; import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; @@ -88,6 +89,7 @@ public class TestingUtilities { IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version)); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); +// ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null); fcontexts.put(v, fcontext); } catch (Exception e) { throw new Error(e); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java index 23c065fed..11f2eb71b 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/i18n/I18nConstants.java @@ -408,7 +408,7 @@ public class I18nConstants { public final static String CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT = "Can_only_specify_profile_in_the_context"; public final static String NO_URL_IN_EXPAND_VALUE_SET_2 = "no_url_in_expand_value_set_2"; public final static String NO_URL_IN_EXPAND_VALUE_SET = "no_url_in_expand_value_set"; - public final static String NO_VALUE_SET = "no_value_set"; + public final static String NO_VALUE_SET_IN_URL = "no_value_set"; public final static String NO_PARAMETERS_PROVIDED_TO_EXPANDVS = "No_Parameters_provided_to_expandVS"; public final static String NO_EXPANSION_PARAMETERS_PROVIDED = "No_Expansion_Parameters_provided"; public final static String UNABLE_TO_RESOLVE_VALUE_SET_ = "Unable_to_resolve_value_Set_"; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java index 77f495f30..5298bcad3 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java @@ -659,4 +659,34 @@ public class XhtmlNode implements IBaseXhtml { return this; } + + public XhtmlNode input(String name, String type, String placeholder, int size) { + XhtmlNode p = new XhtmlNode(NodeType.Element, "input"); + p.attribute("name", name); + p.attribute("type", type); + p.attribute("placeholder", placeholder); + p.attribute("size", Integer.toString(size)); + getChildNodes().add(p); + return p; + } + + public XhtmlNode select(String name) { + XhtmlNode p = new XhtmlNode(NodeType.Element, "select"); + p.attribute("name", name); + p.attribute("size", "1"); + getChildNodes().add(p); + return p; + } + + public XhtmlNode option(String value, String text, boolean selected) { + XhtmlNode p = new XhtmlNode(NodeType.Element, "option"); + p.attribute("value", value); + p.attribute("selected", Boolean.toString(selected)); + p.tx(text); + getChildNodes().add(p); + return p; + } + + + } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 4d06cfea8..8c31c8dc0 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -398,7 +398,7 @@ No_ExpansionProfile_provided = No ExpansionProfile provided Can_only_specify_profile_in_the_context = Can only specify profile in the context no_url_in_expand_value_set_2 = no url in expand value set 2 no_url_in_expand_value_set = no url in expand value set -no_value_set = no value set +no_value_set = value set has no url property No_Parameters_provided_to_expandVS = No Parameters provided to expandVS No_Expansion_Parameters_provided = No Expansion Parameters provided Unable_to_resolve_value_Set_ = Unable to resolve value Set {0} diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index a8db0c4de..edf24a218 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -160,7 +160,7 @@ import com.google.gson.JsonObject; /** * Thinking of using this in a java program? Don't! - * You should use one of the wrappers instead. Either in HAPI, or use ValidationEngine, or NativeHostServices + * You should use one of the wrappers instead. Either in HAPI, or use ValidationEngine *

* Validation todo: * - support @default slices diff --git a/pom.xml b/pom.xml index 485dd96d0..18a95fc39 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 5.0.0 - 1.1.14-SNAPSHOT + 1.1.14 5.6.2 3.0.0-M4 0.8.5