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(); }); }
private HistoricalDiagnosisDto HideDoctorsEgn(HistoricalDiagnosisDto historicalDiagnosis) { if (IsUserInRole(User, UserRole.Patient)) { historicalDiagnosis.Doctor.Egn = "HIDDEN"; } return(historicalDiagnosis); }
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(); }
public void UpdateDiagnosis(Guid id, HistoricalDiagnosisDto historicalDiagnosisDto) { EnsureNotInRole(User, UserRole.Patient, Messages.UnsupportedOperationForRole); Execute(dataContext => UpdateExistingDiagnosisFields(id, historicalDiagnosisDto, dataContext)); }