Search in sources :

Example 1 with StudyAdherenceReport

use of org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceService method getWeeklyAdherenceReport.

public WeeklyAdherenceReport getWeeklyAdherenceReport(String appId, String studyId, Account account) {
    Stopwatch watch = Stopwatch.createStarted();
    DateTime createdOn = getDateTime();
    String timeZone = null;
    if (account.getClientTimeZone() != null) {
        timeZone = account.getClientTimeZone();
    } else {
        timeZone = getDefaultTimeZoneId();
    }
    StudyAdherenceReport report = generateReport(appId, studyId, account.getId(), createdOn, timeZone, (state) -> StudyAdherenceReportGenerator.INSTANCE.generate(state));
    report.setParticipant(new AccountRef(account, studyId));
    report.setTestAccount(account.getDataGroups().contains(TEST_USER_GROUP));
    report.setCreatedOn(createdOn);
    report.setClientTimeZone(timeZone);
    WeeklyAdherenceReport weeklyReport = deriveWeeklyAdherenceFromStudyAdherenceReport(studyId, account, report);
    watch.stop();
    LOG.info("Weekly adherence report took " + watch.elapsed(TimeUnit.MILLISECONDS) + "ms");
    return weeklyReport;
}
Also used : WeeklyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport) Stopwatch(com.google.common.base.Stopwatch) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) StudyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport) DateTime(org.joda.time.DateTime)

Example 2 with StudyAdherenceReport

use of org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport 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 StudyAdherenceReport

use of org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport 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 StudyAdherenceReport

use of org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport 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 StudyAdherenceReport

use of org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport 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

Test (org.testng.annotations.Test)18 AdherenceState (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState)12 EventStreamDay (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay)7 StudyAdherenceReport (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport)5 Account (org.sagebionetworks.bridge.models.accounts.Account)4 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)4 EventStreamWindow (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow)4 DateTime (org.joda.time.DateTime)3 AccountRef (org.sagebionetworks.bridge.models.accounts.AccountRef)3 WeeklyAdherenceReport (org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport)3 Stopwatch (com.google.common.base.Stopwatch)2 RequestContext (org.sagebionetworks.bridge.RequestContext)2 DateRange (org.sagebionetworks.bridge.models.DateRange)2 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)2 ResourceList (org.sagebionetworks.bridge.models.ResourceList)2 AdherenceRecord (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord)2 StudyAdherenceReportGeneratorTest (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReportGeneratorTest)2 NextActivity (org.sagebionetworks.bridge.models.schedules2.adherence.weekly.NextActivity)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1