Search in sources :

Example 16 with IWorkerContext

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

the class TestingUtilities method context.

public static IWorkerContext context(String version) {
    if ("4.5.0".equals(version)) {
        // temporary work around
        version = "4.4.0";
    }
    String v = VersionUtilities.getMajMin(version);
    if (fcontexts == null) {
        fcontexts = new HashMap<>();
    }
    if (!fcontexts.containsKey(v)) {
        FilesystemPackageCacheManager pcm;
        try {
            pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
            IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
            fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
            fcontext.setExpansionProfile(new Parameters());
            // ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
            fcontexts.put(v, fcontext);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Error(e);
        }
    }
    return fcontexts.get(v);
}
Also used : UcumEssenceService(org.fhir.ucum.UcumEssenceService) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) IWorkerContext(org.hl7.fhir.r4b.context.IWorkerContext) Parameters(org.hl7.fhir.r4b.model.Parameters) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 17 with IWorkerContext

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

the class ProfileUtilities method makeExtensionForVersionedURL.

public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
    String epath = url.substring(54);
    if (!epath.contains("."))
        return null;
    String type = epath.substring(0, epath.indexOf("."));
    StructureDefinition sd = context.fetchTypeDefinition(type);
    if (sd == null)
        return null;
    ElementDefinition ed = null;
    for (ElementDefinition t : sd.getSnapshot().getElement()) {
        if (t.getPath().equals(epath)) {
            ed = t;
            break;
        }
    }
    if (ed == null)
        return null;
    if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
        return null;
    } else {
        StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
        StructureDefinition ext = template.copy();
        ext.setUrl(url);
        ext.setId("extension-" + epath);
        ext.setName("Extension-" + epath);
        ext.setTitle("Extension for r4 " + epath);
        ext.setStatus(sd.getStatus());
        ext.setDate(sd.getDate());
        ext.getContact().clear();
        ext.getContact().addAll(sd.getContact());
        ext.setFhirVersion(sd.getFhirVersion());
        ext.setDescription(ed.getDefinition());
        ext.getContext().clear();
        ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
        ext.getDifferential().getElement().clear();
        ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
        ext.getSnapshot().getElement().set(4, ed.copy());
        ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
        return ext;
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) UriType(org.hl7.fhir.r4.model.UriType)

Example 18 with IWorkerContext

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

the class ProfileComparer method checkAddTypeUnion.

private void checkAddTypeUnion(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, List<TypeRefComponent> results, TypeRefComponent nw, IWorkerContext ctxt) throws DefinitionException, IOException, FHIRFormatError {
    boolean pfound = false;
    boolean tfound = false;
    nw = nw.copy();
    if (nw.hasAggregation())
        throw new DefinitionException("Aggregation not supported: " + path);
    for (TypeRefComponent ex : results) {
        if (Utilities.equals(ex.getWorkingCode(), nw.getWorkingCode())) {
            if (!ex.hasProfile() && !nw.hasProfile())
                pfound = true;
            else if (!ex.hasProfile()) {
                pfound = true;
            } else if (!nw.hasProfile()) {
                pfound = true;
                ex.setProfile(null);
            } else {
                // both have profiles. Is one derived from the other?
                StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getProfile().get(0).getValue());
                StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getProfile().get(0).getValue());
                if (sdex != null && sdnw != null) {
                    if (sdex.getUrl().equals(sdnw.getUrl())) {
                        pfound = true;
                    } else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
                        ex.setProfile(nw.getProfile());
                        pfound = true;
                    } else if (derivesFrom(sdnw, sdex, ctxt)) {
                        pfound = true;
                    } else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
                        ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
                        if (compP != null && compP.getUnion() != null) {
                            // might be null if circular
                            pfound = true;
                            ex.addProfile("#" + compP.getId());
                        }
                    }
                }
            }
            if (!ex.hasTargetProfile() && !nw.hasTargetProfile())
                tfound = true;
            else if (!ex.hasTargetProfile()) {
                tfound = true;
            } else if (!nw.hasTargetProfile()) {
                tfound = true;
                ex.setTargetProfile(null);
            } else {
                // both have profiles. Is one derived from the other?
                StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getTargetProfile().get(0).getValue());
                StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getTargetProfile().get(0).getValue());
                if (sdex != null && sdnw != null) {
                    if (matches(sdex, sdnw)) {
                        tfound = true;
                    } else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
                        ex.setTargetProfile(nw.getTargetProfile());
                        tfound = true;
                    } else if (derivesFrom(sdnw, sdex, ctxt)) {
                        tfound = true;
                    } else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
                        ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
                        if (compP.getUnion() != null) {
                            tfound = true;
                            ex.addTargetProfile("#" + compP.getId());
                        }
                    }
                }
            }
        }
    }
    if (!tfound || !pfound) {
        nw.setUserData("ctxt", ctxt);
        results.add(nw);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) IWorkerContext(org.hl7.fhir.r5.context.IWorkerContext) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 19 with IWorkerContext

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

the class ProfileUtilities method makeExtensionForVersionedURL.

