use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ComparisonService method doLeftRightComparison.
public static void doLeftRightComparison(String[] args, String dest, ValidationEngine validator) throws IOException, FHIRException, EOperationOutcome {
// ok now set up the comparison
String left = Params.getParam(args, Params.LEFT);
String right = Params.getParam(args, Params.RIGHT);
Resource resLeft = validator.getContext().fetchResource(Resource.class, left);
Resource resRight = validator.getContext().fetchResource(Resource.class, right);
if (resLeft == null) {
System.out.println("Unable to locate left resource " + left);
}
if (resRight == null) {
System.out.println("Unable to locate right resource " + right);
}
if (resLeft != null && resRight != null) {
if (resLeft instanceof StructureDefinition && resRight instanceof StructureDefinition) {
ComparisonService.compareStructureDefinitions(dest, validator, left, right, (StructureDefinition) resLeft, (StructureDefinition) resRight);
} else if (resLeft instanceof CapabilityStatement && resRight instanceof CapabilityStatement) {
ComparisonService.compareCapabilityStatements(args, dest, validator, left, right, (CanonicalResource) resLeft, (CanonicalResource) resRight);
} else
System.out.println("Unable to compare left resource " + left + " (" + resLeft.fhirType() + ") with right resource " + right + " (" + resRight.fhirType() + ")");
}
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class StructureMappingTests method setUp.
@BeforeAll
public static void setUp() throws Exception {
validationEngine = new ValidationEngine.ValidationEngineBuilder().fromSource("hl7.fhir.r4.core#4.0.1");
context = validationEngine.getContext();
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);
}
}
if (context.getValidatorFactory() == null) {
context.setValidatorFactory(new InstanceValidatorFactory());
}
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class SessionCacheTest method sessionExists.
@Test
@DisplayName("test session exists")
void sessionExists() throws IOException {
SessionCache cache = new SessionCache();
ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
String sessionId = cache.cacheSession(testEngine);
Assertions.assertTrue(cache.sessionExists(sessionId));
Assertions.assertFalse(cache.sessionExists(UUID.randomUUID().toString()));
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class LoadIgTests method testLoad.
@Test
public void testLoad() {
String id = "hl7.fhir.r4.core";
String version = "4.0.1";
int DO_TIMES = 10;
try {
final String fhirSpecVersion = "4.0";
final String definitions = VersionUtilities.packageForVersion(fhirSpecVersion) + "#" + VersionUtilities.getCurrentVersion(fhirSpecVersion);
ValidationEngine hl7Validator = new ValidationEngine.ValidationEngineBuilder().fromSource(definitions);
hl7Validator.setDoNative(false);
hl7Validator.setAnyExtensionsAllowed(true);
hl7Validator.prepare();
IgLoader igLoader = new IgLoader(hl7Validator.getPcm(), hl7Validator.getContext(), hl7Validator.getVersion(), true);
// yes the choice of R5 is deliberate here - it's the same content as R4.
byte[] b = TextFile.streamToBytes(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", "t34-expected.xml"));
for (int i = 0; i < DO_TIMES; i++) {
System.gc();
for (int j = 0; j < 100; j++) {
igLoader.loadResourceByVersion("4.0.1", b, "resource.xml");
}
System.out.print("loading: allocated memory " + getUsedMemoryAsMbs() + " MB, ");
System.out.print("free memory " + getFreeMemoryAsMbs() + " MB, ");
System.out.println("max memory " + getTotalMemoryAsMbs() + " MB");
// The method under test:
igLoader.loadIg(hl7Validator.getIgs(), hl7Validator.getBinaries(), id + (version != null ? "#" + version : ""), true);
}
} catch (Exception e) {
e.printStackTrace();
}
// loadResourceByVersion
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationEngineTests method test102.
@Test
public void test102() throws Exception {
if (inbuild) {
Assertions.assertTrue(true);
return;
}
if (!org.hl7.fhir.validation.tests.utilities.TestUtilities.silent)
System.out.println("Test102: Validate patient-example.xml in v1.0.2 version");
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, FhirPublication.DSTU2, "1.0.2");
ve.setNoInvariantChecks(true);
CacheVerificationLogger logger = new CacheVerificationLogger();
ve.getContext().getTxClient().setLogger(logger);
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient102.xml"), null);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
System.out.println(" " + iss.getSeverity().toCode() + ": " + iss.getDetails().getText());
}
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assertions.assertEquals(1, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
if (!TestUtilities.silent)
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
Aggregations