From 9fca552a5586818d0003ed8a5f691605e93e655f Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Mon, 29 Jul 2024 16:56:02 -0700 Subject: [PATCH] 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()));