Search in sources :

Example 6 with AdherenceState

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

the class StudyAdherenceReportGeneratorTest method timestampAfterSchedule.

@Test
public void timestampAfterSchedule() throws Exception {
    AdherenceState state = createAdherenceState().withNow(DateTime.parse("2022-05-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(), EXPIRED);
                }
            }
        }
    }
}
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 7 with AdherenceState

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

the class StudyAdherenceReportGeneratorTest method nextActivityIsCorrectlySelected.

@Test
public void nextActivityIsCorrectlySelected() throws Exception {
    List<StudyActivityEvent> events = createEvents();
    StudyActivityEvent event = new StudyActivityEvent.Builder().withEventId("custom:event1").withTimestamp(DateTime.parse("2022-05-01T16:23:15.999-08:00")).withObjectType(ActivityEventObjectType.CUSTOM).build();
    events = BridgeUtils.addToList(events, event);
    AdherenceState state = createAdherenceState().withNow(DateTime.parse("2022-04-15T00:00:00.000-08:00")).withEvents(events).build();
    StudyAdherenceReport report = StudyAdherenceReportGenerator.INSTANCE.generate(state);
    assertEquals(report.getNextActivity().getSessionGuid(), "session5");
    assertEquals(report.getNextActivity().getSessionName(), "Supplemental Survey");
    assertEquals(report.getNextActivity().getWeekInStudy(), Integer.valueOf(9));
    assertEquals(report.getNextActivity().getStartDate().toString(), "2022-05-01");
    // This is the day before (and in the same week) as the next activity, so nextActivity
    // should be null in this case.
    state = createAdherenceState().withNow(DateTime.parse("2022-04-30T00:00:00.000-08:00")).withEvents(events).build();
    report = StudyAdherenceReportGenerator.INSTANCE.generate(state);
    assertNull(report.getNextActivity());
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) Test(org.testng.annotations.Test)

Example 8 with AdherenceState

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

the class StudyAdherenceReportGeneratorTest method timestampOnFallowWeek.

@Test
public void timestampOnFallowWeek() throws Exception {
    // To make this work we have to create a fallow week, by delaying the
    // study burst for 4 weeks.
    Schedule2 schedule = createSchedule();
    schedule.getStudyBursts().get(0).setDelay(Period.parse("P4W"));
    StudyActivityEvent e1 = new StudyActivityEvent.Builder().withEventId("timeline_retrieved").withTimestamp(DateTime.parse("2022-03-01T16:23:15.999-08:00")).build();
    StudyActivityEvent e2 = new StudyActivityEvent.Builder().withEventId("custom:event2").withTimestamp(DateTime.parse("2022-03-10T16:23:15.999-08:00")).build();
    // don't forget the study burst events! They are not calculated at the time
    // the schedule is calculated!
    StudyActivityEvent e3 = new StudyActivityEvent.Builder().withEventId("study_burst:Study Burst:01").withTimestamp(DateTime.parse("2022-03-29T16:23:15.999-08:00")).build();
    StudyActivityEvent e4 = new StudyActivityEvent.Builder().withEventId("study_burst:Study Burst:02").withTimestamp(DateTime.parse("2022-04-05T16:23:15.999-08:00")).build();
    StudyActivityEvent e5 = new StudyActivityEvent.Builder().withEventId("study_burst:Study Burst:03").withTimestamp(DateTime.parse("2022-04-12T16:23:15.999-08:00")).build();
    Timeline timeline = Scheduler.INSTANCE.calculateTimeline(schedule);
    AdherenceState state = createAdherenceState().withMetadata(timeline.getMetadata()).withEvents(ImmutableList.of(e1, e2, e3, e4, e5)).build();
    // this now has a gap and the 15th (now) falls into it
    StudyAdherenceReport report = INSTANCE.generate(state);
    List<StudyReportWeek> weeks = ImmutableList.copyOf(report.getWeeks());
    assertEquals(weeks.get(0).getWeekInStudy(), 1);
    assertEquals(weeks.get(0).getStartDate().toString(), "2022-03-01");
    assertEquals(weeks.get(1).getWeekInStudy(), 4);
    assertEquals(weeks.get(1).getStartDate().toString(), "2022-03-22");
    // Nothing is "now" because that's in the gap.
    for (StudyReportWeek week : report.getWeeks()) {
        for (List<EventStreamDay> days : week.getByDayEntries().values()) {
            for (EventStreamDay oneDay : days) {
                assertFalse(oneDay.isToday());
            }
        }
    }
    assertEquals(report.getNextActivity().getSessionGuid(), "finalSurveyGuid");
    assertEquals(report.getNextActivity().getSessionName(), "Final Survey");
    assertEquals(report.getNextActivity().getWeekInStudy(), Integer.valueOf(4));
    assertEquals(report.getNextActivity().getStartDate().toString(), "2022-03-25");
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Timeline(org.sagebionetworks.bridge.models.schedules2.timelines.Timeline) EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) Test(org.testng.annotations.Test)

Example 9 with AdherenceState

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

the class EventStreamAdherenceReportGeneratorTest method stateCalculation_notYetAvailable.

@Test
public void stateCalculation_notYetAvailable() throws Exception {
    StudyActivityEvent event = createEvent("sessionStartEventId", NOW.minusDays(14));
    AdherenceState state = createState(NOW.minusDays(10), META1, event, null);
    EventStreamAdherenceReport report = INSTANCE.generate(state);
    assertEquals(getReportStates(report), ImmutableList.of(NOT_YET_AVAILABLE));
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) Test(org.testng.annotations.Test)

Example 10 with AdherenceState

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

the class EventStreamAdherenceReportGeneratorTest method stateCalculation_ignoresIrrelevantAdherenceRecord.

@Test
public void stateCalculation_ignoresIrrelevantAdherenceRecord() throws Exception {
    AdherenceRecord adherenceRecord = createRecord(STARTED_ON, FINISHED_ON, "otherSessionInstanceGuid", false);
    StudyActivityEvent event = createEvent("sessionStartEventId", NOW.minusDays(14));
    AdherenceState state = createState(NOW, META1, event, adherenceRecord);
    EventStreamAdherenceReport report = INSTANCE.generate(state);
    assertEquals(getReportStates(report), ImmutableList.of(UNSTARTED));
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) AdherenceRecord(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) 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