public static StructureDefinition makeExtensionForVersionedURL(IWorkerContext context, String url) {
    String epath = url.substring(54);
    if (!epath.contains("."))
        return null;
    String type = epath.substring(0, epath.indexOf("."));
    StructureDefinition sd = context.fetchTypeDefinition(type);
    if (sd == null)
        return null;
    ElementDefinition ed = null;
    for (ElementDefinition t : sd.getSnapshot().getElement()) {
        if (t.getPath().equals(epath)) {
            ed = t;
            break;
        }
    }
    if (ed == null)
        return null;
    if ("Element".equals(ed.typeSummary()) || "BackboneElement".equals(ed.typeSummary())) {
        return null;
    } else {
        StructureDefinition template = context.fetchResource(StructureDefinition.class, "http://fhir-registry.smarthealthit.org/StructureDefinition/capabilities");
        StructureDefinition ext = template.copy();
        ext.setUrl(url);
        ext.setId("extension-" + epath);
        ext.setName("Extension-" + epath);
        ext.setTitle("Extension for r4 " + epath);
        ext.setStatus(sd.getStatus());
        ext.setDate(sd.getDate());
        ext.getContact().clear();
        ext.getContact().addAll(sd.getContact());
        ext.setFhirVersion(sd.getFhirVersion());
        ext.setDescription(ed.getDefinition());
        ext.getContext().clear();
        ext.addContext().setType(ExtensionContextType.ELEMENT).setExpression(epath.substring(0, epath.lastIndexOf(".")));
        ext.getDifferential().getElement().clear();
        ext.getSnapshot().getElement().get(3).setFixed(new UriType(url));
        ext.getSnapshot().getElement().set(4, ed.copy());
        ext.getSnapshot().getElement().get(4).setPath("Extension.value" + Utilities.capitalize(ed.typeSummary()));
        return ext;
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) UriType(org.hl7.fhir.r4b.model.UriType)

Example 20 with IWorkerContext

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

the class ProfileComparer method checkAddTypeUnion.

private void checkAddTypeUnion(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, List<TypeRefComponent> results, TypeRefComponent nw, IWorkerContext ctxt) throws DefinitionException, IOException, FHIRFormatError {
    boolean pfound = false;
    boolean tfound = false;
    nw = nw.copy();
    if (nw.hasAggregation())
        throw new DefinitionException("Aggregation not supported: " + path);
    for (TypeRefComponent ex : results) {
        if (Utilities.equals(ex.getWorkingCode(), nw.getWorkingCode())) {
            if (!ex.hasProfile() && !nw.hasProfile())
                pfound = true;
            else if (!ex.hasProfile()) {
                pfound = true;
            } else if (!nw.hasProfile()) {
                pfound = true;
                ex.setProfile(null);
            } else {
                // both have profiles. Is one derived from the other?
                StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getProfile().get(0).getValue());
                StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getProfile().get(0).getValue());
                if (sdex != null && sdnw != null) {
                    if (sdex.getUrl().equals(sdnw.getUrl())) {
                        pfound = true;
                    } else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
                        ex.setProfile(nw.getProfile());
                        pfound = true;
                    } else if (derivesFrom(sdnw, sdex, ctxt)) {
                        pfound = true;
                    } else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
                        ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
                        if (compP != null && compP.getUnion() != null) {
                            // might be null if circular
                            pfound = true;
                            ex.addProfile("#" + compP.getId());
                        }
                    }
                }
            }
            if (!ex.hasTargetProfile() && !nw.hasTargetProfile())
                tfound = true;
            else if (!ex.hasTargetProfile()) {
                tfound = true;
            } else if (!nw.hasTargetProfile()) {
                tfound = true;
                ex.setTargetProfile(null);
            } else {
                // both have profiles. Is one derived from the other?
                StructureDefinition sdex = ((IWorkerContext) ex.getUserData("ctxt")).fetchResource(StructureDefinition.class, ex.getTargetProfile().get(0).getValue());
                StructureDefinition sdnw = ctxt.fetchResource(StructureDefinition.class, nw.getTargetProfile().get(0).getValue());
                if (sdex != null && sdnw != null) {
                    if (matches(sdex, sdnw)) {
                        tfound = true;
                    } else if (derivesFrom(sdex, sdnw, ((IWorkerContext) ex.getUserData("ctxt")))) {
                        ex.setTargetProfile(nw.getTargetProfile());
                        tfound = true;
                    } else if (derivesFrom(sdnw, sdex, ctxt)) {
                        tfound = true;
                    } else if (sdnw.getSnapshot().getElement().get(0).getPath().equals(sdex.getSnapshot().getElement().get(0).getPath())) {
                        ProfileComparison compP = (ProfileComparison) session.compare(sdex, sdnw);
                        if (compP.getUnion() != null) {
                            tfound = true;
                            ex.addTargetProfile("#" + compP.getId());
                        }
                    }
                }
            }
        }
    }
    if (!tfound || !pfound) {
        nw.setUserData("ctxt", ctxt);
        results.add(nw);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) IWorkerContext(org.hl7.fhir.r4b.context.IWorkerContext) TypeRefComponent(org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Aggregations

FileInputStream (java.io.FileInputStream)6 FileOutputStream (java.io.FileOutputStream)6 JsonElement (com.google.gson.JsonElement)5 File (java.io.File)5 IWorkerContext (org.hl7.fhir.r5.context.IWorkerContext)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 UcumEssenceService (org.fhir.ucum.UcumEssenceService)4 TextFile (org.hl7.fhir.utilities.TextFile)4 IWorkerContext (org.hl7.fhir.r4b.context.IWorkerContext)3 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)3 Row (org.apache.poi.ss.usermodel.Row)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinitionMappingComponent (org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent)2 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2