Ejemplo 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));
        }
        public static PsychologicalReport ToPsychologicalReport(this PsychologicalReportMessage message, int participantId)
        {
            var report = new PsychologicalReport {
                ParticipantId                        = participantId,
                DateOfReport                         = message.DateOfReport,
                TrialUserComments                    = message.TrialUserComments,
                TherapistComments                    = message.TherapistComments,
                ThoughtsOnChildren                   = message.ThoughtsOnChildren,
                ThoughtsOnParents                    = message.ThoughtsOnParents,
                StressfulEvents                      = message.StressfulEvents,
                MedicalConditionSelfAssessment       = message.MedicalConditionSelfAssessment,
                PsychologicalConditionSelfAssessment = message.PsychologicalConditionSelfAssessment
            };

            if (int.TryParse(message.IntrinsicFactorsOfWork, out var temp))
            {
                report.IntrinsicFactorsOfWork = temp;
            }
            if (int.TryParse(message.ManagerialRole, out temp))
            {
                report.ManagerialRole = temp;
            }
            if (int.TryParse(message.RelationshipWithOtherPeople, out temp))
            {
                report.RelationshipWithOtherPeople = temp;
            }
            if (int.TryParse(message.CareerAndSuccess, out temp))
            {
                report.CareerAndSuccess = temp;
            }
            if (int.TryParse(message.ClimateAndOrganizationalStructure, out temp))
            {
                report.ClimateAndOrganizationalStructure = temp;
            }
            if (int.TryParse(message.HomeWorkInterface, out temp))
            {
                report.HomeWorkInterface = temp;
            }
            if (int.TryParse(message.AttitudeTowardsLife, out temp))
            {
                report.AttitudeTowardsLife = temp;
            }
            if (int.TryParse(message.StyleOfBehavior, out temp))
            {
                report.StyleOfBehavior = temp;
            }
            if (int.TryParse(message.Ambition, out temp))
            {
                report.Ambition = temp;
            }
            if (int.TryParse(message.TypeASynthetic, out temp))
            {
                report.TypeASynthetic = temp;
            }
            if (int.TryParse(message.TypeATotal, out temp))
            {
                report.TypeATotal = temp;
            }
            if (int.TryParse(message.OrganizationalForces, out temp))
            {
                report.OrganizationalForces = temp;
            }
            if (int.TryParse(message.ManagementProcesses, out temp))
            {
                report.ManagementProcesses = temp;
            }
            if (int.TryParse(message.IndividualInfluences, out temp))
            {
                report.IndividualInfluences = temp;
            }
            if (int.TryParse(message.LocusOfControlSynthetic, out temp))
            {
                report.LocusOfControlSynthetic = temp;
            }
            if (int.TryParse(message.LocusOfControlTotal, out temp))
            {
                report.LocusOfControlTotal = temp;
            }
            if (int.TryParse(message.SocialSupport, out temp))
            {
                report.SocialSupport = temp;
            }
            if (int.TryParse(message.TaskOrientation, out temp))
            {
                report.TaskOrientation = temp;
            }
            if (int.TryParse(message.Logical, out temp))
            {
                report.Logical = temp;
            }
            if (int.TryParse(message.HomeWorkRelationship, out temp))
            {
                report.HomeWorkRelationship = temp;
            }
            if (int.TryParse(message.Time, out temp))
            {
                report.Time = temp;
            }
            if (int.TryParse(message.Involvement, out temp))
            {
                report.Involvement = temp;
            }
            if (int.TryParse(message.CareerSatisfaction, out temp))
            {
                report.CareerSatisfaction = temp;
            }
            if (int.TryParse(message.JobSatisfaction, out temp))
            {
                report.JobSatisfaction = temp;
            }
            if (int.TryParse(message.SettingAndOrganizationalStructureSatisfaction, out temp))
            {
                report.SettingAndOrganizationalStructureSatisfaction = temp;
            }
            if (int.TryParse(message.OrganizationalProcessesSatisfaction, out temp))
            {
                report.OrganizationalProcessesSatisfaction = temp;
            }
            if (int.TryParse(message.InterpersonalRelationshipsSatisfaction, out temp))
            {
                report.InterpersonalRelationshipsSatisfaction = temp;
            }
            if (int.TryParse(message.SyntheticJobSatisfaction, out temp))
            {
                report.SyntheticJobSatisfaction = temp;
            }
            if (int.TryParse(message.TotalJobSatisfaction, out temp))
            {
                report.TotalJobSatisfaction = temp;
            }
            if (int.TryParse(message.PsychologicalHealth, out temp))
            {
                report.PsychologicalHealth = temp;
            }
            if (int.TryParse(message.PhysicalHealth, out temp))
            {
                report.PhysicalHealth = temp;
            }
            if (int.TryParse(message.GlobalSeverityIndex, out temp))
            {
                report.GlobalSeverityIndex = temp;
            }
            if (int.TryParse(message.PositiveSymptomTotal, out temp))
            {
                report.PositiveSymptomTotal = temp;
            }
            if (int.TryParse(message.PositiveSymptomDistressIndex, out temp))
            {
                report.PositiveSymptomDistressIndex = temp;
            }
            if (int.TryParse(message.Somatization, out temp))
            {
                report.Somatization = temp;
            }
            if (int.TryParse(message.ObsessivenessCompulsiveness, out temp))
            {
                report.ObsessivenessCompulsiveness = temp;
            }
            if (int.TryParse(message.InterpersonalHypersensitivity, out temp))
            {
                report.InterpersonalHypersensitivity = temp;
            }
            if (int.TryParse(message.Depression, out temp))
            {
                report.Depression = temp;
            }
            if (int.TryParse(message.Anxiety, out temp))
            {
                report.Anxiety = temp;
            }
            if (int.TryParse(message.Hostility, out temp))
            {
                report.Hostility = temp;
            }
            if (int.TryParse(message.PhobicAnxiety, out temp))
            {
                report.PhobicAnxiety = temp;
            }
            if (int.TryParse(message.ParanoidIdeation, out temp))
            {
                report.ParanoidIdeation = temp;
            }
            if (int.TryParse(message.Psychoticism, out temp))
            {
                report.Psychoticism = temp;
            }
            if (int.TryParse(message.PerceivedStressScale, out temp))
            {
                report.PerceivedStressScale = temp;
            }
            if (int.TryParse(message.SleepProblem, out temp))
            {
                report.SleepProblem = temp;
            }
            return(report);
        }