Search in sources :

Example 21 with AdherenceState

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

the class EventStreamAdherenceReportGeneratorTest method calculatesReport.

@Test
public void calculatesReport() throws Exception {
    AdherenceRecord adherenceRecord = createRecord(STARTED_ON, FINISHED_ON, "sessionInstanceGuid", false);
    StudyActivityEvent event = createEvent("sessionStartEventId", NOW.minusDays(14));
    AdherenceState state = createState(NOW, META1, event, adherenceRecord);
    EventStreamAdherenceReport report = INSTANCE.generate(state);
    assertEquals(report.getTimestamp(), NOW.withZone(DateTimeZone.forID("America/Chicago")));
    assertEquals(report.getAdherencePercent(), 100);
    assertEquals(report.getStreams().size(), 1);
    assertEquals(report.getDayRangeOfAllStreams().getMin(), 13);
    assertEquals(report.getDayRangeOfAllStreams().getMax(), 15);
    assertEquals(report.getDateRangeOfAllStreams().getStartDate().toString(), "2021-10-14");
    assertEquals(report.getDateRangeOfAllStreams().getEndDate().toString(), "2021-10-16");
    assertEquals(report.getClientTimeZone(), "America/Chicago");
    assertEquals(report.getEarliestEventId(), "sessionStartEventId");
}
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)

Example 22 with AdherenceState

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

the class EventStreamAdherenceReportGeneratorTest method stateCalculation_ignoresIrrelevantEvents.

@Test
public void stateCalculation_ignoresIrrelevantEvents() throws Exception {
    AdherenceRecord adherenceRecord = createRecord(STARTED_ON, FINISHED_ON, "sessionInstanceGuid", false);
    StudyActivityEvent event = createEvent("otherStartEventId", NOW.minusDays(14));
    AdherenceState state = createState(NOW, META1, event, adherenceRecord);
    EventStreamAdherenceReport report = INSTANCE.generate(state);
    assertEquals(getReportStates(report), ImmutableList.of(NOT_APPLICABLE));
}
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)

Example 23 with AdherenceState

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

the class EventStreamAdherenceReportGeneratorTest method constructorUsesParticipantTimeZone.

@Test
public void constructorUsesParticipantTimeZone() {
    StudyActivityEvent event = new StudyActivityEvent.Builder().withEventId("enrollment").withTimestamp(MODIFIED_ON).build();
    AdherenceState.Builder builder = new AdherenceState.Builder();
    builder.withClientTimeZone("America/Denver");
    builder.withMetadata(ImmutableList.of());
    builder.withEvents(ImmutableList.of(event));
    builder.withAdherenceRecords(ImmutableList.of());
    builder.withNow(NOW);
    AdherenceState state = builder.build();
    assertEquals(state.getTimeZone().toString(), "America/Denver");
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) Test(org.testng.annotations.Test)

Example 24 with AdherenceState

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

the class ParticipantScheduleGeneratorTest method test.

