From f4da35776949926b753d8903d7ae390609ba2158 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 29 Sep 2021 16:19:43 +1000 Subject: [PATCH] more improving error message resolving slicing --- .../fhir/validation/instance/InstanceValidator.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 9a467c259..45d71ff96 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 @@ -3062,7 +3062,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat return context; } - private List getCriteriaForDiscriminator(String path, ElementDefinition element, String discriminator, StructureDefinition profile, boolean removeResolve) throws FHIRException { + private List getCriteriaForDiscriminator(String path, ElementDefinition element, String discriminator, StructureDefinition profile, boolean removeResolve, StructureDefinition srcProfile) throws FHIRException { List elements = new ArrayList(); if ("value".equals(discriminator) && element.hasFixed()) { elements.add(element); @@ -3088,7 +3088,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat throw new FHIRException(context.formatMessage(I18nConstants.DISCRIMINATOR_BAD_PATH, e.getMessage(), fp), e); } long t2 = System.nanoTime(); - ed = fpe.evaluateDefinition(expr, profile, element); + ed = fpe.evaluateDefinition(expr, profile, element, srcProfile); timeTracker.sd(t2); if (ed != null) elements.add(ed); @@ -3113,7 +3113,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } expr = fpe.parse(fp); t2 = System.nanoTime(); - ed = fpe.evaluateDefinition(expr, profile, element); + ed = fpe.evaluateDefinition(expr, profile, element, srcProfile); timeTracker.sd(t2); if (ed != null) elements.add(ed); @@ -3563,13 +3563,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat * @param ed - the slice for which to test membership * @param errors * @param stack + * @param srcProfile * @return * @throws DefinitionException * @throws DefinitionException * @throws IOException * @throws FHIRException */ - private boolean sliceMatches(ValidatorHostContext hostContext, Element element, String path, ElementDefinition slicer, ElementDefinition ed, StructureDefinition profile, List errors, List sliceInfo, NodeStack stack) throws DefinitionException, FHIRException { + private boolean sliceMatches(ValidatorHostContext hostContext, Element element, String path, ElementDefinition slicer, ElementDefinition ed, StructureDefinition profile, List errors, List sliceInfo, NodeStack stack, StructureDefinition srcProfile) throws DefinitionException, FHIRException { if (!slicer.getSlicing().hasDiscriminator()) return false; // cannot validate in this case @@ -3584,7 +3585,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat String discriminator = s.getPath(); discriminators.add(discriminator); - List criteriaElements = getCriteriaForDiscriminator(path, ed, discriminator, profile, s.getType() == DiscriminatorType.PROFILE); + List criteriaElements = getCriteriaForDiscriminator(path, ed, discriminator, profile, s.getType() == DiscriminatorType.PROFILE, srcProfile); boolean found = false; for (ElementDefinition criteriaElement : criteriaElements) { found = true; @@ -4965,7 +4966,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } else { if (nameMatches(ei.getName(), tail(ed.getPath()))) try { - match = sliceMatches(hostContext, ei.getElement(), ei.getPath(), slicer, ed, profile, errors, sliceInfo, stack); + match = sliceMatches(hostContext, ei.getElement(), ei.getPath(), slicer, ed, profile, errors, sliceInfo, stack, profile); if (match) { ei.slice = slicer;