use of org.sagebionetworks.bridge.models.activities.StudyActivityEvent in project BridgeServer2 by Sage-Bionetworks.
the class TestUtilsTest method findByEventType_eventMatches.
@Test
public void findByEventType_eventMatches() {
StudyActivityEvent event1 = TestUtils.createEvent("enrollment", null, null);
StudyActivityEvent event2 = TestUtils.createEvent("timeline_retrieved", null, null);
List<StudyActivityEvent> events = ImmutableList.of(event1, event2);
assertEquals(TestUtils.findByEventId(events, TIMELINE_RETRIEVED), event2);
}
use of org.sagebionetworks.bridge.models.activities.StudyActivityEvent 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.activities.StudyActivityEvent 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.activities.StudyActivityEvent 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.activities.StudyActivityEvent 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));
}
Aggregations