Search in sources :

Example 1 with EventStreamDay

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

the class NextActivityTest method canSerialize.

@Test
public void canSerialize() {
    EventStreamDay day = new EventStreamDay();
    day.setLabel("label");
    day.setSessionGuid("sessionGuid");
    day.setSessionName("sessionName");
    day.setSessionSymbol("sessionSymbol");
    day.setStartDay(1);
    day.setStartDate(LocalDate.parse("2015-02-02"));
    day.setWeek(2);
    day.setStudyBurstId("burst");
    day.setStudyBurstNum(3);
    NextActivity next = NextActivity.create(day);
    JsonNode node = BridgeObjectMapper.get().valueToTree(next);
    assertEquals(node.size(), 9);
    assertEquals(node.get("label").textValue(), "label");
    assertEquals(node.get("sessionGuid").textValue(), "sessionGuid");
    assertEquals(node.get("sessionName").textValue(), "sessionName");
    assertEquals(node.get("sessionSymbol").textValue(), "sessionSymbol");
    assertEquals(node.get("weekInStudy").intValue(), 2);
    assertEquals(node.get("studyBurstId").textValue(), "burst");
    assertEquals(node.get("studyBurstNum").intValue(), 3);
    assertEquals(node.get("startDate").textValue(), "2015-02-02");
    assertEquals(node.get("type").textValue(), "NextActivity");
}
Also used : EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 2 with EventStreamDay

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

the class WeeklyAdherenceReportTest method canSerialize.

@Test
public void canSerialize() {
    Account account = Account.create();
    account.setId(TEST_USER_ID);
    NextActivity nextActivity = NextActivity.create(new EventStreamDay());
    WeeklyAdherenceReportRow row = new WeeklyAdherenceReportRow();
    row.setLabel("rowLabel");
    row.setSearchableLabel(":rowLabel:");
    row.setSessionGuid("sessionGuid");
    row.setSessionSymbol("sessionSymbol");
    row.setSessionName("sessionName");
    row.setStudyBurstId("studyBurstId");
    row.setStudyBurstNum(2);
    row.setWeekInStudy(4);
    row.setStartEventId("event1");
    WeeklyAdherenceReport report = new WeeklyAdherenceReport();
    report.setAppId(TEST_APP_ID);
    report.setStudyId(TEST_STUDY_ID);
    report.setUserId(TEST_USER_ID);
    report.setClientTimeZone(TEST_CLIENT_TIME_ZONE);
    report.setCreatedOn(MODIFIED_ON);
    report.setSearchableLabels(ImmutableSet.of("label1", "label2"));
    report.setParticipant(new AccountRef(account, "study1"));
    report.setTestAccount(true);
    report.setProgression(IN_PROGRESS);
    report.setWeeklyAdherencePercent(79);
    report.setRows(ImmutableList.of(row));
    report.setWeekInStudy(2);
    report.setStartDate(LocalDate.parse("2022-02-02"));
    report.setByDayEntries(ImmutableMap.of(new Integer(6), ImmutableList.of(new EventStreamDay())));
    report.setNextActivity(nextActivity);
    // It's there, it works, it's persisted, but it's not part of JSON output
    assertTrue(report.isTestAccount());
    // These are not in the JSON
    assertEquals(report.getAppId(), TEST_APP_ID);
    assertEquals(report.getStudyId(), TEST_STUDY_ID);
    assertEquals(report.getUserId(), TEST_USER_ID);
    assertEquals(report.getSearchableLabels(), ImmutableSet.of("label1", "label2"));
    JsonNode node = BridgeObjectMapper.get().valueToTree(report);
    assertEquals(node.size(), 12);
    assertNull(node.get("appId"));
    assertNull(node.get("studyId"));
    assertNull(node.get("userId"));
    assertEquals(node.get("participant").get("identifier").textValue(), "userId");
    assertEquals(node.get("clientTimeZone").textValue(), TEST_CLIENT_TIME_ZONE);
    assertEquals(node.get("createdOn").textValue(), MODIFIED_ON.withZone(DateTimeZone.forID(TEST_CLIENT_TIME_ZONE)).toString());
    assertEquals(node.get("weeklyAdherencePercent").intValue(), 79);
    assertEquals(node.get("participant").get("identifier").textValue(), TEST_USER_ID);
    assertTrue(node.get("testAccount").booleanValue());
    assertEquals(node.get("progression").textValue(), "in_progress");
    assertEquals(node.get("nextActivity").get("type").textValue(), "NextActivity");
    assertEquals(node.get("byDayEntries").get("6").get(0).get("type").textValue(), "EventStreamDay");
    assertEquals(node.get("weekInStudy").intValue(), 2);
    assertEquals(node.get("startDate").textValue(), "2022-02-02");
    assertEquals(node.get("type").textValue(), "WeeklyAdherenceReport");
    assertEquals(node.get("rows").size(), 1);
    JsonNode rowNode = node.get("rows").get(0);
    assertEquals(rowNode.get("label").textValue(), "rowLabel");
    assertEquals(rowNode.get("searchableLabel").textValue(), ":rowLabel:");
    assertEquals(rowNode.get("sessionGuid").textValue(), "sessionGuid");
    assertEquals(rowNode.get("sessionSymbol").textValue(), "sessionSymbol");
    assertEquals(rowNode.get("sessionName").textValue(), "sessionName");
    assertEquals(rowNode.get("studyBurstId").textValue(), "studyBurstId");
    assertEquals(rowNode.get("studyBurstNum").intValue(), 2);
    assertEquals(rowNode.get("weekInStudy").intValue(), 4);
    assertEquals(rowNode.get("startEventId").textValue(), "event1");
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 3 with EventStreamDay

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

the class StudyAdherenceReportGeneratorTest method timestampBeforeSchedule.

@Test
public void timestampBeforeSchedule() throws Exception {
    AdherenceState state = createAdherenceState().withNow(DateTime.parse("2020-01-01T00:00:00.000-08:00")).build();
    StudyAdherenceReport report = INSTANCE.generate(state);
    for (StudyReportWeek week : report.getWeeks()) {
        for (List<EventStreamDay> days : week.getByDayEntries().values()) {
            for (EventStreamDay oneDay : days) {
                for (EventStreamWindow win : oneDay.getTimeWindows()) {
                    assertEquals(win.getState(), NOT_YET_AVAILABLE);
                }
            }
        }
    }
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) EventStreamWindow(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow) Test(org.testng.annotations.Test)

Example 4 with EventStreamDay

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

the class StudyAdherenceReportGeneratorTest method timestampAfterSchedule.

@Test
public void timestampAfterSchedule() throws Exception {
    AdherenceState state = createAdherenceState().withNow(DateTime.parse("2022-05-01T00:00:00.000-08:00")).build();
    StudyAdherenceReport report = INSTANCE.generate(state);
    for (StudyReportWeek week : report.getWeeks()) {
        for (List<EventStreamDay> days : week.getByDayEntries().values()) {
            for (EventStreamDay oneDay : days) {
                for (EventStreamWindow win : oneDay.getTimeWindows()) {
                    assertEquals(win.getState(), EXPIRED);
                }
            }
        }
    }
}
Also used : AdherenceState(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState) EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) EventStreamWindow(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow) Test(org.testng.annotations.Test)

