From c4cff0c7908514fb31a414b0a0e064fffa6a05aa Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 5 Aug 2019 11:55:19 +1000 Subject: [PATCH] fix problem where differential rendering is missing inherited information --- .../fhir/r5/conformance/ProfileUtilities.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 34c76d4c7..8424b0b6a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -448,7 +448,7 @@ public class ProfileUtilities extends TranslatingUtilities { e.clearUserData(GENERATED_IN_SNAPSHOT); // we actually delegate the work to a subroutine so we can re-enter it with a different cursors - StructureDefinitionDifferentialComponent diff = derived.getDifferential().copy(); // we make a copy here because we're sometimes going to hack the differential while processing it. + StructureDefinitionDifferentialComponent diff = cloneDiff(derived.getDifferential()); // we make a copy here because we're sometimes going to hack the differential while processing it. Have to migrate user data back afterwards processPaths("", derived.getSnapshot(), base.getSnapshot(), diff, baseCursor, diffCursor, base.getSnapshot().getElement().size()-1, derived.getDifferential().hasElement() ? derived.getDifferential().getElement().size()-1 : -1, url, webUrl, derived.present(), null, null, false, base.getUrl(), null, false, new ArrayList(), base); @@ -467,6 +467,14 @@ public class ProfileUtilities extends TranslatingUtilities { setIds(derived, false); //Check that all differential elements have a corresponding snapshot element for (ElementDefinition e : diff.getElement()) { + if (!e.hasUserData("diff-source")) + throw new Error("Unxpected internal condition - no source on diff element"); + else { + if (e.hasUserData(DERIVATION_EQUALS)) + ((Base) e.getUserData("diff-source")).setUserData(DERIVATION_EQUALS, e.getUserData(DERIVATION_EQUALS)); + if (e.hasUserData(DERIVATION_POINTER)) + ((Base) e.getUserData("diff-source")).setUserData(DERIVATION_POINTER, e.getUserData(DERIVATION_POINTER)); + } if (!e.hasUserData(GENERATED_IN_SNAPSHOT)) { System.out.println("Error in snapshot generation: Differential for "+derived.getUrl()+" with " + (e.hasId() ? "id: "+e.getId() : "path: "+e.getPath())+" has an element that is not marked with a snapshot match"); if (exception) @@ -489,6 +497,17 @@ public class ProfileUtilities extends TranslatingUtilities { } } + private StructureDefinitionDifferentialComponent cloneDiff(StructureDefinitionDifferentialComponent source) { + StructureDefinitionDifferentialComponent diff = new StructureDefinitionDifferentialComponent(); + for (ElementDefinition sed : source.getElement()) { + ElementDefinition ted = sed.copy(); + diff.getElement().add(ted); + ted.setUserData("diff-source", sed); + } + return diff; + } + + private String constraintSummary(ElementDefinition ed) { CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); if (ed.hasPattern())