From cac82546dab0dccf20bb793d9b115cddf30271a5 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 1 Aug 2019 08:11:21 +1000 Subject: [PATCH] more snapshot generation tests and fixes --- .../org/hl7/fhir/r5/conformance/ProfileUtilities.java | 8 +++++++- .../org/hl7/fhir/r5/utils/OperationOutcomeUtilities.java | 4 ---- .../src/test/resources/snapshot-generation/manifest.xml | 3 ++- .../org/hl7/fhir/r5/validation/InstanceValidator.java | 7 ++++--- .../java/org/hl7/fhir/r5/validation/ValidationEngine.java | 7 +++++++ 5 files changed, 20 insertions(+), 9 deletions(-) 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 442945adc..14fd05d70 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 @@ -794,7 +794,13 @@ public class ProfileUtilities extends TranslatingUtilities { if (!ts.defn.hasSliceName()) ts.defn.setSliceName(tn); else if (!ts.defn.getSliceName().equals(tn)) - throw new FHIRException("Error at path "+(!Utilities.noString(contextPathSrc) ? contextPathSrc : cpath)+": Slice name must be '"+tn+"' but is '"+ts.defn.getSliceName()+"'"); + throw new FHIRException("Error at path "+(!Utilities.noString(contextPathSrc) ? contextPathSrc : cpath)+": Slice name must be '"+tn+"' but is '"+ts.defn.getSliceName()+"'"); + if (!ts.defn.hasType()) + ts.defn.addType().setCode(ts.type); + else if (ts.defn.getType().size() > 1) + throw new FHIRException("Error at path "+(!Utilities.noString(contextPathSrc) ? contextPathSrc : cpath)+": Slice for type '"+tn+"' has more than one type '"+ts.defn.typeSummary()+"'"); + else if (!ts.defn.getType().get(0).getCode().equals(ts.type)) + throw new FHIRException("Error at path "+(!Utilities.noString(contextPathSrc) ? contextPathSrc : cpath)+": Slice for type '"+tn+"' has wrong type '"+ts.defn.typeSummary()+"'"); } // ok passed the checks. diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/OperationOutcomeUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/OperationOutcomeUtilities.java index 8aa031214..07e521bb6 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/OperationOutcomeUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/OperationOutcomeUtilities.java @@ -41,10 +41,6 @@ public class OperationOutcomeUtilities { if (message.getLocation() != null) { // message location has a fhirPath in it. We need to populate the expression issue.addExpression(message.getLocation()); - // also, populate the XPath variant - StringType s = new StringType(); - s.setValue(Utilities.fhirPathToXPath(message.getLocation())+(message.getLine()>= 0 && message.getCol() >= 0 ? " (line "+Integer.toString(message.getLine())+", col"+Integer.toString(message.getCol())+")" : "") ); - issue.getLocation().add(s); } // pass through line/col if they're present if (message.getLine() != 0) diff --git a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/manifest.xml b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/manifest.xml index d28cca726..96db29194 100644 --- a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/manifest.xml +++ b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/manifest.xml @@ -221,7 +221,8 @@ - + + diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java index 3bcf4f27d..5b9879237 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java @@ -2665,9 +2665,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (discriminator.contains("[")) discriminator = discriminator.substring(0, discriminator.indexOf('[')); type = criteriaElement.getType().get(0).getCode(); - } - if (type==null) - throw new DefinitionException("Discriminator (" + discriminator + ") is based on type, but slice " + ed.getId() + " does not declare a type"); + } else if (criteriaElement.getType().size() > 1) { + throw new DefinitionException("Discriminator (" + discriminator + ") is based on type, but slice " + ed.getId() + " in "+profile.getUrl()+" has multiple types: "+criteriaElement.typeSummary()); + } else + throw new DefinitionException("Discriminator (" + discriminator + ") is based on type, but slice " + ed.getId() + " in "+profile.getUrl()+" has no types"); if (discriminator.isEmpty()) expression.append(" and this is " + type); else diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index 8468a916e..0458828c9 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -119,6 +119,7 @@ import org.hl7.fhir.r5.terminologies.ConceptMapEngine; import org.hl7.fhir.r5.utils.IResourceValidator.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.IResourceValidator.CheckDisplayOption; import org.hl7.fhir.r5.utils.IResourceValidator.IdStatus; +import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.NarrativeGenerator; import org.hl7.fhir.r5.utils.OperationOutcomeUtilities; import org.hl7.fhir.r5.utils.StructureMapUtilities; @@ -992,6 +993,12 @@ public class ValidationEngine { private OperationOutcome messagesToOutcome(List messages) throws DefinitionException { OperationOutcome op = new OperationOutcome(); for (ValidationMessage vm : filterMessages(messages)) { + FHIRPathEngine fpe = new FHIRPathEngine(context); + try { + fpe.parse(vm.getLocation()); + } catch (Exception e) { + System.out.println("Internal error in location for message: '"+e.getMessage()+"', loc = '"+vm.getLocation()+"', err = '"+vm.getMessage()+"'"); + } op.getIssue().add(OperationOutcomeUtilities.convertToIssue(vm, op)); } new NarrativeGenerator("", "", context).generate(null, op);