use of org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState in project BridgeServer2 by Sage-Bionetworks.
the class AdherenceService method generateReport.
private <T> T generateReport(String appId, String studyId, String userId, DateTime createdOn, String clientTimeZone, Function<AdherenceState, T> func) {
AdherenceState.Builder builder = new AdherenceState.Builder();
builder.withNow(createdOn);
builder.withClientTimeZone(clientTimeZone);
Study study = studyService.getStudy(appId, studyId, true);
if (study.getScheduleGuid() == null) {
return func.apply(builder.build());
}
List<TimelineMetadata> metadata = scheduleService.getScheduleMetadata(study.getScheduleGuid());
List<StudyActivityEvent> events = studyActivityEventService.getRecentStudyActivityEvents(appId, studyId, userId).getItems();
List<AdherenceRecord> adherenceRecords = getAdherenceRecords(appId, new AdherenceRecordsSearch.Builder().withCurrentTimestampsOnly(true).withIncludeRepeats(true).withAdherenceRecordType(AdherenceRecordType.SESSION).withStudyId(studyId).withUserId(userId).build()).getItems();
builder.withMetadata(metadata);
builder.withEvents(events);
builder.withAdherenceRecords(adherenceRecords);
builder.withStudyStartEventId(study.getStudyStartEventId());
return func.apply(builder.build());
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportGeneratorTest method timestampBeforeSchedule.
@Test
public void timestampBeforeSchedule() throws Exception {
AdherenceState state = createAdherenceState().withNow(DateTime.parse("2020-01-01T00:00:00.000-08:00")).build();
StudyAdherenceReport report = INSTANCE.generate(state);
for (StudyReportWeek week : report.getWeeks()) {
for (List<EventStreamDay> days : week.getByDayEntries().values()) {
for (EventStreamDay oneDay : days) {
for (EventStreamWindow win : oneDay.getTimeWindows()) {
assertEquals(win.getState(), NOT_YET_AVAILABLE);
}
}
}
}
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportGeneratorTest method participantStudyProgress_done.
@Test
public void participantStudyProgress_done() throws Exception {
AdherenceState state = createAdherenceState().withNow(DateTime.parse("2022-05-01T00:00:00.000-08:00")).build();
StudyAdherenceReport report = INSTANCE.generate(state);
assertEquals(report.getProgression(), ParticipantStudyProgress.DONE);
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportGeneratorTest method participantStudyProgress_unstarted.
@Test
public void participantStudyProgress_unstarted() throws Exception {
AdherenceState state = createAdherenceState().withNow(DateTime.parse("2020-01-01T00:00:00.000-08:00")).build();
StudyAdherenceReport report = INSTANCE.generate(state);
assertEquals(report.getProgression(), ParticipantStudyProgress.IN_PROGRESS);
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportGeneratorTest method week_correct.
@Test
public void week_correct() throws Exception {
AdherenceState state = createAdherenceState().withAdherenceRecords(createAdherenceRecords()).build();
StudyAdherenceReport report = INSTANCE.generate(state);
StudyReportWeek week = report.getWeeks().iterator().next();
assertEquals(week.getSearchableLabels(), ImmutableSet.of(":Initial Survey:Week 1:", ":Baseline Tapping Test:Week 1:"));
assertEquals(week.getWeekInStudy(), 1);
assertEquals(week.getStartDate().toString(), "2022-03-01");
assertEquals(week.getAdherencePercent(), Integer.valueOf(100));
assertEquals(week.getByDayEntries().get(1).get(1).getTimeWindows().get(0).getState(), COMPLETED);
assertEquals(week.getByDayEntries().get(2).get(0).getTimeWindows().get(0).getState(), COMPLETED);
}
Aggregations