新增获取就诊人列表-分页

This commit is contained in:
wucongxing 2023-09-18 16:48:22 +08:00
parent 913e1647fb
commit 9d21730305
12 changed files with 389 additions and 54 deletions

View File

@ -45,6 +45,7 @@ type order struct {
// 患者管理
type userPatientManage struct {
UserPatient // 患者列表
PatientFamily // 家庭成员管理
}
// 病例管理

View File

@ -0,0 +1,81 @@
package controller
import (
"github.com/gin-gonic/gin"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/requests"
"hospital-admin-api/api/responses"
"hospital-admin-api/api/responses/patientFamilyResponse"
"hospital-admin-api/api/service"
"hospital-admin-api/global"
"hospital-admin-api/utils"
"strconv"
)
type PatientFamily struct{}
// GetPatientFamilyPage 获取就诊人列表-分页
func (r *PatientFamily) GetPatientFamilyPage(c *gin.Context) {
req := requests.PatientFamilyRequest{}
if err := c.ShouldBind(&req.GetPatientFamilyPage); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req.GetPatientFamilyPage); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
if req.GetPatientFamilyPage.Page == 0 {
req.GetPatientFamilyPage.Page = 1
}
if req.GetPatientFamilyPage.PageSize == 0 {
req.GetPatientFamilyPage.PageSize = 20
}
patientFamilyDao := dao.PatientFamilyDao{}
patientFamily, total, err := patientFamilyDao.GetPatientFamilyPageSearch(req.GetPatientFamilyPage, req.GetPatientFamilyPage.Page, req.GetPatientFamilyPage.PageSize)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
GetPatientFamilyPage := patientFamilyResponse.GetPatientFamilyPageResponse(patientFamily)
result := make(map[string]interface{})
result["page"] = req.GetPatientFamilyPage.Page
result["page_size"] = req.GetPatientFamilyPage.PageSize
result["total"] = total
result["data"] = GetPatientFamilyPage
responses.OkWithData(result, c)
}
// GetUserPatient 患者详情
func (r *PatientFamily) GetUserPatient(c *gin.Context) {
id := c.Param("patient_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
patientId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 业务处理
userPatientService := service.UserPatientService{}
getUserPatientResponses, err := userPatientService.GetUserPatient(patientId)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.OkWithData(getUserPatientResponses, c)
}

View File

@ -80,3 +80,41 @@ func (r *UserPatient) GetUserPatient(c *gin.Context) {
responses.OkWithData(getUserPatientResponses, c)
}
// PutUserDoctorStatus 修改患者状态
func (r *UserPatient) PutUserDoctorStatus(c *gin.Context) {
userPatientRequest := requests.UserPatientRequest{}
if err := c.ShouldBind(&userPatientRequest.PutUserDoctorStatus); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(userPatientRequest.PutUserDoctorStatus); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
id := c.Param("patient_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
patientId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 业务处理
userPatientService := service.UserPatientService{}
_, err = userPatientService.PutUserDoctorStatus(patientId, userPatientRequest.PutUserDoctorStatus)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.Ok(c)
}

View File

@ -3,7 +3,10 @@ package dao
import (
"gorm.io/gorm"
"hospital-admin-api/api/model"
"hospital-admin-api/api/requests"
"hospital-admin-api/global"
"strings"
"time"
)
type PatientFamilyDao struct {
@ -79,3 +82,77 @@ func (r *PatientFamilyDao) AddPatientFamilyByMap(tx *gorm.DB, data map[string]in
}
return userDoctorInfo, nil
}
// GetPatientFamilyPageSearch 获取家庭成员列表-分页
func (r *PatientFamilyDao) GetPatientFamilyPageSearch(req requests.GetPatientFamilyPage, page, pageSize int) (m []*model.PatientFamily, total int64, err error) {
var totalRecords int64
// 构建查询条件
query := global.Db.Model(&model.PatientFamily{}).Select("family_id", "patient_id", "relation", "status", "card_name", "mobile_mask", "created_at")
// 患者表
query = query.Preload("UserPatient", func(db *gorm.DB) *gorm.DB {
return db.Omit("open_id", "union_id", "wx_session_key")
})
// 状态
if req.Status != nil {
query = query.Where("status = ?", req.Status)
}
// 手机号
if req.Mobile != "" {
userSubQuery := global.Db.Model(&model.User{}).
Select("user_id").
Where("mobile = ?", req.Mobile)
userPatientSubQuery := global.Db.Model(&model.UserPatient{}).
Select("patient_id").
Where(gorm.Expr("user_id IN (?)", userSubQuery))
query = query.Where(gorm.Expr("patient_id IN (?)", userPatientSubQuery))
}
// 用户名称-用户-就诊人
if req.UserName != "" {
// 用户
patientFamilySubQuery := global.Db.Model(&model.UserPatient{}).
Select("patient_id").
Where("user_name LIKE ?", "%"+req.UserName+"%")
// 就诊人
query = query.Where("card_name LIKE ?", "%"+req.UserName+"%")
query = query.Or("patient_id IN (?)", patientFamilySubQuery).Or(query)
}
// 注册时间
if req.CreatedAt != "" {
cancelTime := strings.Split(req.CreatedAt, "&")
if len(cancelTime) == 2 {
startTime, _ := time.Parse("2006-01-02", cancelTime[0])
endTime, _ := time.Parse("2006-01-02", cancelTime[1])
if startTime == endTime {
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
}
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
}
}
// 排序
query = query.Order("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
}

View File

@ -6,6 +6,8 @@ import (
"hospital-admin-api/api/model"
"hospital-admin-api/api/requests"
"hospital-admin-api/global"
"strings"
"time"
)
type UserPatientDao struct {
@ -92,7 +94,7 @@ func (r *UserPatientDao) GetUserPatientPageSearch(req requests.GetUserPatientPag
if req.Mobile != "" {
subQuery := global.Db.Model(&model.User{}).
Select("user_id").
Where("mobile LIKE ?", "%"+req.Mobile+"%")
Where("mobile = ?", req.Mobile)
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
}
@ -115,6 +117,21 @@ func (r *UserPatientDao) GetUserPatientPageSearch(req requests.GetUserPatientPag
query = query.Where("status = ?", req.Status)
}
// 注册时间
if req.CreatedAt != "" {
cancelTime := strings.Split(req.CreatedAt, "&")
if len(cancelTime) == 2 {
startTime, _ := time.Parse("2006-01-02", cancelTime[0])
endTime, _ := time.Parse("2006-01-02", cancelTime[1])
if startTime == endTime {
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
}
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
}
}
// 排序
query = query.Order("created_at desc")

View File

@ -35,6 +35,7 @@ type PatientFamily struct {
NationName string `gorm:"column:nation_name;type:varchar(50);comment:民族名称" json:"nation_name"`
JobId int64 `gorm:"column:job_id;type:bigint(19);comment:职业" json:"job_id"`
JobName string `gorm:"column:job_name;type:varchar(50);comment:职业名称" json:"job_name"`
UserPatient *UserPatient `gorm:"foreignKey:PatientId;references:patient_id" json:"user_patient"` // 患者
Model
}

View File

@ -0,0 +1,15 @@
package requests
type PatientFamilyRequest struct {
GetPatientFamilyPage // 获取就诊人列表-分页
}
// GetPatientFamilyPage 获取就诊人列表-分页
type GetPatientFamilyPage struct {
Page int `json:"page" form:"page" label:"页码"`
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
UserName string `json:"user_name" form:"user_name" label:"用户名称"`
Status *int `json:"status" form:"status" label:"状态"` // 0:禁用 1:正常 2:删除)
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
CreatedAt string `json:"created_at" form:"created_at" label:"添加时间"` // 时间区间数组形式下标0为开始时间下标1为结束时间
}

View File

@ -2,6 +2,7 @@ package requests
type UserPatientRequest struct {
GetUserPatientPage // 获取患者列表-分页
PutUserDoctorStatus // 修改患者状态
}
// GetUserPatientPage 获取患者列表-分页
@ -11,5 +12,11 @@ type GetUserPatientPage struct {
UserName string `json:"user_name" form:"user_name" label:"用户名称"`
Status *int `json:"status" form:"status" label:"状态"` // 0:禁用 1:正常 2:删除)
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
CreatedAt string `json:"created_at" form:"created_at" label:"订单创建时间"` // 时间区间数组形式下标0为开始时间下标1为结束时间
CreatedAt string `json:"created_at" form:"created_at" label:"注册时间"` // 时间区间数组形式下标0为开始时间下标1为结束时间
}
// PutUserDoctorStatus 修改患者状态
type PutUserDoctorStatus struct {
Status int `json:"status" form:"status" validate:"oneof=0 1 2" label:"状态"` // 0:禁用 1:正常 2:删除)
DisableReason string `json:"disable_reason" form:"disable_reason" label:"禁用理由"`
}

View File

@ -53,6 +53,19 @@ type GetUserPatient struct {
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
}
// 获取就诊人列表-分页
type getPatientFamilyPage struct {
FamilyId string `json:"family_id"` // 主键id
PatientId string `json:"patient_id"` // 患者id
Relation *int `json:"relation"` // 与患者关系1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他)
Status *int `json:"status"` // 状态1:正常 2:删除)
CardName string `json:"card_name"` // 姓名
MobileMask string `json:"mobile_mask"` // 电话(掩码)
UserName string `json:"user_name"` // 账号名称
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
}
// GetUserPatientResponse 获取患者详情
func GetUserPatientResponse(patientFamilys []*model.PatientFamily) []*GetUserPatient {
// 处理返回值
@ -82,3 +95,31 @@ func GetUserPatientResponse(patientFamilys []*model.PatientFamily) []*GetUserPat
return items
}
// GetPatientFamilyPageResponse 获取用户列表-分页
func GetPatientFamilyPageResponse(patientFamily []*model.PatientFamily) []getPatientFamilyPage {
// 处理返回值
patientFamilyResponses := make([]getPatientFamilyPage, len(patientFamily))
if len(patientFamily) > 0 {
for i, v := range patientFamily {
// 将原始结构体转换为新结构体
// 将原始结构体转换为新结构体
patientFamilyResponse := getPatientFamilyPage{
FamilyId: fmt.Sprintf("%d", v.FamilyId),
PatientId: fmt.Sprintf("%d", v.PatientId),
Relation: &v.Relation,
Status: &v.Status,
CardName: v.CardName,
MobileMask: v.MobileMask,
UserName: v.UserPatient.UserName,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
patientFamilyResponses[i] = patientFamilyResponse
}
}
return patientFamilyResponses
}

View File

@ -422,22 +422,17 @@ func privateRouter(r *gin.Engine, api controller.Api) {
patientGroup.GET("/:patient_id", api.UserPatient.GetUserPatient)
// 修改患者状态
patientGroup.PUT("/status/:patient_id", api.UserDoctor.GetUserDoctor)
patientGroup.PUT("/status/:patient_id", api.UserPatient.PutUserDoctorStatus)
// 就诊人管理
patientFamilyGroup := doctorGroup.Group("/family")
patientFamilyGroup := patientGroup.Group("/family")
{
// 获取就诊人列表-分页
patientFamilyGroup.GET("", api.UserDoctor.GetUserDoctorPendingPage)
patientFamilyGroup.GET("", api.PatientFamily.GetPatientFamilyPage)
// 就诊人详情
patientFamilyGroup.GET("/:family_id", api.UserDoctor.GetUserDoctorPending)
// 删除就诊人
patientFamilyGroup.DELETE("/:family_id", api.UserDoctor.PutUserDoctorPending)
// 修改就诊人状态
patientFamilyGroup.DELETE("/status/:family_id", api.UserDoctor.PutUserDoctorPending)
}
}
}

View File

@ -10,7 +10,7 @@ type PatientFamilyService struct {
}
// GetPatientFamilyListByPatientId 获取患者家庭成员-患者id
func (r *PatientFamilyService) GetPatientFamilyListByPatientId(patientId int64) (u []*patientFamilyResponse.GetUserPatient, err error) {
func (r *PatientFamilyService) GetPatientFamilyListByPatientId(patientId int64) (u []*patientFamilyResponse.PatientFamily, err error) {
patientFamilyDao := dao.PatientFamilyDao{}
patientFamilys, err := patientFamilyDao.GetPatientFamilyListByPatientId(patientId)
@ -19,22 +19,39 @@ func (r *PatientFamilyService) GetPatientFamilyListByPatientId(patientId int64)
}
// 处理返回值
items := make([]*patientFamilyResponse.GetUserPatient, len(patientFamilys))
items := make([]*patientFamilyResponse.PatientFamily, len(patientFamilys))
if len(patientFamilys) > 0 {
for i, v := range patientFamilys {
// 将原始结构体转换为新结构体
item := &patientFamilyResponse.GetUserPatient{
item := &patientFamilyResponse.PatientFamily{
FamilyId: fmt.Sprintf("%d", v.FamilyId),
PatientId: fmt.Sprintf("%d", v.PatientId),
Relation: &v.Relation,
Status: &v.Status,
IsDefault: &v.IsDefault,
CardName: v.CardName,
CardNameMask: v.CardNameMask,
Mobile: v.Mobile,
MobileMask: v.MobileMask,
Type: &v.Type,
IdNumber: v.IdNumber,
IdNumberMask: v.IdNumberMask,
Sex: &v.Sex,
Age: v.Age,
ProvinceId: fmt.Sprintf("%d", v.ProvinceId),
Province: v.Province,
CityId: fmt.Sprintf("%d", v.CityId),
City: v.City,
CountyId: fmt.Sprintf("%d", v.CountyId),
County: v.County,
Height: v.Height,
Weight: v.Weight,
MaritalStatus: &v.MaritalStatus,
NationId: fmt.Sprintf("%d", v.NationId),
NationName: v.NationName,
JobId: fmt.Sprintf("%d", v.JobId),
JobName: v.JobName,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}

View File

@ -4,10 +4,12 @@ import (
"errors"
"fmt"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/requests"
"hospital-admin-api/api/responses/patientFamilyResponse"
"hospital-admin-api/api/responses/userPatientResponse"
"hospital-admin-api/api/responses/userResponse"
"hospital-admin-api/api/responses/userShipAddressResponse"
"hospital-admin-api/global"
"hospital-admin-api/utils"
)
@ -56,3 +58,46 @@ func (r *UserPatientService) GetUserPatient(patientId int64) (getUserPatientResp
return getUserPatientResponse, nil
}
// PutUserDoctorStatus 修改患者状态
func (r *UserPatientService) PutUserDoctorStatus(patientId int64, req requests.PutUserDoctorStatus) (res bool, err error) {
// 获取患者数据
userPatientDao := dao.UserPatientDao{}
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientId)
if err != nil || userPatient == nil {
return false, errors.New("患者错误")
}
if req.Status == userPatient.Status {
return true, nil
}
if req.Status == 0 {
if req.DisableReason == "" {
return false, errors.New("请填写禁用理由")
}
}
// 开始事务
tx := global.Db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
// 修改部门
data := make(map[string]interface{})
data["status"] = req.Status
data["disable_reason"] = req.DisableReason
err = userPatientDao.EditUserPatientById(tx, patientId, data)
if err != nil {
tx.Rollback()
return false, errors.New("修改失败")
}
tx.Commit()
return true, nil
}