Skip to content

Commit

Permalink
MAT-7038: Rework to ensure FHIR only Code Systems are not dropped dur…
Browse files Browse the repository at this point in the history
…ing processing.

Replace index based search with lambda findFirst.

Simplify log conditional, and set logs at debug level.
  • Loading branch information
jkotanchik-SB committed May 9, 2024
1 parent 5cf0b1c commit 9231056
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,48 +123,45 @@ private List<QdmValueSet.Concept> getValueSetConcepts(

public List<CodeSystem> getAllCodeSystems() {
// remove items that are marked as not present in vsac to cut expense
List<CodeSystemEntry> codeSystemEntries = mappingService.getCodeSystemEntries().stream().filter(codeSystemEntry -> !codeSystemEntry.getOid().contains("NOT.IN.VSAC")).toList();
List<CodeSystemEntry> codeSystemMappingEntries =
mappingService.getCodeSystemEntries().stream()
.filter(codeSystemEntry -> !codeSystemEntry.getOid().contains("NOT.IN.VSAC"))
.toList();
List<CodeSystem> codeSystems = codeSystemRepository.findAll();
List<CodeSystem> 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<CodeSystemEntry> 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<CodeSystem> retrieveAllCodeSystems(UmlsUser umlsUser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<CodeSystemEntry> codeSystemEntries = Arrays.asList(ce1, ce2);
List<gov.cms.madie.terminology.models.CodeSystem> 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<CodeSystemEntry> codeSystemEntries = Arrays.asList(ce1, ce2, ce3);
List<gov.cms.madie.terminology.models.CodeSystem> codeSystems = Arrays.asList(c1, c2, c3);
when(mappingService.getCodeSystemEntries()).thenAnswer(invocation -> codeSystemEntries);
when(codeSystemRepository.findAll()).thenAnswer(invocation -> codeSystems);
List<gov.cms.madie.terminology.models.CodeSystem> 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
Expand Down

0 comments on commit 9231056

Please sign in to comment.