From 71a19710a014edb6c9339244c0cbf380f181a5d2 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 21 Mar 2023 06:12:02 +1100 Subject: [PATCH] Fix for where profile_element extension was being ignored when checking types after snapshot generation --- .../conformance/profile/ProfileUtilities.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java index be4e6a328..29b0de37a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java @@ -661,10 +661,7 @@ public class ProfileUtilities extends TranslatingUtilities { System.out.println(" "+ed.getId()+" = "+ed.getPath()+" : "+typeSummaryWithProfile(ed)+"["+ed.getMin()+".."+ed.getMax()+"]"+sliceSummary(ed)+" "+constraintSummary(ed)); } } - if (exception) - throw new DefinitionException(msg); - else - messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url, msg, ValidationMessage.IssueSeverity.ERROR)); + handleError(url, msg); } // hack around a problem in R4 definitions (somewhere?) for (ElementDefinition ed : derived.getSnapshot().getElement()) { @@ -712,14 +709,20 @@ public class ProfileUtilities extends TranslatingUtilities { if (ed.getPath().equals("Bundle.entry.response.outcome")) { wt = "OperationOutcome"; } - if (!sd.getType().equals(wt)) { - boolean ok = isCompatibleType(wt, sd); + String tt = sd.getType(); + boolean elementProfile = u.hasExtension(ToolingExtensions.EXT_PROFILE_ELEMENT); + if (elementProfile) { + ElementDefinition edt = sd.getSnapshot().getElementById(u.getExtensionString(ToolingExtensions.EXT_PROFILE_ELEMENT)); + if (edt == null) { + handleError(url, "The profile "+u.getValue()+" has type "+sd.getType()+" which is not consistent with the stated type "+wt); + } else { + tt = edt.typeSummary(); + } + } + if (!tt.equals(wt)) { + boolean ok = !elementProfile && isCompatibleType(wt, sd); if (!ok) { - String smsg = "The profile "+u.getValue()+" has type "+sd.getType()+" which is not consistent with the stated type "+wt; - if (exception) - throw new DefinitionException(smsg); - else - messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+ed.getId(), smsg, IssueSeverity.ERROR)); + handleError(url, "The profile "+u.getValue()+" has type "+sd.getType()+" which is not consistent with the stated type "+wt); } } } @@ -738,6 +741,13 @@ public class ProfileUtilities extends TranslatingUtilities { } } + private void handleError(String url, String msg) { + if (exception) + throw new DefinitionException(msg); + else + messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url, msg, ValidationMessage.IssueSeverity.ERROR)); + } +