Search in sources :

Example 71 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource 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)

Example 72 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class ComparisonSession method compare.

public ResourceComparison compare(CanonicalResource left, CanonicalResource right) throws DefinitionException, FHIRFormatError, IOException {
    if (left != null && right != null) {
        String key = key(left.getUrl(), left.getVersion(), right.getUrl(), right.getVersion());
        if (compares.containsKey(key)) {
            // this can happen when profiles refer to each other
            return compares.get(key);
        }
        compares.put(key, null);
        try {
            if (left instanceof CodeSystem && right instanceof CodeSystem) {
                CodeSystemComparer cs = new CodeSystemComparer(this);
                CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
                compares.put(key, csc);
                return csc;
            } else if (left instanceof ValueSet && right instanceof ValueSet) {
                ValueSetComparer cs = new ValueSetComparer(this);
                ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
                compares.put(key, csc);
                return csc;
            } else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
                ProfileComparer cs = new ProfileComparer(this, new ProfileUtilities(contextLeft, null, pkp), new ProfileUtilities(contextRight, null, pkp));
                ProfileComparison csc = cs.compare((StructureDefinition) left, (StructureDefinition) right);
                compares.put(key, csc);
                return csc;
            } else {
                throw new FHIRException("Unable to compare resources of type " + left.fhirType() + " and " + right.fhirType());
            }
        } catch (Throwable e) {
            ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right, e);
            compares.put(key, csc);
            return csc;
        }
    } else if (left != null) {
        String key = key(left.getUrl(), left.getVersion(), left.getUrl(), left.getVersion());
        if (compares.containsKey(key)) {
            return compares.get(key);
        }
        ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
        compares.put(key, csc);
        return csc;
    } else {
        String key = key(right.getUrl(), right.getVersion(), right.getUrl(), right.getVersion());
        if (compares.containsKey(key)) {
            return compares.get(key);
        }
        ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
        compares.put(key, csc);
        return csc;
    }
}
Also used : ProfileComparison(org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison) ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CodeSystemComparison(org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)20 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)19 ArrayList (java.util.ArrayList)17 File (java.io.File)11 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)9 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)9 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)9 FileOutputStream (java.io.FileOutputStream)8 IOException (java.io.IOException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 Resource (org.hl7.fhir.r5.model.Resource)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 FileNotFoundException (java.io.FileNotFoundException)7 Resource (org.hl7.fhir.r4b.model.Resource)7 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)5 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 FileInputStream (java.io.FileInputStream)4