Search in sources :

Example 61 with ParametersParameterComponent

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

the class ParametersRenderer method params.

private void params(XhtmlNode tbl, List<ParametersParameterComponent> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
    for (ParametersParameterComponent p : list) {
        XhtmlNode tr = tbl.tr();
        XhtmlNode td = tr.td();
        for (int i = 0; i < indent; i++) {
            td.tx(XhtmlNode.NBSP);
        }
        td.tx(p.getName());
        if (p.hasValue()) {
            render(tr.td(), p.getValue());
        } else if (p.hasResource()) {
            Resource r = p.getResource();
            td = tr.td();
            XhtmlNode para = td.para();
            para.tx(r.fhirType() + "/" + r.getId());
            para.an(r.fhirType() + "_" + r.getId()).tx(" ");
            ResourceRenderer rr = RendererFactory.factory(r, context);
            rr.render(td, r);
        } else if (p.hasPart()) {
            tr.td();
            params(tbl, p.getPart(), 1);
        }
    }
}
Also used : DomainResource(org.hl7.fhir.r5.model.DomainResource) Resource(org.hl7.fhir.r5.model.Resource) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 62 with ParametersParameterComponent

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

the class Parameters method copy.

public Parameters copy() {
    Parameters dst = new Parameters();
    copyValues(dst);
    if (parameter != null) {
        dst.parameter = new ArrayList<ParametersParameterComponent>();
        for (ParametersParameterComponent i : parameter) dst.parameter.add(i.copy());
    }
    ;
    return dst;
}
Also used : IBaseParameters(org.hl7.fhir.instance.model.api.IBaseParameters)

Example 63 with ParametersParameterComponent

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

the class FHIRToolingClient method operateType.

public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
    boolean complex = false;
    for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
    String ps = "";
    try {
        if (!complex)
            for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
                ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
        ResourceRequest<T> result;
        URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
        if (complex) {
            byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
            result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        } else {
            result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        }
        if (result.isUnsuccessfulRequest()) {
            throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
        }
        if (result.getPayload() instanceof Parameters) {
            return (Parameters) result.getPayload();
        } else {
            Parameters p_out = new Parameters();
            p_out.addParameter().setName("return").setResource(result.getPayload());
            return p_out;
        }
    } catch (Exception e) {
        handleException("Error performing tx4 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
    }
    return null;
}
Also used : URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 64 with ParametersParameterComponent

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

the class ParametersRenderer method params.

