Skip to content

Commit

Permalink
only show results for latest corrected/deleted TestEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
zdeveloper committed Nov 3, 2023
1 parent f0455f9 commit 0fc9252
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import gov.cdc.usds.simplereport.db.model.TestEvent;
import gov.cdc.usds.simplereport.db.model.TestEvent_;
import gov.cdc.usds.simplereport.db.model.TestOrder;
import gov.cdc.usds.simplereport.db.model.TestOrder_;
import gov.cdc.usds.simplereport.db.model.auxiliary.PersonRole;
import gov.cdc.usds.simplereport.db.model.auxiliary.TestResult;
import gov.cdc.usds.simplereport.db.repository.ResultRepository;
Expand All @@ -21,6 +22,7 @@
import java.util.Set;
import java.util.UUID;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -35,7 +37,6 @@
@Transactional
public class ResultService {
private final ResultRepository resultRepository;
private final DiseaseService diseaseService;
private final OrganizationService organizationService;

private Specification<Result> buildResultSearchFilter(
Expand All @@ -48,8 +49,13 @@ private Specification<Result> buildResultSearchFilter(
Date endDate) {
return (root, query, cb) -> {
Join<Result, TestEvent> testEventJoin = root.join(Result_.testEvent);
Join<TestEvent, TestOrder> testOrderJoin = testEventJoin.join(TestEvent_.order);
Join<TestEvent, Person> personJoin = testEventJoin.join(TestEvent_.patient);
Predicate p = cb.conjunction();
Path<UUID> latestTestEventUUID =
testOrderJoin.get(TestOrder_.testEvent).get(IdentifiedEntity_.internalId);

p = cb.and(p, cb.equal(testEventJoin.get(IdentifiedEntity_.internalId), latestTestEventUUID));

query.orderBy(cb.desc(root.get(AuditedEntity_.createdAt)));
query.distinct(true);
Expand Down

0 comments on commit 0fc9252

Please sign in to comment.