use of org.hl7.fhir.dstu2016may.model.Period 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.dstu2016may.model.Period 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.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method getEncounter.
public Encounter getEncounter(int year, int month, int day) {
Encounter encounter = new Encounter();
Period encounterPeriod = new Period();
Calendar c = Calendar.getInstance();
c.set(year, month - 1, day);
Date encounterDate = c.getTime();
encounterPeriod.setStart(encounterDate);
encounterPeriod.setEnd(encounterDate);
encounter.setPeriod(encounterPeriod);
return encounter;
}
use of org.hl7.fhir.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.
the class CQLToFHIRMeasureReportHelper method getFhirTypeForInterval.
private static IBaseDatatype getFhirTypeForInterval(Interval interval) {
Object low = interval.getLow();
Object high = interval.getHigh();
if (low instanceof DateTime) {
// Handle DateTime conversion to force UTC timezone
Period period = new Period();
period.setStartElement(createDateTimeType((DateTime) low));
period.setEndElement(createDateTimeType((DateTime) high));
return period;
} else if (low instanceof Quantity) {
return converter.toFhirRange(interval);
} else {
logger.warn("Support not implemented for Interval parameters of type {} on a MeasureReport", low.getClass());
return null;
}
}
use of org.hl7.fhir.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.
the class IdentifierBuilderTest method testBuilder.
@Test
public void testBuilder() {
String system = "TEST SYSTEM";
String code = "TEST CODE";
String display = "TEST DISPLAY";
String value = "TEST VALUE";
Coding coding = new Coding(system, code, display);
CodeableConcept type = new CodeableConcept(coding);
Period period = new Period();
period.setStart(new Date());
period.setEnd(new Date());
Reference assigner = new Reference("TEST REFERENCE");
Identifier identifier = new IdentifierBuilder().buildUse(IdentifierUse.OFFICIAL).buildSystem(system).buildType(type).buildPeriod(period).buildValue(value).buildAssigner(assigner).build();
assertEquals(IdentifierUse.OFFICIAL, identifier.getUse());
assertEquals(system, identifier.getSystem());
assertEquals(type, identifier.getType());
assertEquals(period, identifier.getPeriod());
assertEquals(value, identifier.getValue());
assertEquals(assigner, identifier.getAssigner());
}
Aggregations