Search in sources :

Example 21 with IMultipartBody

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

the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasure_null_request_part.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasure_null_request_part() {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_PATIENT_LIST_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(null);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(mock(IAttachment.class));
    restHandler.evaluatePatientListMeasure(mockRequestContext, VERSION, body);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) 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 22 with IMultipartBody

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

the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingMeasureId.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingMeasureId() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata", getCapabilityStatement());
    mockFhirResourceRetrieval(patient);
    FhirServerConfig clientConfig = getFhirServerConfig();
    MeasureContext measureContext = new MeasureContext("unknown");
    MeasureEvaluation evaluationRequest = new MeasureEvaluation();
    evaluationRequest.setDataServerConfig(clientConfig);
    evaluationRequest.setPatientId(patient.getId());
    evaluationRequest.setMeasureContext(measureContext);
    // evaluationRequest.setEvidenceOptions(evidenceOptions);
    // 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
    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, VERSION, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : Response(javax.ws.rs.core.Response) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) ByteArrayInputStream(java.io.ByteArrayInputStream) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) 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 23 with IMultipartBody

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

the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasureSuccess.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasureSuccess() 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 patient1 = getPatient("patientId1", AdministrativeGender.MALE, 40);
    Patient patient2 = getPatient("patientId2", AdministrativeGender.FEMALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockFhirResourceRetrieval(patient1);
    mockFhirResourceRetrieval(patient2);
    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);
    ArrayList<String> patientIds = new ArrayList<>();
    patientIds.add(patient1.getId());
    patientIds.add(patient2.getId());
    request.setPatientIds(patientIds);
    request.setMeasureContext(measureContext);
    request.setExpandValueSets(true);
    request.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(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);
    assertEquals(mockResponse, loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(Response.Status.OK);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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 24 with IMultipartBody

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

the class CohortEngineRestHandlerTest method testValueSetExists.

@PrepareForTest({ Response.class, ValueSetUtil.class, FHIRRestUtils.class })
@Test
public void testValueSetExists() throws Exception {
    prepMocks();
    mockResponseClasses();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.mockStatic(FHIRRestUtils.class);
    PowerMockito.mockStatic(ValueSetUtil.class);
    PowerMockito.mockStatic(DefaultFhirClientBuilder.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.CREATE_VALUE_SET.getName())).thenReturn(null);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withArguments(Mockito.any()).thenReturn(mockDefaultFhirClientBuilder);
    PowerMockito.when(ValueSetUtil.importArtifact(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.eq(true))).thenReturn("ID");
    File tempFile = new File(VALUE_SET_INPUT);
    IAttachment spreadsheetPart = PowerMockito.mock(IAttachment.class);
    byte[] x = Files.readAllBytes(Paths.get(tempFile.getAbsolutePath()));
    DataHandler dataHandler = PowerMockito.mock(DataHandler.class);
    when(spreadsheetPart.getDataHandler()).thenReturn(dataHandler);
    when(dataHandler.getInputStream()).thenReturn(new ByteArrayInputStream(x));
    IMultipartBody body = getFhirConfigFileBody();
    when(body.getAttachment(CohortEngineRestHandler.VALUE_SET_PART)).thenReturn(spreadsheetPart);
    Response loadResponse = restHandler.createValueSet(VERSION, body, false);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(Status.CONFLICT);
}
Also used : Response(javax.ws.rs.core.Response) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) DataHandler(javax.activation.DataHandler) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with IMultipartBody

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

the class CohortHandlerTestBase method getEnhancedHealthCheckInputConfigFileBody.

protected IMultipartBody getEnhancedHealthCheckInputConfigFileBody(boolean includeTerminologyServer) throws Exception {
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    EnhancedHealthCheckInput input = new EnhancedHealthCheckInput();
    input.setDataServerConfig(getFhirServerConfig());
    if (includeTerminologyServer) {
        input.setTerminologyServerConfig(getFhirServerConfig());
    }
    String json = om.writeValueAsString(input);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestStatusHandler.FHIR_SERVER_CONNECTION_CONFIG)).thenReturn(rootPart);
    return body;
}
Also used : IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) ByteArrayInputStream(java.io.ByteArrayInputStream) EnhancedHealthCheckInput(com.ibm.cohort.engine.api.service.model.EnhancedHealthCheckInput) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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