Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7362a #100

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,25 +65,52 @@ public List<QdmValueSet> 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<QdmValueSet.Concept> concepts =
getValueSetConcepts(ValueSetResource, codeSystemEntries, "QDM");

allValueSets.add(
QdmValueSet.builder()
.oid(ValueSetResource.getIdPart())
.displayName(ValueSetResource.getName())
.version(ValueSetResource.getVersion())
.concepts(concepts)
.build());
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<QdmValueSet.Concept> 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
if (vsParam.getOffset() + vsParam.getCount() < total) {
if (vsParam.getOffset() + vsParam.getCount() <= total) {
vsParam.setOffset(vsParam.getOffset() + 1000);
recursivelyRequestAllValueSetsExpansionsForQDM(
return recursivelyRequestAllValueSetsExpansionsForQDM(
allValueSets, apiKey, vsParam, valueSetsSearchCriteria, codeSystemEntries);
}
return allValueSets;
Expand All @@ -95,7 +119,6 @@ public List<QdmValueSet> recursivelyRequestAllValueSetsExpansionsForQDM(
public List<QdmValueSet> getValueSetsExpansionsForQdm(
ValueSetsSearchCriteria valueSetsSearchCriteria, UmlsUser umlsUser) {
List<CodeSystemEntry> codeSystemEntries = mappingService.getCodeSystemEntries();
List<QdmValueSet> allValueSets = new ArrayList<>(); // going to build all values here.
return valueSetsSearchCriteria.getValueSetParams().stream()
.map(
vsParam -> {
Expand All @@ -106,7 +129,7 @@ public List<QdmValueSet> getValueSetsExpansionsForQdm(
.flatMap(
vsParam ->
recursivelyRequestAllValueSetsExpansionsForQDM(
allValueSets,
new ArrayList<>(),
umlsUser.getApiKey(),
vsParam,
valueSetsSearchCriteria,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public static URI buildValueSetResourceUri(
ManifestExpansion manifestExpansion) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
String expandValueSetUri = "/ValueSet/" + valueSetParams.getOid() + "/$expand";
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()));
} else if (manifestExpansion != null
Expand All @@ -127,6 +137,7 @@ public static URI buildValueSetResourceUri(
} else if (StringUtils.isNotBlank(includeDraft)) {
params.put("includeDraft", List.of("true"));
}

return UriComponentsBuilder.fromPath(expandValueSetUri).queryParams(params).build().toUri();
}

Expand Down
Loading