Example 5 with EventStreamDay

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

the class StudyAdherenceReportGeneratorTest method dayHasNoUnnecessaryFieldsFilledOut.

@Test
public void dayHasNoUnnecessaryFieldsFilledOut() throws Exception {
    StudyAdherenceReport report = createReport();
    for (StudyReportWeek week : report.getWeeks()) {
        for (List<EventStreamDay> days : week.getByDayEntries().values()) {
            for (EventStreamDay oneDay : days) {
                assertNull(oneDay.getStudyBurstId());
                assertNull(oneDay.getStudyBurstNum());
                assertNull(oneDay.getSessionName());
                assertNull(oneDay.getWeek());
                assertNull(oneDay.getStartDay());
                for (EventStreamWindow window : oneDay.getTimeWindows()) {
                    assertNull(window.getEndDay());
                }
            }
        }
    }
}
Also used : EventStreamDay(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay) EventStreamWindow(org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow) Test(org.testng.annotations.Test)

Aggregations

EventStreamDay (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamDay)19 Test (org.testng.annotations.Test)14 EventStreamWindow (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStreamWindow)6 AdherenceState (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceState)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 EventStream (org.sagebionetworks.bridge.models.schedules2.adherence.eventstream.EventStream)4 LocalDate (org.joda.time.LocalDate)3 DateRange (org.sagebionetworks.bridge.models.DateRange)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Account (org.sagebionetworks.bridge.models.accounts.Account)2 AccountRef (org.sagebionetworks.bridge.models.accounts.AccountRef)2 NextActivity (org.sagebionetworks.bridge.models.schedules2.adherence.weekly.NextActivity)2 WeeklyAdherenceReportRow (org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReportRow)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1