Search in sources :

Example 16 with ValidationEngine

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() + ")");
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource)

Example 17 with ValidationEngine

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());
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) InstanceValidatorFactory(org.hl7.fhir.validation.instance.InstanceValidatorFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 18 with ValidationEngine

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()));
}
Also used : ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with ValidationEngine

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
}
Also used : IgLoader(org.hl7.fhir.validation.IgLoader) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.Test)

Example 20 with ValidationEngine

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");
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent) CacheVerificationLogger(org.hl7.fhir.utilities.tests.CacheVerificationLogger) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationEngine (org.hl7.fhir.validation.ValidationEngine)18 Test (org.junit.jupiter.api.Test)10 OperationOutcome (org.hl7.fhir.r5.model.OperationOutcome)7 CacheVerificationLogger (org.hl7.fhir.utilities.tests.CacheVerificationLogger)7 OperationOutcomeIssueComponent (org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent)6 IgLoader (org.hl7.fhir.validation.IgLoader)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DisplayName (org.junit.jupiter.api.DisplayName)3 IOException (java.io.IOException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 TimeTracker (org.hl7.fhir.utilities.TimeTracker)2 Test (org.junit.Test)2 File (java.io.File)1 PrintStream (java.io.PrintStream)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 ComparisonRenderer (org.hl7.fhir.r5.comparison.ComparisonRenderer)1 ComparisonSession (org.hl7.fhir.r5.comparison.ComparisonSession)1 SystemOutLoggingService (org.hl7.fhir.r5.context.SystemOutLoggingService)1