/// <summary> /// Update an appointment /// </summary> /// <param name="Id"></param> /// <param name="PatientId"></param> /// <param name="ContentId"></param> /// <param name="Note"></param> /// <param name="StartTime"></param> /// <param name="EndTime"></param> /// <param name="DoctorUsername"></param> /// <param name="RoomId"></param> /// <returns></returns> private static string UpdateEvent(string Id, string PatientId, string Note, DateTime StartTime, DateTime EndTime, string DoctorUsername, string RoomId, string Status) { string result = string.Empty; TransactionManager tm = DataRepository.Provider.CreateTransaction(); try { #region "Validate" // Check Patient if (string.IsNullOrEmpty(PatientId) || PatientId == "") { result = @"[{ 'result': 'false', 'message': 'You must choose patient.', 'data': [] }]"; return result; } // Get start date and end date DateTime dtStart = StartTime; DateTime dtEnd = EndTime; // If appointment From Date >= To Date if (dtStart >= dtEnd) { result = @"[{ 'result': 'false', 'message': 'From date, time must be less than to date, time.', 'data': [] }]"; goto StepResult; } // If appointment is created in a passed or current day DateTime dtNow = DateTime.Now; if (dtNow >= dtStart) { result = @"[{ 'result': 'false', 'message': 'You can not change roster to passed or current date.', 'data': [] }]"; goto StepResult; } // Check Doctor if (string.IsNullOrEmpty(DoctorUsername) || DoctorUsername == "") { result = @"[{ 'result': 'false', 'message': 'You must choose doctor.', 'data': [] }]"; goto StepResult; } // Check Room if (string.IsNullOrEmpty(RoomId) || RoomId == "") { result = @"[{ 'result': 'false', 'message': 'You must choose room.', 'data': [] }]"; goto StepResult; } // Check Status long lStatus; if (!Int64.TryParse(Status, out lStatus)) { result = @"[{ 'result': 'false', 'message': 'You must choose status.', 'data': [] }]"; goto StepResult; } #endregion string strUserName = EntitiesUtilities.GetAuthName(); string strPatientId = PatientId; long lRoomId = Convert.ToInt64(RoomId); tm.BeginTransaction(); #region "Check infomation" // Check exists Patient Customer objPatient = DataRepository.CustomerProvider.GetByIdIsDisabled(tm, strPatientId, false); if (objPatient == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Patient is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Doctor Staff objDoctor = DataRepository.StaffProvider.GetByUserNameIsDisabled(tm, DoctorUsername, false); if (objDoctor == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Doctor is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Room Room objRoom = DataRepository.RoomProvider.GetByIdIsDisabled(tm, lRoomId, false); if (objRoom == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Room is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Room Status objStatus = DataRepository.StatusProvider.GetByIdIsDisabled(tm, lStatus, false); if (objStatus == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Status is not exist.', 'data': '[]' }]"; goto StepResult; } #endregion #region "Check Conflict" int intCompareValue = 1; // Check conflict Patient if (!CheckConflict(tm, "CustomerId", strPatientId, "", String.Format("{2}. {0} {1}", objPatient.FirstName, objPatient.LastName, objPatient.Title), dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } // Check conflict Doctor if (!CheckConflict(tm, "DoctorUserName", DoctorUsername, "Doctor", objDoctor.ShortName, dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } // Check conflict Room if (!CheckConflict(tm, "RoomId", lRoomId.ToString(), "Room", objRoom.Title, dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } #endregion #region "Update Appointment" Appointment obj = DataRepository.AppointmentProvider.GetByIdIsDisabled(Id, false); if (obj == null || obj.IsComplete == true) { result = @"[{ 'result': 'false', 'message': 'There is no appointment to change or appointment is expired.', 'data': [] }]"; return result; } obj.CustomerId = strPatientId; obj.CustomerName = String.Format("{0} {1}", objPatient.FirstName, objPatient.LastName); obj.DoctorEmail = objDoctor.Email; obj.DoctorUsername = DoctorUsername; obj.DoctorShortName = objDoctor.ShortName; obj.RoomId = lRoomId; obj.RoomTitle = objRoom.Title; obj.Note = Note; obj.StatusId = lStatus; obj.ColorCode = objStatus.ColorCode; obj.StartTime = dtStart; obj.EndTime = dtEnd; obj.UpdateUser = strUserName; obj.UpdateDate = DateTime.Now; DataRepository.AppointmentProvider.Save(tm, obj); #endregion #region "Send Appointment" string strSubject = String.Format("Change Appointment: {0} - {1}", obj.ContentTitle, obj.CustomerName); string strBody = String.Format("You have a new change for appointment"); string strSummary = string.Empty; string strDescription = string.Empty; string strLocation = String.Format("Room {0}", obj.RoomTitle); string strAlarmSummary = String.Format("{0} minutes left for appointment with {1}", ServiceFacade.SettingsHelper.TimeLeftRemindAppointment.ToString(), obj.CustomerName); MailAppointment objMail = new MailAppointment(strSubject, strBody, strSummary, strDescription, strLocation, strAlarmSummary, Convert.ToDateTime(obj.StartTime), Convert.ToDateTime(obj.EndTime)); objMail.AddMailAddress(obj.DoctorEmail, obj.DoctorShortName); if (!objMail.SendMail()) { } #endregion result = @"[{ 'result': 'true', 'message': '', 'data':" + BuildResult(obj) + @" }]"; tm.Commit(); } catch (Exception ex) { //SingletonLogger.Instance.Error("Admin_Appointment_AppointmentIframe.UpdateEvent", ex); tm.Rollback(); result = @"[{ 'result': 'false', 'message': '" + ex.Message + "', 'data': [] }]"; return result; } StepResult: return result; }
public static string DeleteAppointment(string id) { TransactionManager tm = DataRepository.Provider.CreateTransaction(); try { // Validate current user have any right to operate this action // Validate user right for reading if (!CheckDeleting(out _message)) { return WebCommon.BuildFailedResult(_message); } Appointment appointment = DataRepository.AppointmentProvider.GetById(id); if (appointment == null || appointment.IsComplete || appointment.IsDisabled) { return WebCommon.BuildFailedResult("There is no appointment to delete or appointment is expired."); } tm.BeginTransaction(); appointment.IsDisabled = true; appointment.UpdateUser = AccountSession.Session; appointment.UpdateDate = DateTime.Now; DataRepository.AppointmentProvider.Save(tm, appointment); #region "Send Appointment" DataRepository.AppointmentProvider.DeepLoad(appointment); var objPatient = DataRepository.VcsPatientProvider.GetByPatientCode(appointment.PatientCode)[0]; string strSubject = String.Format("Delete Appointment: {0} - {1} {2}", appointment.ServicesIdSource.Title , objPatient.FirstName, objPatient.LastName); string strBody = String.Format("Appointment has been deleted."); string strSummary = string.Empty; string strDescription = string.Empty; string strLocation = string.Empty; string strAlarmSummary = string.Empty; var objMail = new MailAppointment(strSubject, strBody, strSummary, strDescription, strLocation, strAlarmSummary, Convert.ToDateTime(appointment.StartTime), Convert.ToDateTime(appointment.EndTime)); objMail.AddMailAddress(appointment.UsernameSource.Email, appointment.UsernameSource.DisplayName); if (!objMail.SendMail()) { } #endregion tm.Commit(); return WebCommon.BuildSuccessfulResult(); } catch (Exception ex) { LoggerController.WriteLog(System.Runtime.InteropServices.Marshal.GetExceptionCode(), ex, Network.GetIpClient()); tm.Rollback(); return WebCommon.BuildFailedResult(ex.Message); } }
public static string SaveEvent(string PatientId, string Note, string StartTime, string EndTime, string StartDate, string EndDate , string DoctorUsername, string RoomId, string Status) { /* Return Structure * { result: true [success], false [fail], * message: message content [will be showed when fail] * data: [{ * Id: id of roster, * DoctorUserName: Doctor UserName, * DoctorShortName: Doctor ShortName, * RosterTypeId: Roster Type Id, * RosterTypeTitle: Roster Type Title, * start_date: start date, * end_date: end date, * note: note, * text: roster type + note, * color: color of event [get from status], * isnew: false * }, {}, {}] * } */ string result = string.Empty; TransactionManager tm = DataRepository.Provider.CreateTransaction(); try { #region "Validate" // Check Patient if (string.IsNullOrEmpty(PatientId) || PatientId == "") { result = @"[{ 'result': 'false', 'message': 'You must choose patient.', 'data': [] }]"; return result; } // Get start time and end time int intStartHour = Convert.ToInt32(StartTime.Split(':')[0]); int intStartMinute = Convert.ToInt32(StartTime.Split(':')[1]); int intEndHour = Convert.ToInt32(EndTime.Split(':')[0]); int intEndMinute = Convert.ToInt32(EndTime.Split(':')[1]); // Get start date and end date DateTime dtStart = Convert.ToDateTime(StartDate); DateTime dtEnd = Convert.ToDateTime(EndDate); dtStart = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day, intStartHour, intStartMinute, 0); dtEnd = new DateTime(dtEnd.Year, dtEnd.Month, dtEnd.Day, intEndHour, intEndMinute, 0); // If appointment From Date >= To Date if (dtStart >= dtEnd) { result = @"[{ 'result': 'false', 'message': 'From date, time must be less than to date, time.', 'data': [] }]"; goto StepResult; } // If appointment is created in a passed or current day DateTime dtNow = DateTime.Now; if (dtNow >= dtStart) { result = @"[{ 'result': 'false', 'message': 'You can not change roster to passed or current date.', 'data': [] }]"; goto StepResult; } // Check Doctor if (string.IsNullOrEmpty(DoctorUsername) || DoctorUsername == "") { result = @"[{ 'result': 'false', 'message': 'You must choose doctor.', 'data': [] }]"; goto StepResult; } // Check Room if (string.IsNullOrEmpty(RoomId) || RoomId == "") { result = @"[{ 'result': 'false', 'message': 'You must choose room.', 'data': [] }]"; goto StepResult; } // Check Status long lStatus; if (!Int64.TryParse(Status, out lStatus)) { result = @"[{ 'result': 'false', 'message': 'You must choose status.', 'data': [] }]"; goto StepResult; } #endregion string strUserName = EntitiesUtilities.GetAuthName(); string strPatientId = PatientId; long lRoomId = Convert.ToInt64(RoomId); tm.BeginTransaction(); #region "Check infomation" // Check exists Patient Customer objPatient = DataRepository.CustomerProvider.GetByIdIsDisabled(tm, strPatientId, false); if (objPatient == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Patient is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Doctor Staff objDoctor = DataRepository.StaffProvider.GetByUserNameIsDisabled(tm, DoctorUsername, false); if (objDoctor == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Doctor is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Room Room objRoom = DataRepository.RoomProvider.GetByIdIsDisabled(tm, lRoomId, false); if (objRoom == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Room is not exist.', 'data': '[]' }]"; goto StepResult; } // Check exists Room Status objStatus = DataRepository.StatusProvider.GetByIdIsDisabled(tm, lStatus, false); if (objStatus == null) { tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Status is not exist.', 'data': '[]' }]"; goto StepResult; } #endregion #region "Check Conflict" int intCompareValue = 0; // Check conflict Patient if (!CheckConflict(tm, "CustomerId", strPatientId, string.IsNullOrEmpty(objPatient.Title) ? "patient" : objPatient.Title + ".", String.Format("{0} {1}", objPatient.FirstName, objPatient.LastName), dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } // Check conflict Doctor if (!CheckConflict(tm, "DoctorUserName", DoctorUsername, "Dr.", objDoctor.ShortName, dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } // Check conflict Room if (!CheckConflict(tm, "RoomId", lRoomId.ToString(), "Room", objRoom.Title, dtStart, dtEnd, intCompareValue, ref result)) { tm.Rollback(); goto StepResult; } #endregion #region "Insert Appointment" Appointment newObj = new Appointment(); string Perfix = "A" + ServiceFacade.SettingsHelper.AppointmentPrefix + DateTime.Now.ToString("yyMMdd"); int Count = 0; TList<Appointment> objPo = DataRepository.AppointmentProvider.GetPaged(tm, "Id like '" + Perfix + "' + '%'", "Id desc", 0, 1, out Count); if (Count == 0) newObj.Id = Perfix + "001"; else { newObj.Id = Perfix + String.Format("{0:000}", int.Parse(objPo[0].Id.Substring(objPo[0].Id.Length - 3)) + 1); } newObj.CustomerId = strPatientId; newObj.CustomerName = String.Format("{0} {1}", objPatient.FirstName, objPatient.LastName); newObj.DoctorEmail = objDoctor.Email; newObj.DoctorUsername = DoctorUsername; newObj.DoctorShortName = objDoctor.ShortName; newObj.RoomId = lRoomId; newObj.RoomTitle = objRoom.Title; newObj.Note = Note; newObj.StatusId = lStatus; newObj.StartTime = dtStart; newObj.EndTime = dtEnd; newObj.ColorCode = objStatus.ColorCode; newObj.CreateUser = strUserName; newObj.UpdateUser = strUserName; DataRepository.AppointmentProvider.Insert(tm, newObj); #endregion #region "Send Appointment" string strSubject = String.Format("New Appointment: {0} - {1}", newObj.ContentTitle, newObj.CustomerName); string strBody = String.Format("You have a new appointment"); string strSummary = string.Empty; string strDescription = string.Empty; string strLocation = String.Format("Room {0}", newObj.RoomTitle); string strAlarmSummary = String.Format("{0} minutes left for appointment with {1}", ServiceFacade.SettingsHelper.TimeLeftRemindAppointment.ToString(), newObj.CustomerName); MailAppointment objMail = new MailAppointment(strSubject, strBody, strSummary, strDescription, strLocation, strAlarmSummary, Convert.ToDateTime(newObj.StartTime), Convert.ToDateTime(newObj.EndTime)); objMail.AddMailAddress(newObj.DoctorEmail, newObj.DoctorShortName); objMail.SendMail(); #endregion result = @"[{ 'result': 'true', 'message': '', 'data':" + BuildResult(newObj) + @" }]"; tm.Commit(); } catch (Exception ex) { //SingletonLogger.Instance.Error("Admin_Appointment_AppointmentIframe.SaveEvent", ex); tm.Rollback(); result = @"[{ 'result': 'false', 'message': 'Cannot create appointment', 'data': [] }]"; } StepResult: return result; }