Search in sources :

Example 46 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class ProcessMessageProviderIT method testProcessMessage.

@Test
public void testProcessMessage() throws IOException {
    String packagePrefix = "org/opencds/cqf/ruler/casereporting/r4/";
    Bundle bundle = (Bundle) loadResource(packagePrefix + "example-eicr.json");
    Bundle returnBundle = getClient().operation().onServer().named("$process-message-bundle").withParameter(Parameters.class, "content", bundle).returnResourceType(Bundle.class).execute();
    assertNotNull(returnBundle);
    assertNotNull(getClient().read().resource(Patient.class).withId("patient-12742542").execute());
    assertNotNull(getClient().read().resource(Encounter.class).withId("encounter-97953898").execute());
    assertNotNull(getClient().read().resource(MeasureReport.class).withId("diabetes-mp").execute());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Encounter(org.hl7.fhir.r4.model.Encounter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 47 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class HelloWorldProvider method hello_world.

/**
 * Implements the $hello-world operation found in the
 * <a href="https://www.hl7.org/fhir/clinicalreasoning-module.html">FHIR CR
 * Module</a>
 *
 * @return a greeting
 */
@Description(shortDefinition = "returns a greeting", value = "Implements the $hello-world operation found in the <a href=\"https://www.hl7.org/fhir/clinicalreasoning-module.html\">FHIR CR Module</a>")
@Operation(idempotent = true, name = "$hello-world")
public OperationOutcome hello_world() {
    OperationOutcome outcome = new OperationOutcome();
    outcome.addIssue().setDiagnostics(helloWorldProperties.getMessage());
    return outcome;
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 48 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class HelloWorldProviderIT method testHelloWorldConfig.

@Test
public void testHelloWorldConfig() {
    OperationOutcome outcome = getClient().operation().onServer().named("$hello-world").withNoParameters(Parameters.class).returnResourceType(OperationOutcome.class).execute();
    assertNotNull(outcome);
    assertEquals("Howdy", outcome.getIssueFirstRep().getDiagnostics());
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 49 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class Stu3EvaluationContext method applyCqlToResources.

@Override
List<Object> applyCqlToResources(List<Object> resources) {
    if (resources == null || resources.isEmpty()) {
        return new ArrayList<>();
    }
    Bundle bundle = new Bundle();
    for (Object res : resources) {
        bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) res));
    }
    Parameters parameters = new Parameters();
    parameters.addParameter().setName("resourceBundle").setResource(bundle);
    Parameters ret = this.getSystemFhirClient().operation().onType(Bundle.class).named("$apply-cql").withParameters(parameters).execute();
    Bundle appliedResources = (Bundle) ret.getParameter().get(0).getResource();
    return appliedResources.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).collect(Collectors.toList());
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters) Bundle(org.hl7.fhir.dstu3.model.Bundle) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.dstu3.model.Resource)

Example 50 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class CacheValueSetsProvider method cacheValuesets.

/**
 * Using basic authentication this {@link Operation Operation} will update
 * any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
 * provided.
 * Any Valuesets that require expansion will be expanded.
 *
 * @param details    the {@link RequestDetails RequestDetails}
 * @param endpointId the {@link Endpoint Endpoint} id
 * @param valuesets  the {@link StringAndListParam list} of {@link ValueSet
 *                   Valueset} ids
 * @param userName   the userName
 * @param password   the password
 * @return the {@link OperationOutcome OperationOutcome} or the resulting
 *         {@link Bundle Bundle}
 */
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "$cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
    Endpoint endpoint = null;
    try {
        endpoint = this.endpointDao.read(endpointId);
        if (endpoint == null) {
            return createErrorOutcome("Could not find Endpoint/" + endpointId);
        }
    } catch (Exception e) {
        return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
    }
    IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
    if (userName != null || password != null) {
        if (userName == null) {
            return createErrorOutcome("Password was provided, but not a user name.");
        } else if (password == null) {
            return createErrorOutcome("User name was provided, but not a password.");
        }
        BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
        client.registerInterceptor(basicAuth);
    // TODO - more advanced security like bearer tokens, etc...
    }
    try {
        Bundle bundleToPost = new Bundle();
        for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
            for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
                bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
            }
        }
        return (Resource) systemDao.transaction(details, bundleToPost);
    } catch (Exception e) {
        return createErrorOutcome(e.getMessage());
    }
}
Also used : Endpoint(org.hl7.fhir.dstu3.model.Endpoint) BasicAuthInterceptor(ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) Resource(org.hl7.fhir.dstu3.model.Resource) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)72 Test (org.junit.jupiter.api.Test)69 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)63 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)63 StringType (org.hl7.fhir.r4.model.StringType)62 ArrayList (java.util.ArrayList)60 IOException (java.io.IOException)54 List (java.util.List)54 Bundle (org.hl7.fhir.r4.model.Bundle)53 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)52 Collectors (java.util.stream.Collectors)51 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)50 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)48 FileOutputStream (java.io.FileOutputStream)47 Collections (java.util.Collections)47 Optional (java.util.Optional)47 File (java.io.File)46 Arrays (java.util.Arrays)46 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)45 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)45