修正返回目录,新增处方详情。删除原response目录
This commit is contained in:
@@ -2,58 +2,16 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/responses/orderPrescriptionIcdResponse"
|
||||
"hospital-admin-api/api/responses/orderPrescriptionProductResponse"
|
||||
"hospital-admin-api/api/responses/orderPrescriptionResponse"
|
||||
"hospital-admin-api/api/dto"
|
||||
)
|
||||
|
||||
// OrderPrescriptionService 处方
|
||||
type OrderPrescriptionService struct {
|
||||
}
|
||||
|
||||
// GetOrderPrescriptionById 获取处方数据
|
||||
func (r *OrderPrescriptionService) GetOrderPrescriptionById(OrderPrescriptionId int64) (u *orderPrescriptionResponse.OrderPrescription, err error) {
|
||||
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||||
orderPrescription, err := orderPrescriptionDao.GetById(OrderPrescriptionId)
|
||||
if orderPrescription == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
u = &orderPrescriptionResponse.OrderPrescription{
|
||||
OrderPrescriptionId: fmt.Sprintf("%d", orderPrescription.OrderPrescriptionId),
|
||||
OrderInquiryId: fmt.Sprintf("%d", orderPrescription.OrderInquiryId),
|
||||
DoctorId: fmt.Sprintf("%d", orderPrescription.DoctorId),
|
||||
PatientId: fmt.Sprintf("%d", orderPrescription.PatientId),
|
||||
FamilyId: fmt.Sprintf("%d", orderPrescription.FamilyId),
|
||||
PharmacistId: fmt.Sprintf("%d", orderPrescription.PharmacistId),
|
||||
PrescriptionStatus: orderPrescription.PrescriptionStatus,
|
||||
PharmacistAuditStatus: orderPrescription.PharmacistAuditStatus,
|
||||
PharmacistVerifyTime: orderPrescription.PharmacistVerifyTime,
|
||||
PharmacistFailReason: orderPrescription.PharmacistFailReason,
|
||||
PlatformAuditStatus: orderPrescription.PlatformAuditStatus,
|
||||
PlatformFailTime: orderPrescription.PlatformFailTime,
|
||||
PlatformFailReason: orderPrescription.PlatformFailReason,
|
||||
IsAutoPharVerify: orderPrescription.IsAutoPharVerify,
|
||||
DoctorCreatedTime: orderPrescription.DoctorCreatedTime,
|
||||
ExpiredTime: orderPrescription.ExpiredTime,
|
||||
IsDelete: orderPrescription.IsDelete,
|
||||
PrescriptionCode: orderPrescription.PrescriptionCode,
|
||||
DoctorName: orderPrescription.DoctorName,
|
||||
PatientName: orderPrescription.PatientName,
|
||||
PatientSex: orderPrescription.PatientSex,
|
||||
PatientAge: orderPrescription.PatientAge,
|
||||
DoctorAdvice: orderPrescription.DoctorAdvice,
|
||||
CreatedAt: orderPrescription.CreatedAt,
|
||||
UpdatedAt: orderPrescription.UpdatedAt,
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
// GetOrderPrescription 处方详情
|
||||
func (r *OrderPrescriptionService) GetOrderPrescription(OrderPrescriptionId int64) (getOrderPrescriptionResponse *orderPrescriptionResponse.GetOrderPrescription, err error) {
|
||||
func (r *OrderPrescriptionService) GetOrderPrescription(OrderPrescriptionId int64) (g *dto.OrderPrescriptionDto, err error) {
|
||||
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||||
orderPrescription, err := orderPrescriptionDao.GetById(OrderPrescriptionId)
|
||||
if orderPrescription == nil {
|
||||
@@ -61,114 +19,57 @@ func (r *OrderPrescriptionService) GetOrderPrescription(OrderPrescriptionId int6
|
||||
}
|
||||
|
||||
// 获取处方关联疾病数据
|
||||
orderPrescriptionIcds, err := r.GetOrderPrescriptionIcdByOrderPrescriptionId(OrderPrescriptionId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
fmt.Println(orderPrescriptionIcds)
|
||||
// 获取问诊病例
|
||||
orderInquiryService := OrderInquiryService{}
|
||||
orderInquiryCase, err := orderInquiryService.GetOrderInquiryCaseByOrderInquiryId(orderPrescription.OrderInquiryId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
fmt.Println(orderInquiryCase)
|
||||
|
||||
// 获取处方关联问诊数据
|
||||
orderInquiry, err := orderInquiryService.GetOrderInquiryById(orderPrescription.OrderInquiryId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
fmt.Println(orderInquiry)
|
||||
|
||||
// 获取处方商品数据
|
||||
orderPrescriptionProducts, err := r.GetOrderPrescriptionProductByOrderPrescriptionId(OrderPrescriptionId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
fmt.Println(orderPrescriptionProducts)
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorService := UserDoctorService{}
|
||||
userDoctor, err := userDoctorService.GetUserDoctorById(orderPrescription.DoctorId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
fmt.Println(userDoctor)
|
||||
|
||||
// 获取药师数据
|
||||
|
||||
result := &orderPrescriptionResponse.GetOrderPrescription{
|
||||
|
||||
CreatedAt: model.LocalTime{},
|
||||
UpdatedAt: model.LocalTime{},
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetOrderPrescriptionIcdByOrderPrescriptionId 获取处方关联疾病数据-处方id
|
||||
func (r *OrderPrescriptionService) GetOrderPrescriptionIcdByOrderPrescriptionId(OrderPrescriptionId int64) (res *orderPrescriptionIcdResponse.OrderPrescriptionIcd, err error) {
|
||||
orderPrescriptionIcdDao := dao.OrderPrescriptionIcdDao{}
|
||||
orderPrescriptionIcd, err := orderPrescriptionIcdDao.GetOrderPrescriptionIcdById(OrderPrescriptionId)
|
||||
if orderPrescriptionIcd == nil {
|
||||
orderPrescriptionIcds, err := orderPrescriptionIcdDao.GetOrderPrescriptionIcdListByOrderPrescriptionId(OrderPrescriptionId)
|
||||
if len(orderPrescriptionIcds) <= 0 {
|
||||
return nil, errors.New("处方病例错误")
|
||||
}
|
||||
|
||||
result := &orderPrescriptionIcdResponse.OrderPrescriptionIcd{
|
||||
PrescriptionIcdId: fmt.Sprintf("%d", orderPrescriptionIcd.PrescriptionIcdId),
|
||||
OrderPrescriptionId: fmt.Sprintf("%d", orderPrescriptionIcd.OrderPrescriptionId),
|
||||
IcdId: fmt.Sprintf("%d", orderPrescriptionIcd.IcdId),
|
||||
IcdName: orderPrescriptionIcd.IcdName,
|
||||
IcdCode: orderPrescriptionIcd.IcdCode,
|
||||
CreatedAt: orderPrescriptionIcd.CreatedAt,
|
||||
UpdatedAt: orderPrescriptionIcd.UpdatedAt,
|
||||
// 获取问诊病例
|
||||
orderInquiryCaseDao := dao.OrderInquiryCaseDao{}
|
||||
orderInquiryCase, err := orderInquiryCaseDao.GetOrderInquiryCaseByOrderInquiryId(orderPrescription.OrderInquiryId)
|
||||
if orderInquiryCase == nil {
|
||||
return nil, errors.New("数据错误,无问诊病例")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetOrderPrescriptionProductByOrderPrescriptionId 获取处方关联商品数据-处方id
|
||||
func (r *OrderPrescriptionService) GetOrderPrescriptionProductByOrderPrescriptionId(orderPrescriptionId int64) (res []*orderPrescriptionProductResponse.OrderPrescriptionProduct, err error) {
|
||||
// 获取处方商品数据
|
||||
orderPrescriptionProductDao := dao.OrderPrescriptionProductDao{}
|
||||
orderPrescriptionProducts, err := orderPrescriptionProductDao.GetOrderPrescriptionProductListByOrderPrescriptionId(orderPrescriptionId)
|
||||
orderPrescriptionProducts, err := orderPrescriptionProductDao.GetOrderPrescriptionProductListByOrderPrescriptionId(OrderPrescriptionId)
|
||||
if err != nil {
|
||||
return nil, errors.New("数据错误,无处方药品数据")
|
||||
}
|
||||
|
||||
if len(orderPrescriptionProducts) == 0 {
|
||||
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("药师数据错误")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
items := make([]*orderPrescriptionProductResponse.OrderPrescriptionProduct, len(orderPrescriptionProducts))
|
||||
g = dto.GetOrderPrescriptionDto(orderPrescription)
|
||||
|
||||
if len(orderPrescriptionProducts) > 0 {
|
||||
for i, v := range orderPrescriptionProducts {
|
||||
// 将原始结构体转换为新结构体
|
||||
item := &orderPrescriptionProductResponse.OrderPrescriptionProduct{
|
||||
PrescriptionProductId: fmt.Sprintf("%d", v.OrderPrescriptionId),
|
||||
OrderPrescriptionId: fmt.Sprintf("%d", v.OrderPrescriptionId),
|
||||
ProductId: fmt.Sprintf("%d", v.ProductId),
|
||||
UseStatus: v.UseStatus,
|
||||
PrescriptionProductNum: v.PrescriptionProductNum,
|
||||
ProductName: v.ProductName,
|
||||
ProductSpec: v.ProductSpec,
|
||||
LicenseNumber: v.LicenseNumber,
|
||||
Manufacturer: v.Manufacturer,
|
||||
SingleUnit: v.SingleUnit,
|
||||
SingleUse: v.SingleUse,
|
||||
PackagingUnit: v.PackagingUnit,
|
||||
FrequencyUse: v.FrequencyUse,
|
||||
AvailableDays: v.AvailableDays,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
// 加载问诊病例
|
||||
g.LoadOrderInquiryCase(orderInquiryCase)
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
items[i] = item
|
||||
}
|
||||
}
|
||||
return items, nil
|
||||
// 加载处方关联疾病-字符串
|
||||
g.LoadOrderPrescriptionIcdString(orderPrescriptionIcds)
|
||||
|
||||
// 加载医生名称
|
||||
g.LoadDoctorName(userDoctor)
|
||||
|
||||
// 加载药师名称
|
||||
g.LoadPharmacisName(userPharmacist)
|
||||
|
||||
// 加载处方商品数据
|
||||
g.LoadOrderPrescriptionProduct(orderPrescriptionProducts)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user