From 86c98b1130b463ed3fe27575fb92d4ff83a47b68 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Apr 2023 17:27:39 +1000 Subject: [PATCH 1/2] fix missing id --- .../org/hl7/fhir/convertors/txClient/TerminologyClientR4.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java index 091618987..b5f63e10c 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java @@ -63,6 +63,7 @@ public class TerminologyClientR4 implements TerminologyClient { public TerminologyClientR4(String id, String address, String userAgent) throws URISyntaxException { this.client = new FHIRToolingClient(address, userAgent); setClientHeaders(new ClientHeaders()); + this.id = id; } public TerminologyClientR4(String id, String address, String userAgent, ClientHeaders clientHeaders) throws URISyntaxException { From 069dc03c90d3fc59d821a85bdfcda89b3c98bb59 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Apr 2023 17:28:28 +1000 Subject: [PATCH 2/2] Validate Extension Context + fix questionnaire value set validation --- .../fhir/utilities/i18n/I18nConstants.java | 3 ++ .../src/main/resources/Messages.properties | 6 ++- .../instance/type/QuestionnaireValidator.java | 2 +- .../type/StructureDefinitionValidator.java | 37 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) 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 0485a56ae..b88fae543 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 @@ -859,6 +859,9 @@ public class I18nConstants { public static final String UNKNOWN_CODESYSTEM_VERSION = "UNKNOWN_CODESYSTEM_VERSION"; public static final String VALUESET_TOO_COSTLY = "VALUESET_TOO_COSTLY"; public static final String NO_VALID_DISPLAY_FOUND = "NO_VALID_DISPLAY_FOUND"; + public static final String SD_NO_CONTEXT_WHEN_NOT_EXTENSION = "SD_NO_CONTEXT_WHEN_NOT_EXTENSION"; + public static final String SD_CONTEXT_SHOULD_NOT_BE_ELEMENT = "SD_CONTEXT_SHOULD_NOT_BE_ELEMENT"; + public static final String SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = "SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION"; } diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 3f8b8e3dd..42fd69f54 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -72,7 +72,7 @@ Profile_VAL_MissingElement = Missing element ''{0}'' - required by fixed value a Profile_VAL_NotAllowed = The element {0} is present in the instance but not allowed in the applicable {1} specified in profile Measure_MR_M_None = No Measure is identified, so no validation can be performed against the Measure Measure_MR_M_NotFound = The Measure ''{0}'' could not be resolved, so no validation can be performed against the Measure -Questionnaire_QR_Item_BadOption = The code provided {1} 9in the system {0}) is not in the options value set ({2}) in the questionnaire +Questionnaire_QR_Item_BadOption = The code provided {1} in the system {0}) is not in the options value set ({2}) in the questionnaire: {3} QUESTIONNAIRE_QR_ITEM_BADOPTION_CS = The code provided {1} cannot be validated in the options value set ({2}) in the questionnaire because the system {0} is unknown Questionnaire_QR_Item_Coding = Error {0} validating Coding against Questionnaire Options Questionnaire_QR_Item_CodingNoOptions = Cannot validate Coding option because no option list is provided @@ -481,7 +481,6 @@ Unable_to_resolve_system__value_set_has_multiple_matches = Unable to resolve sys Unable_to_resolve_system__value_set_has_no_includes_or_expansion = Unable to resolve system - value set {0} has no includes or expansion Unable_to_resolve_system__no_value_set = Unable to resolve system - no value set This_base_property_must_be_an_Array_not_ = This base property must be an Array, not {0} -This_property_must_be_an_Array_not_ = This property must be an Array, not {0} documentmsg = (document) xml_attr_value_invalid = The XML Attribute {0} has an invalid character xml_encoding_invalid = The XML encoding is invalid (must be UTF-8) @@ -912,6 +911,9 @@ UNABLE_TO_INFER_CODESYSTEM = The System URI could not be determined for the code VALUESET_TOO_COSTLY = The value set {0} has too many codes to display ({1}) NO_VALID_DISPLAY_FOUND_one = No valid Display Names found for {1}#{2} in the language {3} NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {1}#{2} in the languages {3} +SD_NO_CONTEXT_WHEN_NOT_EXTENSION = The type is {0} so an extension context should not be specified +SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = The type is {0} so an extension context invariants should not be specified +SD_CONTEXT_SHOULD_NOT_BE_ELEMENT = Review the extension type: extensions should not have a context of {0} unless it''s really intended that they can be used anywhere diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java index 11568e9f2..ef74c7665 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java @@ -566,7 +566,7 @@ public class QuestionnaireValidator extends BaseValidator { if (res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) { txWarning(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION_CS, c.getSystem(), c.getCode(), vs.present()); } else { - ok = txRule(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode(), vs.present()) && ok; + ok = txRule(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode(), vs.present(), res.getMessage()) && ok; } } else if (res.getSeverity() != null) { super.addValidationMessage(errors, NO_RULE_DATE, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), res.getMessage(), res.getSeverity(), Source.TerminologyEngine, null); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java index 06098d0d3..dbd12284a 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java @@ -73,6 +73,8 @@ public class StructureDefinitionValidator extends BaseValidator { String typeName = null; try { sd = loadAsSD(src); + checkExtensionContext(errors, src, stack); + List snapshot = sd.getSnapshot().getElement(); sd.setSnapshot(null); typeName = sd.getTypeName(); @@ -132,6 +134,41 @@ public class StructureDefinitionValidator extends BaseValidator { return ok; } + private void checkExtensionContext(List errors, Element src, NodeStack stack) { + String type = src.getNamedChildValue("type"); + List eclist = src.getChildren("context"); + List cilist = src.getChildren("contextInvariant"); + int i = 0; + for (Element ec : eclist) { + NodeStack n = stack.push(ec, i, null, null); + if ("Extension".equals(type)) { + String ct = null; + String cv = null; + if (VersionUtilities.isR4Plus(context.getVersion())) { + ct = ec.getNamedChildValue("type"); + cv = ec.getNamedChildValue("expression"); + } else { + ct = src.getNamedChildValue("contextType"); /// todo - this doesn't have the right value + cv = ec.primitiveValue(); + } + if ("element".equals(ct) && "Element".equals(cv)) { + warning(errors, "2023-04-23", IssueType.BUSINESSRULE, n.getLiteralPath(), false, I18nConstants.SD_CONTEXT_SHOULD_NOT_BE_ELEMENT, cv); + } + } else { + rule(errors, "2023-04-23", IssueType.INVALID, n.getLiteralPath(), false, I18nConstants.SD_NO_CONTEXT_WHEN_NOT_EXTENSION, type); + } + } + i = 0; + for (Element ci : cilist) { + NodeStack n = stack.push(ci, i, null, null); + if ("Extension".equals(type)) { + + } else { + rule(errors, "2023-04-23", IssueType.INVALID, n.getLiteralPath(), false, I18nConstants.SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION, type); + } + } + } + private boolean validateElementList(List errors, Element elementList, NodeStack stack, boolean snapshot, boolean hasSnapshot, StructureDefinition sd, String typeName) { boolean ok = true; List elements = elementList.getChildrenByName("element");