Search in sources :

Example 1 with AdherenceState

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());
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Study(org.sagebionetworks.bridge.models.studies.Study) TimelineMetadata(org.sagebionetworks.bridge.models.schedules2.timelines.TimelineMetadata) AdherenceRecord(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent)

Example 2 with AdherenceState

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);
                }
            }
        }
    }
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) EventStreamWindow(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow) Test(org.testng.annotations.Test)

Example 3 with AdherenceState

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);
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Test(org.testng.annotations.Test)

Example 4 with AdherenceState

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);
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Test(org.testng.annotations.Test)

Example 5 with AdherenceState

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);
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Test(org.testng.annotations.Test)

Aggregations

AdherenceState (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState)42 Test (org.testng.annotations.Test)40 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)25 AdherenceRecord (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord)20 EventStreamDay (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay)5 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)4 Timeline (org.sagebionetworks.bridge.models.schedules2.timelines.Timeline)4 DateTime (org.joda.time.DateTime)3 LocalDate (org.joda.time.LocalDate)3 DateRange (org.sagebionetworks.bridge.models.DateRange)3 EventStreamWindow (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow)3 ParticipantSchedule (org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule)3 HashMap (java.util.HashMap)2 Schedule2Test (org.sagebionetworks.bridge.models.schedules2.Schedule2Test)2 TimelineMetadata (org.sagebionetworks.bridge.models.schedules2.timelines.TimelineMetadata)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1