validate fixed/pattern types
This commit is contained in:
parent
9d822536c3
commit
034f2fe630
|
@ -100,6 +100,8 @@ import org.hl7.fhir.utilities.Utilities;
|
||||||
import org.hl7.fhir.utilities.VersionUtilities;
|
import org.hl7.fhir.utilities.VersionUtilities;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationOptions;
|
import org.hl7.fhir.utilities.validation.ValidationOptions;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
|
||||||
|
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
|
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
|
||||||
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
|
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
|
||||||
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell;
|
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell;
|
||||||
|
@ -2374,6 +2376,27 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
dest.addExtension(ex.copy());
|
dest.addExtension(ex.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dest.hasFixed()) {
|
||||||
|
checkTypeOk(dest, dest.getFixed().fhirType());
|
||||||
|
}
|
||||||
|
if (dest.hasPattern()) {
|
||||||
|
checkTypeOk(dest, dest.getPattern().fhirType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void checkTypeOk(ElementDefinition dest, String ft) {
|
||||||
|
boolean ok = false;
|
||||||
|
Set<String> types = new HashSet<>();
|
||||||
|
for (TypeRefComponent t : dest.getType()) {
|
||||||
|
if (t.hasCode()) {
|
||||||
|
types.add(t.getWorkingCode());
|
||||||
|
}
|
||||||
|
ok = ft.equals(t.getWorkingCode());
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.CONFLICT, dest.getId(), "The fixed value has type '"+ft+"' which is not valid (valid "+Utilities.pluralize("type", dest.getType().size())+": "+types.toString()+")", IssueSeverity.ERROR));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasBindableType(ElementDefinition ed) {
|
private boolean hasBindableType(ElementDefinition ed) {
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.hl7.fhir.r5.utils.NarrativeGenerator;
|
||||||
import org.hl7.fhir.utilities.TextFile;
|
import org.hl7.fhir.utilities.TextFile;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
|
||||||
import org.hl7.fhir.utilities.xml.XMLUtil;
|
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -413,19 +414,23 @@ public class SnapShotGenerationTests {
|
||||||
if (test.isFail()) {
|
if (test.isFail()) {
|
||||||
try {
|
try {
|
||||||
if (test.isGen())
|
if (test.isGen())
|
||||||
testGen();
|
testGen(true);
|
||||||
else
|
else
|
||||||
testSort();
|
testSort();
|
||||||
Assert.assertTrue("Should have failed", false);
|
Assert.assertTrue("Should have failed", false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (!Utilities.noString(test.regex))
|
System.out.println("Error running test: "+e.getMessage());
|
||||||
|
if (!Utilities.noString(test.regex)) {
|
||||||
Assert.assertTrue("correct error message", e.getMessage().matches(test.regex));
|
Assert.assertTrue("correct error message", e.getMessage().matches(test.regex));
|
||||||
else
|
} else if ("Should have failed".equals(e.getMessage())) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
Assert.assertTrue("all ok", true);
|
Assert.assertTrue("all ok", true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (test.isGen())
|
} else if (test.isGen())
|
||||||
testGen();
|
testGen(false);
|
||||||
else
|
else
|
||||||
testSort();
|
testSort();
|
||||||
for (Rule r : test.getRules()) {
|
for (Rule r : test.getRules()) {
|
||||||
|
@ -450,7 +455,7 @@ public class SnapShotGenerationTests {
|
||||||
Assert.assertTrue("Output does not match expected", test.expected.equalsDeep(test.output));
|
Assert.assertTrue("Output does not match expected", test.expected.equalsDeep(test.output));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testGen() throws Exception {
|
private void testGen(boolean fail) throws Exception {
|
||||||
if (!Utilities.noString(test.register)) {
|
if (!Utilities.noString(test.register)) {
|
||||||
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
|
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
|
||||||
pu.setNewSlicingProcessing(true);
|
pu.setNewSlicingProcessing(true);
|
||||||
|
@ -479,25 +484,37 @@ public class SnapShotGenerationTests {
|
||||||
throw new FHIRException("Sort failed: "+errors.toString());
|
throw new FHIRException("Sort failed: "+errors.toString());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
messages.clear();
|
||||||
pu.generateSnapshot(base, output, test.getSource().getUrl(), "http://test.org/profile", test.getSource().getName());
|
pu.generateSnapshot(base, output, test.getSource().getUrl(), "http://test.org/profile", test.getSource().getName());
|
||||||
|
List<ValidationMessage> ml = new ArrayList<>();
|
||||||
|
for (ValidationMessage vm : messages) {
|
||||||
|
if (vm.getLevel() == IssueSeverity.ERROR) {
|
||||||
|
ml.add(vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ml.size() > 0) {
|
||||||
|
throw new FHIRException("Snapshot Generation failed: "+ml.toString());
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
System.out.println("\r\nException: "+e.getMessage());
|
System.out.println("\r\nException: "+e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
if (output.getDifferential().hasElement())
|
if (output.getDifferential().hasElement())
|
||||||
new NarrativeGenerator("", "http://hl7.org/fhir", TestingUtilities.context()).setPkp(new TestPKP()).generate(output, null);
|
new NarrativeGenerator("", "http://hl7.org/fhir", TestingUtilities.context()).setPkp(new TestPKP()).generate(output, null);
|
||||||
test.output = output;
|
if (!fail) {
|
||||||
TestingUtilities.context().cacheResource(output);
|
test.output = output;
|
||||||
File dst = new File(TestingUtilities.tempFile("snapshot", test.getId()+"-expected.xml"));
|
TestingUtilities.context().cacheResource(output);
|
||||||
if (dst.exists())
|
File dst = new File(TestingUtilities.tempFile("snapshot", test.getId()+"-expected.xml"));
|
||||||
dst.delete();
|
if (dst.exists())
|
||||||
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId()+"-expected.xml"), new FileOutputStream(dst));
|
dst.delete();
|
||||||
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId()+"-actual.xml")), output);
|
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId()+"-expected.xml"), new FileOutputStream(dst));
|
||||||
StructureDefinition t1 = test.expected.copy();
|
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId()+"-actual.xml")), output);
|
||||||
t1.setText(null);
|
StructureDefinition t1 = test.expected.copy();
|
||||||
StructureDefinition t2 = test.output.copy();
|
t1.setText(null);
|
||||||
t2.setText(null);
|
StructureDefinition t2 = test.output.copy();
|
||||||
Assert.assertTrue("Output does not match expected", t1.equalsDeep(t2));
|
t2.setText(null);
|
||||||
|
Assert.assertTrue("Output does not match expected", t1.equalsDeep(t2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StructureDefinition getSD(String url) throws DefinitionException, FHIRException, IOException {
|
private StructureDefinition getSD(String url) throws DefinitionException, FHIRException, IOException {
|
||||||
|
|
|
@ -32,7 +32,7 @@ call git commit -a -m "Release new version %newver%-SNAPSHOT"
|
||||||
call git push origin master
|
call git push origin master
|
||||||
cd ..\org.hl7.fhir.core
|
cd ..\org.hl7.fhir.core
|
||||||
call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v%newver%-SNAPSHOT released. New Validator at https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=%newver%-SNAPSHOT&e=jar, and also deployed at https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar" --config-file zuliprc
|
call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v%newver%-SNAPSHOT released. New Validator at https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=%newver%-SNAPSHOT&e=jar, and also deployed at https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar" --config-file zuliprc
|
||||||
call python c:\tools\zulip-api\zulip\zulip\send.py --stream tooling/releases --subject "Validator" -m "New Java Validator released (v%newver%) at https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar (and, for maven users, https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots&g=ca.uhn.hapi.fhir&a=org.hl7.fhir.validation.cli&v=%newver%-SNAPSHOT&e=jar" --config-file zuliprc
|
call python c:\tools\zulip-api\zulip\zulip\send.py --stream tooling/releases --subject "Validator" -m "New Validator @ https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.validator.jar (v%newver%)" --config-file zuliprc
|
||||||
|
|
||||||
:DONE
|
:DONE
|
||||||
echo ===============================================================
|
echo ===============================================================
|
||||||
|
|
Loading…
Reference in New Issue