From bb4379f5dd932b1504a0bc5c607754d51d108d16 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 22 Jul 2023 21:01:08 +1000 Subject: [PATCH] fix bugs in type handling --- .../hl7/fhir/r5/context/BaseWorkerContext.java | 17 +++++++++++------ .../hl7/fhir/r5/context/ContextUtilities.java | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index 1e546bf84..97c434943 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -2245,16 +2245,21 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte Set types = new HashSet<>(); types.addAll(fetchTypeDefinitions(typeName)); types.removeIf(sd -> sd.getDerivation() == TypeDerivationRule.CONSTRAINT); - if (types.size() == 1) { + if (types.size() == 0) { + return null; // throw new FHIRException("Unresolved type "+typeName+" (0)"); + } else if (types.size() == 1) { return types.iterator().next(); - } else if (types.size() > 1) { - throw new FHIRException("Ambiguous type "+typeName); - } else { - return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+typeName); + } else { + types.removeIf(sd -> !sd.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/")); + if (types.size() != 1) { + throw new FHIRException("Ambiguous type "+typeName+" ("+types.toString()+") (contact Grahame Grieve for investigation)"); + } else { + return types.iterator().next(); + } } } } - + @Override public List fetchTypeDefinitions(String typeName) { List res = new ArrayList<>(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java index 55b335011..480f8061a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java @@ -32,6 +32,7 @@ import org.hl7.fhir.r5.model.NamingSystem; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.utilities.OIDUtils; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; @@ -156,8 +157,10 @@ public class ContextUtilities implements ProfileKnowledgeProvider { public Set getTypeNameSet() { Set result = new HashSet(); for (StructureDefinition sd : context.fetchResourcesByType(StructureDefinition.class)) { - if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) + if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && + VersionUtilities.versionsCompatible(context.getVersion(), sd.getFhirVersion().toCode())) { result.add(sd.getName()); + } } return result; }