From bda3a74b40c7051b94baa9d9f14aeed1d3a6a961 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 31 Jan 2023 07:23:33 +1100 Subject: [PATCH] handle R3 encoding of primitive values when validating profiles --- .../type/StructureDefinitionValidator.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) 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 c932380f0..2f1e69d94 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 @@ -164,29 +164,30 @@ public class StructureDefinitionValidator extends BaseValidator { tc = type.getExtensionValue(ToolingExtensions.EXT_FHIR_TYPE).primitiveValue(); } if (Utilities.noString(tc) && type.hasChild("code")) { - throw new Error("Snapshot for " + sd.getId() +" element " + path + " has type.code without a value "); -// if (type.getNamedChild("code").hasExtension(" http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type")) { -// tc = "*"; -// } - } - typeCodes.add(tc); - Set tcharacteristics = new HashSet<>(); - StructureDefinition tsd = context.fetchTypeDefinition(tc); - if (tsd != null && tsd.hasExtension(ToolingExtensions.EXT_TYPE_CHARACTERISTICS)) { - for (Extension ext : tsd.getExtensionsByUrl(ToolingExtensions.EXT_TYPE_CHARACTERISTICS)) { - tcharacteristics.add(ext.getValue().primitiveValue()); + if (VersionUtilities.isR4Plus(context.getVersion())) { + throw new Error("Snapshot for " + sd.getId() +" element " + path + " has type.code without a value "); } - } else { - // nothing specified, so infer from known types - addCharacteristics(tcharacteristics, tc); } - characteristics.addAll(tcharacteristics); - if (type.hasChildren("targetProfile")) { - ok = rule(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, stack.getLiteralPath(), tcharacteristics.contains("has-target") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "targetProfile", tc) && ok; - } - // check the stated profile - must be a constraint on the type - if (snapshot || sd != null) { - ok = validateElementType(errors, type, stack.push(type, -1, null, null), sd, path) && ok; + if (!Utilities.noString(tc)) { + typeCodes.add(tc); + Set tcharacteristics = new HashSet<>(); + StructureDefinition tsd = context.fetchTypeDefinition(tc); + if (tsd != null && tsd.hasExtension(ToolingExtensions.EXT_TYPE_CHARACTERISTICS)) { + for (Extension ext : tsd.getExtensionsByUrl(ToolingExtensions.EXT_TYPE_CHARACTERISTICS)) { + tcharacteristics.add(ext.getValue().primitiveValue()); + } + } else { + // nothing specified, so infer from known types + addCharacteristics(tcharacteristics, tc); + } + characteristics.addAll(tcharacteristics); + if (type.hasChildren("targetProfile")) { + ok = rule(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, stack.getLiteralPath(), tcharacteristics.contains("has-target") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "targetProfile", tc) && ok; + } + // check the stated profile - must be a constraint on the type + if (snapshot || sd != null) { + ok = validateElementType(errors, type, stack.push(type, -1, null, null), sd, path) && ok; + } } } if (typeMustSupport) {