Search in sources :

Example 6 with IMultipartBody

use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody 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 7 with IMultipartBody

use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingVersion.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingVersion() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    Response badRequest = Mockito.mock(Response.class);
    PowerMockito.when(ServiceBaseUtility.class, "apiSetup", Mockito.isNull(), Mockito.any(), Mockito.eq(MethodNames.EVALUATE_MEASURE.getName())).thenReturn(badRequest);
    mockResponseClasses();
    // Create the metadata part of the request
    String json = "{}";
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayInputStream zipIs = TestHelper.emptyZip();
    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, null, body);
    assertNotNull(loadResponse);
    assertSame(badRequest, loadResponse);
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiSetup(Mockito.isNull(), Mockito.any(), Mockito.anyString());
    // verifyStatic must be called before each verification
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiCleanup(Mockito.any(), Mockito.eq(MethodNames.EVALUATE_MEASURE.getName()));
}
Also used : Response(javax.ws.rs.core.Response) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceBaseUtility(com.ibm.watson.common.service.base.ServiceBaseUtility) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with IMultipartBody

use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testCohortMultipleDependencies.

@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortMultipleDependencies() throws Exception {
    prepMocks();
    mockResponseClasses();
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.FEMALE, 40);
    mockFhirResourceRetrieval(patient);
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.mockStatic(FHIRRestUtils.class);
    PowerMockito.mockStatic(DefaultFhirClientBuilder.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_COHORT.getName())).thenReturn(null);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withArguments(Mockito.any()).thenReturn(mockDefaultFhirClientBuilder);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ZipOutputStream zos = new ZipOutputStream(baos)) {
        File baseFile = new File("src/test/resources/cql/dependency_test-1.0.0/DependencyTest-1.0.0.cql");
        ZipEntry firstEntry = new ZipEntry("cql/DependencyTest-1.0.0.cql");
        zos.putNextEntry(firstEntry);
        byte[] x = new byte[(int) baseFile.length()];
        new FileInputStream(baseFile).read(x);
        zos.write(x);
        File additionalFile = new File("src/test/resources/cql/dependency_test-1.0.0/ImportantDependency-1.1.1.cql");
        ZipEntry secondEntry = new ZipEntry("cql/ImportantDependency-1.1.1.cql");
        zos.putNextEntry(secondEntry);
        byte[] y = new byte[(int) additionalFile.length()];
        new FileInputStream(additionalFile).read(y);
        zos.write(y);
        zos.closeEntry();
    }
    CohortEvaluation requestData = new CohortEvaluation();
    FhirServerConfig serverConfig = getFhirServerConfig();
    requestData.setDataServerConfig(serverConfig);
    requestData.setTerminologyServerConfig(serverConfig);
    requestData.setDefineToRun("DependentFemale");
    requestData.setEntrypoint("DependencyTest-1.0.0.cql");
    requestData.setPatientIds("123");
    requestData.setLoggingLevel(CqlDebug.TRACE);
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(requestData);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment request = mockAttachment(jsonIs);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = getFhirConfigFileBody();
    when(body.getAttachment(CohortEngineRestHandler.CQL_DEFINITION)).thenReturn(measurePart);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(request);
    when(measurePart.getDataHandler().getName()).thenReturn("dependency_test-1.0.0.zip");
    when(measurePart.getHeader("Content-Disposition")).thenReturn("dependency_test-1.0.0.zip");
    Response loadResponse = restHandler.evaluateCohort(mockRequestContext, null, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(Status.OK);
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiSetup(Mockito.isNull(), Mockito.any(), Mockito.anyString());
    // verifyStatic must be called before each verification
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiCleanup(Mockito.any(), Mockito.eq(MethodNames.EVALUATE_COHORT.getName()));
}
Also used : CohortEvaluation(com.ibm.cohort.engine.api.service.model.CohortEvaluation) ZipEntry(java.util.zip.ZipEntry) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with IMultipartBody

use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testCohortNullMetadataAttachment.

@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortNullMetadataAttachment() throws Exception {
    prepMocks();
    mockResponseClasses();
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = getFhirConfigFileBody();
    Response loadResponse = restHandler.evaluateCohort(mockRequestContext, null, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiSetup(Mockito.isNull(), Mockito.any(), Mockito.anyString());
    // verifyStatic must be called before each verification
    PowerMockito.verifyStatic(ServiceBaseUtility.class);
    ServiceBaseUtility.apiCleanup(Mockito.any(), Mockito.eq(MethodNames.EVALUATE_COHORT.getName()));
}
Also used : Response(javax.ws.rs.core.Response) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with IMultipartBody

use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody 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)

Aggregations

IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)25 Response (javax.ws.rs.core.Response)23 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 Patient (org.hl7.fhir.r4.model.Patient)9 PatientListMeasureEvaluation (com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation)8 FhirContext (ca.uhn.fhir.context.FhirContext)7 IParser (ca.uhn.fhir.parser.IParser)7 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)7 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponse (io.swagger.annotations.ApiResponse)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 POST (javax.ws.rs.POST)7 Path (javax.ws.rs.Path)7