Search in sources :

Example 36 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CqlEvaluatorIntegrationTest method testConditionClinicalStatusActiveIsMatched.

@Test
public void testConditionClinicalStatusActiveIsMatched() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Condition condition = new Condition();
    condition.setId("condition");
    condition.setSubject(new Reference("Patient/123"));
    condition.setClinicalStatus(new CodeableConcept().addCoding(new Coding().setCode("active").setSystem("http://terminology.hl7.org/CodeSystem/condition-clinical")).setText("Active"));
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", condition);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.condition", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "HasActiveCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestStatusActive", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, true);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Coding(org.hl7.fhir.r4.model.Coding) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 37 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CqlEvaluatorIntegrationTest method testConditionDateRangeCriteriaMatched.

@Test
public void testConditionDateRangeCriteriaMatched() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse("2000-01-01");
    Condition condition = new Condition();
    condition.setId("condition");
    condition.setSubject(new Reference("Patient/123"));
    condition.setRecordedDate(date);
    // Wiremock does not support request matching withQueryParam() function does not support
    // the same parameter multiple times, so we do some regex work and try to make it
    // somewhat order independent while still readable.
    // @see https://github.com/tomakehurst/wiremock/issues/398
    MappingBuilder builder = get(urlMatching("/Condition\\?(recorded-date=[lg]e.*&){2}subject=Patient%2F123&_format=json"));
    mockFhirResourceRetrieval(builder, condition);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.condition", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("MeasurementPeriod", new IntervalParameter(new DatetimeParameter("1999-01-01T00:00:00-05:00"), true, new DatetimeParameter("2000-01-01T00:00:00-05:00"), false));
    String expression = "ConditionInInterval";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestDateQuery", "1.0.0"), parameters, newPatientContext("123"), Collections.singleton(expression));
    Assert.assertEquals(1, actual.getExpressionResults().size());
    List<Object> value = (List) actual.getExpressionResults().get(expression);
    Assert.assertEquals(1, value.size());
    assertFhirEquals(condition, (IBaseResource) value.get(0));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 38 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CqlTemporalTests method noEventWithinFourDays.

@Test
public void noEventWithinFourDays() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    Observation observationIN = new Observation();
    DateTimeType observationEffective = new DateTimeType(new Date());
    observationEffective.setYear(2015);
    observationEffective.setMonth(1);
    observationEffective.setDay(15);
    observationIN.setEffective(observationEffective);
    Observation observationOUT = new Observation();
    DateTimeType observationEffective2 = new DateTimeType(new Date());
    observationEffective2.setYear(2015);
    observationEffective2.setMonth(1);
    observationEffective2.setDay(25);
    observationOUT.setEffective(observationEffective2);
    Bundle bundle = new Bundle();
    Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
    firstEncounter.setResource(observationIN);
    Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
    secondEncounter.setResource(observationOUT);
    bundle.addEntry(firstEncounter);
    bundle.addEntry(secondEncounter);
    mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ValidObservation not within 4 days";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test5", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, true);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Observation(org.hl7.fhir.r4.model.Observation) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 39 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CqlTemporalTests method cannotFindEncountersThatDontExist.

@Test
public void cannotFindEncountersThatDontExist() 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_3);
    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, false);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 40 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CqlTemporalTests method cannotFindEventWithoutExistenceOfThirdEvent.

@Test
public void cannotFindEventWithoutExistenceOfThirdEvent() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Observation observation = new Observation();
    DateTimeType observationEffective = new DateTimeType(new Date());
    observationEffective.setYear(2015);
    observationEffective.setMonth(2);
    observationEffective.setDay(5);
    observation.setEffective(observationEffective);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
    mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observation, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ObservationWithin30DaysOfCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test2", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, false);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) HashMap(java.util.HashMap) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Aggregations

FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)63 Test (org.junit.Test)52 Patient (org.hl7.fhir.r4.model.Patient)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 HashMap (java.util.HashMap)21 File (java.io.File)18 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)15 Response (javax.ws.rs.core.Response)15 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)14 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)14 FileWriter (java.io.FileWriter)14 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)13 PrintStream (java.io.PrintStream)13 Writer (java.io.Writer)13 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)10 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IParser (ca.uhn.fhir.parser.IParser)9