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);
}
}
}
}
}
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());
}
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");
}
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));
}
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));
}
Aggregations