Search in sources :

Example 1 with Timeline

use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method twoOneTimeSessions.

@Test
public void twoOneTimeSessions() {
    Schedule2 schedule = createSchedule("P2W");
    Session session1 = createOneTimeSession(null);
    Session session2 = createOneTimeSession("P2D");
    session2.setGuid(SESSION_GUID_4);
    schedule.setSessions(ImmutableList.of(session1, session2));
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getSchedule().size(), 2);
    assertEquals(timeline.getAssessments().size(), 1);
    assertEquals(timeline.getSessions().size(), 2);
    assertDayRange(timeline, 0, 0, 0);
    assertDayRange(timeline, 1, 2, 2);
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 2 with Timeline

use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method timeWindowStartExpiresAfterDayUsingDays.

@Test
public void timeWindowStartExpiresAfterDayUsingDays() {
    Schedule2 schedule = createSchedule("P5D");
    Session session = createOneTimeSession(null);
    session.getTimeWindows().get(0).setExpiration(Period.parse("P4D"));
    schedule.setSessions(ImmutableList.of(session));
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getSchedule().size(), 1);
    ScheduledSession schSession = timeline.getSchedule().get(0);
    assertEquals(schSession.getStartDay(), Integer.valueOf(0));
    assertEquals(schSession.getEndDay(), Integer.valueOf(4));
    assertEquals(schSession.getStartTime(), LocalTime.parse("08:00"));
    assertEquals(schSession.getExpiration(), Period.parse("P4D"));
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 3 with Timeline

use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method timeWindowStartExpiresWithinDay.

@Test
public void timeWindowStartExpiresWithinDay() {
    Schedule2 schedule = createSchedule("P2D");
    // This is the default configuration of the test time window as we expect it to be typical
    Session session = createOneTimeSession(null);
    schedule.setSessions(ImmutableList.of(session));
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getSchedule().size(), 1);
    ScheduledSession schSession = timeline.getSchedule().get(0);
    assertEquals(schSession.getStartDay(), Integer.valueOf(0));
    assertEquals(schSession.getEndDay(), Integer.valueOf(0));
    assertEquals(schSession.getStartTime(), LocalTime.parse("08:00"));
    assertEquals(schSession.getExpiration(), Period.parse("PT8H"));
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 4 with Timeline

use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method assessmentsCopiedToTimeline.

