Search in sources :

Example 16 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceController method getWeeklyAdherenceReport.

@GetMapping("/v5/studies/{studyId}/participants/{userIdToken}/adherence/weekly")
public WeeklyAdherenceReport getWeeklyAdherenceReport(@PathVariable String studyId, @PathVariable String userIdToken) {
    UserSession session = getAuthenticatedSession(DEVELOPER, RESEARCHER, STUDY_DESIGNER, STUDY_COORDINATOR);
    AccountId accountId = BridgeUtils.parseAccountId(session.getAppId(), userIdToken);
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    return service.getWeeklyAdherenceReport(session.getAppId(), studyId, account);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 17 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceController method updateAdherenceRecordsForSelf.

@PostMapping("/v5/studies/{studyId}/participants/self/adherence")
public StatusMessage updateAdherenceRecordsForSelf(@PathVariable String studyId) {
    UserSession session = getAuthenticatedAndConsentedSession();
    AdherenceRecordList recordsList = parseJson(AdherenceRecordList.class);
    for (AdherenceRecord oneRecord : recordsList.getRecords()) {
        oneRecord.setAppId(session.getAppId());
        oneRecord.setUserId(session.getId());
        oneRecord.setStudyId(studyId);
    }
    service.updateAdherenceRecords(session.getAppId(), recordsList);
    return SAVED_MSG;
}
Also used : AdherenceRecordList(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecordList) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) AdherenceRecord(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceController method deleteAdherenceRecord.

@DeleteMapping("/v5/studies/{studyId}/participants/{userIdToken}/adherence/{instanceGuid}/{eventTimestamp}/{startedOn}")
public StatusMessage deleteAdherenceRecord(@PathVariable String studyId, @PathVariable String userIdToken, @PathVariable String instanceGuid, @PathVariable String eventTimestamp, @PathVariable String startedOn) {
    UserSession session = getAuthenticatedSession(DEVELOPER, RESEARCHER, STUDY_DESIGNER, STUDY_COORDINATOR);
    String userId = accountService.getAccountId(session.getAppId(), userIdToken).orElseThrow(() -> new EntityNotFoundException(Account.class));
    AdherenceRecord record = new AdherenceRecord();
    record.setAppId(session.getAppId());
    record.setUserId(userId);
    record.setStudyId(studyId);
    record.setInstanceGuid(instanceGuid);
    record.setEventTimestamp(BridgeUtils.getDateTimeOrDefault(eventTimestamp, null));
    record.setStartedOn(BridgeUtils.getDateTimeOrDefault(startedOn, null));
    service.deleteAdherenceRecord(record);
    return DELETED_MSG;
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) AdherenceRecord(org.sagebionetworks.bridge.models.schedules2.adherence.AdherenceRecord) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 19 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceController method getStudyAdherenceReport.

@GetMapping("/v5/studies/{studyId}/participants/{userIdToken}/adherence/study")
public StudyAdherenceReport getStudyAdherenceReport(@PathVariable String studyId, @PathVariable String userIdToken) {
    UserSession session = getAuthenticatedSession(DEVELOPER, RESEARCHER, STUDY_DESIGNER, STUDY_COORDINATOR);
    AccountId accountId = BridgeUtils.parseAccountId(session.getAppId(), userIdToken);
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    return service.getStudyAdherenceReport(session.getAppId(), studyId, account);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class AdherenceController method getEventStreamAdherenceReportForSelf.

@GetMapping("/v5/studies/{studyId}/participants/self/adherence/eventstream")
public EventStreamAdherenceReport getEventStreamAdherenceReportForSelf(@PathVariable String studyId, @RequestParam(required = false) String datetime, @RequestParam(required = false) String activeOnly) {
    UserSession session = getAuthenticatedAndConsentedSession();
    DateTime now = BridgeUtils.getDateTimeOrDefault(datetime, getDateTime());
    Boolean showActiveOnly = "true".equalsIgnoreCase(activeOnly);
    return service.getEventStreamAdherenceReport(session.getAppId(), studyId, session.getId(), now, session.getParticipant().getClientTimeZone(), showActiveOnly);
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) DateTime(org.joda.time.DateTime) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)483 PostMapping (org.springframework.web.bind.annotation.PostMapping)149 GetMapping (org.springframework.web.bind.annotation.GetMapping)114 App (org.sagebionetworks.bridge.models.apps.App)104 Test (org.testng.annotations.Test)102 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)89 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)65 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)60 Account (org.sagebionetworks.bridge.models.accounts.Account)56 BeforeMethod (org.testng.annotations.BeforeMethod)47 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)45 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)43 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)38 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)31 DateTime (org.joda.time.DateTime)27 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 ResourceList (org.sagebionetworks.bridge.models.ResourceList)21 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)21 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)18