From c6f392b7e03d2d54cbec83c81814ada6b6e42237 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 09:54:22 +1000 Subject: [PATCH] #466: fix problem checking types on logical models --- .../hl7/fhir/dstu3/model/ListResource.java | 6 ---- .../org/hl7/fhir/r4/model/ListResource.java | 6 ---- .../fhir/r5/conformance/ProfileUtilities.java | 28 +++++++++++++++++-- .../hl7/fhir/validation/ValidationEngine.java | 4 +-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java index ed04b1bc3..4203569c2 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java @@ -38,12 +38,6 @@ import java.util.List; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import org.hl7.fhir.r5.model.Device; -import org.hl7.fhir.r5.model.Group; -import org.hl7.fhir.r5.model.Location; -import org.hl7.fhir.r5.model.Patient; -import org.hl7.fhir.r5.model.Practitioner; -import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.utilities.Utilities; import ca.uhn.fhir.model.api.annotation.Block; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java index b9169c401..190a18c59 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java @@ -44,12 +44,6 @@ import ca.uhn.fhir.model.api.annotation.ChildOrder; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Block; import org.hl7.fhir.instance.model.api.*; -import org.hl7.fhir.r5.model.Device; -import org.hl7.fhir.r5.model.Group; -import org.hl7.fhir.r5.model.Location; -import org.hl7.fhir.r5.model.Patient; -import org.hl7.fhir.r5.model.Practitioner; -import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.exceptions.FHIRException; /** * A list is a curated collection of resources. 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 88489aa6c..51d763a71 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 @@ -609,7 +609,8 @@ public class ProfileUtilities extends TranslatingUtilities { derived.setSnapshot(new StructureDefinitionSnapshotComponent()); try { - checkDifferential(derived.getDifferential().getElement(), derived.getType(), derived.getUrl()); + checkDifferential(derived.getDifferential().getElement(), typeName(derived.getType()), derived.getUrl()); + checkDifferentialBaseType(derived); // so we have two lists - the base list, and the differential list // the differential list is only allowed to include things that are in the base list, but @@ -620,8 +621,6 @@ public class ProfileUtilities extends TranslatingUtilities { int baseCursor = 0; int diffCursor = 0; // we need a diff cursor because we can only look ahead, in the bound scoped by longer paths - if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) - throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT)); for (ElementDefinition e : derived.getDifferential().getElement()) e.clearUserData(GENERATED_IN_SNAPSHOT); @@ -771,6 +770,29 @@ public class ProfileUtilities extends TranslatingUtilities { derived.clearUserData("profileutils.snapshot.generating"); } + public void checkDifferentialBaseType(StructureDefinition derived) throws Error { + if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) { + if (typeMatchesAncestor(derived.getDifferential().getElementFirstRep().getType(), derived.getBaseDefinition())) { + derived.getDifferential().getElementFirstRep().getType().clear(); + } else { + throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT)); + } + } + } + + private boolean typeMatchesAncestor(List type, String baseDefinition) { + StructureDefinition sd = context.fetchResource(StructureDefinition.class, baseDefinition); + return sd != null && type.size() == 1 && sd.getType().equals(type.get(0).getCode()); + } + + private String typeName(String type) { + if (Utilities.isAbsoluteUrl(type)) { + return type.substring(type.lastIndexOf("/")+1); + } else { + return type; + } + } + private void checkGroupConstraints(StructureDefinition derived) { List toRemove = new ArrayList<>(); // List processed = new ArrayList<>(); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 7e71fa3d6..ae3bc199c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -485,9 +485,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst makeSnapshot(sd); } catch (Exception e) { System.out.println("Process Note: Unable to generate snapshot for " + sd.present() + ": " + e.getMessage()); - if (debug) { +// if (debug) { e.printStackTrace(); - } +// } } } }