public async Task <IActionResult> CreateOuraActivity([FromBody] OuraActivityRequest ouraActivityRequest)
        {
            if (ouraActivityRequest == null)
            {
                _logger.LogError("CreateOuraActivity: OuraActivityRequest object sent from client is null.");
                return(BadRequest("OuraActivityRequest object is null"));
            }
            if (!ModelState.IsValid)
            {
                _logger.LogError("CreateOuraActivity: Invalid OuraActivityRequest object sent from client.");
                return(BadRequest("Invalid OuraActivityRequest object"));
            }
            string userId = HttpContext.User.Claims.Single(x => x.Type == "id").Value;
            string role   = HttpContext.User.Claims.Single(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role").Value;

            if (role == Role.SubAdministratorRole)
            {
                if (!await ParticipantInOrganizationOfUserIdAsync(ouraActivityRequest.ParticipantId, userId))
                {
                    return(BadRequest("A sub-administrator can create only oura activities of a participant of own organization"));
                }
            }
            else if (role == Role.SupervisorRole)
            {
                if (!await ParticipantInStudiesOfUserIdAsync(ouraActivityRequest.ParticipantId, userId))
                {
                    return(BadRequest("A supervisor can create only oura activities of a participant of own studies"));
                }
            }
            else if (role == Role.ParticipantRole)
            {
                if (!await ParticipantSameAsUserIdAsync(ouraActivityRequest.ParticipantId, userId))
                {
                    return(BadRequest("A participant can create only own oura activities"));
                }
            }
            else if (role == Role.TherapistRole)
            {
                var participant = await _coadaptService.Participant.GetParticipantByIdAsync(ouraActivityRequest.ParticipantId);

                if (!await ParticipantMonitoredByTherapistOfUserIdAsync(participant, userId))
                {
                    return(BadRequest("A therapist can create only oura activities of monitored participants"));
                }
            }
            var ouraActivity = new OuraActivity();

            ouraActivity.FromRequest(ouraActivityRequest);
            _coadaptService.OuraActivity.CreateOuraActivity(ouraActivity);
            await _coadaptService.SaveAsync();

            return(CreatedAtRoute("OuraActivityById", new { id = ouraActivity.Id }, ouraActivity));
        }
Esempio n. 2
0
        public static OuraActivity ToOuraActivity(this OuraActivityMessage message, int participantId)
        {
            var activity = new OuraActivity {
                ParticipantId          = participantId,
                SummaryDate            = message.SummaryDate,
                TimezoneOffset         = message.TimezoneOffset,
                DayStart               = message.DayStart,
                DayEnd                 = message.DayEnd,
                Score                  = message.Score,
                ScoreStayActive        = message.ScoreStayActive,
                ScoreMoveEveryHour     = message.ScoreMoveEveryHour,
                ScoreMeetDailyTargets  = message.ScoreMeetDailyTargets,
                ScoreTrainingFrequency = message.ScoreTrainingFrequency,
                ScoreTrainingVolume    = message.ScoreTrainingVolume,
                ScoreRecoveryTime      = message.ScoreRecoveryTime,
                DailyMovement          = message.DailyMovement,
                NonWear                = message.NonWear,
                Rest             = message.Rest,
                Inactive         = message.Inactive,
                InactivityAlerts = message.InactivityAlerts,
                Low              = message.Low,
                Medium           = message.Medium,
                High             = message.High,
                Steps            = message.Steps,
                CaloriesTotal    = message.CaloriesTotal,
                CaloriesActive   = message.CaloriesActive,
                MetMinInactive   = message.MetMinInactive,
                MetMinLow        = message.MetMinLow,
                MetMinMedium     = message.MetMinMedium,
                MetMinMediumPlus = message.MetMinMediumPlus,
                MetMinHigh       = message.MetMinHigh,
                AverageMet       = message.AverageMet,
                Class5Min        = message.Class5Min,
                TargetCalories   = message.TargetCalories,
                TargetKm         = message.TargetKm,
                TargetMiles      = message.TargetMiles,
                ToTargetKm       = message.ToTargetKm,
                ToTargetMiles    = message.ToTargetMiles,
                Met1Min          = string.Join(",", message.Met1Min)
            };

            return(activity);
        }
Esempio n. 3
0
 public static void Map(this OuraActivity dbOuraActivity, OuraActivity ouraActivity)
 {
     dbOuraActivity.ParticipantId          = ouraActivity.ParticipantId;
     dbOuraActivity.SummaryDate            = ouraActivity.SummaryDate;
     dbOuraActivity.TimezoneOffset         = ouraActivity.TimezoneOffset;
     dbOuraActivity.DayStart               = ouraActivity.DayStart;
     dbOuraActivity.DayEnd                 = ouraActivity.DayEnd;
     dbOuraActivity.Score                  = ouraActivity.Score;
     dbOuraActivity.ScoreRecoveryTime      = ouraActivity.ScoreRecoveryTime;
     dbOuraActivity.ScoreStayActive        = ouraActivity.ScoreStayActive;
     dbOuraActivity.ScoreTrainingFrequency = ouraActivity.ScoreTrainingFrequency;
     dbOuraActivity.ScoreTrainingVolume    = ouraActivity.ScoreTrainingVolume;
     dbOuraActivity.ScoreMeetDailyTargets  = ouraActivity.ScoreMeetDailyTargets;
     dbOuraActivity.ScoreMoveEveryHour     = ouraActivity.ScoreMoveEveryHour;
     dbOuraActivity.DailyMovement          = ouraActivity.DailyMovement;
     dbOuraActivity.NonWear                = ouraActivity.NonWear;
     dbOuraActivity.Rest             = ouraActivity.Rest;
     dbOuraActivity.Inactive         = ouraActivity.Inactive;
     dbOuraActivity.InactivityAlerts = ouraActivity.InactivityAlerts;
     dbOuraActivity.Low              = ouraActivity.Low;
     dbOuraActivity.Medium           = ouraActivity.Medium;
     dbOuraActivity.High             = ouraActivity.High;
     dbOuraActivity.Steps            = ouraActivity.Steps;
     dbOuraActivity.CaloriesActive   = ouraActivity.CaloriesActive;
     dbOuraActivity.CaloriesTotal    = ouraActivity.CaloriesTotal;
     dbOuraActivity.Met1Min          = ouraActivity.Met1Min;
     dbOuraActivity.MetMinHigh       = ouraActivity.MetMinHigh;
     dbOuraActivity.MetMinInactive   = ouraActivity.MetMinInactive;
     dbOuraActivity.MetMinLow        = ouraActivity.MetMinLow;
     dbOuraActivity.MetMinMedium     = ouraActivity.MetMinMedium;
     dbOuraActivity.MetMinMediumPlus = ouraActivity.MetMinMediumPlus;
     dbOuraActivity.AverageMet       = ouraActivity.AverageMet;
     dbOuraActivity.Class5Min        = ouraActivity.Class5Min;
     dbOuraActivity.TargetCalories   = ouraActivity.TargetCalories;
     dbOuraActivity.TargetKm         = ouraActivity.TargetKm;
     dbOuraActivity.TargetMiles      = ouraActivity.TargetMiles;
     dbOuraActivity.ToTargetKm       = ouraActivity.ToTargetKm;
     dbOuraActivity.ToTargetMiles    = ouraActivity.ToTargetMiles;
 }
Esempio n. 4
0
 public static void FromRequest(this OuraActivity ouraActivity, OuraActivityRequest request)
 {
     ouraActivity.ParticipantId          = request.ParticipantId;
     ouraActivity.SummaryDate            = request.SummaryDate;
     ouraActivity.TimezoneOffset         = request.TimezoneOffset;
     ouraActivity.DayStart               = request.DayStart;
     ouraActivity.DayEnd                 = request.DayEnd;
     ouraActivity.Score                  = request.Score;
     ouraActivity.ScoreRecoveryTime      = request.ScoreRecoveryTime;
     ouraActivity.ScoreStayActive        = request.ScoreStayActive;
     ouraActivity.ScoreTrainingFrequency = request.ScoreTrainingFrequency;
     ouraActivity.ScoreTrainingVolume    = request.ScoreTrainingVolume;
     ouraActivity.ScoreMeetDailyTargets  = request.ScoreMeetDailyTargets;
     ouraActivity.ScoreMoveEveryHour     = request.ScoreMoveEveryHour;
     ouraActivity.DailyMovement          = request.DailyMovement;
     ouraActivity.NonWear                = request.NonWear;
     ouraActivity.Rest             = request.Rest;
     ouraActivity.Inactive         = request.Inactive;
     ouraActivity.InactivityAlerts = request.InactivityAlerts;
     ouraActivity.Low              = request.Low;
     ouraActivity.Medium           = request.Medium;
     ouraActivity.High             = request.High;
     ouraActivity.Steps            = request.Steps;
     ouraActivity.CaloriesActive   = request.CaloriesActive;
     ouraActivity.CaloriesTotal    = request.CaloriesTotal;
     ouraActivity.Met1Min          = string.Join(",", request.Met1Min);
     ouraActivity.MetMinHigh       = request.MetMinHigh;
     ouraActivity.MetMinInactive   = request.MetMinInactive;
     ouraActivity.MetMinLow        = request.MetMinLow;
     ouraActivity.MetMinMedium     = request.MetMinMedium;
     ouraActivity.MetMinMediumPlus = request.MetMinMediumPlus;
     ouraActivity.AverageMet       = request.AverageMet;
     ouraActivity.Class5Min        = request.Class5Min;
     ouraActivity.TargetCalories   = request.TargetCalories;
     ouraActivity.TargetKm         = request.TargetKm;
     ouraActivity.TargetMiles      = request.TargetMiles;
     ouraActivity.ToTargetKm       = request.ToTargetKm;
     ouraActivity.ToTargetMiles    = request.ToTargetMiles;
 }