use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class SnapShotGenerationXTests method test.
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String id, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
version = test.version;
this.context = context;
if (fp == null)
fp = new FHIRPathEngine(UtilitiesXTests.context(version));
fp.setHostServices(context);
messages = new ArrayList<ValidationMessage>();
if (test.isFail()) {
try {
if (test.isGen())
testGen(true, test);
else
testSort(test);
Assertions.assertTrue(false, "Should have failed");
} catch (Throwable e) {
System.out.println("Error running test: " + e.getMessage());
if (!Utilities.noString(test.regex)) {
Assertions.assertTrue(e.getMessage().matches(test.regex), "correct error message");
} else if ("Should have failed".equals(e.getMessage())) {
throw e;
} else {
Assertions.assertTrue(true, "all ok");
}
}
} else if (test.isGen())
testGen(false, test);
else
testSort(test);
for (Rule r : test.getRules()) {
StructureDefinition sdn = new StructureDefinition();
boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
Assertions.assertTrue(ok, r.description);
}
}
use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project kindling by HL7.
the class ExampleInspector method prepare.
public void prepare() throws Exception {
validator = new InstanceValidator(context, hostServices, null);
validator.setSuppressLoincSnomedMessages(true);
validator.setResourceIdRule(IdStatus.REQUIRED);
validator.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
validator.getExtensionDomains().add("http://hl7.org/fhir/us");
validator.setFetcher(this);
validator.setAllowExamples(true);
validator.setDebug(false);
xml = new XmlValidator(errorsInt, loadSchemas(), loadTransforms());
if (VALIDATE_BY_JSON_SCHEMA) {
String source = TextFile.fileToString(Utilities.path(rootDir, "fhir.schema.json"));
JSONObject rawSchema = new JSONObject(new JSONTokener(source));
jschema = SchemaLoader.load(rawSchema);
}
if (VALIDATE_RDF) {
shex = new ShExValidator(Utilities.path(rootDir, "fhir.shex"));
}
fpe = new FHIRPathEngine(context);
checkJsonLd();
}
use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class CDARoundTripTests method setUp.
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
// System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
}
use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
public OperationOutcome validate(String location, byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationRecord> record) throws FHIRException, IOException, EOperationOutcome, SAXException {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
if (doNative) {
SchemaValidator.validateSchema(location, cntType, messages);
}
InstanceValidator validator = getValidator(cntType);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
if (showTimes) {
System.out.println(location + ": " + validator.reportTimes());
}
if (record != null) {
record.add(new ValidationRecord(location, messages));
}
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
public OperationOutcome validate(String location, byte[] source, FhirFormat cntType, List<String> profiles, IdStatus resourceIdRule, boolean anyExtensionsAllowed, BestPracticeWarningLevel bpWarnings, CheckDisplayOption displayOption) throws FHIRException, IOException, EOperationOutcome, SAXException {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
if (doNative) {
SchemaValidator.validateSchema(location, cntType, messages);
}
InstanceValidator validator = getValidator(cntType);
validator.setResourceIdRule(resourceIdRule);
validator.setBestPracticeWarningLevel(bpWarnings);
validator.setCheckDisplay(displayOption);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
Aggregations