Search in sources :

Example 76 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandler method evaluateMeasure.

@POST
@Path("/evaluation")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Evaluates a measure bundle for a single patient", notes = EVALUATION_API_NOTES, response = String.class, tags = { "Measure Evaluation" }, nickname = "evaluate_measure", extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION) }) })
@ApiImplicitParams({ // This is necessary for the dark launch feature
@ApiImplicitParam(access = DarkFeatureSwaggerFilter.DARK_FEATURE_CONTROLLED, paramType = "header", dataType = "string"), // These are necessary to create a proper view of the request body that is all wrapped up in the Liberty IMultipartBody parameter
@ApiImplicitParam(name = REQUEST_DATA_PART, value = EXAMPLE_REQUEST_DATA_JSON, dataTypeClass = MeasureEvaluation.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = MEASURE_PART, value = EXAMPLE_MEASURE_ZIP, dataTypeClass = File.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation: This API returns the JSON representation of a FHIR MeasureReport. A full example can be found at https://www.hl7.org/fhir/measurereport-cms146-cat1-example.html"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response evaluateMeasure(@Context HttpServletRequest request, @ApiParam(value = ServiceBaseConstants.MINOR_VERSION_DESCRIPTION, required = true, defaultValue = ServiceBuildConstants.DATE) @QueryParam(CohortEngineRestHandler.VERSION) String version, @ApiParam(hidden = true, type = "file", required = true) IMultipartBody multipartBody) {
    final String methodName = MethodNames.EVALUATE_MEASURE.getName();
    Response response = null;
    // Error out if feature is not enabled
    ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION);
    try {
        // Perform api setup
        Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
        if (errorResponse != null) {
            return errorResponse;
        }
        if (multipartBody == null) {
            throw new IllegalArgumentException("A multipart/form-data body is required");
        }
        IAttachment metadataAttachment = multipartBody.getAttachment(REQUEST_DATA_PART);
        if (metadataAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", REQUEST_DATA_PART));
        }
        IAttachment measureAttachment = multipartBody.getAttachment(MEASURE_PART);
        if (measureAttachment == null) {
            throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", MEASURE_PART));
        }
        // deserialize the MeasuresEvaluation request
        ObjectMapper om = new ObjectMapper();
        MeasureEvaluation evaluationRequest = om.readValue(metadataAttachment.getDataHandler().getInputStream(), MeasureEvaluation.class);
        // validate the contents of the evaluationRequest
        validateBean(evaluationRequest);
        FhirContext fhirContext = FhirContext.forR4();
        try (InputStream is = measureAttachment.getDataHandler().getInputStream();
            RetrieveCacheContext retrieveCacheContext = new DefaultRetrieveCacheContext()) {
            MeasureEvaluator evaluator = createMeasureEvaluator(is, evaluationRequest.getDataServerConfig(), evaluationRequest.getTerminologyServerConfig(), evaluationRequest.isExpandValueSets(), evaluationRequest.getSearchPageSize(), retrieveCacheContext, fhirContext);
            MeasureReport report = evaluator.evaluatePatientMeasure(evaluationRequest.getPatientId(), evaluationRequest.getMeasureContext(), evaluationRequest.getEvidenceOptions());
            // The default serializer gets into an infinite loop when trying to serialize MeasureReport, so we use the
            // HAPI encoder instead.
            IParser parser = fhirContext.newJsonParser();
            ResponseBuilder responseBuilder = Response.status(Response.Status.OK).header("Content-Type", "application/json").entity(parser.encodeResourceToString(report));
            response = responseBuilder.build();
        }
    } catch (Throwable e) {
        // map any exceptions caught into the proper REST error response objects
        response = new CohortServiceExceptionMapper().toResponse(e);
    } finally {
        // Perform api cleanup
        Response errorResponse = ServiceBaseUtility.apiCleanup(logger, methodName);
        if (errorResponse != null) {
            response = errorResponse;
        }
    }
    return response;
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) RetrieveCacheContext(com.ibm.cohort.engine.measure.cache.RetrieveCacheContext) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) DefaultRetrieveCacheContext(com.ibm.cohort.engine.measure.cache.DefaultRetrieveCacheContext) MeasureEvaluator(com.ibm.cohort.engine.measure.MeasureEvaluator) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) Path(javax.ws.rs.Path) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 77 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProvider method lookup.

/**
 * This is a small patch to the OSS implementation to use named-parameter lookup on
 * the operation response instead of just assuming a positional location.
 */
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    Parameters respParam = fhirClient.operation().onType(CodeSystem.class).named("lookup").withParameter(Parameters.class, "code", new CodeType(code.getCode())).andParameter("system", new UriType(codeSystem.getId())).execute();
    StringType display = (StringType) respParam.getParameter("display");
    if (display != null) {
        code.withDisplay(display.getValue());
    }
    return code.withSystem(codeSystem.getId());
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) CodeType(org.hl7.fhir.r4.model.CodeType) UriType(org.hl7.fhir.r4.model.UriType)

Example 78 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project elexis-server by elexis.

the class PatientTest method searchPatientMultipleNameValue.

