Search in sources :

Example 6 with PackageVersion

use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.

the class ValidationEngine method loadCoreDefinitions.

/**
 * @param src
 * @param recursive
 * @param terminologyCachePath
 * @param userAgent
 * @param tt
 * @param loggingService
 * @throws FHIRException
 * @throws IOException
 *
 * @see IgLoader#loadIgSource(String, boolean, boolean) loadIgSource for detailed description of the src parameter
 */
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt, IWorkerContext.ILoggingService loggingService) throws FHIRException, IOException {
    NpmPackage npm = getPcm().loadPackage(src, null);
    if (npm != null) {
        version = npm.fhirVersion();
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
    } else {
        Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
        if (version == null) {
            version = getVersionFromPack(source);
        }
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src, new Date()));
        ValidatorUtils.grabNatives(getBinaries(), source, "http://hl7.org/fhir");
    }
    // on https://chat.fhir.org/#narrow/stream/179167-hapi
    try {
        ClassLoader classLoader = ValidationEngine.class.getClassLoader();
        InputStream ue = classLoader.getResourceAsStream("ucum-essence.xml");
        context.setUcumService(new UcumEssenceService(ue));
    } catch (Exception e) {
        throw new FHIRException("Error loading UCUM from embedded ucum-essence.xml: " + e.getMessage(), e);
    }
    initContext(tt);
}
Also used : SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext) PackageVersion(org.hl7.fhir.r5.context.IWorkerContext.PackageVersion) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UcumEssenceService(org.fhir.ucum.UcumEssenceService) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 7 with PackageVersion

use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.

the class CanonicalResourceManagerTests method testUTG2.

@Test
public void testUTG2() {
    CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(false);
    ValueSet vs1 = new ValueSet();
    vs1.setId("234");
    vs1.setUrl("http://terminology.hl7.org/ValueSet/234");
    vs1.setVersion("2.0.0");
    vs1.setName("1");
    ValueSet vs2 = new ValueSet();
    vs2.setId("234");
    vs2.setUrl("http://terminology.hl7.org/ValueSet/234");
    vs2.setVersion("2000.0.0");
    vs2.setName("2");
    mrm.see(vs1, new PackageVersion("hl7.fhir.r4.core", "4.0.1"));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
    Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
    mrm.see(vs2, new PackageVersion("hl7.terminology.r4", "4.0.1"));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
    Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
    // this will get dropped completely because of UTG rules
    Assertions.assertNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
}
Also used : CanonicalResourceManager(org.hl7.fhir.r4b.context.CanonicalResourceManager) ValueSet(org.hl7.fhir.r4b.model.ValueSet) PackageVersion(org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion) Test(org.junit.jupiter.api.Test)

Example 8 with PackageVersion

use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.

the class CanonicalResourceManagerTests method testUTG2.

@Test
public void testUTG2() {
    CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(false);
    ValueSet vs1 = new ValueSet();
    vs1.setId("234");
    vs1.setUrl("http://terminology.hl7.org/ValueSet/234");
    vs1.setVersion("2.0.0");
    vs1.setName("1");
    ValueSet vs2 = new ValueSet();
    vs2.setId("234");
    vs2.setUrl("http://terminology.hl7.org/ValueSet/234");
    vs2.setVersion("2000.0.0");
    vs2.setName("2");
    mrm.see(vs1, new PackageVersion("hl7.fhir.r4.core", "4.0.1", new Date()));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
    Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
    mrm.see(vs2, new PackageVersion("hl7.terminology.r4", "4.0.1", new Date()));
    Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
    Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
    // this will get dropped completely because of UTG rules
    Assertions.assertNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
}
Also used : CanonicalResourceManager(org.hl7.fhir.r5.context.CanonicalResourceManager) ValueSet(org.hl7.fhir.r5.model.ValueSet) PackageVersion(org.hl7.fhir.r5.context.IWorkerContext.PackageVersion) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with PackageVersion

use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method cacheResourceFromPackage.

