Skip to content

Commit

Permalink
Merge pull request #100 from MeasureAuthoringTool/MAT-7362a
Browse files Browse the repository at this point in the history
MAT-7362a
  • Loading branch information
mcmcphillips authored Jul 31, 2024
2 parents 495ff76 + 9fca552 commit 6d2c97f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
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

0 comments on commit 6d2c97f

Please sign in to comment.