Skip to content

Commit

Permalink
ISTO-125 Fixes #638 LOINC pagination fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicode authored and pgwilliams committed Dec 19, 2024
1 parent 0d526e5 commit b87deca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ca.uhn.fhir.jpa.entity.TermConcept;
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import com.google.common.collect.Iterables;

import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.CodeType;
import org.slf4j.Logger;
Expand All @@ -19,10 +18,11 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.stereotype.Service;

import java.util.*;
Expand Down Expand Up @@ -182,16 +182,18 @@ public FHIRConcept findConcept(FHIRCodeSystemVersion systemVersion, String code)
public Page<FHIRConcept> findConcepts(BoolQuery.Builder fhirConceptQuery, PageRequest pageRequest) {
NativeQuery searchQuery = new NativeQueryBuilder()
.withQuery(fhirConceptQuery.build()._toQuery())
.withSort(Sort.by(FHIRConcept.Fields.CODE))
.withPageable(pageRequest)
.build();
searchQuery.setTrackTotalHits(true);
updateQueryWithSearchAfter(searchQuery, pageRequest);
return toPage(elasticsearchOperations.search(searchQuery, FHIRConcept.class), pageRequest);
}

public SearchAfterPage<String> findConceptCodes(BoolQuery.Builder fhirConceptQuery, PageRequest pageRequest) {
public SearchAfterPage<String> findConceptCodes(BoolQuery fhirConceptQuery, PageRequest pageRequest) {
NativeQuery searchQuery = new NativeQueryBuilder()
.withQuery(fhirConceptQuery.build()._toQuery())
.withQuery(fhirConceptQuery._toQuery())
.withSort(Sort.by(FHIRConcept.Fields.CODE))
.withPageable(pageRequest)
.build();
searchQuery.setTrackTotalHits(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public ValueSet expand(final ValueSetExpansionParameters params, String displayL
// FHIR Concept Expansion (non-SNOMED)
String sortField = filter != null ? "displayLen" : "code";
pageRequest = PageRequest.of(pageRequest.getPageNumber(), pageRequest.getPageSize(), Sort.Direction.ASC, sortField);
BoolQuery.Builder fhirConceptQuery = getFhirConceptQuery(codeSelectionCriteria, filter);
BoolQuery fhirConceptQuery = getFhirConceptQuery(codeSelectionCriteria, filter).build();

int offsetRequested = (int) pageRequest.getOffset();
int limitRequested = (int) (pageRequest.getOffset() + pageRequest.getPageSize());
Expand Down Expand Up @@ -317,14 +317,16 @@ public ValueSet expand(final ValueSetExpansionParameters params, String displayL
conceptsToLoad = new ArrayList<>();
}
if (!conceptsToLoad.isEmpty()) {
fhirConceptQuery.must(termsQuery(FHIRConcept.Fields.CODE, conceptsToLoad));
conceptsPage = conceptService.findConcepts(fhirConceptQuery, LARGE_PAGE);
BoolQuery.Builder conceptsToLoadQuery = bool()
.must(fhirConceptQuery._toQuery())
.must(termsQuery(FHIRConcept.Fields.CODE, conceptsToLoad));
conceptsPage = conceptService.findConcepts(conceptsToLoadQuery, LARGE_PAGE);
conceptsPage = new PageImpl<>(conceptsPage.getContent(), pageRequest, totalResults);
} else {
conceptsPage = new PageImpl<>(new ArrayList<>(), pageRequest, totalResults);
}
} else {
conceptsPage = conceptService.findConcepts(fhirConceptQuery, pageRequest);
conceptsPage = conceptService.findConcepts(bool().must(fhirConceptQuery._toQuery()), pageRequest);
}
}

Expand Down

0 comments on commit b87deca

Please sign in to comment.