Search in sources :

Example 11 with DataRow

use of com.ibm.cohort.datarow.model.DataRow in project quality-measure-and-cohort-service by Alvearie.

the class AnyColumnFunctionsTest method testAnyColumnRegexHasMatches.

@Test
public void testAnyColumnRegexHasMatches() {
    String matchingField1 = "matchingField1";
    String matchingField2 = "matchingField2";
    String nonMatchingField = "nonMatchingField";
    String expectedValue1 = "matchingValue1";
    String expectedValue2 = "matchingValue2";
    DataRow row = spy(DataRow.class);
    Set<String> allFields = new HashSet<>();
    allFields.add(matchingField1);
    allFields.add(matchingField2);
    allFields.add(nonMatchingField);
    doReturn(allFields).when(row).getFieldNames();
    doReturn(expectedValue1).when(row).getValue(matchingField1);
    doReturn(expectedValue2).when(row).getValue(matchingField2);
    doReturn("nonMatchingValue").when(row).getValue(nonMatchingField);
    String regex = "matchingField[0-9]+";
    List<Object> actual = (List<Object>) AnyColumnFunctions.AnyColumnRegex(row, regex);
    assertThat(actual, containsInAnyOrder("matchingValue1", "matchingValue2"));
}
Also used : List(java.util.List) DataRow(com.ibm.cohort.datarow.model.DataRow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with DataRow

use of com.ibm.cohort.datarow.model.DataRow in project quality-measure-and-cohort-service by Alvearie.

the class AnyColumnFunctionsTest method testAnyColumnNoMatches.

@Test
public void testAnyColumnNoMatches() {
    DataRow row = spy(DataRow.class);
    Set<String> allFields = new HashSet<>();
    allFields.add("nonMatchingField1");
    allFields.add("nonMatchingField2");
    doReturn(allFields).when(row).getFieldNames();
    String prefix = "prefix";
    List<Object> actual = (List<Object>) AnyColumnFunctions.AnyColumn(row, prefix);
    assertThat(actual, empty());
}
Also used : List(java.util.List) DataRow(com.ibm.cohort.datarow.model.DataRow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with DataRow

use of com.ibm.cohort.datarow.model.DataRow in project quality-measure-and-cohort-service by Alvearie.

the class DataRowRetrieveProvider method retrieve.

@Override
public Iterable<Object> retrieve(String context, String contextPath, Object contextValue, String dataType, String templateId, String codePath, Iterable<Code> codes, String valueSet, String datePath, String dateLowPath, String dateHighPath, Interval dateRange) {
    Iterable<Object> result;
    // Fast fail for an unsupported operation scenario
    if (datePath != null || dateLowPath != null || dateHighPath != null) {
        throw new UnsupportedOperationException("Date-based filtering is not supported at this time.");
    }
    Iterable<Object> allRows = data.get(dataType);
    if (codePath != null) {
        // Calculate an index of code to matching rows based on the dataType and
        // codePath
        Map<String, Map<Object, List<Object>>> codePathToCodeMap = indexes.computeIfAbsent(dataType, key -> new HashMap<>());
        Map<Object, List<Object>> indexedRows = codePathToCodeMap.computeIfAbsent(codePath, key -> {
            Map<Object, List<Object>> codeMap = new HashMap<>();
            if (allRows != null) {
                for (Object obj : allRows) {
                    DataRow row = (DataRow) obj;
                    Object code = row.getValue(codePath);
                    if (code != null) {
                        if (code instanceof Code) {
                            code = new CodeKey((Code) code);
                        } else {
                            code = new CodeKey().withCode(String.valueOf(code));
                        }
                        List<Object> list = codeMap.computeIfAbsent(code, codeKey -> new ArrayList<>());
                        list.add(row);
                    }
                }
            }
            return codeMap;
        });
        if (valueSet != null) {
            // expand the valueset into codes
            ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
            codes = terminologyProvider.expand(valueSetInfo);
        }
        if (codes != null) {
            List<Object> allMatches = new ArrayList<>();
            for (Code codeToCheck : codes) {
                CodeKey indexKey = new CodeKey(codeToCheck);
                List<Object> matches = indexedRows.get(indexKey);
                if (matches != null) {
                    allMatches.addAll(matches);
                }
            }
            result = allMatches;
        } else {
            throw new IllegalArgumentException(String.format("No codes found for filtered retrieve of dataType %s, codePath %s", dataType, codePath));
        }
    } else {
        result = (allRows != null) ? allRows : Collections.emptyList();
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CodeKey(com.ibm.cohort.datarow.model.CodeKey) DataRow(com.ibm.cohort.datarow.model.DataRow) Code(org.opencds.cqf.cql.engine.runtime.Code) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with DataRow

use of com.ibm.cohort.datarow.model.DataRow in project quality-measure-and-cohort-service by Alvearie.

the class DataRowModelResolverTest method testIsTypeType.

@Test
public void testIsTypeType() {
    DataRow row = new SimpleDataRow(Collections.emptyMap());
    assertTrue(resolver.is(row, DataRow.class));
}
Also used : SimpleDataRow(com.ibm.cohort.datarow.model.SimpleDataRow) SimpleDataRow(com.ibm.cohort.datarow.model.SimpleDataRow) DataRow(com.ibm.cohort.datarow.model.DataRow) Test(org.junit.Test)

Example 15 with DataRow

use of com.ibm.cohort.datarow.model.DataRow in project quality-measure-and-cohort-service by Alvearie.

the class DataRowModelResolverTest method testRowEqualsRow.

@Test
public void testRowEqualsRow() {
    Map<String, Object> expectations = new HashMap<>();
    expectations.put("field1", "Hello");
    DataRow left = new SimpleDataRow(expectations);
    DataRow right = new SimpleDataRow(expectations);
    assertTrue(resolver.objectEqual(left, right));
    assertTrue(resolver.objectEquivalent(left, right));
}
Also used : SimpleDataRow(com.ibm.cohort.datarow.model.SimpleDataRow) HashMap(java.util.HashMap) SimpleDataRow(com.ibm.cohort.datarow.model.SimpleDataRow) DataRow(com.ibm.cohort.datarow.model.DataRow) Test(org.junit.Test)

Aggregations

DataRow (com.ibm.cohort.datarow.model.DataRow)17 Test (org.junit.Test)13 SimpleDataRow (com.ibm.cohort.datarow.model.SimpleDataRow)9 List (java.util.List)6 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 PrefixStringMatcher (com.ibm.cohort.cql.util.PrefixStringMatcher)2 RegexStringMatcher (com.ibm.cohort.cql.util.RegexStringMatcher)2 StringMatcher (com.ibm.cohort.cql.util.StringMatcher)2 ArrayList (java.util.ArrayList)2 Code (org.opencds.cqf.cql.engine.runtime.Code)2 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)1 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)1 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)1 SparkDataRow (com.ibm.cohort.cql.spark.data.SparkDataRow)1 SparkOutputColumnEncoder (com.ibm.cohort.cql.spark.data.SparkOutputColumnEncoder)1 DataRowDataProvider (com.ibm.cohort.datarow.engine.DataRowDataProvider)1 DataRowRetrieveProvider (com.ibm.cohort.datarow.engine.DataRowRetrieveProvider)1 CodeKey (com.ibm.cohort.datarow.model.CodeKey)1 Map (java.util.Map)1