From d6ab8cf7c7e2ea0ea1a854daa4fd541fef831114 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 26 Jul 2024 09:42:45 -0700 Subject: [PATCH 1/4] 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); From 6aea6215a984ee81e3700508fbb4a2a728e536b7 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 26 Jul 2024 11:28:45 -0700 Subject: [PATCH 2/4] MAT-7362-fix --- .../terminology/service/FhirTerminologyService.java | 10 +++------- 1 file changed, 3 insertions(+), 7 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 9dd54fb..0ecaeb4 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -19,11 +19,8 @@ import org.springframework.web.util.UriComponentsBuilder; import java.time.Instant; +import java.util.*; import java.util.stream.Collectors; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; @Service @Slf4j @@ -107,7 +104,7 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( // of our last request, then we request again if (vsParam.getOffset() + vsParam.getCount() <= total) { vsParam.setOffset(vsParam.getOffset() + 1000); - recursivelyRequestAllValueSetsExpansionsForQDM( + return recursivelyRequestAllValueSetsExpansionsForQDM( allValueSets, apiKey, vsParam, valueSetsSearchCriteria, codeSystemEntries); } return allValueSets; @@ -116,7 +113,6 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( public List getValueSetsExpansionsForQdm( ValueSetsSearchCriteria valueSetsSearchCriteria, UmlsUser umlsUser) { List codeSystemEntries = mappingService.getCodeSystemEntries(); - List allValueSets = new ArrayList<>(); // going to build all values here. return valueSetsSearchCriteria.getValueSetParams().stream() .map( vsParam -> { @@ -127,7 +123,7 @@ public List getValueSetsExpansionsForQdm( .flatMap( vsParam -> recursivelyRequestAllValueSetsExpansionsForQDM( - allValueSets, + new ArrayList<>(), umlsUser.getApiKey(), vsParam, valueSetsSearchCriteria, From 125b80b01841971da77e17e51f2785637db77d64 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Mon, 29 Jul 2024 16:42:43 -0700 Subject: [PATCH 3/4] MAT-7362: fix calls to correctly use uri --- .../terminology/service/FhirTerminologyService.java | 12 ++++++------ .../terminology/util/TerminologyServiceUtil.java | 7 +++++++ 2 files changed, 13 insertions(+), 6 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 0ecaeb4..1ff3dd4 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -65,12 +65,12 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( valueSetsSearchCriteria.getProfile(), valueSetsSearchCriteria.getIncludeDraft(), valueSetsSearchCriteria.getManifestExpansion()); - ValueSet ValueSetResource = parser.parseResource(ValueSet.class, resource); - var total = ValueSetResource.getExpansion().getTotal(); // total valuesets + ValueSet valueSetResource = parser.parseResource(ValueSet.class, resource); + var total = valueSetResource.getExpansion().getTotal(); // total valuesets List concepts = - getValueSetConcepts(ValueSetResource, codeSystemEntries, "QDM"); + 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 @@ -93,9 +93,9 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( } else { allValueSets.add( QdmValueSet.builder() - .oid(ValueSetResource.getIdPart()) - .displayName(ValueSetResource.getName()) - .version(ValueSetResource.getVersion()) + .oid(valueSetResource.getIdPart()) + .displayName(valueSetResource.getName()) + .version(valueSetResource.getVersion()) .concepts(concepts) .build()); diff --git a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java index 0613705..53d27a5 100644 --- a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java +++ b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java @@ -119,6 +119,12 @@ public static URI buildValueSetResourceUri( ManifestExpansion manifestExpansion) { MultiValueMap params = new LinkedMultiValueMap<>(); String expandValueSetUri = "/ValueSet/" + valueSetParams.getOid() + "/$expand"; + if (valueSetParams.getOffset() >= 0) { + params.put("offset", List.of(String.valueOf(valueSetParams.getOffset()))); + } + if (valueSetParams.getCount() >= 0) { + params.put("count", List.of(String.valueOf(valueSetParams.getCount()))); + } if (StringUtils.isNotBlank(valueSetParams.getVersion())) { params.put("valueSetVersion", List.of(valueSetParams.getVersion())); } else if (manifestExpansion != null @@ -127,6 +133,7 @@ public static URI buildValueSetResourceUri( } else if (StringUtils.isNotBlank(includeDraft)) { params.put("includeDraft", List.of("true")); } + return UriComponentsBuilder.fromPath(expandValueSetUri).queryParams(params).build().toUri(); } From 9fca552a5586818d0003ed8a5f691605e93e655f Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Mon, 29 Jul 2024 16:56:02 -0700 Subject: [PATCH 4/4] MAT-7362: Fix tests --- .../service/FhirTerminologyService.java | 54 ++++++++++--------- .../util/TerminologyServiceUtil.java | 14 +++-- 2 files changed, 39 insertions(+), 29 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 1ff3dd4..213253d 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -71,34 +71,40 @@ public List recursivelyRequestAllValueSetsExpansionsForQDM( List concepts = getValueSetConcepts(valueSetResource, codeSystemEntries, "QDM"); - log.info("vs total [{}] count: [{}] offset: [{}], oid: [{}]", total, vsParam.getCount(), vsParam.getOffset(), vsParam.getOid()); + 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() + 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()); - + 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()); } // if the total results in the searchSet are still greater than our current offset + the count // of our last request, then we request again @@ -123,7 +129,7 @@ public List getValueSetsExpansionsForQdm( .flatMap( vsParam -> recursivelyRequestAllValueSetsExpansionsForQDM( - new ArrayList<>(), + new ArrayList<>(), umlsUser.getApiKey(), vsParam, valueSetsSearchCriteria, diff --git a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java index 53d27a5..35f17e2 100644 --- a/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java +++ b/src/main/java/gov/cms/madie/terminology/util/TerminologyServiceUtil.java @@ -119,11 +119,15 @@ public static URI buildValueSetResourceUri( ManifestExpansion manifestExpansion) { MultiValueMap params = new LinkedMultiValueMap<>(); String expandValueSetUri = "/ValueSet/" + valueSetParams.getOid() + "/$expand"; - if (valueSetParams.getOffset() >= 0) { - params.put("offset", List.of(String.valueOf(valueSetParams.getOffset()))); - } - if (valueSetParams.getCount() >= 0) { - params.put("count", List.of(String.valueOf(valueSetParams.getCount()))); + if (valueSetParams != null) { + Integer offset = valueSetParams.getOffset(); + Integer count = valueSetParams.getCount(); + if (offset != null && offset >= 0) { + params.put("offset", List.of(String.valueOf(offset))); + } + if (count != null && count >= 0) { + params.put("count", List.of(String.valueOf(count))); + } } if (StringUtils.isNotBlank(valueSetParams.getVersion())) { params.put("valueSetVersion", List.of(valueSetParams.getVersion()));