more snapshot generation tests and fixes

This commit is contained in:
Grahame Grieve 2019-08-01 08:11:21 +10:00
parent 613a7bd809
commit cac82546da
5 changed files with 20 additions and 9 deletions

View File

@ -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.

View File

@ -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)

View File

@ -221,7 +221,8 @@
<rule text="The element definition for value[x].value quantity slice should have sliceName = 'Quantity'" fhirpath="fixture('t44-output').snapshot.element.where(id = 'Observation.value[x]:valueQuantity.value').check(exists(), 'no slice').min = 1"/>
</test>
<test gen="true" id="samply1"/>
<test gen="true" id="au1" include="au1a"/>
<!-- <test gen="true" id="au1" include="au1a"/> -->
<test gen="true" id="au2"/>
<test gen="true" id="au3"/>
<test gen="true" id="dv1"/>
</snapshot-generation-tests>

View File

@ -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

View File

@ -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<ValidationMessage> 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);