public async Task <IActionResult> CancellPrescription([FromBody] CancellPrescriptionRequestDto request) { var prescriptionBiz = new PrescriptionBiz(); var prescription = await prescriptionBiz.GetAsync(request.PrescriptionGuid); if (prescription is null) { return(Failed(ErrorCode.Empty, "处方记录不存在,请检查")); } var name = prescription.PrescriptionName; if (prescription.Status == PrescriptionStatusEnum.Paied.ToString()) { return(Failed(ErrorCode.Empty, $"处方【{name}】已完成付款不可作废")); } if (prescription.Status == PrescriptionStatusEnum.Cancellation.ToString()) { return(Failed(ErrorCode.Empty, $"处方【{name}】已作废,请勿重复提交")); } prescription.Status = PrescriptionStatusEnum.Cancellation.ToString(); prescription.LastUpdatedBy = UserID; prescription.LastUpdatedDate = DateTime.Now; prescription.Reason = request.Reason; var informationBiz = new PrescriptionInformationBiz(); var information = await informationBiz.GetAsync(prescription.InformationGuid); if (information is null) { return(Failed(ErrorCode.Empty, "处方记录不存在")); } lock (locker) { information.TotalCost -= prescription.TotalCost; } var context = new PrescriptionContext(null) { InformationModel = information }; var prescriptionModels = await prescriptionBiz.GetAllPrescriptionsAsync(information.InformationGuid, prescription.PrescriptionGuid); context.dbPrescriptionModels = prescriptionModels; UpdatePrescriptionInformationPaidStatus(context); var result = await prescriptionBiz.CancellPrescription(context.InformationModel, prescription); if (!result) { return(Failed(ErrorCode.DataBaseError, $"作废处方【{prescription.PrescriptionName}】失败")); } return(Success()); }
public async Task <IActionResult> UpdatePrescription([FromBody] ProcessPrescriptionRequestDto request) { if (string.IsNullOrEmpty(request.InformationGuid)) { return(Failed(ErrorCode.Empty, "预约不存在,请检查")); } Logger.Info($"{nameof(UpdatePrescription)}: {JsonConvert.SerializeObject(request)}"); var context = new PrescriptionContext(request); var appointmentBiz = new DoctorAppointmentBiz(); var appointment = await appointmentBiz.GetAsync(request.AppointmentGuid); if (appointment is null) { return(Failed(ErrorCode.Empty, "预约不存在,请检查")); } context.AppointmentModel = appointment; var informationBiz = new PrescriptionInformationBiz(); var information = await informationBiz.GetAsync(request.InformationGuid); if (information is null) { return(Failed(ErrorCode.Empty, "用户信息不存在,请检查")); } if (!information.AppointmentGuid.Equals(request.AppointmentGuid)) { return(Failed(ErrorCode.Empty, "预约记录和用户信息不一致,无法操作")); } context.InformationModel = information; var prescriptionBiz = new PrescriptionBiz(); var prescriptionModels = await prescriptionBiz.GetAllPrescriptionsAsync(information.InformationGuid); prescriptionModels = prescriptionModels.Where(d => d.Status != PrescriptionStatusEnum.Cancellation.ToString()).ToList(); context.dbPrescriptionModels = prescriptionModels; var validateResult = Validate(context); if (validateResult.Code != ErrorCode.Success) { return(validateResult); } context.dbPrescriptionModels = prescriptionModels .Concat(context.PrescriptionModels).ToList(); UpdatePrescriptionInformationPaidStatus(context); var result = await prescriptionBiz.UpdatePrescription(context); if (!result) { return(Failed(ErrorCode.DataBaseError, "更新处方记录失败")); } var prescriptions = prescriptionModels.Where(d => d.Status != PrescriptionStatusEnum.Cancellation.ToString()) .OrderBy(d => d.CreationDate) .Concat(context.PrescriptionModels) .Select(d => new SubmitPrescriptionSuccessItemDto() { PrescriptionGuid = d.PrescriptionGuid, PrescriptionName = d.PrescriptionName }); var response = new SubmitPrescriptionSuccessResponseDto() { InformationGuid = information.InformationGuid, PrescriptionSuccess = prescriptions }; return(Success(response)); }