Search in sources :

Example 1 with InstanceValidatorFactory

use of org.hl7.fhir.validation.instance.InstanceValidatorFactory in project org.hl7.fhir.core by hapifhir.

the class R3R4ConversionTests method checkLoad.

/*
   * Supporting multiple versions at once is a little tricky. We're going to have
   * 2 contexts: - an R3 context which is used to read/write R3 instances - an R4
   * context which is used to perform the transforms
   *
   * R3 structure definitions are cloned into R3 context with a modified URL (as
   * 3.0/)
   *
   */
private void checkLoad() throws IOException, FHIRException, Exception {
    if (contextR3 != null)
        return;
    pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
    System.out.println("loading R3");
    contextR3 = new SimpleWorkerContext();
    contextR3.setAllowLoadingDuplicates(true);
    contextR3.setOverrideVersionNs("http://hl7.org/fhir/3.0/StructureDefinition");
    contextR3.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "3.0.1"), ldr, new String[] {});
    System.out.println("loading R4");
    contextR4 = new SimpleWorkerContext();
    contextR4 = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
    contextR4.setCanRunWithoutTerminology(true);
    for (StructureDefinition sd : contextR3.allStructures()) {
        StructureDefinition sdn = sd.copy();
        sdn.getExtension().clear();
        contextR4.cacheResource(sdn);
    }
    for (StructureDefinition sd : contextR4.allStructures()) {
        if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
            contextR3.cacheResource(sd);
            StructureDefinition sdn = sd.copy();
            sdn.setUrl(sdn.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
            sdn.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
            contextR3.cacheResource(sdn);
            contextR4.cacheResource(sdn);
        }
    }
    contextR3.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
    contextR4.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
    contextR3.setName("R3");
    contextR4.setName("R4");
    // contextR4.setValidatorFactory(new InstanceValidatorFactory());
    // TODO: this has to be R% now...    contextR4.setValidatorFactory(new InstanceValidatorFactory());
    System.out.println("loading Maps");
    loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R4toR3"));
    loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R3toR4"));
    System.out.println("loaded");
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) SimpleWorkerContext(org.hl7.fhir.r4.context.SimpleWorkerContext) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) UriType(org.hl7.fhir.r4.model.UriType)

Example 2 with InstanceValidatorFactory

use of org.hl7.fhir.validation.instance.InstanceValidatorFactory 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)

Aggregations

R3ToR4Loader (org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader)1 SimpleWorkerContext (org.hl7.fhir.r4.context.SimpleWorkerContext)1 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)1 UriType (org.hl7.fhir.r4.model.UriType)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)1 InstanceValidatorFactory (org.hl7.fhir.validation.instance.InstanceValidatorFactory)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1