Search in sources :

Example 31 with NamingSystem

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

the class BaseWorkerContext method oid2Uri.

@Override
public String oid2Uri(String oid) {
    synchronized (lock) {
        if (oid != null && oid.startsWith("urn:oid:")) {
            oid = oid.substring(8);
        }
        if (oidCache.containsKey(oid)) {
            return oidCache.get(oid);
        }
        String uri = OIDUtils.getUriForOid(oid);
        if (uri != null) {
            oidCache.put(oid, uri);
            return uri;
        }
        CodeSystem cs = fetchCodeSystem("http://terminology.hl7.org/CodeSystem/v2-tables");
        if (cs != null) {
            for (ConceptDefinitionComponent cc : cs.getConcept()) {
                for (ConceptPropertyComponent cp : cc.getProperty()) {
                    if (Utilities.existsInList(cp.getCode(), "v2-table-oid", "v2-cs-oid") && oid.equals(cp.getValue().primitiveValue())) {
                        for (ConceptPropertyComponent cp2 : cc.getProperty()) {
                            if ("v2-cs-uri".equals(cp2.getCode())) {
                                oidCache.put(oid, cp2.getValue().primitiveValue());
                                return cp2.getValue().primitiveValue();
                            }
                        }
                    }
                }
            }
        }
        for (CodeSystem css : codeSystems.getList()) {
            if (("urn:oid:" + oid).equals(css.getUrl())) {
                oidCache.put(oid, css.getUrl());
                return css.getUrl();
            }
            for (Identifier id : css.getIdentifier()) {
                if ("urn:ietf:rfc:3986".equals(id.getSystem()) && ("urn:oid:" + oid).equals(id.getValue())) {
                    oidCache.put(oid, css.getUrl());
                    return css.getUrl();
                }
            }
        }
        for (NamingSystem ns : systems.getList()) {
            if (hasOid(ns, oid)) {
                uri = getUri(ns);
                if (uri != null) {
                    oidCache.put(oid, null);
                    return null;
                }
            }
        }
    }
    oidCache.put(oid, null);
    return null;
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) Identifier(org.hl7.fhir.r5.model.Identifier) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) NamingSystem(org.hl7.fhir.r5.model.NamingSystem) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Example 32 with NamingSystem

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

the class SimpleWorkerContext method loadFromPackageInt.

public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws IOException, FHIRException {
    int t = 0;
    if (progress) {
        System.out.println("Load Package " + pi.name() + "#" + pi.version());
    }
    if (loadedPackages.contains(pi.id() + "#" + pi.version())) {
        return 0;
    }
    loadedPackages.add(pi.id() + "#" + pi.version());
    if ((types == null || types.length == 0) && loader != null) {
        types = loader.getTypes();
    }
    if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad()) {
        // can't lazy load R2 because of valueset/codesystem implementation
        if (types.length == 0) {
            types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
        }
        for (String s : pi.listResources(types)) {
            try {
                loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
                t++;
            } catch (Exception e) {
                throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
            }
        }
    } else {
        if (types.length == 0) {
            types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" };
        }
        for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
            if (!pri.getFilename().contains("ig-r4")) {
                try {
                    registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
                    t++;
                } catch (FHIRException e) {
                    throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
                }
            }
        }
    }
    for (String s : pi.list("other")) {
        binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
    }
    if (version == null) {
        version = pi.version();
    }
    return t;
}
Also used : PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)6 NamingSystem (org.hl7.fhir.r5.model.NamingSystem)6 Test (org.junit.jupiter.api.Test)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)4 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)3 CapabilityStatement (org.hl7.fhir.r5.model.CapabilityStatement)3 NamingSystemUniqueIdComponent (org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 File (java.io.File)2 TransformerException (javax.xml.transform.TransformerException)2