Search in sources :

Example 1 with ScheduledAssessment

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

the class ScheduledSessionTest method copyWithoutAssessments.

@Test
public void copyWithoutAssessments() {
    Session session = new Session();
    session.setGuid(SESSION_GUID_1);
    session.setStartEventIds(ImmutableList.of("enrollment"));
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_WINDOW_GUID_1);
    ScheduledAssessment asmt = new ScheduledAssessment.Builder().withRefKey("ref").withInstanceGuid("instanceGuid").build();
    ScheduledSession.Builder builder = new ScheduledSession.Builder().withSession(session).withTimeWindow(window).withStartEventId("timeline_retrieved").withInstanceGuid("instanceGuid").withStartDay(10).withEndDay(13).withDelayTime(Period.parse("PT3H")).withStartTime(LocalTime.parse("17:00")).withExpiration(Period.parse("PT30M")).withPersistent(true).withScheduledAssessment(asmt);
    ScheduledSession.Builder copy = builder.build().toBuilder();
    ScheduledSession schSession = copy.build();
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getInstanceGuid(), "instanceGuid");
    assertEquals(schSession.getStartEventId(), "timeline_retrieved");
    assertEquals(schSession.getStartDay(), Integer.valueOf(10));
    assertEquals(schSession.getEndDay(), Integer.valueOf(13));
    assertEquals(schSession.getStartTime(), LocalTime.parse("17:00"));
    assertEquals(schSession.getDelayTime(), Period.parse("PT3H"));
    assertEquals(schSession.getExpiration(), Period.parse("PT30M"));
    assertEquals(schSession.getTimeWindow(), window);
    assertTrue(schSession.isPersistent());
    assertTrue(schSession.getAssessments().isEmpty());
    assertNull(schSession.getStudyBurstId());
    assertNull(schSession.getStudyBurstNum());
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 2 with ScheduledAssessment

use of org.sagebionetworks.bridge.models.schedules2.timelines.ScheduledAssessment 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 3 with ScheduledAssessment

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

the class SchedulerTest method assessmentInstanceGuidsAreUnique.