private void params(XhtmlNode tbl, List<ParametersParameterComponent> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
    for (ParametersParameterComponent p : list) {
        XhtmlNode tr = tbl.tr();
        XhtmlNode td = tr.td();
        for (int i = 0; i < indent; i++) {
            td.tx(XhtmlNode.NBSP);
        }
        td.tx(p.getName());
        if (p.hasValue()) {
            render(tr.td(), p.getValue());
        } else if (p.hasResource()) {
            Resource r = p.getResource();
            td = tr.td();
            XhtmlNode para = td.para();
            para.tx(r.fhirType() + "/" + r.getId());
            para.an(r.fhirType() + "_" + r.getId()).tx(" ");
            ResourceRenderer rr = RendererFactory.factory(r, context);
            rr.render(td, r);
        } else if (p.hasPart()) {
            tr.td();
            params(tbl, p.getPart(), 1);
        }
    }
}
Also used : Resource(org.hl7.fhir.r4b.model.Resource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) ParametersParameterComponent(org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 65 with ParametersParameterComponent

use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project CRD by HL7-DaVinci.

the class QuestionnairePackageOperation method execute.

/*
     * Do the work retrieving all of the Questionnaire, Library and Valueset Resources.
     */
public String execute(String resourceString) {
    Parameters outputParameters = new Parameters();
    IBaseResource resource = null;
    try {
        resource = org.hl7.davinci.r4.Utilities.parseFhirData(resourceString);
    } catch (DataFormatException exception) {
        logger.error("Failed to process input parameters: " + exception.getMessage());
        return null;
    }
    if (resource.fhirType().equalsIgnoreCase("Parameters")) {
        Parameters parameters = (Parameters) resource;
        // TODO: handle multiple FHIR Coverage Resources
        Coverage coverage = (Coverage) getResource(parameters, "coverage");
        // list of all of the orders
        Bundle orders = getAllResources(parameters, "order");
        if (coverage == null || orders.isEmpty()) {
            logger.error("Failed to find order or coverage within parameters");
            return null;
        }
        // create a single new bundle for all of the resources
        Bundle completeBundle = new Bundle();
        // list of items in bundle to avoid duplicates
        List<String> bundleContents = new ArrayList<>();
        // process the orders to find the topics
        FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl);
        fhirBundleProcessor.processDeviceRequests(orders);
        fhirBundleProcessor.processMedicationRequests(orders);
        fhirBundleProcessor.processServiceRequests(orders);
        fhirBundleProcessor.processMedicationDispenses(orders);
        List<String> topics = createTopicList(fhirBundleProcessor);
        for (String topic : topics) {
            logger.info("--> process topic: " + topic);
            // get all of the Quesionnaires for the topic
            Bundle bundle = fileStore.getFhirResourcesByTopicAsFhirBundle("R4", "Questionnaire", topic.toLowerCase(), baseUrl);
            List<BundleEntryComponent> bundleEntries = bundle.getEntry();
            for (BundleEntryComponent entry : bundleEntries) {
                addResourceToBundle(entry.getResource(), bundleContents, completeBundle);
                if (entry.getResource().fhirType().equalsIgnoreCase("Questionnaire")) {
                    Questionnaire questionnaire = (Questionnaire) entry.getResource();
                    List<Extension> extensions = questionnaire.getExtension();
                    for (Extension extension : extensions) {
                        if (extension.getUrl().endsWith("cqf-library")) {
                            CanonicalType data = (CanonicalType) extension.getValue();
                            String url = data.asStringValue();
                            Resource libraryResource = null;
                            // look in the map and retrieve it instead of looking it up on disk if found
                            if (resources.containsKey(url)) {
                                libraryResource = resources.get(url);
                            } else {
                                libraryResource = fileStore.getFhirResourceByUrlAsFhirResource("R4", "Library", url, baseUrl);
                                resources.put(url, libraryResource);
                            }
                            if (addResourceToBundle(libraryResource, bundleContents, completeBundle)) {
                                // recursively add the depends-on libraries if added to bundle
                                addLibraryDependencies((Library) libraryResource, bundleContents, completeBundle);
                            }
                        }
                    }
                }
            }
        // Questionnaires
        }
        // add the bundle to the output parameters if it contains any resources
        if (!completeBundle.isEmpty()) {
            ParametersParameterComponent parameter = new ParametersParameterComponent();
            parameter.setName("return");
            parameter.setResource(completeBundle);
            outputParameters.addParameter(parameter);
        } else {
            logger.info("No matching Questionnaires found");
        }
    }
    // if none found return null
    if (outputParameters.isEmpty()) {
        return null;
    }
    // convert the outputParameters to a string
    FhirContext ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
    IParser parser = ctx.newJsonParser().setPrettyPrint(true);
    return parser.encodeResourceToString(outputParameters);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) Parameters(org.hl7.fhir.r4.model.Parameters) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirBundleProcessor(org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Coverage(org.hl7.fhir.r4.model.Coverage) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Extension(org.hl7.fhir.r4.model.Extension) DataFormatException(ca.uhn.fhir.parser.DataFormatException) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

ParametersParameterComponent (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)26 Parameters (org.hl7.fhir.r4.model.Parameters)21 HashMap (java.util.HashMap)18 JsonObject (javax.json.JsonObject)15 GET (javax.ws.rs.GET)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 ExtraParameters (org.apache.camel.component.fhir.api.ExtraParameters)15 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 IOException (java.io.IOException)7 CodeType (org.hl7.fhir.r4.model.CodeType)7 URISyntaxException (java.net.URISyntaxException)6 Nonnull (javax.annotation.Nonnull)6 Parameters (org.hl7.fhir.dstu3.model.Parameters)6 ParametersParameterComponent (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)6 Bundle (org.hl7.fhir.r4.model.Bundle)6 Slf4j (lombok.extern.slf4j.Slf4j)5 Parameters (org.hl7.fhir.dstu2.model.Parameters)5 Parameters (org.hl7.fhir.dstu2016may.model.Parameters)5