抄方 处方列表
This commit is contained in:
parent
0a0f85321a
commit
9ee32f80ed
@ -1,7 +1,6 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"hospital-admin-api/api/dao"
|
"hospital-admin-api/api/dao"
|
||||||
"hospital-admin-api/api/dto"
|
"hospital-admin-api/api/dto"
|
||||||
"hospital-admin-api/api/requests"
|
"hospital-admin-api/api/requests"
|
||||||
@ -10,6 +9,8 @@ import (
|
|||||||
"hospital-admin-api/global"
|
"hospital-admin-api/global"
|
||||||
"hospital-admin-api/utils"
|
"hospital-admin-api/utils"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OrderPrescription struct{}
|
type OrderPrescription struct{}
|
||||||
@ -55,6 +56,47 @@ func (r *OrderPrescription) GetOrderPrescriptionPage(c *gin.Context) {
|
|||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrderPrescriptionTransferPage 获取抄方的处方列表-分页
|
||||||
|
func (r *OrderPrescription) GetOrderPrescriptionTransferPage(c *gin.Context) {
|
||||||
|
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); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Page == 0 {
|
||||||
|
req.Page = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.PageSize == 0 {
|
||||||
|
req.PageSize = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||||||
|
orderPrescription, total, err := orderPrescriptionDao.GetOrderPrescriptionTransferPageSearch(req, req.Page, req.PageSize)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回值
|
||||||
|
GetOrderPrescriptionPage := dto.GetOrderPrescriptionListDto(orderPrescription)
|
||||||
|
|
||||||
|
result := make(map[string]interface{})
|
||||||
|
result["page"] = req.Page
|
||||||
|
result["page_size"] = req.PageSize
|
||||||
|
result["total"] = total
|
||||||
|
result["data"] = GetOrderPrescriptionPage
|
||||||
|
responses.OkWithData(result, c)
|
||||||
|
}
|
||||||
|
|
||||||
// GetOrderPrescription 处方详情
|
// GetOrderPrescription 处方详情
|
||||||
func (r *OrderPrescription) GetOrderPrescription(c *gin.Context) {
|
func (r *OrderPrescription) GetOrderPrescription(c *gin.Context) {
|
||||||
id := c.Param("order_prescription_id")
|
id := c.Param("order_prescription_id")
|
||||||
|
|||||||
@ -254,6 +254,179 @@ func (r *OrderPrescriptionDao) GetOrderPrescriptionPageSearch(req requests.GetOr
|
|||||||
return m, totalRecords, nil
|
return m, totalRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrderPrescriptionTransferPageSearch 获取抄方的处方列表-分页
|
||||||
|
func (r *OrderPrescriptionDao) GetOrderPrescriptionTransferPageSearch(req requests.GetOrderPrescriptionPage, page, pageSize int) (m []*model.OrderPrescription, total int64, err error) {
|
||||||
|
var totalRecords int64
|
||||||
|
prescriptionTable := (&model.OrderPrescription{}).TableName()
|
||||||
|
inquiryTable := (&model.OrderInquiry{}).TableName()
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
query := global.Db.Model(&model.OrderPrescription{})
|
||||||
|
|
||||||
|
// 关联问诊表,只查询TransferDoctorId不等于null的记录
|
||||||
|
query = query.Joins("INNER JOIN "+inquiryTable+" ON "+prescriptionTable+".order_inquiry_id = "+inquiryTable+".order_inquiry_id").
|
||||||
|
Where(inquiryTable+".transfer_doctor_id IS NOT NULL")
|
||||||
|
|
||||||
|
// 患者表
|
||||||
|
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("UserPharmacist", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Omit("open_id", "union_id", "wx_session_key")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 处方关联疾病表
|
||||||
|
query = query.Preload("OrderPrescriptionIcd")
|
||||||
|
|
||||||
|
// 处方关联问诊表(抄方用)
|
||||||
|
query = query.Preload("OrderInquiry", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Select("user_id", "user_name", "doctor_id")
|
||||||
|
}).Preload("TransferUserDoctor", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Select("user_id", "user_name", "doctor_id")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// 患者家庭成员表
|
||||||
|
query = query.Preload("PatientFamily")
|
||||||
|
|
||||||
|
// 处方编号
|
||||||
|
if req.PrescriptionCode != "" {
|
||||||
|
query = query.Where(prescriptionTable+".prescription_code = ?", req.PrescriptionCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 医生名称
|
||||||
|
if req.DoctorName != "" {
|
||||||
|
query = query.Where(prescriptionTable+".doctor_name LIKE ?", "%"+req.DoctorName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 患者姓名-就诊人
|
||||||
|
if req.PatientName != "" {
|
||||||
|
query = query.Where(prescriptionTable+".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(prescriptionTable+".patient_id IN (?)", patientSubQuery).Or(prescriptionTable+".doctor_id IN (?)", doctorSubQuery).Or(prescriptionTable+".family_id IN (?)", patientFamilySubQuery)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处方状态
|
||||||
|
if req.PrescriptionStatus != nil {
|
||||||
|
query = query.Where(prescriptionTable+".prescription_status = ?", req.PrescriptionStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 药师审核状态
|
||||||
|
if req.PharmacistAuditStatus != nil {
|
||||||
|
query = query.Where(prescriptionTable+".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(prescriptionTable+".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(prescriptionTable+".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(prescriptionTable+".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(prescriptionTable+".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(prescriptionTable+".expired_time BETWEEN ? AND ?", startTime, endTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
query = query.Order(prescriptionTable + ".created_at desc")
|
||||||
|
|
||||||
|
// 查询总数量
|
||||||
|
if err := query.Count(&totalRecords).Error; err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, totalRecords, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetOrderPrescriptionExportListSearch 获取处方列表-导出
|
// GetOrderPrescriptionExportListSearch 获取处方列表-导出
|
||||||
func (r *OrderPrescriptionDao) GetOrderPrescriptionExportListSearch(req requests.OrderPrescriptionExportList) (m []*model.OrderPrescription, err error) {
|
func (r *OrderPrescriptionDao) GetOrderPrescriptionExportListSearch(req requests.OrderPrescriptionExportList) (m []*model.OrderPrescription, err error) {
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
|
|||||||
@ -2,13 +2,14 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"hospital-admin-api/api/controller"
|
"hospital-admin-api/api/controller"
|
||||||
"hospital-admin-api/api/exception"
|
"hospital-admin-api/api/exception"
|
||||||
"hospital-admin-api/api/middlewares"
|
"hospital-admin-api/api/middlewares"
|
||||||
"hospital-admin-api/config"
|
"hospital-admin-api/config"
|
||||||
"hospital-admin-api/consts"
|
"hospital-admin-api/consts"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init 初始化路由
|
// Init 初始化路由
|
||||||
@ -529,6 +530,9 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 获取处方列表-分页
|
// 获取处方列表-分页
|
||||||
prescriptionGroup.GET("", api.OrderPrescription.GetOrderPrescriptionPage)
|
prescriptionGroup.GET("", api.OrderPrescription.GetOrderPrescriptionPage)
|
||||||
|
|
||||||
|
// 获取抄方的处方列表-分页
|
||||||
|
prescriptionGroup.GET("/transfer", api.OrderPrescription.GetOrderPrescriptionTransferPage)
|
||||||
|
|
||||||
// 处方详情
|
// 处方详情
|
||||||
prescriptionGroup.GET("/:order_prescription_id", api.OrderPrescription.GetOrderPrescription)
|
prescriptionGroup.GET("/:order_prescription_id", api.OrderPrescription.GetOrderPrescription)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user