Search in sources :

Example 1 with WeeklyAdherenceReport

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;
}
Also used : WeeklyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport) Stopwatch(com.google.common.base.Stopwatch) AccountRef(org.sagebionetworks.bridge.models.accounts.AccountRef) StudyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport) DateTime(org.joda.time.DateTime)

Example 2 with WeeklyAdherenceReport

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");
}
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 WeeklyAdherenceReport

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%");
}
Also used : WeeklyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport) AdherenceReportSearch(org.sagebionetworks.bridge.models.AdherenceReportSearch) Test(org.testng.annotations.Test)

Example 4 with WeeklyAdherenceReport

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);
}
Also used : WeeklyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport) AdherenceReportSearch(org.sagebionetworks.bridge.models.AdherenceReportSearch) Test(org.testng.annotations.Test)

Example 5 with WeeklyAdherenceReport

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));
}
Also used : WeeklyAdherenceReport(org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport) AdherenceReportSearch(org.sagebionetworks.bridge.models.AdherenceReportSearch) Test(org.testng.annotations.Test)

Aggregations

WeeklyAdherenceReport (org.sagebionetworks.bridge.models.schedules2.adherence.weekly.WeeklyAdherenceReport)22 Test (org.testng.annotations.Test)20 AdherenceReportSearch (org.sagebionetworks.bridge.models.AdherenceReportSearch)12 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)12 RequestContext (org.sagebionetworks.bridge.RequestContext)7 Account (org.sagebionetworks.bridge.models.accounts.Account)7 StudyAdherenceReportGeneratorTest (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReportGeneratorTest)5 ResourceList (org.sagebionetworks.bridge.models.ResourceList)4 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)4 AdherenceRecord (org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord)4 Study (org.sagebionetworks.bridge.models.studies.Study)4 AccountRef (org.sagebionetworks.bridge.models.accounts.AccountRef)2 StudyAdherenceReport (org.sagebionetworks.bridge.models.schedules2.adherence.study.StudyAdherenceReport)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Stopwatch (com.google.common.base.Stopwatch)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 WhereClauseBuilder (org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder)1 StudyActivityEventIdsMap (org.sagebionetworks.bridge.models.activities.StudyActivityEventIdsMap)1 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)1