Search in sources :

Example 1 with ReportDataKey

use of org.sagebionetworks.bridge.models.reports.ReportDataKey in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantReportControllerTest method getParticipantReportIndex.

@Test
public void getParticipantReportIndex() throws Exception {
    ReportIndex index = ReportIndex.create();
    index.setIdentifier(REPORT_ID);
    index.setPublic(true);
    index.setStudyIds(USER_STUDY_IDS);
    when(mockReportService.getReportIndex(any())).thenReturn(index);
    ReportIndex result = controller.getParticipantReportIndex(REPORT_ID);
    assertEquals(result.getIdentifier(), REPORT_ID);
    assertEquals(result.getStudyIds(), USER_STUDY_IDS);
    verify(mockReportService).getReportIndex(reportDataKeyCaptor.capture());
    ReportDataKey key = reportDataKeyCaptor.getValue();
    assertEquals(key.getAppId(), TEST_APP_ID);
    assertEquals(key.getIdentifier(), REPORT_ID);
    assertEquals(key.getReportType(), PARTICIPANT);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) Test(org.testng.annotations.Test)

Example 2 with ReportDataKey

use of org.sagebionetworks.bridge.models.reports.ReportDataKey in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getParticipantReportV4.

/**
 * Return set of participant report records based on the provided datetime range. Study memberships are enforced.
 */
public ForwardCursorPagedResourceList<ReportData> getParticipantReportV4(final String appId, final String userId, final String identifier, final String healthCode, final DateTime startTime, final DateTime endTime, final String offsetKey, final int pageSize) {
    if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
        throw new BadRequestException(BridgeConstants.PAGE_SIZE_ERROR);
    }
    RangeTuple<DateTime> finalTimes = validateDateTimeRange(startTime, endTime);
    ReportDataKey key = new ReportDataKey.Builder().withHealthCode(healthCode).withReportType(ReportType.PARTICIPANT).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkParticipantReportAccess(userId, index);
    return reportDataDao.getReportDataV4(key, finalTimes.getStart(), finalTimes.getEnd(), offsetKey, pageSize);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) DateTime(org.joda.time.DateTime)

Example 3 with ReportDataKey

use of org.sagebionetworks.bridge.models.reports.ReportDataKey in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getStudyReportV4.

/**
 * Return set of study report records based on the provided datetime range. Study memberships are enforced.
 */
public ForwardCursorPagedResourceList<ReportData> getStudyReportV4(final String appId, final String identifier, final DateTime startTime, final DateTime endTime, final String offsetKey, final int pageSize) {
    if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
        throw new BadRequestException(BridgeConstants.PAGE_SIZE_ERROR);
    }
    RangeTuple<DateTime> finalTimes = validateDateTimeRange(startTime, endTime);
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkStudyReportAccess(index);
    return reportDataDao.getReportDataV4(key, finalTimes.getStart(), finalTimes.getEnd(), offsetKey, pageSize);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) DateTime(org.joda.time.DateTime)

Example 4 with ReportDataKey

use of org.sagebionetworks.bridge.models.reports.ReportDataKey in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method deleteStudyReport.

/**
 * Delete all records for a study report. Study memberships will be enforced.
 */
public void deleteStudyReport(String appId, String identifier) {
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkStudyReportAccess(index);
    reportDataDao.deleteReportData(key);
    reportIndexDao.removeIndex(key);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey)

Example 5 with ReportDataKey

use of org.sagebionetworks.bridge.models.reports.ReportDataKey in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getParticipantReport.

/**
 * Return set of participant report records based on the provided local date range. Study memberships are
 * enforced.
 */
public DateRangeResourceList<? extends ReportData> getParticipantReport(String appId, String userId, String identifier, String healthCode, LocalDate startDate, LocalDate endDate) {
    RangeTuple<LocalDate> finalDates = validateLocalDateRange(startDate, endDate);
    startDate = finalDates.getStart();
    endDate = finalDates.getEnd();
    ReportDataKey key = new ReportDataKey.Builder().withHealthCode(healthCode).withReportType(ReportType.PARTICIPANT).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkParticipantReportAccess(userId, index);
    return reportDataDao.getReportData(key, startDate, endDate);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) LocalDate(org.joda.time.LocalDate)

Aggregations

ReportDataKey (org.sagebionetworks.bridge.models.reports.ReportDataKey)50 ReportIndex (org.sagebionetworks.bridge.models.reports.ReportIndex)36 Test (org.testng.annotations.Test)26 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)11 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)9 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 DateTime (org.joda.time.DateTime)4 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)4 Account (org.sagebionetworks.bridge.models.accounts.Account)4 LocalDate (org.joda.time.LocalDate)3 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)3 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)3 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)2 ReportDataValidator (org.sagebionetworks.bridge.validators.ReportDataValidator)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InvalidEntityException (org.sagebionetworks.bridge.exceptions.InvalidEntityException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1