From 89b263a202da9fc9894a31bd26f9e50688dd86c1 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Tue, 30 Apr 2024 10:24:39 -0700 Subject: [PATCH] MAT-7038: Modify cs retrieve to return displayValues for vsac version --- .../madie/terminology/models/CodeSystem.java | 1 + .../service/FhirTerminologyService.java | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/gov/cms/madie/terminology/models/CodeSystem.java b/src/main/java/gov/cms/madie/terminology/models/CodeSystem.java index 58e19fb..6a7016e 100644 --- a/src/main/java/gov/cms/madie/terminology/models/CodeSystem.java +++ b/src/main/java/gov/cms/madie/terminology/models/CodeSystem.java @@ -22,6 +22,7 @@ public class CodeSystem { private String title; private String name; private String version; + private String displayVersion; // match version HL7V3.0_2019-12 against fhir private String versionId; private String oid; // identifier[0].value oid of identifier List private Instant lastUpdated; // when queried 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 689bf74..736132c 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -25,8 +25,10 @@ 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 @@ -122,7 +124,49 @@ private List getValueSetConcepts( } public List getAllCodeSystems() { - return codeSystemRepository.findAll(); + // 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 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()); + } + } + } + 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; } public List retrieveAllCodeSystems(UmlsUser umlsUser) {