diff --git a/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java b/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java index 549283e..2bdc1c3 100644 --- a/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java +++ b/src/main/java/gov/cms/madie/terminology/dto/ValueSetsSearchCriteria.java @@ -21,5 +21,7 @@ public static class ValueSetParams { private String oid; private String release; private String version; + private Integer count; + private Integer offset; } } 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 c6563a8..6251f1d 100644 --- a/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java +++ b/src/main/java/gov/cms/madie/terminology/service/FhirTerminologyService.java @@ -53,32 +53,66 @@ public List getManifests(UmlsUser umlsUser) { return manifestOptions; } + // spin off requests based on values provided in the expansion + public List recursivelyRequestAllValueSetsExpansionsForQDM( + List allValueSets, + String apiKey, + ValueSetsSearchCriteria.ValueSetParams vsParam, + ValueSetsSearchCriteria valueSetsSearchCriteria, + List codeSystemEntries) { + IParser parser = fhirContext.newJsonParser(); + String resource = + fhirTerminologyServiceWebClient.getValueSetResource( + apiKey, + vsParam, + valueSetsSearchCriteria.getProfile(), + valueSetsSearchCriteria.getIncludeDraft(), + valueSetsSearchCriteria.getManifestExpansion()); + ValueSet ValueSetResource = parser.parseResource(ValueSet.class, resource); + + var total = ValueSetResource.getExpansion().getTotal(); // total valuesets + + List concepts = + getValueSetConcepts(ValueSetResource, codeSystemEntries, "QDM"); + + 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 + if (vsParam.getOffset() + vsParam.getCount() < total) { + vsParam.setOffset(vsParam.getOffset() + 1000); + recursivelyRequestAllValueSetsExpansionsForQDM( + allValueSets, apiKey, vsParam, valueSetsSearchCriteria, codeSystemEntries); + } + return allValueSets; + } + 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 -> { - String resource = - fhirTerminologyServiceWebClient.getValueSetResource( - umlsUser.getApiKey(), - vsParam, - valueSetsSearchCriteria.getProfile(), - valueSetsSearchCriteria.getIncludeDraft(), - valueSetsSearchCriteria.getManifestExpansion()); - IParser parser = fhirContext.newJsonParser(); - ValueSet ValueSetResource = parser.parseResource(ValueSet.class, resource); - // Converting a ValueSet FHIR Resource into QDM Value Set DTO - List concepts = - getValueSetConcepts(ValueSetResource, codeSystemEntries, "QDM"); - return QdmValueSet.builder() - .oid(ValueSetResource.getIdPart()) - .displayName(ValueSetResource.getName()) - .version(ValueSetResource.getVersion()) - .concepts(concepts) - .build(); + vsParam.setCount(1000); + vsParam.setOffset(0); + return vsParam; }) - .toList(); + .flatMap( + vsParam -> + recursivelyRequestAllValueSetsExpansionsForQDM( + allValueSets, + umlsUser.getApiKey(), + vsParam, + valueSetsSearchCriteria, + codeSystemEntries) + .stream()) + .collect(Collectors.toList()); } /**