// Author: DucBM public ResponseObjectDto DeleteAppointment(int appointmentId) { var responseObject = new ResponseObjectDto(); responseObject.Success = true; var appRepo = this.RepositoryHelper.GetRepository <IAppointmentRepository>(this.UnitOfWork); // get existing appointment by AppointmentCode var appointment = appRepo.GetAppointmentById(appointmentId); if (appointment == null) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; return(responseObject); } else { // assign IsDeleted = true appointment.IsDeleted = true; // update entity appRepo.Update(appointment); try { // save to DB var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = ex; } } return(responseObject); }
// DucBM public ResponseObjectDto AddLabTestingIndexes(List <LabTestingIndex> labTestingIndexes) { var respObj = new ResponseObjectDto(); respObj.Success = true; respObj.Message = "Thêm các chỉ số thành công."; respObj.Data = null; var ltRepo = RepositoryHelper.GetRepository <ILabTestingRepository>(UnitOfWork); var repo = RepositoryHelper.GetRepository <ILabTestingIndexRepository>(UnitOfWork); try { var labTestingId = -1; foreach (var item in labTestingIndexes) { repo.Create(item); labTestingId = (int)item.LabTestingId; } // change status of LabTesting var lt = ltRepo.GetById(labTestingId); lt.Status = "LabtestDone"; var result = UnitOfWork.SaveChanges(); if (result.Any()) { respObj.Success = false; respObj.Message = "Có lỗi xảy ra"; respObj.Data = result; } } catch (Exception ex) { respObj.Success = false; respObj.Message = "Có lỗi xảy ra"; respObj.Data = ex; } return(respObj); }
public ResponseObjectDto Create(AppointmentDto appointmentDto) { var responseObject = new ResponseObjectDto(); responseObject.Success = true; responseObject.Message = "Đặt lịch thành công"; try { var appointmentRepo = this.RepositoryHelper.GetRepository <IAppointmentRepository>(this.UnitOfWork); var sgRepo = this.RepositoryHelper.GetRepository <ISampleGettingRepository>(this.UnitOfWork); var sampleRepo = this.RepositoryHelper.GetRepository <ISampleRepository>(this.UnitOfWork); var tableRepo = this.RepositoryHelper.GetRepository <ITableRepository>(this.UnitOfWork); var patientRepo = this.RepositoryHelper.GetRepository <IPatientRepository>(this.UnitOfWork); var patientAccountRepo = this.RepositoryHelper.GetRepository <IPatientAccountRepository>(this.UnitOfWork); var accRepo = this.RepositoryHelper.GetRepository <IAccountRepository>(this.UnitOfWork); Patient patient = null; if (appointmentDto.PatientDto != null) // Make Ap. without Login { //var idcNumber = appointmentDto.PatientDto.IdentityCardNumber; //patient = patientRepo.GetByIDCNumber(idcNumber); var phone = appointmentDto.PatientDto.PhoneNumber; var account = accRepo.GetByPhoneNumber(phone); if (account == null) { account = new Account(); account.FullName = appointmentDto.PatientDto.FullName; account.PhoneNumber = phone; account.Password = ConstantManager.DEFAULT_PASSWORD; account.RoleId = (int)RoleEnum.Patient; account.IsDeleted = false; accRepo.Create(account); try { var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; return(responseObject); } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = ex; return(responseObject); } responseObject.Data = new { appointmentDto.PatientDto.PhoneNumber, DefaultPassword = account.Password }; } int accountId = account.AccountId; var dateOfBirth = DateTime.Parse(appointmentDto.PatientDto.DateOfBirth); patient = patientRepo.GetBy(accountId, appointmentDto.PatientDto.FullName, dateOfBirth); if (patient == null) { // Create a new Patient patient = new Patient(); patient.AccountId = accountId; patient.FullName = appointmentDto.PatientDto.FullName; patient.IdentityCardNumber = appointmentDto.PatientDto.IdentityCardNumber; patient.PhoneNumber = appointmentDto.PatientDto.PhoneNumber; patient.DateOfBirth = dateOfBirth; patient.Gender = appointmentDto.PatientDto.Gender; patient.HomeAddress = appointmentDto.PatientDto.HomeAddress; patient.IsDeleted = false; patientRepo.Create(patient); try { var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; return(responseObject); } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = ex; return(responseObject); } patient.PatientCode = "BN" + patient.PatientId; } if (account != null && patient != null) { var patientAccount = new PatientAccount(); patientAccount.AccountId = account.AccountId; patientAccount.PatientId = patient.PatientId; patientAccount.IsDeleted = false; patientAccountRepo.Create(patientAccount); var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; return(responseObject); } } appointmentDto.PatientId = patient.PatientId; } else if (appointmentDto.PatientId != null) // Make Ap. with Login { patient = patientRepo.GetById((int)appointmentDto.PatientId); if (patient == null) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = new { MessageForDev = "Không tồn tại PatientId này" }; return(responseObject); } } else { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = new { MessageForDev = "PatientId truyền vào là Null" }; return(responseObject); } var appointment = new Appointment(); // Convert AppointmentDto to Appointment var now = DateTime.Now; var sDate = now.ToString("yyyy-MM-dd"); // Generate code var lastcode = appointmentRepo.GetLastCode(sDate); var count = 0; if (lastcode != null) { count = int.Parse(lastcode.Substring("yyyy-MM-dd-".Length)); } var code = sDate + "-" + (count + 1); appointment.PatientId = patient.PatientId; appointment.AppointmentCode = code; appointment.Status = "NEW"; appointment.PatientId = appointmentDto.PatientId; appointment.EnterTime = now; appointment.IsOnline = true; appointment.IsDeleted = false; appointment.SampleGettings = new List <SampleGetting>(); var sampleGettingDtos = appointmentDto.SampleGettingDtos; foreach (var sgDto in appointmentDto.SampleGettingDtos) { var duplicatedSG = sgRepo.GetFirst(sgDto.SampleId, sgDto.GettingDate, (int)appointmentDto.PatientId); if (duplicatedSG != null) { var sampleName = sampleRepo.GetById(sgDto.SampleId).SampleName; var date = DateTime.Parse(sgDto.GettingDate).ToString("dd-MM-yyyy"); responseObject.Success = false; responseObject.Message = string.Format("Bạn đã từng đăng ký lấy mẫu {0} vào ngày {1}.\n Bạn không thể lấy mẫu {0} 2 lần 1 ngày.", sampleName, date); return(responseObject); } var sg = Mapper.Map <SampleGettingDto, SampleGetting>(sgDto); var avaiTable = tableRepo.GetFirstAvailableTable((int)sg.SlotId, (DateTime)sg.GettingDate); if (avaiTable == null) { responseObject.Success = false; responseObject.Message = "Có ca xét nghiệm đã hết chỗ"; return(responseObject); } sg.TableId = avaiTable.TableId; sg.Status = "NEW"; sg.LabTestings = new List <LabTesting>(); sg.IsGot = false; sg.IsPaid = false; sg.IsDeleted = false; foreach (var id in sgDto.LabTestIds) { var labTesting = new LabTesting(); labTesting.LabTestId = id; labTesting.SampleGettingId = sg.SampleGettingId; labTesting.Status = "NEW"; labTesting.IsDeleted = false; sg.LabTestings.Add(labTesting); } appointment.SampleGettings.Add(sg); } // Create appointmentRepo.Create(appointment); try { var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; return(responseObject); } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = ex; return(responseObject); } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = ex; return(responseObject); } return(responseObject); }
// Author: DucBM public ResponseObjectDto UpdateAppointment(int appointmentId, List <SampleGettingDto> sampleGettingDtos) { var responseObject = new ResponseObjectDto(); responseObject.Success = true; responseObject.Message = "Chỉnh sửa lịch thành công"; var appRepo = this.RepositoryHelper.GetRepository <IAppointmentRepository>(this.UnitOfWork); // get existing appointment by AppointmentCode var appointment = appRepo.GetAppointmentByIdInclude(appointmentId); // delete old records // TEMPORARY !! -> too waist memory !! foreach (var sg in appointment.SampleGettings) { sg.IsDeleted = true; foreach (var lt in sg.LabTestings) { lt.IsDeleted = true; } } // modify SampleGettings property appointment.SampleGettings = new List <SampleGetting>(); foreach (var sgDto in sampleGettingDtos) { var sg = Mapper.Map <SampleGettingDto, SampleGetting>(sgDto); sg.LabTestings = new List <LabTesting>(); sg.Status = "NEW"; sg.TableId = 1; sg.IsDeleted = false; foreach (var id in sgDto.LabTestIds) { var lt = new LabTesting(); lt.LabTestId = id; sg.LabTestings.Add(lt); } appointment.SampleGettings.Add(sg); } try { // update entity appRepo.Update(appointment); // save to DB var result = this.UnitOfWork.SaveChanges(); if (result.Any()) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = result; } } catch (Exception ex) { responseObject.Success = false; responseObject.Message = "Có lỗi xảy ra"; responseObject.Data = new { ErrorMessage = ex.Message, StackTrace = ex.StackTrace }; } return(responseObject); }