From d6ab8cf7c7e2ea0ea1a854daa4fd541fef831114 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 26 Jul 2024 09:42:45 -0700 Subject: [PATCH] MAT-7362a --- .../service/FhirTerminologyService.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) 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 6251f1d..9dd54fb 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -74,17 +74,38 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( List concepts = getValueSetConcepts(ValueSetResource, codeSystemEntries, "QDM"); - + log.info("vs total [{}] count: [{}] offset: [{}], oid: [{}]", total, vsParam.getCount(), vsParam.getOffset(), vsParam.getOid()); + + // Check if the ValueSet with the same oid already exists in allValueSets + QdmValueSet existingValueSet = allValueSets.stream() + .filter(vs -> vs.getOid().equals(vsParam.getOid())) + .findFirst() + .orElse(null); + if (existingValueSet != null) { + List updatedConcepts = new ArrayList<>(existingValueSet.getConcepts()); + updatedConcepts.addAll(concepts); + // Create a new QdmValueSet with the updated concepts + QdmValueSet updatedValueSet = QdmValueSet.builder() + .oid(existingValueSet.getOid()) + .displayName(existingValueSet.getDisplayName()) + .version(existingValueSet.getVersion()) + .concepts(updatedConcepts) + .build(); + // Replace the existing QdmValueSet in the list + allValueSets.set(allValueSets.indexOf(existingValueSet), updatedValueSet); + } else { allValueSets.add( - QdmValueSet.builder() - .oid(ValueSetResource.getIdPart()) - .displayName(ValueSetResource.getName()) - .version(ValueSetResource.getVersion()) - .concepts(concepts) - .build()); + QdmValueSet.builder() + .oid(ValueSetResource.getIdPart()) + .displayName(ValueSetResource.getName()) + .version(ValueSetResource.getVersion()) + .concepts(concepts) + .build()); + + } // if the total results in the searchSet are still greater than our current offset + the count // of our last request, then we request again - if (vsParam.getOffset() + vsParam.getCount() < total) { + if (vsParam.getOffset() + vsParam.getCount() <= total) { vsParam.setOffset(vsParam.getOffset() + 1000); recursivelyRequestAllValueSetsExpansionsForQDM( allValueSets, apiKey, vsParam, valueSetsSearchCriteria, codeSystemEntries);