public async Task <IActionResult> CreatePrescription([FromBody] ProcessPrescriptionRequestDto request) { Logger.Info($"{nameof(CreatePrescription)}: {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, "预约不存在,请检查")); } var informationBiz = new PrescriptionInformationBiz(); var prescriptionInformation = await informationBiz.ExistInformation(appointment.AppointmentGuid); if (prescriptionInformation != null) { return(Failed(ErrorCode.Empty, "该处方已提交,请勿重复提交")); } context.AppointmentModel = appointment; var validateResult = Validate(context); if (validateResult.Code != ErrorCode.Success) { return(validateResult); } context.AppointmentModel.Status = AppointmentStatusEnum.Treated.ToString(); var prescriptionBiz = new PrescriptionBiz(); var result = await prescriptionBiz.CreatePrescription(context); if (!result) { return(Failed(ErrorCode.DataBaseError, "创建处方记录失败,请稍后重试")); } var response = new SubmitPrescriptionSuccessResponseDto { InformationGuid = context.InformationModel.InformationGuid, PrescriptionSuccess = context.PrescriptionModels.Select(d => new SubmitPrescriptionSuccessItemDto() { PrescriptionGuid = d.PrescriptionGuid, PrescriptionName = d.PrescriptionName }) }; return(Success(response)); }
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)); }