Skip to content

Commit c96eaa6

Browse files
author
Rupert Westenthaler
committed
MORE-Platform#180: This fixes the SQL query for listing participants for closing. Also added a component test that triggered the
1 parent 69e7f3e commit c96eaa6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

studymanager-services/src/main/java/io/redlink/more/studymanager/repository/ParticipantRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ ON CONFLICT (study_id, participant_id) DO UPDATE SET token = excluded.token
8686
" AND p.status = 'active' " +
8787
" AND p.start IS NOT NULL " +
8888
" AND COALESCE(sg.duration, s.duration) IS NOT NULL " +
89-
" AND (p.start + ((COALESCE(sg.duration, s.duration)->>'value')::int || ' ' || (COALESCE(sg.duration, s.duration)->>'unit'))::interval) < NOW()";
89+
" AND (p.start + ((COALESCE(sg.duration, s.duration)->>'value')::int || ' ' || (COALESCE(sg.duration, s.duration)->>'unit'))::interval) < NOW()" +
90+
"GROUP BY p.study_id, p.participant_id";
9091

9192
/*
9293
* SQL Statements for managing participant_observation_groups mapping for participants

studymanager-services/src/test/java/io/redlink/more/studymanager/repository/ParticipantRepositoryTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import org.springframework.beans.factory.annotation.Autowired;
1818
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
1919
import org.springframework.boot.test.context.SpringBootTest;
20+
import org.springframework.scheduling.config.TaskExecutionOutcome;
2021
import org.springframework.test.annotation.DirtiesContext;
2122
import org.springframework.test.context.ActiveProfiles;
2223
import org.springframework.test.context.ContextConfiguration;
2324
import org.testcontainers.containers.PostgreSQLContainer;
2425
import org.testcontainers.junit.jupiter.Container;
2526
import org.testcontainers.junit.jupiter.Testcontainers;
2627

28+
import java.time.Instant;
2729
import java.util.Set;
2830
import java.util.concurrent.TimeUnit;
2931

@@ -189,4 +191,16 @@ void testUndefinedStudyGroup() {
189191
assertThat(participant.getStudyGroupId()).isNull();
190192
}
191193

194+
@Test
195+
@DisplayName("Participants for closing")
196+
void testClosing() {
197+
Study study = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test")));
198+
studyRepository.setStateById(study.getStudyId(), Study.Status.ACTIVE);
199+
Participant participant = participantRepository
200+
.insert(new Participant().setStudyId(study.getStudyId()).setRegistrationToken("abc").setStart(Instant.now()));
201+
participantRepository.setStatusByIds(study.getStudyId(), participant.getParticipantId(), Participant.Status.ACTIVE);
202+
203+
var participants = participantRepository.listParticipantsForClosing();
204+
}
205+
192206
}

0 commit comments

Comments
 (0)