public void cacheResourceFromPackage(Resource r, PackageVersion packageInfo) throws FHIRException {
    synchronized (lock) {
        Map<String, ResourceProxy> map = allResourcesById.get(r.fhirType());
        if (map == null) {
            map = new HashMap<String, ResourceProxy>();
            allResourcesById.put(r.fhirType(), map);
        }
        if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
            map.put(r.getId(), new ResourceProxy(r));
        } else {
            System.out.println("Ignore " + r.fhirType() + "/" + r.getId() + " from package " + packageInfo.toString());
        }
        if (r instanceof CodeSystem || r instanceof NamingSystem) {
            oidCache.clear();
        }
        if (r instanceof CanonicalResource) {
            CanonicalResource m = (CanonicalResource) r;
            String url = m.getUrl();
            if (!allowLoadingDuplicates && hasResource(r.getClass(), url)) {
                // spcial workaround for known problems with existing packages
                if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
                    return;
                }
                throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
            }
            if (r instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) m;
                if ("1.4.0".equals(version)) {
                    fixOldSD(sd);
                }
                structures.see(sd, packageInfo);
            } else if (r instanceof ValueSet) {
                valueSets.see((ValueSet) m, packageInfo);
            } else if (r instanceof CodeSystem) {
                CodeSystemUtilities.crossLinkCodeSystem((CodeSystem) r);
                codeSystems.see((CodeSystem) m, packageInfo);
            } else if (r instanceof ImplementationGuide) {
                guides.see((ImplementationGuide) m, packageInfo);
            } else if (r instanceof CapabilityStatement) {
                capstmts.see((CapabilityStatement) m, packageInfo);
            } else if (r instanceof Measure) {
                measures.see((Measure) m, packageInfo);
            } else if (r instanceof Library) {
                libraries.see((Library) m, packageInfo);
            } else if (r instanceof SearchParameter) {
                searchParameters.see((SearchParameter) m, packageInfo);
            } else if (r instanceof PlanDefinition) {
                plans.see((PlanDefinition) m, packageInfo);
            } else if (r instanceof OperationDefinition) {
                operations.see((OperationDefinition) m, packageInfo);
            } else if (r instanceof Questionnaire) {
                questionnaires.see((Questionnaire) m, packageInfo);
            } else if (r instanceof ConceptMap) {
                maps.see((ConceptMap) m, packageInfo);
            } else if (r instanceof StructureMap) {
                transforms.see((StructureMap) m, packageInfo);
            } else if (r instanceof NamingSystem) {
                systems.see((NamingSystem) m, packageInfo);
            }
        }
    }
}
Also used : Questionnaire(org.hl7.fhir.r4b.model.Questionnaire) ImplementationGuide(org.hl7.fhir.r4b.model.ImplementationGuide) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy) StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) NamingSystem(org.hl7.fhir.r4b.model.NamingSystem) CapabilityStatement(org.hl7.fhir.r4b.model.CapabilityStatement) Measure(org.hl7.fhir.r4b.model.Measure) PlanDefinition(org.hl7.fhir.r4b.model.PlanDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) Library(org.hl7.fhir.r4b.model.Library) SearchParameter(org.hl7.fhir.r4b.model.SearchParameter) ConceptMap(org.hl7.fhir.r4b.model.ConceptMap) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) ValueSet(org.hl7.fhir.r4b.model.ValueSet) OperationDefinition(org.hl7.fhir.r4b.model.OperationDefinition)

Example 10 with PackageVersion

use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method registerResourceFromPackage.

public void registerResourceFromPackage(CanonicalResourceProxy r, PackageVersion packageInfo) throws FHIRException {
    synchronized (lock) {
        Map<String, ResourceProxy> map = allResourcesById.get(r.getType());
        if (map == null) {
            map = new HashMap<String, ResourceProxy>();
            allResourcesById.put(r.getType(), map);
        }
        if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
            map.put(r.getId(), new ResourceProxy(r));
        }
        String url = r.getUrl();
        if (!allowLoadingDuplicates && hasResource(r.getType(), url)) {
            // spcial workaround for known problems with existing packages
            if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
                return;
            }
            throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
        }
        switch(r.getType()) {
            case "StructureDefinition":
                if ("1.4.0".equals(version)) {
                    StructureDefinition sd = (StructureDefinition) r.getResource();
                    fixOldSD(sd);
                }
                structures.register(r, packageInfo);
                break;
            case "ValueSet":
                valueSets.register(r, packageInfo);
                break;
            case "CodeSystem":
                codeSystems.register(r, packageInfo);
                break;
            case "ImplementationGuide":
                guides.register(r, packageInfo);
                break;
            case "CapabilityStatement":
                capstmts.register(r, packageInfo);
                break;
            case "Measure":
                measures.register(r, packageInfo);
                break;
            case "Library":
                libraries.register(r, packageInfo);
                break;
            case "SearchParameter":
                searchParameters.register(r, packageInfo);
                break;
            case "PlanDefinition":
                plans.register(r, packageInfo);
                break;
            case "OperationDefinition":
                operations.register(r, packageInfo);
                break;
            case "Questionnaire":
                questionnaires.register(r, packageInfo);
                break;
            case "ConceptMap":
                maps.register(r, packageInfo);
                break;
            case "StructureMap":
                transforms.register(r, packageInfo);
                break;
            case "NamingSystem":
                systems.register(r, packageInfo);
                break;
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 PackageVersion (org.hl7.fhir.r5.context.IWorkerContext.PackageVersion)3 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2 ResourceProxy (org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)2 CanonicalResourceProxy (org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy)2 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2 ValueSet (org.hl7.fhir.r4b.model.ValueSet)2 CanonicalResourceProxy (org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy)2 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 ValueSet (org.hl7.fhir.r5.model.ValueSet)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1