Search in sources :

Example 26 with Code

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

the class R4RestFhirTerminologyProviderTest method inOperationHandlesNullSystem.

@Test
public void inOperationHandlesNullSystem() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId("urn:oid:Test");
    Code code = new Code();
    code.setCode(TEST_CODE);
    code.setDisplay(TEST_DISPLAY);
    Parameters parameters = new Parameters();
    parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(true));
    mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&_format=json", parameters);
    boolean result = provider.in(code, info);
    assertTrue(result);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) BooleanType(org.hl7.fhir.r4.model.BooleanType) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 27 with Code

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

the class SparkDataRow method getValue.

@Override
public Object getValue(String fieldName) {
    Object result = null;
    Object sparkVal = sparkRow.getAs(fieldName);
    if (sparkVal != null) {
        boolean isCode = false;
        /**
         * The following logic uses column metadata fields provided in the Spark schema
         * to identify columns
         */
        Metadata metadata = MetadataUtils.getColumnMetadata(sparkRow.schema(), fieldName);
        isCode = MetadataUtils.isCodeCol(metadata);
        if (isCode) {
            Code code = new Code().withCode((String) sparkVal);
            String system = MetadataUtils.getDefaultSystem(metadata);
            if (system != null) {
                code.withSystem(system);
            }
            String systemCol = MetadataUtils.getSystemCol(metadata);
            if (systemCol != null) {
                code.withSystem(sparkRow.getAs(systemCol));
            }
            String displayCol = MetadataUtils.getDisplayCol(metadata);
            if (displayCol != null) {
                code.withDisplay(sparkRow.getAs(displayCol));
            }
            result = code;
        } else {
            result = doDefaultConversion(sparkVal);
        }
    }
    return result;
}
Also used : Metadata(org.apache.spark.sql.types.Metadata) Code(org.opencds.cqf.cql.engine.runtime.Code)

Example 28 with Code

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

the class R4FileSystemFhirTerminologyProviderTest method lookupOperationSuccess.

@Test(expected = UnsupportedOperationException.class)
public void lookupOperationSuccess() throws Exception {
    CodeSystemInfo info = new CodeSystemInfo();
    info.setId(TEST_SYSTEM);
    info.setVersion(TEST_SYSTEM_VERSION1);
    Code code = new Code();
    code.setCode(TEST_CODE);
    code.setSystem(TEST_SYSTEM);
    code.setDisplay(TEST_DISPLAY);
    provider.lookup(code, info);
}
Also used : CodeSystemInfo(org.opencds.cqf.cql.engine.terminology.CodeSystemInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 29 with Code

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

the class R4FileSystemFhirTerminologyProviderTest method expandOperationReturnsCorrectCodesMoreThanZero.

@Test
public void expandOperationReturnsCorrectCodesMoreThanZero() {
    ValueSetInfo info = new ValueSetInfo();
    info.setId(setId);
    ValueSet valueSet = new ValueSet();
    valueSet.setId("Test");
    valueSet.getExpansion().getContainsFirstRep().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
    Iterable<Code> codes = provider.expand(info);
    List<Code> list = StreamSupport.stream(codes.spliterator(), false).collect(Collectors.toList());
    assertEquals(list.size(), 4);
    for (Code code : list) {
        if (code.getCode() == null || code.getCode().isEmpty()) {
            Assert.fail("Code not present");
        }
        if (code.getSystem() == null || code.getSystem().isEmpty()) {
            Assert.fail("CodeSystem not present");
        }
        if (code.getVersion() == null || code.getVersion().isEmpty()) {
            Assert.fail("Version not present");
        }
        if (code.getDisplay() == null || code.getDisplay().isEmpty()) {
            Assert.fail("Display not present");
        }
    }
}
Also used : ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) ValueSet(org.hl7.fhir.r4.model.ValueSet) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 30 with Code

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

the class R4FileSystemFhirTerminologyProviderTest method inOperationReturnsTrueWithVersion1.

@Test
public void inOperationReturnsTrueWithVersion1() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId(setId);
    Code code = new Code();
    code.setSystem(TEST_SYSTEM);
    code.setCode(TEST_CODE);
    code.setDisplay(TEST_DISPLAY);
    code.setVersion(TEST_SYSTEM_VERSION1);
    boolean result = provider.in(code, info);
    assertTrue(result);
}
Also used : ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) 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