Search in sources :

Example 1 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project kindling by HL7.

the class BookMaker method addContent.

private void addContent(XhtmlNode body) throws Exception {
    List<String> list = new ArrayList<String>();
    loadResources(list, page.getDefinitions().getResources().keySet());
    XhtmlNode e = body.getElement("contents");
    XhtmlNode div = body.addTag(body.getChildNodes().indexOf(e), "div");
    body.getChildNodes().remove(e);
    List<String> links = new ArrayList<String>();
    LevelCounter lvl = new LevelCounter();
    lvl.l1 = 0;
    for (Navigation.Category s : page.getNavigation().getCategories()) {
        lvl.l1++;
        // div.addTag("div").setAttribute("class", "page-break");
        XhtmlNode divS = div.addTag("div");
        divS.attribute("class", "section");
        XhtmlNode h1 = divS.addTag("h1");
        h1.addText(Integer.toString(lvl.l1) + ": " + s.getName());
        addPageContent(lvl, divS, s.getLink(), s.getName());
        links.add(s.getLink());
        lvl.l2 = 0;
        for (Navigation.Entry n : s.getEntries()) {
            lvl.l2++;
            lvl.l3 = 0;
            if (n.getLink() != null) {
                if (n.getLink().equals("[codes]")) {
                    lvl.l2--;
                    List<String> names = new ArrayList<String>();
                    throw new Error("fix this");
                // for (BindingSpecification bs : page.getDefinitions().getBindings().values()) {
                // if (bs.getBinding() == Binding.CodeList)
                // names.add(bs.getReference());
                // }
                // Collections.sort(names);
                // for (String l : names) {
                // addPageContent(lvl, divS, l.substring(1), page.getDefinitions().getBindingByReference(l).getName());
                // //              links.add(l.substring(1));
                // }
                } else {
                    addPageContent(lvl, divS, n.getLink(), n.getName());
                    links.add(n.getLink());
                }
            }
            for (Navigation.Entry g : n.getEntries()) {
                if (g.getLink() != null) {
                    addPageContent(lvl, divS, g.getLink(), g.getName());
                    links.add(g.getLink());
                }
            }
        }
        if (s.getEntries().size() == 0 && s.getLink().equals("resourcelist")) {
            for (String rn : list) {
                if (!links.contains(rn.toLowerCase())) {
                    lvl.l2++;
                    lvl.l3 = 0;
                    ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                    addPageContent(lvl, divS, rn.toLowerCase(), r.getName());
                }
            }
        }
        if (s.getLink().equals("page") && s.getName().equals("Examples")) {
            for (String rn : list) {
                lvl.l2++;
                lvl.l3 = 0;
                ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                addPageContent(lvl, divS, rn.toLowerCase() + "Ex", r.getName());
            }
        }
        if (s.getLink().equals("page") && s.getName().equals("Detailed Descriptions")) {
            for (String rn : list) {
                lvl.l2++;
                lvl.l3 = 0;
                ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                addPageContent(lvl, divS, rn.toLowerCase() + "Defn", r.getName());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 2 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project kindling by HL7.

the class SourceParser method loadIgs.

private void loadIgs() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(srcDir + "igs.xml"));
    Element root = xdoc.getDocumentElement();
    if (root.getNodeName().equals("igs")) {
        Element ig = XMLUtil.getFirstChild(root);
        while (ig != null) {
            if (ig.getNodeName().equals("ig") && (!ig.hasAttribute("local") || isOkLocally(ig.getAttribute("code"))) && !isRuledOutLocally(ig.getAttribute("code"))) {
                ImplementationGuideDefn igg = new ImplementationGuideDefn(ig.getAttribute("committee"), ig.getAttribute("code"), ig.getAttribute("name"), ig.getAttribute("brief"), ig.getAttribute("source").replace('\\', File.separatorChar), "1".equals(ig.getAttribute("review")), ig.getAttribute("ballot"), ig.getAttribute("fmm"), ig.getAttribute("section"), "yes".equals(ig.getAttribute("core")), page.getValidationErrors());
                definitions.getIgs().put(igg.getCode(), igg);
                definitions.getSortedIgs().add(igg);
            }
            ig = XMLUtil.getNextSibling(ig);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 3 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project kindling by HL7.

the class SchematronGenerator method genChildren.

private void genChildren(Section section, String path, String typeCode, ElementDefn ed, Definitions definitions, List<String> parents) throws Exception {
    if (!path.contains("//")) {
        ArrayList<String> l = new ArrayList<String>(parents);
        l.add(typeCode);
        for (ElementDefn cd : ed.getElements()) {
            if (!Utilities.noString(cd.typeCode()) && l.contains(cd.typeCode())) {
                // well, we've recursed. What's going to happen now is that we're going to write this as // because we're going to keep recursing.
                // the next call will write this rule, and then terminate
                generateInvariants(section, path + "/", cd, definitions, l, cd.getName());
            } else
                generateInvariants(section, path, cd, definitions, l, cd.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 4 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project cqf-ruler by DBCG.

the class CompositionSectionComponentBuilder method initializeDstu2_1.

@Override
protected void initializeDstu2_1(T theResource) {
    super.initializeDstu2_1(theResource);
    org.hl7.fhir.dstu2016may.model.Composition.SectionComponent section = (org.hl7.fhir.dstu2016may.model.Composition.SectionComponent) theResource;
    section.setTitle(myTitle).setId(getId());
    getEntries().forEach(entry -> section.addEntry(new Reference(entry)));
    if (myText != null) {
        Narrative narrative = new Narrative();
        narrative.setStatusAsString(myText.getStatus());
        narrative.setDivAsString(myText.getText());
        section.setText(narrative);
    }
// no focus
}
Also used : Narrative(org.hl7.fhir.dstu2016may.model.Narrative) Reference(org.hl7.fhir.dstu2016may.model.Reference)

Example 5 with Section

use of org.hl7.fhir.r4.utils.formats.Turtle.Section in project cqf-ruler by DBCG.

the class CqlExecutionProvider method evaluate.

/**
 * Evaluates a CQL expression and returns the results as a Parameters resource.
 *
 * @param theRequestDetails   the {@link RequestDetails RequestDetails}
 * @param subject             ***Only Patient is supported as of now*** Subject
 *                            for which the expression will be
 *                            evaluated. This corresponds to the context in
 *                            which the expression will be evaluated and is
 *                            represented as a relative FHIR id (e.g.
 *                            Patient/123), which establishes both the context
 *                            and context value for the evaluation
 * @param expression          Expression to be evaluated. Note that this is an
 *                            expression of CQL, not the text of a library with
 *                            definition statements.
 * @param parameters          Any input parameters for the expression.
 *                            {@link Parameters} Parameters defined in this
 *                            input will be made available by name to the CQL
 *                            expression. Parameter types are mapped to CQL as
 *                            specified in the Using CQL section of the CPG
 *                            Implementation guide. If a parameter appears more
 *                            than once in the input Parameters resource, it is
 *                            represented with a List in the input CQL. If a
 *                            parameter has parts, it is represented as a Tuple
 *                            in the input CQL.
 * @param library             A library to be included. The {@link Library}
 *                            library is resolved by url and made available by
 *                            name within the expression to be evaluated.
 * @param useServerData       Whether to use data from the server performing the
 *                            evaluation. If this parameter is true (the
 *                            default), then the operation will use data first
 *                            from any bundles provided as parameters (through
 *                            the data and prefetch parameters), second data
 *                            from the server performing the operation, and
 *                            third, data from the dataEndpoint parameter (if
 *                            provided). If this parameter is false, the
 *                            operation will use data first from the bundles
 *                            provided in the data or prefetch parameters, and
 *                            second from the dataEndpoint parameter (if
 *                            provided).
 * @param data                Data to be made available to the library
 *                            evaluation. This parameter is exclusive with the
 *                            prefetchData parameter (i.e. either provide all
 *                            data as a single bundle, or provide data using
 *                            multiple bundles with prefetch descriptions).
 * @param prefetchData        ***Not Yet Implemented***
 * @param dataEndpoint        An {@link Endpoint} endpoint to use to access data
 *                            referenced by retrieve operations in the library.
 *                            If provided, this endpoint is used after the data
 *                            or prefetchData bundles, and the server, if the
 *                            useServerData parameter is true.
 * @param contentEndpoint     An {@link Endpoint} endpoint to use to access
 *                            content (i.e. libraries) referenced by the
 *                            library. If no content endpoint is supplied, the
 *                            evaluation will attempt to retrieve content from
 *                            the server on which the operation is being
 *                            performed.
 * @param terminologyEndpoint An {@link Endpoint} endpoint to use to access
 *                            terminology (i.e. valuesets, codesystems, and
 *                            membership testing) referenced by the library. If
 *                            no terminology endpoint is supplied, the
 *                            evaluation will attempt to use the server on which
 *                            the operation is being performed as the
 *                            terminology server.
 * @return The result of evaluating the given expression, returned as a FHIR
 *         type, either a {@link Resource} resource, or a FHIR-defined type
 *         corresponding to the CQL return type, as defined in the Using CQL
 *         section of the CPG Implementation guide. If the result is a List of
 *         resources, the result will be a {@link Bundle} Bundle . If the result
 *         is a CQL system-defined or FHIR-defined type, the result is returned
 *         as a {@link Parameters} Parameters resource
 */
@Operation(name = "$cql")
@Description(shortDefinition = "$cql", value = "Evaluates a CQL expression and returns the results as a Parameters resource. Defined: http://build.fhir.org/ig/HL7/cqf-recommendations/OperationDefinition-cpg-cql.html", example = "$cql?expression=5*5")
public Parameters evaluate(RequestDetails theRequestDetails, @OperationParam(name = "subject", max = 1) String subject, @OperationParam(name = "expression", min = 1, max = 1) String expression, @OperationParam(name = "parameters", max = 1) Parameters parameters, @OperationParam(name = "library") List<Parameters> library, @OperationParam(name = "useServerData", max = 1) BooleanType useServerData, @OperationParam(name = "data", max = 1) Bundle data, @OperationParam(name = "prefetchData") List<Parameters> prefetchData, @OperationParam(name = "dataEndpoint", max = 1) Endpoint dataEndpoint, @OperationParam(name = "contentEndpoint", max = 1) Endpoint contentEndpoint, @OperationParam(name = "terminologyEndpoint", max = 1) Endpoint terminologyEndpoint) {
    if (prefetchData != null) {
        throw new NotImplementedException("prefetchData is not yet supported.");
    }
    if (useServerData == null) {
        useServerData = new BooleanType(true);
    }
    List<LibraryParameter> libraryParameters = new ArrayList<>();
    if (library != null) {
        for (Parameters libraryParameter : library) {
            String url = null;
            String name = null;
            for (ParametersParameterComponent param : libraryParameter.getParameter()) {
                switch(param.getName()) {
                    case "url":
                        url = ((StringType) param.getValue()).asStringValue();
                        break;
                    case "name":
                        name = ((StringType) param.getValue()).asStringValue();
                        break;
                    default:
                        throw new IllegalArgumentException("Only url and name parts are allowed for Parameter: library");
                }
            }
            if (url == null) {
                throw new IllegalArgumentException("If library parameter must provide a url parameter part.");
            }
            libraryParameters.add(new LibraryParameter().withUrl(url).withName(name));
        }
    // Remove LocalLibrary from cache first...
    }
    VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary").withVersion("1.0.0");
    globalLibraryCache.remove(localLibraryIdentifier);
    CqlEngine engine = setupEngine(localLibraryIdentifier, expression, libraryParameters, subject, parameters, contentEndpoint, dataEndpoint, terminologyEndpoint, data, useServerData.booleanValue(), theRequestDetails);
    Map<String, Object> resolvedParameters = new HashMap<String, Object>();
    if (parameters != null) {
        for (Parameters.ParametersParameterComponent pc : parameters.getParameter()) {
            resolvedParameters.put(pc.getName(), pc.getValue());
        }
    }
    String contextType = subject != null ? subject.substring(0, subject.lastIndexOf("/") - 1) : null;
    String subjectId = subject != null ? subject.substring(0, subject.lastIndexOf("/") - 1) : null;
    EvaluationResult evalResult = engine.evaluate(localLibraryIdentifier, null, Pair.of(contextType != null ? contextType : "Unspecified", subjectId == null ? "null" : subject), resolvedParameters, this.getDebugMap());
    if (evalResult != null && evalResult.expressionResults != null) {
        if (evalResult.expressionResults.size() > 1) {
            logger.debug("Evaluation resulted in more than one expression result.  ");
        }
        Parameters result = new Parameters();
        resolveResult(theRequestDetails, evalResult, result);
        return result;
    }
    return null;
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters) HashMap(java.util.HashMap) NotImplementedException(org.apache.commons.lang3.NotImplementedException) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ArrayList(java.util.ArrayList) CqlEngine(org.opencds.cqf.cql.engine.execution.CqlEngine) EvaluationResult(org.opencds.cqf.cql.engine.execution.EvaluationResult) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Aggregations

ArrayList (java.util.ArrayList)21 Element (org.w3c.dom.Element)11 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)9 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)9 POCDMT000002UK01Section (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section)8 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 POCDMT000002UK01Component3 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 HashMap (java.util.HashMap)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 IdType (org.hl7.fhir.dstu3.model.IdType)4 Section (org.hl7.fhir.utilities.turtle.Turtle.Section)4 Subject (org.hl7.fhir.utilities.turtle.Turtle.Subject)4 POCDMT000002UK01Component5 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component5)4 FileNotFoundException (java.io.FileNotFoundException)3