@Test
public void assessmentsCopiedToTimeline() throws Exception {
    // must respect configuration differences and create separate entries in the timeline,
    // and line up the $ref values between ScheduledAssessments and AssessmentInfo
    // stanzas. We don't have to test the copy factory methods for ScheduledAssessment as
    // this is tested separately.
    Schedule2 schedule = createSchedule("P1W");
    AssessmentReference ref1 = createAssessmentRef(ASSESSMENT_1_GUID);
    AssessmentReference ref2 = createAssessmentRef(ASSESSMENT_2_GUID);
    AssessmentReference ref3 = createAssessmentRef(ASSESSMENT_2_GUID);
    ref3.setColorScheme(new ColorScheme("#111111", "#222222", "#333333", "#444444"));
    AssessmentReference ref4 = createAssessmentRef(ASSESSMENT_3_GUID);
    AssessmentReference ref5 = createAssessmentRef(ASSESSMENT_3_GUID);
    ref5.setLabels(ImmutableList.of(new Label("en", "English")));
    AssessmentReference ref6 = createAssessmentRef(ASSESSMENT_4_GUID);
    Session session1 = createOneTimeSession(null);
    session1.setAssessments(ImmutableList.of(ref1, ref2, ref3, ref4));
    Session session2 = createRepeatingSession(null, "P10W");
    session2.setAssessments(ImmutableList.of(ref3, ref4, ref5, ref6));
    schedule.setSessions(ImmutableList.of(session1, session2));
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getAssessments().size(), 6);
    AssessmentInfo info1 = getByKey(timeline.getAssessments(), "932e4de6932e4de6");
    assertEquals(info1.getGuid(), ASSESSMENT_1_GUID);
    AssessmentInfo info2 = getByKey(timeline.getAssessments(), "5fa66c675fa66c67");
    assertEquals(info2.getGuid(), ASSESSMENT_2_GUID);
    assertNotNull(info2.getColorScheme());
    AssessmentInfo info3 = getByKey(timeline.getAssessments(), "24df134324df1343");
    assertEquals(info3.getGuid(), ASSESSMENT_3_GUID);
    assertEquals(info3.getLabel(), "English");
    AssessmentInfo info4 = getByKey(timeline.getAssessments(), "fa3150eafa3150ea");
    assertEquals(info4.getGuid(), ASSESSMENT_2_GUID);
    assertNull(info4.getColorScheme());
    AssessmentInfo info5 = getByKey(timeline.getAssessments(), "75705eb175705eb1");
    assertEquals(info5.getGuid(), ASSESSMENT_4_GUID);
    AssessmentInfo info6 = getByKey(timeline.getAssessments(), "ae40875fae40875f");
    assertEquals(info6.getGuid(), ASSESSMENT_3_GUID);
    assertEquals(info6.getLabel(), "Assessment 3");
    Set<String> infoRefs = timeline.getAssessments().stream().map(AssessmentInfo::getKey).collect(toSet());
    Set<String> schAsmtRefs = new HashSet<>();
    timeline.getSchedule().stream().forEach(schSession -> {
        for (ScheduledAssessment schAsmt : schSession.getAssessments()) {
            schAsmtRefs.add(schAsmt.getRefKey());
        }
    });
    assertEquals(infoRefs, schAsmtRefs);
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) ColorScheme(org.sagebionetworks.bridge.models.assessments.ColorScheme) Label(org.sagebionetworks.bridge.models.Label) AssessmentReference(org.sagebionetworks.bridge.models.schedules2.AssessmentReference) Session(org.sagebionetworks.bridge.models.schedules2.Session) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Timeline

use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method sessionInstanceGuidsAreIdemptotent.

@Test
public void sessionInstanceGuidsAreIdemptotent() {
    Schedule2 schedule = createComplexSchedule();
    Set<String> sessionInstanceGuids = new HashSet<>();
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    for (ScheduledSession schSession : timeline.getSchedule()) {
        sessionInstanceGuids.add(schSession.getInstanceGuid());
    }
    // Re-running gets you the same set of GUIDs
    Set<String> secondSessionInstanceGuids = new HashSet<>();
    timeline = INSTANCE.calculateTimeline(schedule);
    for (ScheduledSession schSession : timeline.getSchedule()) {
        secondSessionInstanceGuids.add(schSession.getInstanceGuid());
    }
    assertEquals(secondSessionInstanceGuids, sessionInstanceGuids);
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)68 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)67 Session (org.sagebionetworks.bridge.models.schedules2.Session)35 Timeline (org.sagebionetworks.bridge.models.schedules2.timelines.Timeline)20 Schedule2Test (org.sagebionetworks.bridge.models.schedules2.Schedule2Test)13 Study (org.sagebionetworks.bridge.models.studies.Study)11 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)10 HashSet (java.util.HashSet)8 RequestContext (org.sagebionetworks.bridge.RequestContext)8 AssessmentReference (org.sagebionetworks.bridge.models.schedules2.AssessmentReference)7 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)6 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)5 TimeWindow (org.sagebionetworks.bridge.models.schedules2.TimeWindow)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)4 AdherenceState (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState)4 ParticipantSchedule (org.sagebionetworks.bridge.models.schedules2.participantschedules.ParticipantSchedule)4 TimelineMetadata (org.sagebionetworks.bridge.models.schedules2.timelines.TimelineMetadata)4 DateTime (org.joda.time.DateTime)3 Stopwatch (com.google.common.base.Stopwatch)2