use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class AdherenceService method getWeeklyAdherenceReport.
public WeeklyAdherenceReport getWeeklyAdherenceReport(String appId, String studyId, Account account) {
Stopwatch watch = Stopwatch.createStarted();
DateTime createdOn = getDateTime();
String timeZone = null;
if (account.getClientTimeZone() != null) {
timeZone = account.getClientTimeZone();
} else {
timeZone = getDefaultTimeZoneId();
}
StudyAdherenceReport report = generateReport(appId, studyId, account.getId(), createdOn, timeZone, (state) -> StudyAdherenceReportGenerator.INSTANCE.generate(state));
report.setParticipant(new AccountRef(account, studyId));
report.setTestAccount(account.getDataGroups().contains(TEST_USER_GROUP));
report.setCreatedOn(createdOn);
report.setClientTimeZone(timeZone);
WeeklyAdherenceReport weeklyReport = deriveWeeklyAdherenceFromStudyAdherenceReport(studyId, account, report);
watch.stop();
LOG.info("Weekly adherence report took " + watch.elapsed(TimeUnit.MILLISECONDS) + "ms");
return weeklyReport;
}
use of org.sagebionetworks.bridge.models.accounts.AccountRef 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");
}
use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentDetailTest method test.
@Test
public void test() throws Exception {
Account account1 = Account.create();
account1.setEmail("email1@email.com");
AccountRef ref1 = new AccountRef(account1);
Account account2 = Account.create();
account2.setEmail("email2@email.com");
AccountRef ref2 = new AccountRef(account2);
Account account3 = Account.create();
account3.setEmail("email3@email.com");
AccountRef ref3 = new AccountRef(account3);
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setExternalId("anExternalId");
enrollment.setConsentRequired(true);
enrollment.setNote(TEST_NOTE);
EnrollmentDetail detail = new EnrollmentDetail(enrollment, ref1, ref2, ref3);
assertEquals(detail.getExternalId(), "anExternalId");
assertEquals(detail.getParticipant().getEmail(), "email1@email.com");
assertEquals(detail.getEnrolledBy().getEmail(), "email2@email.com");
assertEquals(detail.getWithdrawnBy().getEmail(), "email3@email.com");
assertEquals(detail.getNote(), TEST_NOTE);
JsonNode node = BridgeObjectMapper.get().valueToTree(detail);
assertEquals(node.size(), 8);
// Note that other than email and type properties, there's nothing else exposed about account
assertEquals(node.get("studyId").textValue(), TEST_STUDY_ID);
assertEquals(node.get("participant").size(), 2);
assertEquals(node.get("enrolledBy").size(), 2);
assertEquals(node.get("withdrawnBy").size(), 2);
assertEquals(node.get("participant").get("email").textValue(), "email1@email.com");
assertEquals(node.get("enrolledBy").get("email").textValue(), "email2@email.com");
assertEquals(node.get("withdrawnBy").get("email").textValue(), "email3@email.com");
assertEquals(node.get("externalId").textValue(), "anExternalId");
assertTrue(node.get("consentRequired").booleanValue());
assertEquals(node.get("note").textValue(), TEST_NOTE);
assertEquals(node.get("type").textValue(), "EnrollmentDetail");
// This object is not deserialized on the server.
}
use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportTest method canSerialize.
@Test
public void canSerialize() throws Exception {
Account account = Account.create();
account.setFirstName("firstName");
account.setEmail(EMAIL);
account.setId(TEST_USER_ID);
StudyReportWeek week = new StudyReportWeek();
EventStreamDay day = new EventStreamDay();
day.setLabel("label");
NextActivity nextActivity = NextActivity.create(day);
StudyAdherenceReport report = new StudyAdherenceReport();
report.setParticipant(new AccountRef(account, TEST_STUDY_ID));
report.setTestAccount(true);
report.setClientTimeZone("America/Chicago");
report.setCreatedOn(CREATED_ON);
report.setAdherencePercent(56);
report.setProgression(ParticipantStudyProgress.IN_PROGRESS);
report.setUnsetEventIds(ImmutableSet.of("event1", "event2"));
report.setDateRange(new DateRange(LocalDate.parse("2022-02-02"), LocalDate.parse("2022-02-04")));
report.setWeeks(ImmutableList.of(week));
report.setEventTimestamps(ImmutableMap.of("event3", MODIFIED_ON));
report.setUnscheduledSessions(ImmutableSet.of("session1", "session2"));
report.setCurrentWeek(week);
report.setNextActivity(nextActivity);
JsonNode node = BridgeObjectMapper.get().valueToTree(report);
assertEquals(node.get("participant").get("identifier").textValue(), "userId");
assertEquals(node.get("participant").get("firstName").textValue(), "firstName");
assertEquals(node.get("participant").get("email").textValue(), "email@email.com");
assertTrue(node.get("testAccount").booleanValue());
assertEquals(node.get("clientTimeZone").textValue(), "America/Chicago");
assertEquals(node.get("createdOn").textValue(), CREATED_ON.withZone(DateTimeZone.forID("America/Chicago")).toString());
assertEquals(node.get("adherencePercent").intValue(), 56);
assertEquals(node.get("progression").textValue(), "in_progress");
assertEquals(node.get("dateRange").get("startDate").textValue(), "2022-02-02");
assertEquals(node.get("dateRange").get("endDate").textValue(), "2022-02-04");
assertNull(node.get("currentWeek"));
assertEquals(node.get("type").textValue(), "StudyAdherenceReport");
ArrayNode weeksArray = (ArrayNode) node.get("weeks");
assertEquals(weeksArray.get(0).get("weekInStudy").intValue(), 0);
assertEquals(weeksArray.get(0).get("byDayEntries").size(), 7);
assertEquals(weeksArray.get(0).get("type").textValue(), "StudyReportWeek");
assertEquals(node.get("unsetEventIds").get(0).textValue(), "event1");
assertEquals(node.get("unsetEventIds").get(1).textValue(), "event2");
assertEquals(node.get("unscheduledSessions").get(0).textValue(), "session1");
assertEquals(node.get("unscheduledSessions").get(1).textValue(), "session2");
assertEquals(node.get("eventTimestamps").get("event3").textValue(), MODIFIED_ON.toString());
assertEquals(node.get("nextActivity").get("label").textValue(), "label");
assertEquals(node.get("nextActivity").get("type").textValue(), "NextActivity");
assertEquals(node.get("type").textValue(), "StudyAdherenceReport");
}
use of org.sagebionetworks.bridge.models.accounts.AccountRef in project BridgeServer2 by Sage-Bionetworks.
the class AdherenceService method getStudyAdherenceReport.
public StudyAdherenceReport getStudyAdherenceReport(String appId, String studyId, Account account) {
checkNotNull(appId);
checkNotNull(studyId);
checkNotNull(account);
Stopwatch watch = Stopwatch.createStarted();
DateTime createdOn = getDateTime();
String timeZone = null;
if (account.getClientTimeZone() != null) {
timeZone = account.getClientTimeZone();
} else {
timeZone = getDefaultTimeZoneId();
}
StudyAdherenceReport report = generateReport(appId, studyId, account.getId(), createdOn, timeZone, (state) -> StudyAdherenceReportGenerator.INSTANCE.generate(state));
report.setParticipant(new AccountRef(account, studyId));
report.setTestAccount(account.getDataGroups().contains(TEST_USER_GROUP));
report.setCreatedOn(createdOn);
report.setClientTimeZone(timeZone);
deriveWeeklyAdherenceFromStudyAdherenceReport(studyId, account, report);
watch.stop();
LOG.info("Study adherence report took " + watch.elapsed(TimeUnit.MILLISECONDS) + "ms");
return report;
}
Aggregations