diff --git a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java index 736132c..362f88c 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -25,10 +25,8 @@ import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; @Service @Slf4j @@ -125,48 +123,45 @@ private List getValueSetConcepts( public List getAllCodeSystems() { // remove items that are marked as not present in vsac to cut expense - List codeSystemEntries = mappingService.getCodeSystemEntries().stream().filter(codeSystemEntry -> !codeSystemEntry.getOid().contains("NOT.IN.VSAC")).toList(); + List codeSystemMappingEntries = + mappingService.getCodeSystemEntries().stream() + .filter(codeSystemEntry -> !codeSystemEntry.getOid().contains("NOT.IN.VSAC")) + .toList(); List codeSystems = codeSystemRepository.findAll(); - List transformedResults = new ArrayList<>(Collections.emptyList()); - codeSystems.forEach(codeSystem -> { - // if the oid shows up at all - int index = -1; - for (int i = 0; i < codeSystems.size(); i++) { - if (codeSystems.get(i).getOid().equals(codeSystem.getOid())) { - index = i; - break; - } - } - if(index != -1) { - CodeSystemEntry matchingEntry = null; - for (CodeSystemEntry entry : codeSystemEntries) { - if (entry.getOid().equals(codeSystem.getOid())) { - matchingEntry = entry; - break; - } - } - if (matchingEntry != null) { - AtomicBoolean usableVersionFound = new AtomicBoolean(false); - matchingEntry.getVersions().forEach(version -> { - // we use fhir csv to interact with api. goal here is to look for fhir version, then give users a display version - // that looks like vsac because that's what they understand. - if (version.getFhir().equals(codeSystem.getVersion()) && version.getVsac() != null) { - codeSystem.setDisplayVersion(version.getVsac()); - transformedResults.add(codeSystem); - usableVersionFound.set(true); - } - }); - if (usableVersionFound.get()){ - log.info("CodeSystem title {} , version: {} was not found in mapping document", codeSystem.getTitle(), codeSystem.getVersion()); + codeSystems.forEach( + codeSystem -> { + Optional matchingEntry = + codeSystemMappingEntries.stream() + .filter(entry -> entry.getOid().equals(codeSystem.getOid())) + .findFirst(); + if (matchingEntry.isPresent()) { + matchingEntry + .get() + .getVersions() + .forEach( + version -> { + // We use fhir url to interact with VSAC FHIR Term Service. + // Goal here is to look for fhir version, then give users + // viewing QDM measures a display version that looks like + // svs vsac because that's what they expect. + if (version.getFhir().equals(codeSystem.getVersion()) + && version.getVsac() != null) { + codeSystem.setQdmDisplayVersion(version.getVsac()); + log.debug( + "CodeSystem title {} , version: {} was found in mapping document", + codeSystem.getTitle(), + codeSystem.getVersion()); + } + }); + } else { + // it was not found, we log that it's not located within vsac. + log.debug( + "CodeSystem title {} , version: {} was NOT found in mapping document", + codeSystem.getTitle(), + codeSystem.getName()); } - } - } - else { - // it was not found, we log that it's not located within vsac. - log.info("CodeSystem title {} , version: {} was not found in mapping document", codeSystem.getTitle(), codeSystem.getName()); - } - }); - return transformedResults; + }); + return codeSystems; } public List retrieveAllCodeSystems(UmlsUser umlsUser) { diff --git a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java index 0f94767..727071e 100644 --- a/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java +++ b/src/test/java/gov/cms/madie/terminology/service/FhirTerminologyServiceTest.java @@ -1,7 +1,6 @@ package gov.cms.madie.terminology.service; import ca.uhn.fhir.context.FhirContext; -import com.okta.commons.lang.Collections; import gov.cms.madie.models.mapping.CodeSystemEntry; import gov.cms.madie.models.measure.ManifestExpansion; import gov.cms.madie.terminology.dto.Code; @@ -27,6 +26,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; @@ -35,12 +35,10 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.Array; import java.nio.charset.Charset; import java.time.Instant; import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; @@ -144,7 +142,7 @@ public void setUp() throws IOException { .name("Icd10CM") .oid("urn:oid:2.16.840.1.113883.6.90") .url("http://hl7.org/fhir/sid/icd-10-cm") - .versions(Collections.toList(version)) + .versions(List.of(version)) .build(); codeSystemEntries.add(codeSystemEntry); } @@ -341,22 +339,39 @@ void testGetAllCodeSystems() { c2.setTitle("t2"); c2.setOid("fakeoid2"); c2.setVersion("2.0"); - CodeSystemEntry.Version cv1 = new CodeSystemEntry.Version().toBuilder().fhir("1.0").vsac("exists").build(); - CodeSystemEntry.Version cv2 = new CodeSystemEntry.Version().toBuilder().fhir("2.0").vsac("exists").build(); - var ce1 = new CodeSystemEntry().toBuilder().versions(java.util.Collections.singletonList(cv1)).oid("fakeoid1").build(); - var ce2 = new CodeSystemEntry().toBuilder().versions(java.util.Collections.singletonList(cv2)).oid("fakeoid2").build(); - - List codeSystemEntries = Arrays.asList(ce1, ce2); - List codeSystems = Arrays.asList(c1, c2); + var c3 = new gov.cms.madie.terminology.models.CodeSystem(); + c3.setTitle("t3"); + c3.setOid("fakeoid3"); + c3.setVersion("2024"); + + CodeSystemEntry.Version cv1 = + new CodeSystemEntry.Version().toBuilder().fhir("1.0").vsac("1").build(); + CodeSystemEntry.Version cv2 = + new CodeSystemEntry.Version().toBuilder().fhir("2.0").vsac("2").build(); + CodeSystemEntry.Version cv3 = new CodeSystemEntry.Version().toBuilder().fhir("latest").build(); + var ce1 = new CodeSystemEntry().toBuilder().versions(List.of(cv1)).oid("fakeoid1").build(); + var ce2 = new CodeSystemEntry().toBuilder().versions(List.of(cv2)).oid("fakeoid2").build(); + var ce3 = new CodeSystemEntry().toBuilder().versions(List.of(cv3)).oid("NOT.IN.VSAC").build(); + + List codeSystemEntries = Arrays.asList(ce1, ce2, ce3); + List codeSystems = Arrays.asList(c1, c2, c3); when(mappingService.getCodeSystemEntries()).thenAnswer(invocation -> codeSystemEntries); when(codeSystemRepository.findAll()).thenAnswer(invocation -> codeSystems); List result = fhirTerminologyService.getAllCodeSystems(); verify(codeSystemRepository).findAll(); - assertEquals(2, result.size()); + assertEquals(3, result.size()); assertEquals("t1", result.get(0).getTitle()); + assertEquals("1", result.get(0).getQdmDisplayVersion()); + assertEquals("t2", result.get(1).getTitle()); + assertEquals("2", result.get(1).getQdmDisplayVersion()); + + // Verify FHIR only Code Systems appear in the result set + assertEquals("t3", result.get(2).getTitle()); + assertEquals("2024", result.get(2).getVersion()); + assertNull(result.get(2).getQdmDisplayVersion()); } @Test