Search in sources :

Example 21 with NamingSystem

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

the class RdfParser method composeNamingSystemNamingSystemUniqueIdComponent.

protected void composeNamingSystemNamingSystemUniqueIdComponent(Complex parent, String parentType, String name, NamingSystem.NamingSystemUniqueIdComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "uniqueId", name, element, index);
    if (element.hasTypeElement())
        composeEnum(t, "NamingSystem", "type", element.getTypeElement(), -1);
    if (element.hasValueElement())
        composeString(t, "NamingSystem", "value", element.getValueElement(), -1);
    if (element.hasPreferredElement())
        composeBoolean(t, "NamingSystem", "preferred", element.getPreferredElement(), -1);
    if (element.hasCommentElement())
        composeString(t, "NamingSystem", "comment", element.getCommentElement(), -1);
    if (element.hasPeriod())
        composePeriod(t, "NamingSystem", "period", element.getPeriod(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 22 with NamingSystem

use of org.hl7.fhir.r5.model.NamingSystem 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 23 with NamingSystem

use of org.hl7.fhir.r5.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.r4b.model.CodeSystem.ConceptPropertyComponent) Identifier(org.hl7.fhir.r4b.model.Identifier) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) NamingSystem(org.hl7.fhir.r4b.model.NamingSystem) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem)

Example 24 with NamingSystem

use of org.hl7.fhir.r5.model.NamingSystem 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 25 with NamingSystem

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

the class ComparisonTests method test.

@ParameterizedTest(name = "{index}: id {0}")
@MethodSource("data")
public void test(String name, JsonObject content) throws Exception {
    this.content = content;
    if (content.has("use-test") && !content.get("use-test").getAsBoolean())
        return;
    if (context == null) {
        System.out.println("---- Load R5 ----------------------------------------------------------------");
        context = TestingUtilities.getSharedWorkerContext();
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
        BaseWorkerContext bc = (BaseWorkerContext) context;
        boolean dupl = bc.isAllowLoadingDuplicates();
        bc.setAllowLoadingDuplicates(true);
        context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" }, new NullLoaderKnowledgeProviderR5(), context.getVersion()));
        bc.setAllowLoadingDuplicates(dupl);
    }
    if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
        System.out.println("---- Set up Output ----------------------------------------------------------");
        Utilities.createDirectory(Utilities.path("[tmp]", "comparison"));
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
        for (String f : npm.list("other")) {
            TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f));
        }
    }
    System.out.println("---- " + name + " ----------------------------------------------------------------");
    CanonicalResource left = load("left");
    CanonicalResource right = load("right");
    ComparisonSession session = new ComparisonSession(context, context, "Comparison Tests", null);
    if (left instanceof CodeSystem && right instanceof CodeSystem) {
        CodeSystemComparer cs = new CodeSystemComparer(session);
        CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
        Assertions.assertTrue(csc.getUnion().getConcept().size() > csc.getIntersection().getConcept().size());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderConcepts(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Concepts") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof ValueSet && right instanceof ValueSet) {
        ValueSetComparer cs = new ValueSetComparer(session);
        ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderCompose(csc, "", ""));
        String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Definition") + xml2 + BREAK + hd("Expansion") + xml3 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
        ProfileUtilities utils = new ProfileUtilities(context, null, null);
        genSnapshot(utils, (StructureDefinition) left);
        genSnapshot(utils, (StructureDefinition) right);
        ProfileComparer pc = new ProfileComparer(session, utils, utils);
        ProfileComparison csc = pc.compare((StructureDefinition) left, (StructureDefinition) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStructure(csc, "", "", "http://hl7.org/fhir"));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof CapabilityStatement && right instanceof CapabilityStatement) {
        CapabilityStatementComparer pc = new CapabilityStatementComparer(session);
        CapabilityStatementComparison csc = pc.compare((CapabilityStatement) left, (CapabilityStatement) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStatements(csc, "", ""));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else {
        throw new FHIRException("Can't compare " + left.fhirType() + " to " + right.fhirType());
    }
}
Also used : ProfileComparison(org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison) ComparisonSession(org.hl7.fhir.r5.comparison.ComparisonSession) ProfileComparer(org.hl7.fhir.r5.comparison.ProfileComparer) BaseWorkerContext(org.hl7.fhir.r5.context.BaseWorkerContext) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CapabilityStatementComparison(org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) CapabilityStatementComparer(org.hl7.fhir.r5.comparison.CapabilityStatementComparer) ValueSet(org.hl7.fhir.r5.model.ValueSet) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeSystemComparer(org.hl7.fhir.r5.comparison.CodeSystemComparer) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) CodeSystemComparison(org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) R4ToR5Loader(org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader) FileOutputStream(java.io.FileOutputStream) ValueSetComparer(org.hl7.fhir.r5.comparison.ValueSetComparer) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) NullLoaderKnowledgeProviderR5(org.hl7.fhir.convertors.loaders.loaderR5.NullLoaderKnowledgeProviderR5) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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