Search in sources :

Example 16 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.

the class UtilitiesXTests method context.

public static IWorkerContext context(String version) {
    if (fcontexts == null) {
        fcontexts = new HashMap<>();
    }
    if (!fcontexts.containsKey(version)) {
        FilesystemPackageCacheManager pcm;
        try {
            pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
            IWorkerContext fcontext = TestingUtilities.getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
            fcontext.setUcumService(new UcumEssenceService(UtilitiesXTests.loadTestResourceStream("ucum", "ucum-essence.xml")));
            fcontext.setExpansionProfile(new Parameters());
            fcontexts.put(version, fcontext);
        } catch (Exception e) {
            throw new Error(e);
        }
    }
    return fcontexts.get(version);
}
Also used : UcumEssenceService(org.fhir.ucum.UcumEssenceService) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) IWorkerContext(org.hl7.fhir.r5.context.IWorkerContext) Parameters(org.hl7.fhir.r5.model.Parameters) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 17 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager 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 18 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager 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 19 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager 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 = SimpleWorkerContext.fromPackage(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);
        }
    }
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) FHIRPathEngine(org.hl7.fhir.r4b.utils.FHIRPathEngine) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 20 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.

the class PackageCacheTests method testPatchWildCard.

@Test
public void testPatchWildCard() throws IOException {
    FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    cache.clear();
    Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.0").version(), "3.1.0");
    Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.1").version(), "3.1.1");
    Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.x").version(), "3.1.1");
    Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.0.x").version(), "3.0.1");
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) Test(org.junit.jupiter.api.Test)

Aggregations

FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)34 NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)13 IOException (java.io.IOException)9 BeforeAll (org.junit.jupiter.api.BeforeAll)8 FileNotFoundException (java.io.FileNotFoundException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 Test (org.junit.jupiter.api.Test)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 ArrayList (java.util.ArrayList)4 UcumEssenceService (org.fhir.ucum.UcumEssenceService)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 R3ToR4Loader (org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader)2