@Test
public void test() throws Exception {
    Schedule2 schedule = Schedule2Test.createValidSchedule();
    Timeline timeline = Scheduler.INSTANCE.calculateTimeline(schedule);
    StudyActivityEvent e1 = new StudyActivityEvent.Builder().withEventId("timeline_retrieved").withTimestamp(TIMESTAMP).build();
    AdherenceState state = new AdherenceState.Builder().withClientTimeZone(TIME_ZONE.getID()).withNow(TIMESTAMP.withZone(TIMEZONE_MSK)).withEvents(ImmutableList.of(e1)).build();
    ParticipantSchedule retValue = INSTANCE.generate(state, timeline);
    assertEquals(retValue.getCreatedOn(), TIMESTAMP.withZone(TIME_ZONE));
    assertEquals(retValue.getClientTimeZone(), TIME_ZONE.getID());
    assertEquals(retValue.getDateRange().getStartDate().toString(), "2015-02-02");
    assertEquals(retValue.getDateRange().getEndDate().toString(), "2015-03-16");
    // These values are all copied over from the timeline, so they don't need to be
    // examined very closely. They are all tested in other tests.
    assertEquals(retValue.getSessions().size(), 1);
    assertEquals(retValue.getStudyBursts().size(), 1);
    assertEquals(retValue.getAssessments().size(), 2);
    assertEquals(retValue.getEventTimestamps().size(), 1);
    assertEquals(retValue.getEventTimestamps().get("timeline_retrieved"), TIMESTAMP.withZone(TIME_ZONE));
    // But the schedule is different
    assertEquals(retValue.getSchedule().size(), 7);
    assertScheduledSession(retValue.getSchedule().get(0), "NpLGwpRYGr3cYjJvp945zQ", LocalDate.parse("2015-02-02"), LocalDate.parse("2015-02-02"), "MDoRIcMJpAZ3Xqy_uZAbnw", "AzGvv4ph-7Xzi9VRIrFyWw");
    assertScheduledSession(retValue.getSchedule().get(1), "0dVupumHdJENCi5rzjA1sQ", LocalDate.parse("2015-02-09"), LocalDate.parse("2015-02-09"), "mZTon_L0lXXErPKme-Ojhg", "okkx1iuHoh6MV8I8I9vYYQ");
    assertScheduledSession(retValue.getSchedule().get(2), "JzKooqt2k1rdn7A1E7j1Hg", LocalDate.parse("2015-02-16"), LocalDate.parse("2015-02-16"), "Pp55NkTwC1MWmAhdZWLD7A", "B2hnjJKGkFQ83rLCzkPDmA");
    assertScheduledSession(retValue.getSchedule().get(3), "8arBYlLtL93TdSjhVYDjfg", LocalDate.parse("2015-02-23"), LocalDate.parse("2015-02-23"), "4_qpTNQfPsIwVK9m0ok7YQ", "h-0BJQhWuU34QODRfLjRlg");
    assertScheduledSession(retValue.getSchedule().get(4), "qUvQ7R3FYbl2j-pEZ42ESQ", LocalDate.parse("2015-03-02"), LocalDate.parse("2015-03-02"), "y0deGrdsyat-i3CHxWzzkg", "9HaDixbXUid_O4Dc5m7Zog");
    assertScheduledSession(retValue.getSchedule().get(5), "XuyuOyJF5zs5s4cdqQISCg", LocalDate.parse("2015-03-09"), LocalDate.parse("2015-03-09"), "_IHC7vBzvy62AAOZDXqe6A", "MmMA1dT66qzTSnugAY-reQ");
    assertScheduledSession(retValue.getSchedule().get(6), "ym78tZHtMLaEfvx4-f9OGg", LocalDate.parse("2015-03-16"), LocalDate.parse("2015-03-16"), "xkucPnJH3lz_BAJ5X1DaLw", "mBwW2oM-rXEcNO7LIVi5PQ");
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Timeline(org.sagebionetworks.bridge.models.schedules2.timelines.Timeline) Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) ParticipantSchedule(org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule) Test(org.testng.annotations.Test) Schedule2Test(org.sagebionetworks.bridge.models.schedules2.Schedule2Test)

Example 25 with AdherenceState

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

the class ParticipantScheduleGeneratorTest method emptyScheduleWorks.

@Test
public void emptyScheduleWorks() throws Exception {
    AdherenceState state = new AdherenceState.Builder().withClientTimeZone(DateTimeZone.getDefault().getID()).withNow(TIMESTAMP).build();
    Timeline timeline = Scheduler.INSTANCE.calculateTimeline(new Schedule2());
    ParticipantSchedule retValue = INSTANCE.generate(state, timeline);
    assertEquals(retValue.getCreatedOn(), TIMESTAMP.withZone(DateTimeZone.getDefault()));
    assertEquals(retValue.getClientTimeZone(), DateTimeZone.getDefault().getID());
    assertNull(retValue.getDateRange());
    assertTrue(retValue.getSchedule().isEmpty());
    assertTrue(retValue.getSessions().isEmpty());
    assertTrue(retValue.getAssessments().isEmpty());
    assertTrue(retValue.getStudyBursts().isEmpty());
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) Timeline(org.sagebionetworks.bridge.models.schedules2.timelines.Timeline) Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) ParticipantSchedule(org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule) Test(org.testng.annotations.Test) Schedule2Test(org.sagebionetworks.bridge.models.schedules2.Schedule2Test)

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