use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testCohortBadDefine.
@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortBadDefine() throws Exception {
prepMocks();
mockResponseClasses();
// Create the ZIP part of the request
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
File tempFile = new File("src/test/resources/cql/basic/Test-1.0.0.cql");
ZipEntry entry = new ZipEntry("cql/Test-1.0.0.cql");
zos.putNextEntry(entry);
byte[] x = new byte[(int) tempFile.length()];
new FileInputStream(tempFile).read(x);
zos.write(x);
zos.closeEntry();
}
ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
IAttachment measurePart = mockAttachment(zipIs);
CohortEvaluation requestData = new CohortEvaluation();
FhirServerConfig serverConfig = getFhirServerConfig();
requestData.setDataServerConfig(serverConfig);
requestData.setTerminologyServerConfig(serverConfig);
requestData.setDefineToRun(null);
requestData.setLoggingLevel(CqlDebug.TRACE);
requestData.setEntrypoint("Test-1.0.0.cql");
requestData.setPatientIds("123");
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(requestData);
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment request = mockAttachment(jsonIs);
// 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("cql/basic/Test-1.0.0.cql");
when(measurePart.getHeader("Content-Disposition")).thenReturn("cql/basic/Test-1.0.0.cql");
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()));
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testCohortEvaluation.
@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortEvaluation() 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 tempFile = new File("src/test/resources/cql/basic/Test-1.0.0.cql");
ZipEntry entry = new ZipEntry("cql/Test-1.0.0.cql");
zos.putNextEntry(entry);
byte[] x = new byte[(int) tempFile.length()];
new FileInputStream(tempFile).read(x);
zos.write(x);
zos.closeEntry();
}
CohortEvaluation requestData = new CohortEvaluation();
FhirServerConfig serverConfig = getFhirServerConfig();
requestData.setDataServerConfig(serverConfig);
requestData.setTerminologyServerConfig(serverConfig);
requestData.setDefineToRun("Female");
requestData.setEntrypoint("Test-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("Test_1.0.0.zip");
when(measurePart.getHeader("Content-Disposition")).thenReturn("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()));
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class PatientListMeasureEvaluationTest method when_serialize_deserialize___properties_are_unchanged.
@Test
public void when_serialize_deserialize___properties_are_unchanged() throws Exception {
FhirServerConfig dataServerConfig = new FhirServerConfig();
dataServerConfig.setEndpoint("dataserver");
FhirServerConfig termServerConfig = new FhirServerConfig();
termServerConfig.setEndpoint("termserver");
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 ctx = new MeasureContext("measureId", parameterOverrides);
PatientListMeasureEvaluation evaluation = new PatientListMeasureEvaluation();
evaluation.setDataServerConfig(dataServerConfig);
evaluation.setTerminologyServerConfig(termServerConfig);
List<String> patientIds = new ArrayList<>();
patientIds.add("patientId1");
patientIds.add("patientId2");
evaluation.setPatientIds(patientIds);
evaluation.setMeasureContext(ctx);
evaluation.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.ALL));
ObjectMapper om = new ObjectMapper();
String serialized = om.writeValueAsString(evaluation);
PatientListMeasureEvaluation deserialized = om.readValue(serialized, PatientListMeasureEvaluation.class);
assertEquals(evaluation, deserialized);
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluatorIntegrationTest method testSimplestHTTPRequestSettings.
@Test
public void testSimplestHTTPRequestSettings() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.basic");
String expression = "Female";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test", "1.0.0"), null, new ImmutablePair<>("Patient", "123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method canFindMultipleEncountersFollowingEachOther.
@Test
public void canFindMultipleEncountersFollowingEachOther() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
Bundle bundle = new Bundle();
Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
firstEncounter.setResource(ENCOUNTER_1);
Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
secondEncounter.setResource(ENCOUNTER_2);
bundle.addEntry(firstEncounter);
bundle.addEntry(secondEncounter);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "ValidEncounters2";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test3", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
Aggregations