@Test
@Ignore("unclear use case, deactivated")
public void searchPatientMultipleNameValue() {
    Bundle results = client.search().forResource(Patient.class).where(Patient.NAME.matches().value("Test")).and(Patient.NAME.matches().value("name")).returnBundle(Bundle.class).execute();
    assertEquals(2, results.getEntry().size());
    Optional<BundleEntryComponent> found = results.getEntry().stream().filter(e -> e.getResource().getId().contains("s9b71824bf6b877701111")).findFirst();
    assertTrue(found.isPresent());
}
Also used : IIdType(org.hl7.fhir.instance.model.api.IIdType) BeforeClass(org.junit.BeforeClass) Date(java.util.Date) XidConstants(ch.elexis.core.constants.XidConstants) Identifier(org.hl7.fhir.r4.model.Identifier) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) AddressUse(org.hl7.fhir.r4.model.Address.AddressUse) NameUse(org.hl7.fhir.r4.model.HumanName.NameUse) IReadExecutable(ca.uhn.fhir.rest.gclient.IReadExecutable) Address(org.hl7.fhir.r4.model.Address) SQLException(java.sql.SQLException) TestDatabaseInitializer(ch.elexis.core.test.initializer.TestDatabaseInitializer) ContactPointUse(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse) HumanName(org.hl7.fhir.r4.model.HumanName) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Patient(org.hl7.fhir.r4.model.Patient) IPatient(ch.elexis.core.model.IPatient) GregorianCalendar(java.util.GregorianCalendar) PreferReturnEnum(ca.uhn.fhir.rest.api.PreferReturnEnum) AllTests(info.elexis.server.fhir.rest.core.test.AllTests) Month(java.time.Month) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) List(java.util.List) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) TestEntities(ch.elexis.core.test.TestEntities) Collections(java.util.Collections) FhirUtil(info.elexis.server.fhir.rest.core.test.FhirUtil) Assert.assertEquals(org.junit.Assert.assertEquals) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 79 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderIntegrationTest method shouldSupportMultiplePagesAsJson.

@Test
public void shouldSupportMultiplePagesAsJson() throws Exception {
    MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Observation> observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList());
    Bundle.BundleLinkComponent link = results.getLink("next");
    while (link != null) {
        String nextUrl = link.getUrl();
        URL url = new URL(nextUrl);
        // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query
        // string
        response = get("?" + url.getQuery()).accept(FhirMediaTypes.JSON).go();
        assertThat(response, isOk());
        assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
        assertThat(response.getContentAsString(), notNullValue());
        results = readBundleResponse(response);
        assertThat(results, notNullValue());
        assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
        assertThat(results.hasEntry(), is(true));
        observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()));
        link = results.getLink("next");
    }
    assertThat(observations, hasSize(equalTo(results.getTotal())));
    for (int i = 1; i < observations.size(); i++) {
        assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue()));
    }
}
Also used : DateMatchers.sameOrAfter(org.exparity.hamcrest.date.DateMatchers.sameOrAfter) Getter(lombok.Getter) Bundle(org.hl7.fhir.dstu3.model.Bundle) URL(java.net.URL) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) Autowired(org.springframework.beans.factory.annotation.Autowired) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) BigDecimal(java.math.BigDecimal) AccessLevel(lombok.AccessLevel) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Test(org.junit.Test) Observation(org.hl7.fhir.dstu3.model.Observation) Collectors(java.util.stream.Collectors) Matchers.startsWith(org.hamcrest.Matchers.startsWith) StandardCharsets(java.nio.charset.StandardCharsets) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) FhirEncounterDao(org.openmrs.module.fhir2.api.dao.FhirEncounterDao) Comparator(java.util.Comparator) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.endsWith(org.hamcrest.Matchers.endsWith) InputStream(java.io.InputStream) Bundle(org.hl7.fhir.dstu3.model.Bundle) Observation(org.hl7.fhir.dstu3.model.Observation) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) URL(java.net.URL) Test(org.junit.Test)

Example 80 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderIntegrationTest method shouldSupportMultiplePagesAsJson.

@Test
public void shouldSupportMultiplePagesAsJson() throws Exception {
    MockHttpServletResponse response = get("/Observation?subject.name=Chebaskwony&_sort=-date").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Observation> observations = results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList());
    Bundle.BundleLinkComponent link = results.getLink("next");
    while (link != null) {
        String nextUrl = link.getUrl();
        URL url = new URL(nextUrl);
        // NB Because we cannot use the *full* URL, we use the relevant portion, which in this case, is just the query
        // string
        response = get("?" + url.getQuery()).accept(FhirMediaTypes.JSON).go();
        assertThat(response, isOk());
        assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
        assertThat(response.getContentAsString(), notNullValue());
        results = readBundleResponse(response);
        assertThat(results, notNullValue());
        assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
        assertThat(results.hasEntry(), is(true));
        observations.addAll(results.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).filter(it -> it instanceof Observation).map(it -> (Observation) it).collect(Collectors.toList()));
        link = results.getLink("next");
    }
    assertThat(observations, hasSize(equalTo(results.getTotal())));
    for (int i = 1; i < observations.size(); i++) {
        assertThat(observations.get(i - 1).getEffectiveDateTimeType().getValue(), sameOrAfter(observations.get(i).getEffectiveDateTimeType().getValue()));
    }
}
Also used : DateMatchers.sameOrAfter(org.exparity.hamcrest.date.DateMatchers.sameOrAfter) Getter(lombok.Getter) URL(java.net.URL) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) Autowired(org.springframework.beans.factory.annotation.Autowired) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) BigDecimal(java.math.BigDecimal) AccessLevel(lombok.AccessLevel) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Observation(org.hl7.fhir.r4.model.Observation) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.startsWith(org.hamcrest.Matchers.startsWith) StandardCharsets(java.nio.charset.StandardCharsets) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Bundle(org.hl7.fhir.r4.model.Bundle) FhirEncounterDao(org.openmrs.module.fhir2.api.dao.FhirEncounterDao) Comparator(java.util.Comparator) Matchers.endsWith(org.hamcrest.Matchers.endsWith) InputStream(java.io.InputStream) Bundle(org.hl7.fhir.r4.model.Bundle) Observation(org.hl7.fhir.r4.model.Observation) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20