diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java index 72340c0e6..6905e9ef4 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java @@ -34,6 +34,8 @@ package org.hl7.fhir.r5.model; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -42,12 +44,21 @@ import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent; import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus; +import org.hl7.fhir.r5.model.TypeDetails.ProfiledTypeSorter; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.Utilities; - public class TypeDetails { + public class ProfiledTypeSorter implements Comparator { + + @Override + public int compare(ProfiledType o1, ProfiledType o2) { + return o1.uri.compareTo(o2.uri); + } + + } + public static final String FHIR_NS = "http://hl7.org/fhir/StructureDefinition/"; public static final String FP_NS = "http://hl7.org/fhirpath/"; public static final String FP_String = "http://hl7.org/fhirpath/System.String"; @@ -419,20 +430,30 @@ public class TypeDetails { } return false; } + public String describe() { - return getTypes().toString(); + return Utilities.sorted(getTypes()).toString(); } + public String describeMin() { CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); - for (ProfiledType pt : types) + for (ProfiledType pt : sortedTypes(types)) b.append(pt.describeMin()); return b.toString(); } + + private List sortedTypes(List types2) { + List list = new ArrayList<>(); + Collections.sort(list, new ProfiledTypeSorter()); + return list; + } + public String getType() { for (ProfiledType pt : types) return pt.uri; return null; } + @Override public String toString() { return (collectionStatus == null ? collectionStatus.SINGLETON.toString() : collectionStatus.toString()) + getTypes().toString(); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 7f86fd091..5730242bd 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -4748,7 +4748,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat throw new DefinitionException(context.formatMessagePlural(criteriaElement.getType().size(), I18nConstants.DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_MULTIPLE_TYPES, discriminator, ed.getId(), profile.getVersionedUrl(), criteriaElement.typeSummary())); } else throw new DefinitionException(context.formatMessage(I18nConstants.DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_NO_TYPES, discriminator, ed.getId(), profile.getVersionedUrl())); - if (discriminator.isEmpty()) { + if (discriminator.isEmpty()) { expression.append(" and $this is " + type); } else { expression.append(" and " + discriminator + " is " + type); @@ -4830,11 +4830,11 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat private String makeTypeForFHIRPath(String type) { if (Utilities.isAbsoluteUrl(type)) { if (type.startsWith("http://hl7.org/fhir/StructureDefinition/")) { - return tail(type); + return typeTail(type); } else if (type.startsWith("http://hl7.org/cda/stds/core/StructureDefinition/")) { - return "CDA."+tail(type); + return "CDA."+typeTail(type); } else { - return tail(type); // todo? + return typeTail(type); // todo? } } else { String ptype = type.substring(0, 1).toLowerCase() + type.substring(1); @@ -4846,6 +4846,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } + private String typeTail(String type) { + return type.contains("/") ? type.substring(type.lastIndexOf("/")+1) : type; + } + private boolean isBaseDefinition(String url) { boolean b = url.startsWith("http://hl7.org/fhir/") && !url.substring(40).contains("/"); return b;