Search in sources :

Example 61 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingPatient.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingPatient() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Library library = TestHelper.getTemplateLibrary();
    Measure measure = TestHelper.getTemplateMeasure(library);
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockNotFound("/Patient/" + patient.getId() + "\\?_format=json");
    FhirServerConfig clientConfig = getFhirServerConfig();
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
    MeasureEvaluation evaluationRequest = new MeasureEvaluation();
    evaluationRequest.setDataServerConfig(clientConfig);
    evaluationRequest.setPatientId(patient.getId());
    evaluationRequest.setMeasureContext(measureContext);
    // evaluationRequest.setEvidenceOptions(evidenceOptions);
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(evaluationRequest);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
    Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasureMissingPatient.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasureMissingPatient() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_PATIENT_LIST_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Library library = TestHelper.getTemplateLibrary();
    Measure measure = TestHelper.getTemplateMeasure(library);
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockNotFound("/Patient/" + patient.getId() + "\\?_format=json");
    FhirServerConfig clientConfig = getFhirServerConfig();
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
    PatientListMeasureEvaluation request = new PatientListMeasureEvaluation();
    request.setDataServerConfig(clientConfig);
    request.setPatientIds(Collections.singletonList(patient.getId()));
    request.setMeasureContext(measureContext);
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(request);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
    Response loadResponse = restHandler.evaluatePatientListMeasure(mockRequestContext, VERSION, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluateMeasureSuccess.

/**
 * Test the successful building of a response.
 */
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureSuccess() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Library library = TestHelper.getTemplateLibrary();
    Measure measure = TestHelper.getTemplateMeasure(library);
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockFhirResourceRetrieval(patient);
    FhirServerConfig clientConfig = getFhirServerConfig();
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
    MeasureEvaluation evaluationRequest = new MeasureEvaluation();
    evaluationRequest.setDataServerConfig(clientConfig);
    evaluationRequest.setPatientId(patient.getId());
    evaluationRequest.setMeasureContext(measureContext);
    // evaluationRequest.setEvidenceOptions(evidenceOptions);
    evaluationRequest.setExpandValueSets(true);
    evaluationRequest.setSearchPageSize(500);
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(evaluationRequest);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
    Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
    assertEquals(mockResponse, loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(Response.Status.OK);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 64 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class RestFhirLibraryResolverIntegrationTest method resolveLibraryById_twice___returns_cached_data.

@Test
public void resolveLibraryById_twice___returns_cached_data() throws Exception {
    resolver = new CachingFhirResourceResolver<>(resolver);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Library library = getLibrary("Test", DEFAULT_VERSION, "cql/basic/Test-1.0.0.cql");
    mockFhirResourceRetrieval(library);
    Library actual = resolver.resolveById(library.getId());
    assertNotNull(actual);
    actual = resolver.resolveById(library.getId());
    assertNotNull(actual);
    verify(1, getRequestedFor(urlMatching("/Library.*")));
}
Also used : Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 65 with Library

use of org.hl7.fhir.r5.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class RestFhirLibraryResolverIntegrationTest method resolveLibraryById___null_when_not_found.

@Test
public void resolveLibraryById___null_when_not_found() {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    MappingBuilder builder = get(urlMatching("/Library.+"));
    setAuthenticationParameters(getFhirServerConfig(), builder);
    stubFor(builder.willReturn(aResponse().withStatus(404)));
    Library actual = resolver.resolveById("Test");
    assertNull(actual);
}
Also used : MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Aggregations

Library (org.hl7.fhir.r4.model.Library)130 Test (org.junit.Test)85 Measure (org.hl7.fhir.r4.model.Measure)60 Patient (org.hl7.fhir.r4.model.Patient)41 HashMap (java.util.HashMap)36 Test (org.junit.jupiter.api.Test)34 ArrayList (java.util.ArrayList)32 Library (org.hl7.fhir.dstu3.model.Library)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)21 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)21 StringType (org.hl7.fhir.r4.model.StringType)21 IOException (java.io.IOException)20 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)20 FhirContext (ca.uhn.fhir.context.FhirContext)19 IParser (ca.uhn.fhir.parser.IParser)19 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)19 Bundle (org.hl7.fhir.r4.model.Bundle)19 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)18