Search in sources :

Example 6 with ResourceProxy

use of org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy 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)

Example 7 with ResourceProxy

use of org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method fetchResourceWithException.

@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, CanonicalResource source) throws FHIRException {
    if (uri == null) {
        return null;
    }
    if (class_ == StructureDefinition.class) {
        uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
    }
    synchronized (lock) {
        if (uri.contains("|")) {
            version = uri.substring(uri.lastIndexOf("|") + 1);
            uri = uri.substring(0, uri.lastIndexOf("|"));
        }
        if (uri.contains("#")) {
            uri = uri.substring(0, uri.indexOf("#"));
        }
        if (class_ == Resource.class || class_ == null) {
            if (structures.has(uri)) {
                return (T) structures.get(uri, version);
            }
            if (guides.has(uri)) {
                return (T) guides.get(uri, version);
            }
            if (capstmts.has(uri)) {
                return (T) capstmts.get(uri, version);
            }
            if (measures.has(uri)) {
                return (T) measures.get(uri, version);
            }
            if (libraries.has(uri)) {
                return (T) libraries.get(uri, version);
            }
            if (valueSets.has(uri)) {
                return (T) valueSets.get(uri, version);
            }
            if (codeSystems.has(uri)) {
                return (T) codeSystems.get(uri, version);
            }
            if (operations.has(uri)) {
                return (T) operations.get(uri, version);
            }
            if (searchParameters.has(uri)) {
                return (T) searchParameters.get(uri, version);
            }
            if (plans.has(uri)) {
                return (T) plans.get(uri, version);
            }
            if (maps.has(uri)) {
                return (T) maps.get(uri, version);
            }
            if (transforms.has(uri)) {
                return (T) transforms.get(uri, version);
            }
            if (questionnaires.has(uri)) {
                return (T) questionnaires.get(uri, version);
            }
            if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
                return null;
            }
            // it might be a special URL.
            if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
                // findTxValueSet(uri);
                Resource res = null;
                if (res != null) {
                    return (T) res;
                }
            }
            for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
                for (ResourceProxy r : rt.values()) {
                    if (uri.equals(r.getUrl())) {
                        if (version == null || version == r.getResource().getMeta().getVersionId()) {
                            return (T) r.getResource();
                        }
                    }
                }
            }
            return null;
        } else if (class_ == ImplementationGuide.class) {
            return (T) guides.get(uri, version);
        } else if (class_ == CapabilityStatement.class) {
            return (T) capstmts.get(uri, version);
        } else if (class_ == Measure.class) {
            return (T) measures.get(uri, version);
        } else if (class_ == Library.class) {
            return (T) libraries.get(uri, version);
        } else if (class_ == StructureDefinition.class) {
            return (T) structures.get(uri, version);
        } else if (class_ == StructureMap.class) {
            return (T) transforms.get(uri, version);
        } else if (class_ == ValueSet.class) {
            return (T) valueSets.get(uri, version);
        } else if (class_ == CodeSystem.class) {
            return (T) codeSystems.get(uri, version);
        } else if (class_ == ConceptMap.class) {
            return (T) maps.get(uri, version);
        } else if (class_ == PlanDefinition.class) {
            return (T) plans.get(uri, version);
        } else if (class_ == OperationDefinition.class) {
            OperationDefinition od = operations.get(uri, version);
            return (T) od;
        } else if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        } else if (class_ == SearchParameter.class) {
            SearchParameter res = searchParameters.get(uri, version);
            return (T) res;
        }
        if (class_ == CodeSystem.class && codeSystems.has(uri)) {
            return (T) codeSystems.get(uri, version);
        }
        if (class_ == ValueSet.class && valueSets.has(uri)) {
            return (T) valueSets.get(uri, version);
        }
        if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        }
        if (supportedCodeSystems.contains(uri)) {
            return null;
        }
        throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r4b.model.ImplementationGuide) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) Measure(org.hl7.fhir.r4b.model.Measure) ConceptMap(org.hl7.fhir.r4b.model.ConceptMap) SearchParameter(org.hl7.fhir.r4b.model.SearchParameter) ValueSet(org.hl7.fhir.r4b.model.ValueSet) OperationDefinition(org.hl7.fhir.r4b.model.OperationDefinition)

Example 8 with ResourceProxy

use of org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method fetchResourceWithException.

