use of org.hl7.fhir.dstu2.formats.IParser 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);
}
use of org.hl7.fhir.dstu2.formats.IParser 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);
}
use of org.hl7.fhir.dstu2.formats.IParser in project quality-measure-and-cohort-service by Alvearie.
the class DefaultVT method testMeasureEvaluationByMeasureIdentifier.
// to tag a specific test to be part of DVT (deployment verification test)
@Category(DVT.class)
@Test
public /**
* Test a successful measure evaluation using identifier and version as the lookup key
*/
void testMeasureEvaluationByMeasureIdentifier() throws Exception {
// You want -Denabled.dark.features=all in your Liberty jvm.options
Assume.assumeTrue(isServiceDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION));
final String RESOURCE = getUrlBase() + CohortServiceAPISpec.CREATE_DELETE_EVALUATION_PATH;
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
Library library = TestHelper.getTemplateLibrary();
Identifier identifier = new Identifier().setValue("measure-identifier").setSystem("http://ibm.com/health/test");
Measure measure = TestHelper.getTemplateMeasure(library);
measure.setIdentifier(Arrays.asList(identifier));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
// Files.write( baos.toByteArray(), new File("target/test_measure_v1_0_0.zip"));
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureEvaluation requestData = new MeasureEvaluation();
requestData.setDataServerConfig(dataServerConfig);
requestData.setTerminologyServerConfig(termServerConfig);
// This is a patient ID that is assumed to exist in the target FHIR server
requestData.setPatientId(VALID_PATIENT_ID);
requestData.setMeasureContext(new MeasureContext(null, parameterOverrides, new com.ibm.cohort.engine.measure.Identifier(identifier.getSystem(), identifier.getValue()), measure.getVersion()));
requestData.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.NONE));
ObjectMapper om = new ObjectMapper();
System.out.println(om.writeValueAsString(requestData));
RequestSpecification request = buildBaseRequest(new Headers()).queryParam(CohortEngineRestHandler.VERSION, ServiceBuildConstants.DATE).multiPart(CohortEngineRestHandler.REQUEST_DATA_PART, requestData, "application/json").multiPart(CohortEngineRestHandler.MEASURE_PART, "test_measure_v1_0_0.zip", new ByteArrayInputStream(baos.toByteArray()));
ValidatableResponse response = request.post(RESOURCE, getServiceVersion()).then();
ValidatableResponse vr = runSuccessValidation(response, ContentType.JSON, HttpStatus.SC_OK);
String expected = getJsonFromFile(ServiceAPIGlobalSpec.EXP_FOLDER_TYPE, "measure_evaluation_exp.json");
String actual = vr.extract().asString();
assertMeasureReportEquals(parser, expected, actual, false);
}
use of org.hl7.fhir.dstu2.formats.IParser in project openmrs-module-fhir2 by openmrs.
the class FhirImmunizationServiceImplTest method updateImmunization_shouldUpdateImmunizationAccordingly.
@Test
public void updateImmunization_shouldUpdateImmunizationAccordingly() {
// setup
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
Immunization updatedImmunization = parser.parseResource(Immunization.class, "{\n" + " \"resourceType\": \"Immunization\",\n" + " \"id\": \"9353776b-dead-4588-8723-d687197d8438\",\n" + " \"status\": \"completed\",\n" + " \"vaccineCode\": {\n" + " \"coding\": [\n" + " {\n" + " \"code\": \"d144d24f-6913-4b63-9660-a9108c2bebef\",\n" + " \"display\": \"STAVUDINE LAMIVUDINE AND NEVIRAPINE\"\n" + " }\n" + " ]\n" + " },\n" + " \"patient\": {\n" + " \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + " \"type\": \"Patient\"\n" + " },\n" + " \"encounter\": {\n" + " \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + " \"type\": \"Encounter\"\n" + " },\n" + " \"occurrenceDateTime\": \"2020-07-08T20:30:00+02:00\",\n" + " \"manufacturer\": {\n" + " \"display\": \"Pharma Inc.\"\n" + " },\n" + " \"lotNumber\": \"YU765YT-1\",\n" + " \"expirationDate\": \"2020-10-08\",\n" + " \"performer\": [\n" + " {\n" + " \"actor\": {\n" + " \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + " \"type\": \"Practitioner\"\n" + " }\n" + " }\n" + " ],\n" + " \"protocolApplied\": [\n" + " {\n" + " \"doseNumberPositiveInt\": 4\n" + " }\n" + " ]\n" + "}");
// replay
Immunization savedImmunization = service.update("9353776b-dead-4588-8723-d687197d8438", updatedImmunization);
Obs obs = obsService.getObsByUuid(savedImmunization.getId());
// verify
helper.validateImmunizationObsGroup(obs);
assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
obs.getGroupMembers().forEach(o -> {
assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
});
Map<String, Obs> members = helper.getObsMembersMap(obs);
assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("d144d24f-6913-4b63-9660-a9108c2bebef"));
assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T20:30:00+02:00").getValue()));
assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(4.0));
assertThat(members.get(CIEL_1419).getValueText(), is("Pharma Inc."));
assertThat(members.get(CIEL_1420).getValueText(), is("YU765YT-1"));
assertThat(members.get(CIEL_165907).getValueDate(), equalTo(new DateType("2020-10-08").getValue()));
}
use of org.hl7.fhir.dstu2.formats.IParser in project ab2d by CMSgov.
the class CapabilityAPIV2 method capabilityStatement.
@Operation(summary = CAP_REQ)
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = CAP_DESC + " http://hl7.org/fhir/capabilitystatement.html") })
@ResponseStatus(value = HttpStatus.OK)
@GetMapping(value = "/metadata")
public ResponseEntity<String> capabilityStatement(HttpServletRequest request) {
IParser parser = R4.getJsonParser();
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, HttpStatus.OK, CAP_STMT, CAP_RET, (String) request.getAttribute(REQUEST_ID)));
String server = common.getCurrentUrl(request).replace("/metadata", "");
CapabilityStatement capabilityStatement = CapabilityStatementR4.populateCS(server);
return new ResponseEntity<>(parser.encodeResourceToString(capabilityStatement), null, HttpStatus.OK);
}
Aggregations