Search in sources :

Example 1 with StudyActivityEvent

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

Example 2 with StudyActivityEvent

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());
}
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 3 with StudyActivityEvent

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

Example 4 with StudyActivityEvent

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");
}
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 5 with StudyActivityEvent

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

Aggregations

StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)98 Test (org.testng.annotations.Test)83 AdherenceState (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState)26 AdherenceRecord (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord)24 Study (org.sagebionetworks.bridge.models.studies.Study)23 Account (org.sagebionetworks.bridge.models.accounts.Account)20 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)17 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)16 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)13 ResourceList (org.sagebionetworks.bridge.models.ResourceList)10 StudyActivityEventIdsMap (org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap)10 DateTime (org.joda.time.DateTime)9 StudyAdherenceReportGeneratorTest (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReportGeneratorTest)9 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)8 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)7 StudyCustomEvent (org.sagebionetworks.bridge.models.studies.StudyCustomEvent)7 RequestContext (org.sagebionetworks.bridge.RequestContext)5 ParticipantSchedule (org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule)5 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)4 App (org.sagebionetworks.bridge.models.apps.App)4