package service import ( "errors" "hospital-admin-api/api/dao" "hospital-admin-api/api/dto" ) // OrderPrescriptionService 处方 type OrderPrescriptionService struct { } // GetOrderPrescription 处方详情 func (r *OrderPrescriptionService) GetOrderPrescription(OrderPrescriptionId int64) (g *dto.OrderPrescriptionDto, err error) { orderPrescriptionDao := dao.OrderPrescriptionDao{} orderPrescription, err := orderPrescriptionDao.GetById(OrderPrescriptionId) if orderPrescription == nil { return nil, errors.New("处方错误") } // 获取处方关联疾病数据 orderPrescriptionIcdDao := dao.OrderPrescriptionIcdDao{} orderPrescriptionIcds, err := orderPrescriptionIcdDao.GetOrderPrescriptionIcdListByOrderPrescriptionId(OrderPrescriptionId) if len(orderPrescriptionIcds) <= 0 { return nil, errors.New("处方病例错误") } // 获取问诊病例 orderInquiryCaseDao := dao.OrderInquiryCaseDao{} orderInquiryCase, err := orderInquiryCaseDao.GetOrderInquiryCaseByOrderInquiryId(orderPrescription.OrderInquiryId) if orderInquiryCase == nil { return nil, errors.New("数据错误,无问诊病例") } // 获取处方商品数据 orderPrescriptionProductDao := dao.OrderPrescriptionProductDao{} orderPrescriptionProducts, err := orderPrescriptionProductDao.GetOrderPrescriptionProductListByOrderPrescriptionId(OrderPrescriptionId) if err != nil { return nil, errors.New("数据错误,无处方药品数据") } // 获取医生数据 userDoctorDao := dao.UserDoctorDao{} userDoctor, err := userDoctorDao.GetUserDoctorById(orderPrescription.DoctorId) if err != nil || userDoctor == nil { return nil, errors.New("医生数据错误") } // 获取药师数据 userPharmacistDao := dao.UserPharmacistDao{} userPharmacist, err := userPharmacistDao.GetUserPharmacistById(orderPrescription.PharmacistId) if err != nil || userPharmacist == nil { return nil, errors.New("药师数据错误") } // 处理返回值 g = dto.GetOrderPrescriptionDto(orderPrescription) // 加载问诊病例 g.LoadOrderInquiryCase(orderInquiryCase) // 加载处方关联疾病-字符串 g.LoadOrderPrescriptionIcdString(orderPrescriptionIcds) // 加载医生名称 g.LoadDoctorName(userDoctor) // 加载药师名称 g.LoadPharmacisName(userPharmacist) // 加载处方商品数据 g.LoadOrderPrescriptionProduct(orderPrescriptionProducts) return g, nil }