@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, CanonicalResource source) throws FHIRException {
    if (uri == null) {
        return null;
    }
    if (class_ == StructureDefinition.class) {
        uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
    }
    synchronized (lock) {
        if (uri.contains("|")) {
            version = uri.substring(uri.lastIndexOf("|") + 1);
            uri = uri.substring(0, uri.lastIndexOf("|"));
        }
        if (uri.contains("#")) {
            uri = uri.substring(0, uri.indexOf("#"));
        }
        if (class_ == Resource.class || class_ == null) {
            if (structures.has(uri)) {
                return (T) structures.get(uri, version);
            }
            if (guides.has(uri)) {
                return (T) guides.get(uri, version);
            }
            if (capstmts.has(uri)) {
                return (T) capstmts.get(uri, version);
            }
            if (measures.has(uri)) {
                return (T) measures.get(uri, version);
            }
            if (libraries.has(uri)) {
                return (T) libraries.get(uri, version);
            }
            if (valueSets.has(uri)) {
                return (T) valueSets.get(uri, version);
            }
            if (codeSystems.has(uri)) {
                return (T) codeSystems.get(uri, version);
            }
            if (operations.has(uri)) {
                return (T) operations.get(uri, version);
            }
            if (searchParameters.has(uri)) {
                return (T) searchParameters.get(uri, version);
            }
            if (plans.has(uri)) {
                return (T) plans.get(uri, version);
            }
            if (maps.has(uri)) {
                return (T) maps.get(uri, version);
            }
            if (transforms.has(uri)) {
                return (T) transforms.get(uri, version);
            }
            if (questionnaires.has(uri)) {
                return (T) questionnaires.get(uri, version);
            }
            if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
                return null;
            }
            // it might be a special URL.
            if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
                // findTxValueSet(uri);
                Resource res = null;
                if (res != null) {
                    return (T) res;
                }
            }
            for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
                for (ResourceProxy r : rt.values()) {
                    if (uri.equals(r.getUrl())) {
                        if (version == null || version == r.getResource().getMeta().getVersionId()) {
                            return (T) r.getResource();
                        }
                    }
                }
            }
            return null;
        } else if (class_ == ImplementationGuide.class) {
            return (T) guides.get(uri, version);
        } else if (class_ == CapabilityStatement.class) {
            return (T) capstmts.get(uri, version);
        } else if (class_ == Measure.class) {
            return (T) measures.get(uri, version);
        } else if (class_ == Library.class) {
            return (T) libraries.get(uri, version);
        } else if (class_ == StructureDefinition.class) {
            return (T) structures.get(uri, version);
        } else if (class_ == StructureMap.class) {
            return (T) transforms.get(uri, version);
        } else if (class_ == ValueSet.class) {
            return (T) valueSets.get(uri, version);
        } else if (class_ == CodeSystem.class) {
            return (T) codeSystems.get(uri, version);
        } else if (class_ == ConceptMap.class) {
            return (T) maps.get(uri, version);
        } else if (class_ == PlanDefinition.class) {
            return (T) plans.get(uri, version);
        } else if (class_ == OperationDefinition.class) {
            OperationDefinition od = operations.get(uri, version);
            return (T) od;
        } else if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        } else if (class_ == SearchParameter.class) {
            SearchParameter res = searchParameters.get(uri, version);
            return (T) res;
        }
        if (class_ == CodeSystem.class && codeSystems.has(uri)) {
            return (T) codeSystems.get(uri, version);
        }
        if (class_ == ValueSet.class && valueSets.has(uri)) {
            return (T) valueSets.get(uri, version);
        }
        if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        }
        if (supportedCodeSystems.contains(uri)) {
            return null;
        }
        throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) CanonicalResourceProxy(org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Measure(org.hl7.fhir.r5.model.Measure) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) ValueSet(org.hl7.fhir.r5.model.ValueSet) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 ResourceProxy (org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)4 CanonicalResourceProxy (org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy)4 CanonicalResourceProxy (org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy)4 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)3 OperationDefinition (org.hl7.fhir.r4b.model.OperationDefinition)3 SearchParameter (org.hl7.fhir.r4b.model.SearchParameter)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)3 OperationDefinition (org.hl7.fhir.r5.model.OperationDefinition)3 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)2 ConceptMap (org.hl7.fhir.r4b.model.ConceptMap)2 ImplementationGuide (org.hl7.fhir.r4b.model.ImplementationGuide)2 Measure (org.hl7.fhir.r4b.model.Measure)2 Resource (org.hl7.fhir.r4b.model.Resource)2 ValueSet (org.hl7.fhir.r4b.model.ValueSet)2 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2