use of org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport 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.schedules2.adherence.weekly.WeeklyAdherenceReport 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.schedules2.adherence.weekly.WeeklyAdherenceReport in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAdherenceReportDaoTest method getWeeklyAdherenceReports_multipleLabels.
@Test
public void getWeeklyAdherenceReports_multipleLabels() {
AdherenceReportSearch search = new AdherenceReportSearch();
search.setLabelFilters(ImmutableSet.of("A", "B"));
List<WeeklyAdherenceReport> reports = ImmutableList.of();
when(mockHelper.queryCount(any(), any())).thenReturn(1000);
when(mockHelper.queryGet(any(), any(), eq(0), eq(50), eq(WeeklyAdherenceReport.class))).thenReturn(reports);
PagedResourceList<WeeklyAdherenceReport> retValue = dao.getWeeklyAdherenceReports(TEST_APP_ID, TEST_STUDY_ID, search);
assertEquals(retValue.getTotal(), Integer.valueOf(1000));
assertSame(retValue.getItems(), reports);
verify(mockHelper).queryCount(stringCaptor.capture(), paramsCaptor.capture());
verify(mockHelper).queryGet(stringCaptor.capture(), paramsCaptor.capture(), eq(0), eq(50), eq(WeeklyAdherenceReport.class));
assertEquals(stringCaptor.getAllValues().get(0), SELECT_COUNT + LABELS_SQL);
assertEquals(stringCaptor.getAllValues().get(1), SELECT_DISTINCT + LABELS_SQL);
assertEquals(paramsCaptor.getValue().get(LABEL_FILTER_FIELD + "0"), "%A%");
assertEquals(paramsCaptor.getValue().get(LABEL_FILTER_FIELD + "1"), "%B%");
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAdherenceReportDaoTest method getWeeklyAdherenceReports_productionOnly.
@Test
public void getWeeklyAdherenceReports_productionOnly() {
List<WeeklyAdherenceReport> reports = ImmutableList.of();
when(mockHelper.queryCount(any(), any())).thenReturn(1000);
when(mockHelper.queryGet(any(), any(), eq(0), eq(50), eq(WeeklyAdherenceReport.class))).thenReturn(reports);
AdherenceReportSearch search = new AdherenceReportSearch();
search.setTestFilter(PRODUCTION);
PagedResourceList<WeeklyAdherenceReport> retValue = dao.getWeeklyAdherenceReports(TEST_APP_ID, TEST_STUDY_ID, search);
assertEquals(retValue.getTotal(), Integer.valueOf(1000));
assertSame(retValue.getItems(), reports);
verify(mockHelper).queryCount(stringCaptor.capture(), paramsCaptor.capture());
verify(mockHelper).queryGet(stringCaptor.capture(), paramsCaptor.capture(), eq(0), eq(50), eq(WeeklyAdherenceReport.class));
assertEquals(stringCaptor.getAllValues().get(0), SELECT_COUNT + PROD_ACCOUNTS_SQL);
assertEquals(stringCaptor.getAllValues().get(1), SELECT_DISTINCT + PROD_ACCOUNTS_SQL);
}
use of org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAdherenceReportDaoTest method getWeeklyAdherenceReports.
@Test
public void getWeeklyAdherenceReports() {
List<WeeklyAdherenceReport> reports = ImmutableList.of();
when(mockHelper.queryCount(any(), any())).thenReturn(1000);
when(mockHelper.queryGet(any(), any(), eq(50), eq(100), eq(WeeklyAdherenceReport.class))).thenReturn(reports);
AdherenceReportSearch search = new AdherenceReportSearch();
search.setTestFilter(BOTH);
search.setLabelFilters(ImmutableSet.of("label"));
// verify ends of the range are included
search.setAdherenceMin(0);
search.setAdherenceMax(100);
search.setProgressionFilters(ImmutableSet.of(IN_PROGRESS));
search.setIdFilter("anId");
search.setOffsetBy(50);
search.setPageSize(100);
PagedResourceList<WeeklyAdherenceReport> retValue = dao.getWeeklyAdherenceReports(TEST_APP_ID, TEST_STUDY_ID, search);
assertEquals(retValue.getTotal(), Integer.valueOf(1000));
assertSame(retValue.getItems(), reports);
verify(mockHelper).queryCount(stringCaptor.capture(), paramsCaptor.capture());
verify(mockHelper).queryGet(stringCaptor.capture(), paramsCaptor.capture(), eq(50), eq(100), eq(WeeklyAdherenceReport.class));
assertEquals(stringCaptor.getAllValues().get(0), SELECT_COUNT + FULL_SQL);
assertEquals(stringCaptor.getAllValues().get(1), SELECT_DISTINCT + FULL_SQL);
assertEquals(paramsCaptor.getValue().get(LABEL_FILTER_FIELD + "0"), "%label%");
assertEquals(paramsCaptor.getValue().get(ADHERENCE_MIN_FIELD), 0);
assertEquals(paramsCaptor.getValue().get(ADHERENCE_MAX_FIELD), 100);
assertEquals(paramsCaptor.getValue().get(PROGRESSION_FILTER_FIELD), ImmutableSet.of(IN_PROGRESS));
}
Aggregations