Search in sources :

Example 6 with CompartmentDefinition

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

the class CompartmentDefinitionRenderer method render.

public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
    StringBuilder in = new StringBuilder();
    StringBuilder out = new StringBuilder();
    for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
        CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
        if (!cc.hasParam()) {
            out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
        } else if (!rules.equals("{def}")) {
            for (StringType p : cc.getParam()) rules.append(p.asStringValue());
            in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
        }
    }
    XhtmlNode xn;
    xn = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.r4b.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.r4b.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 7 with CompartmentDefinition

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

the class CompartmentDefinitionRenderer method render.

public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
    StringBuilder in = new StringBuilder();
    StringBuilder out = new StringBuilder();
    for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
        CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
        if (!cc.hasParam()) {
            out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
        } else if (!rules.equals("{def}")) {
            for (StringType p : cc.getParam()) rules.append(p.asStringValue());
            in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
        }
    }
    XhtmlNode xn;
    xn = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.r5.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 8 with CompartmentDefinition

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

the class DataRenderer method isCanonical.

private boolean isCanonical(String path) {
    if (!path.endsWith(".url"))
        return false;
    String t = path.substring(0, path.length() - 4);
    StructureDefinition sd = getContext().getWorker().fetchTypeDefinition(t);
    if (sd == null)
        return false;
    if (Utilities.existsInList(t, VersionUtilities.getCanonicalResourceNames(getContext().getWorker().getVersion()))) {
        return true;
    }
    if (Utilities.existsInList(t, "ActivityDefinition", "CapabilityStatement", "CapabilityStatement2", "ChargeItemDefinition", "Citation", "CodeSystem", "CompartmentDefinition", "ConceptMap", "ConditionDefinition", "EventDefinition", "Evidence", "EvidenceReport", "EvidenceVariable", "ExampleScenario", "GraphDefinition", "ImplementationGuide", "Library", "Measure", "MessageDefinition", "NamingSystem", "PlanDefinition"))
        return true;
    return sd.getBaseDefinitionElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-codegen-super");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 9 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project pathling by aehrc.

the class ManifestConverter method populateScope.

void populateScope(@Nonnull final PassportScope passportScope, @Nonnull final VisaManifest manifest) {
    // Create a filter for the Patient resource.
    final String patientIdCollection = manifest.getPatientIds().stream().map(id -> "'" + id + "'").collect(Collectors.joining(" combine "));
    final String patientIdFilter = "identifier.where(system = '" + StringLiteralPath.escapeFhirPathString(patientIdSystem) + "').where(value in (" + patientIdCollection + "))" + ".empty().not()";
    final Set<String> patientFilters = passportScope.get(ResourceType.PATIENT);
    if (patientFilters == null) {
        passportScope.put(ResourceType.PATIENT, new HashSet<>(List.of(patientIdFilter)));
    } else {
        patientFilters.add(patientIdFilter);
    }
    // See: https://www.hl7.org/fhir/r4/compartmentdefinition-patient.html
    for (final ResourceType resourceType : ResourceType.values()) {
        if (resourceType.equals(ResourceType.DOMAINRESOURCE) || resourceType.equals(ResourceType.RESOURCE) || resourceType.equals(ResourceType.NULL)) {
            continue;
        }
        final RuntimeResourceDefinition definition = fhirContext.getResourceDefinition(resourceType.toCode());
        final List<RuntimeSearchParam> searchParams = definition.getSearchParamsForCompartmentName("Patient");
        for (final RuntimeSearchParam searchParam : searchParams) {
            final String path = searchParam.getPath();
            // Remove the leading "[resource type]." from the path.
            final String pathTrimmed = path.replaceFirst("^" + resourceType.toCode() + "\\.", "");
            // Paths that end with this resolve pattern are polymorphic references, and will need
            // to be resolved using `ofType()` within our implementation.
            final String resolvePattern = ".where(resolve() is Patient)";
            final String filter;
            if (pathTrimmed.endsWith(resolvePattern)) {
                filter = pathTrimmed.replace(resolvePattern, ".resolve().ofType(Patient)." + patientIdFilter);
            } else {
                final Set<String> targets = searchParam.getTargets();
                if (targets.size() > 0 && !targets.contains("Patient")) {
                    // Patient, we need to skip it altogether.
                    continue;
                } else if (targets.size() == 1) {
                    // If the search parameter is monomorphic, we can resolve it without `ofType`.
                    filter = pathTrimmed + ".resolve()." + patientIdFilter;
                } else {
                    // If the search parameter is polymorphic, we also need to resolve it to Patient. Note
                    // that polymorphic references with an "Any" type have zero targets.
                    filter = pathTrimmed + ".resolve().ofType(Patient)." + patientIdFilter;
                }
            }
            // Add the filter to the map.
            final Set<String> filters = passportScope.get(resourceType);
            if (filters == null) {
                passportScope.put(resourceType, new HashSet<>(List.of(filter)));
            } else {
                filters.add(filter);
            }
        }
    }
}
Also used : RuntimeSearchParam(ca.uhn.fhir.context.RuntimeSearchParam) Configuration(au.csiro.pathling.Configuration) Set(java.util.Set) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) HashSet(java.util.HashSet) FhirContext(ca.uhn.fhir.context.FhirContext) List(java.util.List) Component(org.springframework.stereotype.Component) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) RuntimeResourceDefinition(ca.uhn.fhir.context.RuntimeResourceDefinition) Nonnull(javax.annotation.Nonnull) RuntimeResourceDefinition(ca.uhn.fhir.context.RuntimeResourceDefinition) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) RuntimeSearchParam(ca.uhn.fhir.context.RuntimeSearchParam)

Example 10 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project kindling by HL7.

the class PageProcessor method compartmentlist.

private String compartmentlist() {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"grid\">\r\n");
    b.append(" <tr><td><b>Title</b></td><td><b>Description</b></td><td><b>Identity</b></td><td><b>Membership</b></td></tr>\r\n");
    for (Compartment c : definitions.getCompartments()) {
        b.append(" <tr><td><a href=\"compartmentdefinition-").append(c.getName().toLowerCase()).append(".html\">").append(c.getTitle()).append("</a></td><td>").append(Utilities.escapeXml(c.getDescription())).append("</td>").append("<td>").append(Utilities.escapeXml(c.getIdentity())).append("</td><td>").append(Utilities.escapeXml(c.getMembership())).append("</td></tr>\r\n");
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) Compartment(org.hl7.fhir.definitions.model.Compartment)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)8 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 CompartmentDefinitionResourceComponent (org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent)3 ParseException (java.text.ParseException)2 Compartment (org.hl7.fhir.definitions.model.Compartment)2 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)2 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)2 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)2 CompartmentDefinition (org.hl7.fhir.r5.model.CompartmentDefinition)2 StringType (org.hl7.fhir.r5.model.StringType)2 Configuration (au.csiro.pathling.Configuration)1 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)1 FhirContext (ca.uhn.fhir.context.FhirContext)1