Search in sources :

Example 1 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluationTest method testProcessAccumulators_notSDESex.

@Test
public void testProcessAccumulators_notSDESex() {
    /* 
		 * Jill - I don't like how this part of the code works.  The code grabs everything after (and including) the "-", 
		 * and then looks for that to exist as an extension on the Patient resource.  This works for race and ethnicity 
		 * on the US-core patient profile, but since we already calculated this in the populate SDE accumulator method
		 * the only reason it's "recalculating" is because the system and display aren't on the passed in map.
		 * Plus, it's coded assuming there is a list of extensions within the extension (which is how US-Core handles race and eth) 
		 * and it magically grabs the first one... so if you have multiple this doesn't match all of them.
		*/
    Code white = new Code();
    white.setCode(WHITE_CODE);
    Map<String, Map<String, Integer>> sdeAccumulators = getSDEAccumulators(SDE_RACE, null, white, new HashMap<>());
    MeasureReport report = new MeasureReport();
    Patient mockPatient = mockPatient();
    Extension raceExtension = new Extension();
    // This can be anything as long as it includes "-race"
    raceExtension.setUrl("something-race");
    // This example was stolen from https://www.hl7.org/fhir/us/core/Patient-example.xml.html
    Extension valueExtension = new Extension();
    valueExtension.setUrl("ombCategory");
    valueExtension.setValue(getWhiteCoding());
    raceExtension.setExtension(Arrays.asList(valueExtension));
    Mockito.when(mockPatient.getExtension()).thenReturn(Arrays.asList(raceExtension));
    MeasureSupplementalDataEvaluation.processAccumulators(report, sdeAccumulators, true, Arrays.asList(mockPatient));
    assertNotNull(report);
    // EvaluatedResource should contain a reference to an observation record created for supplemental data
    assertEquals(1, report.getEvaluatedResource().size());
    // The observation record mentioned previously should exist within the contained resources of the measure report
    assertEquals(1, report.getContained().size());
    assertTrue(report.getContained().get(0) instanceof Observation);
    Observation obs = (Observation) report.getContained().get(0);
    // For a single patient, the code of the observation should be the supplemental data text
    assertEquals(SDE_RACE, obs.getCode().getText());
    // For a single patient, the value of the observation should be the result of the appropriate define
    assertTrue(obs.getValue() instanceof CodeableConcept);
    assertEquals(WHITE_CODE, ((CodeableConcept) obs.getValue()).getCoding().get(0).getCode());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Code(org.opencds.cqf.cql.engine.runtime.Code) HashMap(java.util.HashMap) Map(java.util.Map) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 2 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluationTest method getMaleCode.

private Code getMaleCode() {
    Code male = new Code();
    male.setCode(MALE_CODE);
    male.setSystem(AdministrativeGender.MALE.getSystem());
    male.setDisplay(AdministrativeGender.MALE.getDisplay());
    return male;
}
Also used : Code(org.opencds.cqf.cql.engine.runtime.Code)

Example 3 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testConcept.

@Test
public void testConcept() {
    String codeString1 = "code1";
    String system1 = "system1";
    String display1 = "display1";
    String version1 = "version1";
    String codeString2 = "code2";
    String system2 = "system2";
    String display2 = "display2";
    String version2 = "version2";
    String conceptDisplay = "conceptDisplay";
    Code code1 = new Code().withCode(codeString1).withSystem(system1).withDisplay(display1).withVersion(version1);
    Code code2 = new Code().withCode(codeString2).withSystem(system2).withDisplay(display2).withVersion(version2);
    Concept concept = new Concept().withCodes(Arrays.asList(code1, code2)).withDisplay(conceptDisplay);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(concept);
    assertTrue(fhirTypeValue instanceof CodeableConcept);
    CodeableConcept castResult = (CodeableConcept) fhirTypeValue;
    List<Coding> codingList = castResult.getCoding();
    boolean code1Found = false;
    boolean code2Found = false;
    for (Coding coding : codingList) {
        if (coding.getCode().equals(codeString1)) {
            verifyBaseTypeAsCode(coding, codeString1, system1, display1, version1);
            code1Found = true;
        } else if (coding.getCode().equals(codeString2)) {
            verifyBaseTypeAsCode(coding, codeString2, system2, display2, version2);
            code2Found = true;
        } else {
            Assert.fail();
        }
    }
    assertTrue(code1Found && code2Found);
    assertEquals(2, codingList.size());
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.opencds.cqf.cql.engine.runtime.Concept) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Coding(org.hl7.fhir.r4.model.Coding) Code(org.opencds.cqf.cql.engine.runtime.Code) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 4 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testCode.

@Test
public void testCode() {
    String codeString = "code";
    String system = "system";
    String display = "display";
    String version = "version";
    Code code = new Code().withCode(codeString).withSystem(system).withDisplay(display).withVersion(version);
    verifyBaseTypeAsCode(CQLToFHIRMeasureReportHelper.getFhirTypeValue(code), codeString, system, display, version);
}
Also used : Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 5 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class RetrieveCacheCodeTest method create.

@Test
public void create() {
    String code = "code";
    String system = "system";
    String display = "display";
    String version = "version";
    Code source = new Code().withCode(code).withSystem(system).withDisplay(display).withVersion(version);
    RetrieveCacheCode expected = new RetrieveCacheCode(code, system, display, version);
    RetrieveCacheCode actual = RetrieveCacheCode.create(source);
    Assert.assertEquals(expected, actual);
}
Also used : Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Aggregations

Code (org.opencds.cqf.cql.engine.runtime.Code)45 Test (org.junit.Test)35 ValueSetInfo (org.opencds.cqf.cql.engine.terminology.ValueSetInfo)17 Parameters (org.hl7.fhir.r4.model.Parameters)6 HashMap (java.util.HashMap)5 Metadata (org.apache.spark.sql.types.Metadata)4 ValueSet (org.hl7.fhir.r4.model.ValueSet)4 BaseSparkTest (com.ibm.cohort.cql.spark.BaseSparkTest)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 MetadataBuilder (org.apache.spark.sql.types.MetadataBuilder)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 CodeSystemInfo (org.opencds.cqf.cql.engine.terminology.CodeSystemInfo)3 DataRow (com.ibm.cohort.datarow.model.DataRow)2 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 ConfigurationException (ca.uhn.fhir.context.ConfigurationException)1 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 CodeKey (com.ibm.cohort.datarow.model.CodeKey)1 SimpleDataRow (com.ibm.cohort.datarow.model.SimpleDataRow)1