From 494c7e5aca1332831dd1b72c4480cceb3f08cebe Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 15 Nov 2023 15:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E6=96=B9-=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/export.go | 34 ++++++ api/controller/orderPrescription.go | 21 ++-- api/dao/orderPrescription.go | 170 ++++++++++++++++++++++++++++ api/dto/OrderPrescription.go | 3 +- api/requests/orderPrescription.go | 20 +++- api/router/router.go | 2 +- api/service/export.go | 143 +++++++++++++++++++++++ utils/intToString.go | 56 +++++++++ 8 files changed, 435 insertions(+), 14 deletions(-) diff --git a/api/controller/export.go b/api/controller/export.go index db681e0..df77d86 100644 --- a/api/controller/export.go +++ b/api/controller/export.go @@ -357,3 +357,37 @@ func (r *Export) OrderProduct(c *gin.Context) { responses.OkWithData(ossAddress, c) } + +// OrderPrescription 处方 +func (r *Export) OrderPrescription(c *gin.Context) { + orderPrescriptionRequest := requests.OrderPrescriptionRequest{} + req := orderPrescriptionRequest.OrderPrescriptionExportList + if err := c.ShouldBind(&req); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(req); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + // 获取数据 + orderPrescriptionDao := dao.OrderPrescriptionDao{} + orderPrescriptions, err := orderPrescriptionDao.GetOrderPrescriptionExportListSearch(req) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 业务处理 + exportService := service.ExportService{} + ossAddress, err := exportService.OrderPrescription(orderPrescriptions) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + responses.OkWithData(ossAddress, c) +} diff --git a/api/controller/orderPrescription.go b/api/controller/orderPrescription.go index 4aba9fa..4cb151b 100644 --- a/api/controller/orderPrescription.go +++ b/api/controller/orderPrescription.go @@ -16,28 +16,29 @@ type OrderPrescription struct{} // GetOrderPrescriptionPage 获取处方列表-分页 func (r *OrderPrescription) GetOrderPrescriptionPage(c *gin.Context) { - req := requests.OrderPrescriptionRequest{} - if err := c.ShouldBind(&req.GetOrderPrescriptionPage); err != nil { + orderPrescriptionRequest := requests.OrderPrescriptionRequest{} + req := orderPrescriptionRequest.GetOrderPrescriptionPage + if err := c.ShouldBind(&req); err != nil { responses.FailWithMessage(err.Error(), c) return } // 参数验证 - if err := global.Validate.Struct(req.GetOrderPrescriptionPage); err != nil { + if err := global.Validate.Struct(req); err != nil { responses.FailWithMessage(utils.Translate(err), c) return } - if req.GetOrderPrescriptionPage.Page == 0 { - req.GetOrderPrescriptionPage.Page = 1 + if req.Page == 0 { + req.Page = 1 } - if req.GetOrderPrescriptionPage.PageSize == 0 { - req.GetOrderPrescriptionPage.PageSize = 20 + if req.PageSize == 0 { + req.PageSize = 20 } orderPrescriptionDao := dao.OrderPrescriptionDao{} - orderPrescription, total, err := orderPrescriptionDao.GetOrderPrescriptionPageSearch(req.GetOrderPrescriptionPage, req.GetOrderPrescriptionPage.Page, req.GetOrderPrescriptionPage.PageSize) + orderPrescription, total, err := orderPrescriptionDao.GetOrderPrescriptionPageSearch(req, req.Page, req.PageSize) if err != nil { responses.FailWithMessage(err.Error(), c) return @@ -47,8 +48,8 @@ func (r *OrderPrescription) GetOrderPrescriptionPage(c *gin.Context) { GetOrderPrescriptionPage := dto.GetOrderPrescriptionListDto(orderPrescription) result := make(map[string]interface{}) - result["page"] = req.GetOrderPrescriptionPage.Page - result["page_size"] = req.GetOrderPrescriptionPage.PageSize + result["page"] = req.Page + result["page_size"] = req.PageSize result["total"] = total result["data"] = GetOrderPrescriptionPage responses.OkWithData(result, c) diff --git a/api/dao/orderPrescription.go b/api/dao/orderPrescription.go index 6354444..601ae84 100644 --- a/api/dao/orderPrescription.go +++ b/api/dao/orderPrescription.go @@ -1,6 +1,7 @@ package dao import ( + "errors" "gorm.io/gorm" "hospital-admin-api/api/model" "hospital-admin-api/api/requests" @@ -231,3 +232,172 @@ func (r *OrderPrescriptionDao) GetOrderPrescriptionPageSearch(req requests.GetOr return m, totalRecords, nil } + +// GetOrderPrescriptionExportListSearch 获取处方列表-导出 +func (r *OrderPrescriptionDao) GetOrderPrescriptionExportListSearch(req requests.OrderPrescriptionExportList) (m []*model.OrderPrescription, err error) { + // 构建查询条件 + query := global.Db.Model(&model.OrderPrescription{}) + + // 患者表 + query = query.Preload("UserPatient", func(db *gorm.DB) *gorm.DB { + return db.Omit("open_id", "union_id", "wx_session_key") + }) + + // 用户表 + query = query.Preload("UserPatient.User", func(db *gorm.DB) *gorm.DB { + return db.Omit("user_password", "salt") + }) + + // 医生表 + query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB { + return db.Omit("open_id", "union_id", "wx_session_key") + }) + + // 药师表 + query = query.Preload("UserPharmacist", func(db *gorm.DB) *gorm.DB { + return db.Omit("open_id", "union_id", "wx_session_key") + }) + + // 处方关联疾病表 + query = query.Preload("OrderPrescriptionIcd") + + // 患者家庭成员表 + query = query.Preload("PatientFamily") + + // 当前搜索数据 + if req.Type == 1 { + // 处方编号 + if req.PrescriptionCode != "" { + query = query.Where("prescription_code = ?", req.PrescriptionCode) + } + + // 医生名称 + if req.DoctorName != "" { + query = query.Where("doctor_name LIKE ?", "%"+req.DoctorName+"%") + } + + // 患者姓名-就诊人 + if req.PatientName != "" { + query = query.Where("patient_name LIKE ?", "%"+req.PatientName+"%") + } + + // 手机号-医生/患者/就诊人 + if req.Mobile != "" { + // 就诊人 + patientFamilySubQuery := global.Db.Model(&model.PatientFamily{}). + Select("family_id"). + Where("mobile = ?", req.Mobile) + + // 患者 + patientUserSubQuery := global.Db.Model(&model.User{}). + Select("user_id"). + Where("mobile = ?", req.Mobile) + + patientSubQuery := global.Db.Model(&model.UserPatient{}). + Select("patient_id"). + Where(gorm.Expr("user_id IN (?)", patientUserSubQuery)) + + // 医生 + doctorUserSubQuery := global.Db.Model(&model.User{}). + Select("user_id"). + Where("mobile = ?", req.Mobile) + + doctorSubQuery := global.Db.Model(&model.UserDoctor{}). + Select("doctor_id"). + Where(gorm.Expr("user_id IN (?)", doctorUserSubQuery)) + + query = query.Where("patient_id IN (?)", patientSubQuery).Or("doctor_id IN (?)", doctorSubQuery).Or("family_id IN (?)", patientFamilySubQuery) + } + + // 处方状态 + if req.PrescriptionStatus != nil { + query = query.Where("prescription_status = ?", req.PrescriptionStatus) + } + + // 药师审核状态 + if req.PharmacistAuditStatus != nil { + query = query.Where("pharmacist_audit_status = ?", req.PharmacistAuditStatus) + } + + // 问诊订单编号 + if req.InquiryNo != "" { + subQuery := global.Db.Model(&model.OrderInquiry{}). + Select("order_inquiry_id"). + Where("inquiry_no = ?", req.InquiryNo) + query = query.Where("order_inquiry_id IN (?)", subQuery) + } + + // 药品订单编号 + if req.OrderProductNo != "" { + subQuery := global.Db.Model(&model.OrderInquiry{}). + Select("order_prescription_id"). + Where("order_product_no = ?", req.OrderProductNo) + query = query.Where("order_prescription_id IN (?)", subQuery) + } + + // 药师审核时间 + if req.PharmacistVerifyTime != "" { + pharmacistVerifyTime := strings.Split(req.PharmacistVerifyTime, "&") + if len(pharmacistVerifyTime) == 2 { + startTime, _ := time.Parse("2006-01-02", pharmacistVerifyTime[0]) + endTime, _ := time.Parse("2006-01-02", pharmacistVerifyTime[1]) + + if startTime == endTime { + endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second) + } + + query = query.Where("pharmacist_verify_time BETWEEN ? AND ?", startTime, endTime) + } + } + + // 医生开具处方时间 + if req.DoctorCreatedTime != "" { + doctorCreatedTime := strings.Split(req.DoctorCreatedTime, "&") + if len(doctorCreatedTime) == 2 { + startTime, _ := time.Parse("2006-01-02", doctorCreatedTime[0]) + endTime, _ := time.Parse("2006-01-02", doctorCreatedTime[1]) + + if startTime == endTime { + endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second) + } + + query = query.Where("doctor_created_time BETWEEN ? AND ?", startTime, endTime) + } + } + + // 处方过期时间 + if req.ExpiredTime != "" { + expiredTime := strings.Split(req.ExpiredTime, "&") + if len(expiredTime) == 2 { + startTime, _ := time.Parse("2006-01-02", expiredTime[0]) + endTime, _ := time.Parse("2006-01-02", expiredTime[1]) + + if startTime == endTime { + endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second) + } + + query = query.Where("expired_time BETWEEN ? AND ?", startTime, endTime) + } + } + } + + // 当前选中数据 + if req.Type == 2 { + if req.Id == "" { + return nil, errors.New("未提供需导出数据编号") + } + + id := strings.Split(req.Id, ",") + query = query.Where("order_prescription_id IN (?)", id) + } + + // 排序 + query = query.Order("created_at desc") + + err = query.Find(&m).Error + if err != nil { + return nil, err + } + + return m, nil +} diff --git a/api/dto/OrderPrescription.go b/api/dto/OrderPrescription.go index 42b957f..d707913 100644 --- a/api/dto/OrderPrescription.go +++ b/api/dto/OrderPrescription.go @@ -25,7 +25,6 @@ type OrderPrescriptionDto struct { IsAutoPharVerify int `json:"is_auto_phar_verify"` // 是否药师自动审核(0:否 1:是) DoctorCreatedTime model.LocalTime `json:"doctor_created_time"` // 医生开具处方时间 ExpiredTime model.LocalTime `json:"expired_time"` // 处方过期时间 - VoidTime model.LocalTime `json:"void_time"` // 处方作废时间 IsDelete int `json:"is_delete"` // 是否删除(0:否 1:是) PrescriptionCode string `json:"prescription_code"` // 处方编号 DoctorName string `json:"doctor_name"` // 医生名称 @@ -168,7 +167,7 @@ func (r *OrderPrescriptionDto) LoadPatientMobileMask(m *model.User) *OrderPrescr // LoadOrderPrescriptionIcdString 加载处方诊断疾病-字符串 func (r *OrderPrescriptionDto) LoadOrderPrescriptionIcdString(m []*model.OrderPrescriptionIcd) *OrderPrescriptionDto { - if m != nil { + if len(m) > 0 { var orderPrescriptionIcd []string for _, icd := range m { orderPrescriptionIcd = append(orderPrescriptionIcd, icd.IcdName) diff --git a/api/requests/orderPrescription.go b/api/requests/orderPrescription.go index bcc47ba..4028618 100644 --- a/api/requests/orderPrescription.go +++ b/api/requests/orderPrescription.go @@ -1,7 +1,8 @@ package requests type OrderPrescriptionRequest struct { - GetOrderPrescriptionPage // 获取处方列表-分页 + GetOrderPrescriptionPage // 获取处方列表-分页 + OrderPrescriptionExportList // 处方-导出 } // GetOrderPrescriptionPage 获取处方列表-分页 @@ -20,3 +21,20 @@ type GetOrderPrescriptionPage struct { InquiryNo string `json:"inquiry_no" form:"inquiry_no" label:"问诊订单编号"` OrderProductNo string `json:"order_product_no" form:"order_product_no" label:"药品订单编号"` } + +// OrderPrescriptionExportList 处方-导出 +type OrderPrescriptionExportList struct { + Type int `json:"type" form:"type" label:"类型" validate:"required,oneof=1 2 3"` // 1:当前搜索数据 2:当前选择数据 3:全部数据 + Id string `json:"id" form:"id" label:"id"` // 选择数据的id,逗号分隔,当type为2时必填 + PrescriptionCode string `json:"prescription_code" form:"prescription_code" label:"处方编号"` + DoctorName string `json:"doctor_name" form:"doctor_name" label:"医生名称"` + PatientName string `json:"patient_name" form:"patient_name" label:"患者姓名-就诊人"` + Mobile string `json:"mobile" form:"mobile" label:"手机号-医生/患者/就诊人"` + PrescriptionStatus *int `json:"prescription_status" form:"prescription_status" label:"处方状态"` // (1:待审核 2:待使用 3:已失效 4:已使用) + PharmacistAuditStatus *int `json:"pharmacist_audit_status" form:"pharmacist_audit_status" label:"药师审核状态"` // (0:审核中 1:审核成功 2:审核驳回) + PharmacistVerifyTime string `json:"pharmacist_verify_time" form:"pharmacist_verify_time" label:"药师审核时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间 + DoctorCreatedTime string `json:"doctor_created_time" form:"doctor_created_time" label:"医生开具处方时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间 + ExpiredTime string `json:"expired_time" form:"expired_time" label:"处方过期时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间 + InquiryNo string `json:"inquiry_no" form:"inquiry_no" label:"问诊订单编号"` + OrderProductNo string `json:"order_product_no" form:"order_product_no" label:"药品订单编号"` +} diff --git a/api/router/router.go b/api/router/router.go index d19ef6d..7914f7b 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -645,7 +645,7 @@ func privateRouter(r *gin.Engine, api controller.Api) { prescriptionGroup := exportGroup.Group("/prescription") { // 处方 - prescriptionGroup.POST("", api.UserCaCert.RenewUserCloudCert) + prescriptionGroup.POST("", api.Export.OrderPrescription) } } } diff --git a/api/service/export.go b/api/service/export.go index 0eb1d8d..2c3e577 100644 --- a/api/service/export.go +++ b/api/service/export.go @@ -279,6 +279,31 @@ type OrderProductData struct { CreatedAt time.Time // 创建时间 } +// OrderPrescriptionData 处方 +type OrderPrescriptionData struct { + DoctorName string // 医生姓名 + PharmacistName string // 药师姓名 + PrescriptionStatus string // 处方状态(1:待审核 2:待使用 3:已失效 4:已使用) + PharmacistAuditStatus string // 药师审核状态(0:审核中 1:审核成功 2:审核驳回) + PharmacistVerifyTime time.Time // 药师审核时间 + PharmacistFailReason string // 药师审核驳回原因 + PlatformAuditStatus string // 处方平台审核状态(0:审核中 1:审核成功 2:审核驳回) + PlatformFailTime time.Time // 平台审核失败时间 + PlatformFailReason string // 处方平台驳回原因 + IsAutoPharVerify string // 是否药师自动审核(0:否 1:是) + DoctorCreatedTime time.Time // 医生开具处方时间 + ExpiredTime time.Time // 处方过期时间 + IsDelete string // 是否删除(0:否 1:是) + PrescriptionCode string // 处方编号 + PatientName string // 患者姓名-就诊人 + PatientSex string // 患者性别-就诊人(1:男 2:女) + PatientAge string // 患者年龄-就诊人 + PatientMobile string // 患者电话 + DoctorAdvice string // 医嘱 + OrderPrescriptionIcd string // 处方诊断疾病 + CreatedAt time.Time // 创建时间 +} + // DoctorWithdrawal 提现记录 func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) { header := []utils.HeaderCellData{ @@ -1556,3 +1581,121 @@ func (r *ExportService) OrderProduct(d []*model.OrderProduct) (string, error) { ossPath = utils.AddOssDomain("/" + ossPath) return ossPath, nil } + +// OrderPrescription 处方 +func (r *ExportService) OrderPrescription(d []*model.OrderPrescription) (string, error) { + header := []utils.HeaderCellData{ + {Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "药师姓名", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "处方状态", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "药师审核状态", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "药师审核时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + {Value: "药师审核驳回原因", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "处方平台审核状态", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "平台审核失败时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + {Value: "处方平台驳回原因", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "是否药师自动审核", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "医生开具处方时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + {Value: "处方过期时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + {Value: "是否删除", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "处方编号", CellType: "string", NumberFmt: "", ColWidth: 28}, + {Value: "患者姓名-就诊人", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "患者性别-就诊人", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "患者年龄-就诊人", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "患者电话", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "医嘱", CellType: "string", NumberFmt: "", ColWidth: 30}, + {Value: "处方诊断疾病", CellType: "string", NumberFmt: "", ColWidth: 30}, + {Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + } + + var dataSlice []interface{} + for _, v := range d { + data := OrderPrescriptionData{ + PrescriptionStatus: utils.PrescriptionStatusToString(v.PrescriptionStatus), + PharmacistAuditStatus: utils.PharmacistAuditStatusToString(v.PharmacistAuditStatus), + PharmacistFailReason: v.PharmacistFailReason, + PlatformAuditStatus: utils.PlatformAuditStatusToString(v.PlatformAuditStatus), + PlatformFailReason: v.PlatformFailReason, + IsAutoPharVerify: utils.IsAutoPharVerifyToString(v.IsAutoPharVerify), + IsDelete: utils.IsDeleteToString(v.IsDelete), + PrescriptionCode: v.PrescriptionCode, + PatientName: v.PatientName, + PatientSex: utils.SexToString(v.PatientSex), + PatientAge: fmt.Sprintf("%d", v.PatientAge), + DoctorAdvice: v.DoctorAdvice, + } + + if v.UserDoctor != nil { + // 医生姓名 + data.DoctorName = v.UserDoctor.UserName + } + + if v.UserPharmacist != nil { + // 医生姓名 + data.PharmacistName = v.UserPharmacist.UserName + } + + if v.UserPatient != nil { + if v.UserPatient.User != nil { + data.PatientMobile = v.UserPatient.User.Mobile + } + } + + // 处方诊断疾病 + if len(v.OrderPrescriptionIcd) > 0 { + var orderPrescriptionIcd []string + for _, icd := range v.OrderPrescriptionIcd { + orderPrescriptionIcd = append(orderPrescriptionIcd, icd.IcdName) + } + + data.OrderPrescriptionIcd = strings.Join(orderPrescriptionIcd, "、") + } + + if v.PharmacistVerifyTime != (model.LocalTime{}) { + t := time.Time(v.PharmacistVerifyTime) + data.PharmacistVerifyTime = t + } + + if v.PlatformFailTime != (model.LocalTime{}) { + t := time.Time(v.PlatformFailTime) + data.PlatformFailTime = t + } + + if v.DoctorCreatedTime != (model.LocalTime{}) { + t := time.Time(v.DoctorCreatedTime) + data.DoctorCreatedTime = t + } + + if v.ExpiredTime != (model.LocalTime{}) { + t := time.Time(v.ExpiredTime) + data.ExpiredTime = t + } + + if v.CreatedAt != (model.LocalTime{}) { + t := time.Time(v.CreatedAt) + data.CreatedAt = t + } + + dataSlice = append(dataSlice, data) + } + + file, err := utils.Export(header, dataSlice) + if err != nil { + return "", err + } + + // 设置文件名字 + now := time.Now() + dateTimeString := now.Format("20060102150405") // 当前时间字符串 + rand.Seed(time.Now().UnixNano()) // 设置随机数 + ossPath := "admin/export/output" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".xlsx" + + // 上传oss + _, err = aliyun.PutObjectByte(ossPath, file.Bytes()) + if err != nil { + return "", err + } + + ossPath = utils.AddOssDomain("/" + ossPath) + return ossPath, nil +} diff --git a/utils/intToString.go b/utils/intToString.go index ef3c8b5..26f2a11 100644 --- a/utils/intToString.go +++ b/utils/intToString.go @@ -509,3 +509,59 @@ func ReportPreStatusToString(i int) string { return "" } } + +// PrescriptionStatusToString 处方状态(1:待审核 2:待使用 3:已失效 4:已使用) +func PrescriptionStatusToString(i int) string { + switch i { + case 1: + return "待审核" + case 2: + return "待使用" + case 3: + return "已失效" + case 4: + return "已使用" + default: + return "" + } +} + +// PharmacistAuditStatusToString 药师审核状态(0:审核中 1:审核成功 2:审核驳回) +func PharmacistAuditStatusToString(i int) string { + switch i { + case 0: + return "审核中" + case 1: + return "审核成功" + case 2: + return "审核驳回" + default: + return "" + } +} + +// PlatformAuditStatusToString 处方平台审核状态(0:审核中 1:审核成功 2:审核驳回) +func PlatformAuditStatusToString(i int) string { + switch i { + case 0: + return "审核中" + case 1: + return "审核成功" + case 2: + return "审核驳回" + default: + return "" + } +} + +// IsAutoPharVerifyToString 是否药师自动审核(0:否 1:是) +func IsAutoPharVerifyToString(i int) string { + switch i { + case 0: + return "否" + case 1: + return "是" + default: + return "" + } +}