diff --git a/src/main/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaService.java b/src/main/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaService.java index ffef4abe..2bcdf67e 100644 --- a/src/main/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaService.java +++ b/src/main/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaService.java @@ -114,7 +114,9 @@ public List getSourceDataCriteria(String cql, String accessT DataCriteria dataCriteria = parseDataCriteriaFromCql(cql, accessToken); Map> criteriaWithValueSet = dataCriteria.getDataCriteriaWithValueSets(); - if (MapUtils.isEmpty(criteriaWithValueSet)) { + + Map> criteriaWithCodes = dataCriteria.getDataCriteriaWithCodes(); + if (MapUtils.isEmpty(criteriaWithValueSet) && MapUtils.isEmpty(criteriaWithCodes)) { log.info("Data criteria not found for given cql"); return Collections.emptyList(); } @@ -127,7 +129,6 @@ public List getSourceDataCriteria(String cql, String accessT .collect(Collectors.toList()); // data criteria from direct reference codes - Map> criteriaWithCodes = dataCriteria.getDataCriteriaWithCodes(); List codeCriteria = criteriaWithCodes.entrySet().stream() .map(criteria -> buildSourceDataCriteriaForCode(criteria.getKey(), criteria.getValue())) diff --git a/src/test/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaServiceTest.java b/src/test/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaServiceTest.java index e4c9030b..0ae3393f 100644 --- a/src/test/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaServiceTest.java +++ b/src/test/java/gov/cms/mat/cql_elm_translation/service/DataCriteriaServiceTest.java @@ -119,6 +119,36 @@ void testGetSourceDataCriteriaWhenNoSourceCriteriaFound() { assertThat(sourceDataCriteria.size(), is(equalTo(0))); } + @Test + void testGetSourceDataCriteriaWithCriteriaWithCodes() { + String cql = + "library DRCTest version '0.0.000'\n" + + "using QDM version '5.6'\n" + + "codesystem \"LOINC\": 'urn:oid:2.16.840.1.113883.6.1'\n" + + "valueset \"Palliative Care Encounter\": 'urn:oid:2.16.840.1.113883.3.464.1003.101.12.1090'\n" + + "code \"Functional Assessment of Chronic Illness Therapy - Palliative Care Questionnaire (FACIT-Pal)\": '71007-9' from \"LOINC\" display 'Functional Assessment of Chronic Illness Therapy - Palliative Care Questionnaire (FACIT-Pal)'\n" + + "parameter \"Measurement Period\" Interval\n" + + "context Patient\n" + + "define \"Palliative Care in the Measurement Period\":\n" + + "( [\"Encounter, Performed\": \"Functional Assessment of Chronic Illness Therapy - Palliative Care Questionnaire (FACIT-Pal)\"]\n" + + ")"; + + RequestData data = requestData.toBuilder().cqlData(cql).build(); + CqlTranslator translator = + TranslationResource.getInstance(false) + .buildTranslator(data.getCqlDataInputStream(), data.createMap(), data.getSourceInfo()); + + Mockito.doNothing() + .when(cqlConversionService) + .setUpLibrarySourceProvider(anyString(), anyString()); + when(cqlConversionService.processCqlData(any(RequestData.class))).thenReturn(translator); + + List sourceDataCriteria = + dataCriteriaService.getSourceDataCriteria(cql, token); + + assertThat(sourceDataCriteria.size(), is(equalTo(1))); + } + @Test void testGetSourceDataCriteriaWhenNoCqlProvided() { List sourceDataCriteria =