diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index aa766d10f..64d8d36c3 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -668,7 +668,7 @@ public class FHIRPathEngine { if (sd == null) { throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT, t); } - types = new TypeDetails(CollectionStatus.SINGLETON, sd.getUrl()); + types.addType(sd.getUrl()); } else { String ctxt = t.substring(0, t.indexOf('.')); StructureDefinition sd = cu.findType(ctxt); @@ -680,11 +680,10 @@ public class FHIRPathEngine { throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT_ELEMENT, t); } if (ed.fixedType != null) { - types = new TypeDetails(CollectionStatus.SINGLETON, ed.fixedType); + types.addType(ed.fixedType); } else if (ed.getDefinition().getType().isEmpty() || isAbstractType(ed.getDefinition().getType())) { - types = new TypeDetails(CollectionStatus.SINGLETON, sd.getType()+"#"+t); + types.addType(sd.getType()+"#"+t); } else { - types = new TypeDetails(CollectionStatus.SINGLETON); for (TypeRefComponent tt : ed.getDefinition().getType()) { types.addType(tt.getCode()); } @@ -3545,7 +3544,7 @@ public class FHIRPathEngine { return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_DateTime); case Resolve : { checkContextReference(focus, "resolve", exp); - return new TypeDetails(CollectionStatus.ORDERED, "DomainResource"); + return new TypeDetails(focus.getCollectionStatus(), "Resource"); } case Extension : { checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java index 76028b10b..644fb6cc7 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java @@ -865,8 +865,12 @@ public class ValidationMessage implements Comparator, Compara if (other.location != null) { return false; } - } else if (!location.equals(other.location)) { - return false; + } else { + String l1 = preprocessLocation(location); + String l2 = preprocessLocation(other.location); + if (!l1.equals(l2)) { + return false; + } } if (message == null) { if (other.message != null) { @@ -890,6 +894,14 @@ public class ValidationMessage implements Comparator, Compara } return true; } + + private String preprocessLocation(String loc) { + // some locations are prefixes with a location but they're not different since the location is fixed where .match is called from + if (loc.contains(": ")) { + return loc.substring(loc.indexOf(": ")+2); + } + return loc; + } 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 9e341a33c..fa6ada3b0 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 @@ -5969,7 +5969,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (ed.hasSlicing()) { if (slicer != null && slicer.getPath().equals(ed.getPath())) { String errorContext = "profile " + profile.getVersionedUrl(); - if (!resource.getChildValue(ID).isEmpty()) { + if (resource.hasChild(ID) && !resource.getChildValue(ID).isEmpty()) { errorContext += "; instance " + resource.getChildValue("id"); } throw new DefinitionException(context.formatMessage(I18nConstants.SLICE_ENCOUNTERED_MIDWAY_THROUGH_SET_PATH___ID___, slicer.getPath(), slicer.getId(), errorContext)); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java index 960ece31e..b39da1e41 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java @@ -103,8 +103,8 @@ public class StructureDefinitionValidator extends BaseValidator { for (ValidationMessage msg : msgs) { // we need to set the location for the context String loc = msg.getLocation(); - if (loc.contains("#")) { - msg.setLocation(stack.getLiteralPath()+".differential.element.where(path = '"+loc.substring(loc.indexOf("#")+1)+"')"); + if (loc.startsWith("StructureDefinition.")) { + msg.setLocation(stack.getLiteralPath()+loc.substring(loc.indexOf("."))); } else { msg.setLocation(stack.getLiteralPath()); } diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java index 98af4d75f..2c3f2d201 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java @@ -107,7 +107,7 @@ public class SnapShotGenerationXTests { sort = "true".equals(test.getAttribute("sort")); fail = "true".equals(test.getAttribute("fail")); newSliceProcessing = !"false".equals(test.getAttribute("new-slice-processing")); - debug = false; // "true".equals(test.getAttribute("debug")); + debug = "true".equals(test.getAttribute("debug")); id = test.getAttribute("id"); include = test.getAttribute("include"); @@ -510,7 +510,7 @@ public class SnapShotGenerationXTests { pu.setAllowUnknownProfile(AllowUnknownProfile.ALL_TYPES); if (test.isSort()) { List errors = new ArrayList(); - int lastCount = output.getDifferential().getElement().size(); +// int lastCount = output.getDifferential().getElement().size(); pu.sortDifferential(base, output, test.getSource().getName(), errors, false); if (errors.size() > 0) throw new FHIRException("Sort failed: " + errors.toString());