Ejemplo n.º 1
0
        public void CreateNewDiagnosis([FromBody] HistoricalDiagnosisDto historicalDiagnosisDto)
        {
            EnsureNotInRole(User, UserRole.Patient, Messages.PatientCannotCreateDiagnoses);
            Execute(dataContext =>
            {
                var diagnosis =
                    Map <HistoricalDiagnosisDto, HistoricalDiagnosis>(historicalDiagnosisDto);

                if (IsUserInRole(User, UserRole.Doctor))
                {
                    if (!dataContext.SysUsers.First(user => user.Username.Equals(User.Identity.Name)).Doctors
                        .Any(doctor => doctor.Guid.Equals(diagnosis.DoctorId)))
                    {
                        throw GetResponseException(HttpStatusCode.Forbidden,
                                                   Messages.DoctorNotAllowedToPostDiagnosisOnOtherDoctors);
                    }
                }
                if (!dataContext.Patients.Any(patient => patient.Guid.Equals(diagnosis.PatientId)))
                {
                    throw GetResponseException(HttpStatusCode.NotFound, Messages.PatientDoesNotExist);
                }
                if (!dataContext.Doctors.Any(doctor => doctor.Guid.Equals(diagnosis.DoctorId)))
                {
                    throw GetResponseException(HttpStatusCode.NotFound, Messages.DoctorDoesNotExist);
                }

                diagnosis.Guid = Guid.Empty;
                dataContext.HistoricalDiagnosis.InsertOnSubmit(diagnosis);
                dataContext.SubmitChanges();
            });
        }
Ejemplo n.º 2
0
 private HistoricalDiagnosisDto HideDoctorsEgn(HistoricalDiagnosisDto historicalDiagnosis)
 {
     if (IsUserInRole(User, UserRole.Patient))
     {
         historicalDiagnosis.Doctor.Egn = "HIDDEN";
     }
     return(historicalDiagnosis);
 }
Ejemplo n.º 3
0
        private static void UpdateExistingDiagnosisFields(Guid id, HistoricalDiagnosisDto historicalDiagnosisDto,
                                                          PersistenceClassesDataContext dataContext)
        {
            var diagnosis = dataContext.HistoricalDiagnosis.FirstOrDefault(r => r.Guid.Equals(id));

            if (diagnosis == null)
            {
                throw GetResponseException(HttpStatusCode.NotFound, Messages.DiagnosisDoesNotExist);
            }
            if (historicalDiagnosisDto.DiagnosisDescription != null)
            {
                diagnosis.SicknessDescription = historicalDiagnosisDto.DiagnosisDescription;
            }
            if (historicalDiagnosisDto.DiagnosisTime != DateTime.MinValue)
            {
                diagnosis.DiagnosisTime = historicalDiagnosisDto.DiagnosisTime;
            }
            dataContext.SubmitChanges();
        }
Ejemplo n.º 4
0
 public void UpdateDiagnosis(Guid id, HistoricalDiagnosisDto historicalDiagnosisDto)
 {
     EnsureNotInRole(User, UserRole.Patient, Messages.UnsupportedOperationForRole);
     Execute(dataContext => UpdateExistingDiagnosisFields(id, historicalDiagnosisDto, dataContext));
 }