121 lines
3.2 KiB
Go
121 lines
3.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/api/responses"
|
|
"hospital-admin-api/api/service"
|
|
"hospital-admin-api/global"
|
|
"hospital-admin-api/utils"
|
|
"strconv"
|
|
)
|
|
|
|
type UserPatient struct{}
|
|
|
|
// GetUserPatientPage 获取患者列表-分页
|
|
func (r *UserPatient) GetUserPatientPage(c *gin.Context) {
|
|
userPatientRequest := requests.UserPatientRequest{}
|
|
if err := c.ShouldBind(&userPatientRequest.GetUserPatientPage); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(userPatientRequest.GetUserPatientPage); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
if userPatientRequest.GetUserPatientPage.Page == 0 {
|
|
userPatientRequest.GetUserPatientPage.Page = 1
|
|
}
|
|
|
|
if userPatientRequest.GetUserPatientPage.PageSize == 0 {
|
|
userPatientRequest.GetUserPatientPage.PageSize = 20
|
|
}
|
|
|
|
userPatientDao := dao.UserPatientDao{}
|
|
userPatient, total, err := userPatientDao.GetUserPatientPageSearch(userPatientRequest.GetUserPatientPage, userPatientRequest.GetUserPatientPage.Page, userPatientRequest.GetUserPatientPage.PageSize)
|
|
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 处理返回值
|
|
getUserDoctorPageResponses := dto.GetUserPatientListDto(userPatient)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = userPatientRequest.GetUserPatientPage.Page
|
|
result["page_size"] = userPatientRequest.GetUserPatientPage.PageSize
|
|
result["total"] = total
|
|
result["data"] = getUserDoctorPageResponses
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetUserPatient 患者详情
|
|
func (r *UserPatient) 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)
|
|
}
|
|
|
|
// 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)
|
|
}
|