Search in sources :

Example 11 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class TestingUtilities method getWorkerContext.

public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage, IWorkerContext.IContextResourceLoader loader) throws Exception {
    SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage, loader);
    TerminologyCache.setCacheErrors(true);
    return swc;
}
Also used : SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext)

Example 12 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.SimpleWorkerContext 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 13 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class IgLoaderTests method testFailIfInvalidFHIRVersion.

@Test
public void testFailIfInvalidFHIRVersion() throws IOException {
    IgLoader igLoader = Mockito.spy(new IgLoader(filesystemPackageCacheManager, simpleWorkerContext, "4.0.1"));
    Exception exception = assertThrows(FHIRException.class, () -> {
        List<ImplementationGuide> igs = Collections.emptyList();
        igLoader.loadIg(igs, Collections.emptyMap(), "[0.1.2]" + DUMMY_PATH, false);
    });
    assertLinesMatch(Arrays.asList(".*Unsupported FHIR Version.*"), Arrays.asList(exception.getMessage()));
}
Also used : ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class TestingUtilities method context.

public static IWorkerContext context(String version) {
    if ("4.5.0".equals(version)) {
        // temporary work around
        version = "4.4.0";
    }
    String v = VersionUtilities.getMajMin(version);
    if (fcontexts == null) {
        fcontexts = new HashMap<>();
    }
    if (!fcontexts.containsKey(v)) {
        FilesystemPackageCacheManager pcm;
        try {
            pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
            IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
            fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
            fcontext.setExpansionProfile(new Parameters());
            // ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
            fcontexts.put(v, fcontext);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Error(e);
        }
    }
    return fcontexts.get(v);
}
Also used : UcumEssenceService(org.fhir.ucum.UcumEssenceService) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) IWorkerContext(org.hl7.fhir.r4b.context.IWorkerContext) Parameters(org.hl7.fhir.r4b.model.Parameters) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method fromClassPath.

public static SimpleWorkerContext fromClassPath(String name) throws IOException, FHIRException {
    InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
    SimpleWorkerContext res = new SimpleWorkerContext();
    res.loadFromStream(s, null);
    return res;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Aggregations

FileInputStream (java.io.FileInputStream)7 IOException (java.io.IOException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 ZipInputStream (java.util.zip.ZipInputStream)5 SimpleWorkerContext (org.hl7.fhir.r4.context.SimpleWorkerContext)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 FileOutputStream (java.io.FileOutputStream)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 SimpleWorkerContext (org.hl7.fhir.r5.context.SimpleWorkerContext)4 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)4 File (java.io.File)3 InputStream (java.io.InputStream)3 SimpleWorkerContext (org.hl7.fhir.dstu3.context.SimpleWorkerContext)3 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)3 HashMap (java.util.HashMap)2 XmlParser (org.hl7.fhir.dstu2016may.formats.XmlParser)2 Element (org.hl7.fhir.dstu2016may.metamodel.Element)2 Bundle (org.hl7.fhir.dstu2016may.model.Bundle)2 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)2