Exemplo n.º 1
0
 public static void FromRequest(this PsychologicalReport psychologicalReport, PsychologicalReportRequest request)
 {
     psychologicalReport.ParticipantId                     = request.ParticipantId;
     psychologicalReport.IntrinsicFactorsOfWork            = request.IntrinsicFactorsOfWork;
     psychologicalReport.ManagerialRole                    = request.ManagerialRole;
     psychologicalReport.RelationshipWithOtherPeople       = request.RelationshipWithOtherPeople;
     psychologicalReport.CareerAndSuccess                  = request.CareerAndSuccess;
     psychologicalReport.ClimateAndOrganizationalStructure = request.ClimateAndOrganizationalStructure;
     psychologicalReport.HomeWorkInterface                 = request.HomeWorkInterface;
     psychologicalReport.AttitudeTowardsLife               = request.AttitudeTowardsLife;
     psychologicalReport.StyleOfBehavior                   = request.StyleOfBehavior;
     psychologicalReport.Ambition                = request.Ambition;
     psychologicalReport.TypeASynthetic          = request.TypeASynthetic;
     psychologicalReport.TypeATotal              = request.TypeATotal;
     psychologicalReport.OrganizationalForces    = request.OrganizationalForces;
     psychologicalReport.ManagementProcesses     = request.ManagementProcesses;
     psychologicalReport.IndividualInfluences    = request.IndividualInfluences;
     psychologicalReport.LocusOfControlSynthetic = request.LocusOfControlSynthetic;
     psychologicalReport.LocusOfControlTotal     = request.LocusOfControlTotal;
     psychologicalReport.SocialSupport           = request.SocialSupport;
     psychologicalReport.TaskOrientation         = request.TaskOrientation;
     psychologicalReport.Logical = request.Logical;
     psychologicalReport.HomeWorkRelationship = request.HomeWorkRelationship;
     psychologicalReport.Time               = request.Time;
     psychologicalReport.Involvement        = request.Involvement;
     psychologicalReport.CareerSatisfaction = request.CareerSatisfaction;
     psychologicalReport.JobSatisfaction    = request.JobSatisfaction;
     psychologicalReport.SettingAndOrganizationalStructureSatisfaction = request.SettingAndOrganizationalStructureSatisfaction;
     psychologicalReport.OrganizationalProcessesSatisfaction           = request.OrganizationalProcessesSatisfaction;
     psychologicalReport.InterpersonalRelationshipsSatisfaction        = request.InterpersonalRelationshipsSatisfaction;
     psychologicalReport.SyntheticJobSatisfaction     = request.SyntheticJobSatisfaction;
     psychologicalReport.TotalJobSatisfaction         = request.TotalJobSatisfaction;
     psychologicalReport.PsychologicalHealth          = request.PsychologicalHealth;
     psychologicalReport.PhysicalHealth               = request.PhysicalHealth;
     psychologicalReport.GlobalSeverityIndex          = request.GlobalSeverityIndex;
     psychologicalReport.PositiveSymptomTotal         = request.PositiveSymptomTotal;
     psychologicalReport.PositiveSymptomDistressIndex = request.PositiveSymptomDistressIndex;
     psychologicalReport.Somatization = request.Somatization;
     psychologicalReport.ObsessivenessCompulsiveness   = request.ObsessivenessCompulsiveness;
     psychologicalReport.InterpersonalHypersensitivity = request.InterpersonalHypersensitivity;
     psychologicalReport.Depression                           = request.Depression;
     psychologicalReport.Anxiety                              = request.Anxiety;
     psychologicalReport.Hostility                            = request.Hostility;
     psychologicalReport.PhobicAnxiety                        = request.PhobicAnxiety;
     psychologicalReport.ParanoidIdeation                     = request.ParanoidIdeation;
     psychologicalReport.Psychoticism                         = request.Psychoticism;
     psychologicalReport.PerceivedStressScale                 = request.PerceivedStressScale;
     psychologicalReport.SleepProblem                         = request.SleepProblem;
     psychologicalReport.TrialUserComments                    = request.TrialUserComments;
     psychologicalReport.TherapistComments                    = request.TherapistComments;
     psychologicalReport.ThoughtsOnChildren                   = request.ThoughtsOnChildren;
     psychologicalReport.ThoughtsOnParents                    = request.ThoughtsOnParents;
     psychologicalReport.StressfulEvents                      = request.StressfulEvents;
     psychologicalReport.MedicalConditionSelfAssessment       = request.MedicalConditionSelfAssessment;
     psychologicalReport.PsychologicalConditionSelfAssessment = request.PsychologicalConditionSelfAssessment;
 }
        public async Task <IActionResult> CreatePersonalInformation([FromBody] PsychologicalReportRequest personalInformationRequest)
        {
            if (personalInformationRequest == null)
            {
                _logger.LogError("CreatePsychologicalReport: PersonalInformationRequest object sent from client is null.");
                return(BadRequest("PersonalInformationRequest object is null"));
            }
            if (!ModelState.IsValid)
            {
                _logger.LogError("CreatePsychologicalReport: Invalid PersonalInformationRequest object sent from client.");
                return(BadRequest("Invalid PersonalInformationRequest 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(personalInformationRequest.ParticipantId, userId))
                {
                    return(BadRequest("A sub-administrator can create only personal information of a participant of own organization"));
                }
            }
            else if (role == Role.SupervisorRole)
            {
                if (!await ParticipantInStudiesOfUserIdAsync(personalInformationRequest.ParticipantId, userId))
                {
                    return(BadRequest("A supervisor can create only personal information of a participant of own studies"));
                }
            }
            else if (role == Role.ParticipantRole)
            {
                if (!await ParticipantSameAsUserIdAsync(personalInformationRequest.ParticipantId, userId))
                {
                    return(BadRequest("A participant can create only own personal information"));
                }
            }
            else if (role == Role.TherapistRole)
            {
                var participant = await _coadaptService.Participant.GetParticipantByIdAsync(personalInformationRequest.ParticipantId);

                if (!await ParticipantMonitoredByTherapistOfUserIdAsync(participant, userId))
                {
                    return(BadRequest("A therapist can create only personal information of monitored participants"));
                }
            }
            var personalInformation = new PsychologicalReport();

            personalInformation.FromRequest(personalInformationRequest);
            _coadaptService.PsychologicalReport.CreatePsychologicalReport(personalInformation);
            await _coadaptService.SaveAsync();

            return(CreatedAtRoute("PersonalInformationById", new { id = personalInformation.Id }, personalInformation));
        }