Search in sources :

Example 11 with DateParameter

use of com.ibm.cohort.cql.evaluation.parameters.DateParameter in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluateMeasureMoreThanOneFormOfId.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMoreThanOneFormOfId() 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", 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, new Identifier().setValue("identifier"));
    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) Identifier(com.ibm.cohort.engine.measure.Identifier) 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 12 with DateParameter

use of com.ibm.cohort.cql.evaluation.parameters.DateParameter 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 13 with DateParameter

use of com.ibm.cohort.cql.evaluation.parameters.DateParameter in project quality-measure-and-cohort-service by Alvearie.

the class DefaultMeasurementPeriodStrategy method intervalToPair.

protected Pair<String, String> intervalToPair(IntervalParameter interval) {
    String start = null;
    String end = null;
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(TARGET_DATE_FORMAT);
    // weird CQL-language formatting such as the "@" char.
    if (interval.getStart() instanceof DatetimeParameter) {
        DateTime cqlType = null;
        DatetimeParameter dtStart = (DatetimeParameter) interval.getStart();
        cqlType = (DateTime) dtStart.toCqlType();
        start = formatter.format(cqlType.getDateTime());
        DatetimeParameter dtEnd = (DatetimeParameter) interval.getEnd();
        cqlType = (DateTime) dtEnd.toCqlType();
        end = formatter.format(cqlType.getDateTime());
    } else if (interval.getStart() instanceof DateParameter) {
        org.opencds.cqf.cql.engine.runtime.Date cqlType = null;
        DateParameter dStart = (DateParameter) interval.getStart();
        cqlType = (org.opencds.cqf.cql.engine.runtime.Date) dStart.toCqlType();
        start = formatter.format(cqlType.getDate());
        DateParameter dEnd = (DateParameter) interval.getEnd();
        cqlType = (org.opencds.cqf.cql.engine.runtime.Date) dEnd.toCqlType();
        end = formatter.format(cqlType.getDate());
    } else {
        throw new IllegalArgumentException(String.format("Unexpected interval data type '%s'", interval.getStart().getClass()));
    }
    return new ImmutablePair<String, String>(start, end);
}
Also used : DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) Date(java.util.Date)

Example 14 with DateParameter

use of com.ibm.cohort.cql.evaluation.parameters.DateParameter in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.

public static Parameter toCohortParameter(Extension extension) {
    Parameter parameter;
    Type extensionValue = extension.getValue();
    if (extensionValue instanceof Base64BinaryType) {
        parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
    } else if (extensionValue instanceof BooleanType) {
        parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
    } else if (extensionValue instanceof DateType) {
        parameter = new DateParameter(((DateType) extensionValue).asStringValue());
    } else if (extensionValue instanceof DateTimeType) {
        parameter = convertDateTimeType((DateTimeType) extensionValue);
    } else if (extensionValue instanceof DecimalType) {
        parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof InstantType) {
        parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof IntegerType) {
        parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
    } else if (extensionValue instanceof StringType) {
        parameter = new StringParameter(((StringType) extensionValue).getValue());
    } else if (extensionValue instanceof TimeType) {
        parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
    } else if (extensionValue instanceof UriType) {
        parameter = new StringParameter(((UriType) extensionValue).getValue());
    } else if (extensionValue instanceof Coding) {
        parameter = convertCoding((Coding) extensionValue);
    } else if (extensionValue instanceof CodeableConcept) {
        parameter = convertCodeableConcept((CodeableConcept) extensionValue);
    } else if (extensionValue instanceof Period) {
        Period castValue = (Period) extensionValue;
        parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
    } else if (extensionValue instanceof Quantity) {
        parameter = convertQuantity((Quantity) extensionValue);
    } else if (extensionValue instanceof Range) {
        Range castValue = (Range) extensionValue;
        parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
    } else if (extensionValue instanceof Ratio) {
        Ratio castValue = (Ratio) extensionValue;
        parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
    } else {
        throw new UnsupportedFhirTypeException(extensionValue);
    }
    return parameter;
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringType(org.hl7.fhir.r4.model.StringType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) UriType(org.hl7.fhir.r4.model.UriType) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Coding(org.hl7.fhir.r4.model.Coding) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) BooleanType(org.hl7.fhir.r4.model.BooleanType) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) IntegerType(org.hl7.fhir.r4.model.IntegerType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) StringType(org.hl7.fhir.r4.model.StringType) DecimalType(org.hl7.fhir.r4.model.DecimalType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) InstantType(org.hl7.fhir.r4.model.InstantType) UriType(org.hl7.fhir.r4.model.UriType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DecimalType(org.hl7.fhir.r4.model.DecimalType) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 15 with DateParameter

use of com.ibm.cohort.cql.evaluation.parameters.DateParameter in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluationTest 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);
    MeasureEvaluation evaluation = new MeasureEvaluation();
    evaluation.setDataServerConfig(dataServerConfig);
    evaluation.setTerminologyServerConfig(termServerConfig);
    evaluation.setPatientId("patientId");
    evaluation.setMeasureContext(ctx);
    evaluation.setEvidenceOptions(new MeasureEvidenceOptions(false, MeasureEvidenceOptions.DefineReturnOptions.ALL));
    ObjectMapper om = new ObjectMapper();
    String serialized = om.writeValueAsString(evaluation);
    MeasureEvaluation deserialized = om.readValue(serialized, MeasureEvaluation.class);
    assertEquals(evaluation, deserialized);
}
Also used : MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) HashMap(java.util.HashMap) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)18 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)16 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Measure (org.hl7.fhir.r4.model.Measure)11 MeasureContext (com.ibm.cohort.engine.measure.MeasureContext)10 Library (org.hl7.fhir.r4.model.Library)9 FhirContext (ca.uhn.fhir.context.FhirContext)8 IParser (ca.uhn.fhir.parser.IParser)8 PatientListMeasureEvaluation (com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation)8 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)6 Patient (org.hl7.fhir.r4.model.Patient)6 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)5 MeasureEvaluation (com.ibm.cohort.engine.api.service.model.MeasureEvaluation)5 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)5