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"));
}
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());
}
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;
}
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));
}
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));
}
Aggregations