@Test
public void assessmentInstanceGuidsAreUnique() {
    Schedule2 schedule = createComplexSchedule();
    Set<String> asmtInstanceGuids = new HashSet<>();
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    for (ScheduledSession schSession : timeline.getSchedule()) {
        for (ScheduledAssessment schAsmt : schSession.getAssessments()) {
            asmtInstanceGuids.add(schAsmt.getInstanceGuid());
        }
    }
    // There are 2,184 scheduled assessments and all must have a unique guid.
    assertEquals(asmtInstanceGuids.size(), 2366);
    // Just changing the schedule GUID will create 2,184 more unique GUIDs
    schedule.setGuid(ASSESSMENT_4_GUID);
    timeline = INSTANCE.calculateTimeline(schedule);
    for (ScheduledSession schSession : timeline.getSchedule()) {
        for (ScheduledAssessment schAsmt : schSession.getAssessments()) {
            asmtInstanceGuids.add(schAsmt.getInstanceGuid());
        }
    }
    assertEquals(asmtInstanceGuids.size(), 4732);
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with ScheduledAssessment

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

the class SchedulerTest method oneOneTimeSession.

@Test
public void oneOneTimeSession() {
    Schedule2 schedule = createSchedule(null);
    Session session = createOneTimeSession(null);
    schedule.getSessions().add(session);
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getDuration(), Period.parse("P10D"));
    assertEquals(timeline.getSchedule().size(), 1);
    assertEquals(timeline.getSessions().size(), 1);
    assertEquals(timeline.getAssessments().size(), 1);
    // The schedule proper with the instance GUIDs
    ScheduledSession schSession = timeline.getSchedule().get(0);
    assertEquals(schSession.getRefGuid(), SESSION_GUID_3);
    // instance guid
    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"));
    assertNull(schSession.isPersistent());
    assertEquals(schSession.getAssessments().size(), 1);
    ScheduledAssessment schAsmt = schSession.getAssessments().get(0);
    assertEquals(schAsmt.getRefKey(), String.valueOf(schSession.getAssessments().get(0).getRefKey()));
    // instance guid
    SessionInfo sessionInfo = timeline.getSessions().get(0);
    assertEquals(sessionInfo.getGuid(), SESSION_GUID_3);
    assertEquals(sessionInfo.getLabel(), "One Time Session");
    assertEquals(sessionInfo.getMinutesToComplete(), Integer.valueOf(10));
    AssessmentInfo asmtInfo = timeline.getAssessments().get(0);
    assertEquals(asmtInfo.getGuid(), ASSESSMENT_1_GUID);
    assertEquals(asmtInfo.getAppId(), TEST_APP_ID);
    assertEquals(asmtInfo.getIdentifier(), "assessment-1");
    assertEquals(asmtInfo.getLabel(), "Assessment 1");
    assertEquals(asmtInfo.getKey(), "932e4de6932e4de6");
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 5 with ScheduledAssessment

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

the class ParticipantScheduleGenerator method generate.

public ParticipantSchedule generate(AdherenceState state, Timeline timeline) {
    Multimap<LocalDate, ScheduledSession> chronology = LinkedHashMultimap.create();
    LocalDate earliestDate = LATEST_LOCAL_DATE;
    LocalDate latestDate = EARLIEST_LOCAL_DATE;
    Map<String, DateTime> eventTimestamps = new HashMap<>();
    for (ScheduledSession schSession : timeline.getSchedule()) {
        String eventId = schSession.getStartEventId();
        DateTime eventTimestamp = state.getEventTimestampById(eventId);
        if (eventTimestamp == null) {
            continue;
        }
        LocalDate startDate = eventTimestamp.plusDays(schSession.getStartDay()).toLocalDate();
        LocalDate endDate = eventTimestamp.plusDays(schSession.getEndDay()).toLocalDate();
        eventTimestamps.put(eventId, eventTimestamp);
        ScheduledSession.Builder builder = schSession.toBuilder();
        builder.withStartDate(startDate);
        builder.withEndDate(endDate);
        if (startDate.isBefore(earliestDate)) {
            earliestDate = startDate;
        }
        if (endDate.isAfter(latestDate)) {
            latestDate = endDate;
        }
        for (ScheduledAssessment schAssessment : schSession.getAssessments()) {
            ScheduledAssessment.Builder asmtBuilder = new ScheduledAssessment.Builder().withRefKey(schAssessment.getRefKey()).withInstanceGuid(schAssessment.getInstanceGuid());
            builder.withScheduledAssessment(asmtBuilder.build());
        }
        // null these out, not useful
        schSession.getTimeWindow().setGuid(null);
        builder.withStartDay(null);
        builder.withEndDay(null);
        chronology.put(startDate, builder.build());
    }
    // chronology.size() is the total number of pairs, not the total number of keys (and thus correct).
    List<ScheduledSession> scheduledSessions = Lists.newArrayListWithCapacity(chronology.size());
    for (LocalDate date : chronology.keySet()) {
        scheduledSessions.addAll(chronology.get(date));
    }
    scheduledSessions.sort(SCHEDULED_SESSION_COMPARATOR);
    DateRange range = null;
    if (earliestDate.isBefore(latestDate)) {
        range = new DateRange(earliestDate, latestDate);
    }
    ParticipantSchedule schedule = new ParticipantSchedule();
    schedule.setCreatedOn(state.getNow());
    schedule.setClientTimeZone(state.getClientTimeZone());
    schedule.setDateRange(range);
    schedule.setSchedule(scheduledSessions);
    schedule.setSessions(timeline.getSessions().stream().map(SessionInfo::createScheduleEntry).collect(toList()));
    schedule.setAssessments(timeline.getAssessments());
    schedule.setStudyBursts(timeline.getStudyBursts());
    schedule.setEventTimestamps(eventTimestamps);
    return schedule;
}
Also used : HashMap(java.util.HashMap) SessionInfo(org.sagebionetworks.bridge.models.schedules2.timelines.SessionInfo) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) ScheduledAssessment(org.sagebionetworks.bridge.models.schedules2.timelines.ScheduledAssessment) DateRange(org.sagebionetworks.bridge.models.DateRange) ScheduledSession(org.sagebionetworks.bridge.models.schedules2.timelines.ScheduledSession)

Aggregations

Test (org.testng.annotations.Test)10 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)7 HashSet (java.util.HashSet)4 Session (org.sagebionetworks.bridge.models.schedules2.Session)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 AssessmentReference (org.sagebionetworks.bridge.models.schedules2.AssessmentReference)3 TimeWindow (org.sagebionetworks.bridge.models.schedules2.TimeWindow)2 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalTime (org.joda.time.LocalTime)1 Period (org.joda.time.Period)1 DateRange (org.sagebionetworks.bridge.models.DateRange)1 Label (org.sagebionetworks.bridge.models.Label)1 ColorScheme (org.sagebionetworks.bridge.models.assessments.ColorScheme)1 Schedule2Test (org.sagebionetworks.bridge.models.schedules2.Schedule2Test)1 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)1 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)1 ScheduledAssessment (org.sagebionetworks.bridge.models.schedules2.timelines.ScheduledAssessment)1 ScheduledSession (org.sagebionetworks.bridge.models.schedules2.timelines.ScheduledSession)1