82 lines
2.1 KiB
Go
82 lines
2.1 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 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 := dto.GetPatientFamilyListDto(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)
|
|
}
|
|
|
|
// GetPatientFamily 就诊人详情
|
|
func (r *PatientFamily) GetPatientFamily(c *gin.Context) {
|
|
id := c.Param("family_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
familyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
patientFamilyService := service.PatientFamilyService{}
|
|
getPatientFamilyResponse, err := patientFamilyService.GetPatientFamily(familyId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(getPatientFamilyResponse, c)
|
|
}
|