297 lines
7.8 KiB
Go
297 lines
7.8 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"
|
|
)
|
|
|
|
// InquiryConfig 问诊配置
|
|
type InquiryConfig struct{}
|
|
|
|
// GetDoctorInquiryConfigPage 获取开启问诊配置医生列表-分页
|
|
func (r *InquiryConfig) GetDoctorInquiryConfigPage(c *gin.Context) {
|
|
req := requests.InquiryConfigRequest{}
|
|
if err := c.ShouldBind(&req.GetDoctorInquiryConfigPage); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(req.GetDoctorInquiryConfigPage); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
if req.GetDoctorInquiryConfigPage.Page == 0 {
|
|
req.GetDoctorInquiryConfigPage.Page = 1
|
|
}
|
|
|
|
if req.GetDoctorInquiryConfigPage.PageSize == 0 {
|
|
req.GetDoctorInquiryConfigPage.PageSize = 20
|
|
}
|
|
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
doctorInquiryConfig, total, err := doctorInquiryConfigDao.GetUserDoctorPageSearch(req.GetDoctorInquiryConfigPage, req.GetDoctorInquiryConfigPage.Page, req.GetDoctorInquiryConfigPage.PageSize)
|
|
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 处理返回值
|
|
res := dto.GetDoctorInquiryConfigListDto(doctorInquiryConfig)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = req.GetDoctorInquiryConfigPage.Page
|
|
result["page_size"] = req.GetDoctorInquiryConfigPage.PageSize
|
|
result["total"] = total
|
|
result["data"] = res
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetDoctorInquiryConfig 医生问诊配置详情
|
|
func (r *InquiryConfig) GetDoctorInquiryConfig(c *gin.Context) {
|
|
id := c.Param("inquiry_config_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
inquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
inquiryConfigService := service.InquiryConfigService{}
|
|
getUserDoctorResponses, err := inquiryConfigService.GetDoctorInquiryConfig(inquiryConfigId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(getUserDoctorResponses, c)
|
|
}
|
|
|
|
// PutDoctorInquiryConfig 修改医生问诊配置
|
|
func (r *InquiryConfig) PutDoctorInquiryConfig(c *gin.Context) {
|
|
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
|
req := inquiryConfigRequest.PutDoctorInquiryConfig
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(req); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
id := c.Param("inquiry_config_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
inquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
if req.InquiryMode == 6 {
|
|
responses.FailWithMessage("疑难问诊暂不可使用", c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
doctorInquiryConfigService := service.DoctorInquiryConfigService{}
|
|
_, err = doctorInquiryConfigService.PutDoctorInquiryConfig(inquiryConfigId, req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// AddDoctorInquiryConfig 新增医生问诊配置
|
|
func (r *InquiryConfig) AddDoctorInquiryConfig(c *gin.Context) {
|
|
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
|
req := inquiryConfigRequest.AddDoctorInquiryConfig
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(req); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
doctorInquiryConfigService := service.DoctorInquiryConfigService{}
|
|
_, err := doctorInquiryConfigService.AddDoctorInquiryConfig(req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// GetSystemInquiryConfigPage 获取系统问诊配置列表-分页
|
|
func (r *InquiryConfig) GetSystemInquiryConfigPage(c *gin.Context) {
|
|
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
|
req := inquiryConfigRequest.GetSystemInquiryConfigPage
|
|
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
|
|
}
|
|
|
|
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
|
systemInquiryConfig, total, err := systemInquiryConfigDao.GetSystemInquiryConfigPageSearch(req, req.Page, req.PageSize)
|
|
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 处理返回值
|
|
res := dto.GetSystemInquiryConfigListDto(systemInquiryConfig)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = req.Page
|
|
result["page_size"] = req.PageSize
|
|
result["total"] = total
|
|
result["data"] = res
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetSystemInquiryConfig 系统问诊配置详情-id
|
|
func (r *InquiryConfig) GetSystemInquiryConfig(c *gin.Context) {
|
|
id := c.Param("system_inquiry_config_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
systemInquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 获取数据
|
|
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
|
systemInquiryConfig, err := systemInquiryConfigDao.GetSystemInquiryConfigById(systemInquiryConfigId)
|
|
if err != nil || systemInquiryConfig == nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 获取系统问诊时间
|
|
systemInquiryTimeDao := dao.SystemInquiryTimeDao{}
|
|
systemInquiryTimes, err := systemInquiryTimeDao.GetSystemInquiryTimeListBySystemInquiryConfigId(systemInquiryConfigId)
|
|
|
|
// 处理返回值
|
|
res := dto.GetSystemInquiryConfigDto(systemInquiryConfig)
|
|
|
|
// 加载系统问诊时间
|
|
res.LoadSystemInquiryTime(systemInquiryTimes)
|
|
|
|
responses.OkWithData(res, c)
|
|
}
|
|
|
|
// PutSystemInquiryConfig 修改系统问诊配置
|
|
func (r *InquiryConfig) PutSystemInquiryConfig(c *gin.Context) {
|
|
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
|
req := inquiryConfigRequest.PutSystemInquiryConfig
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(req); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
id := c.Param("system_inquiry_config_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
systemInquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
systemInquiryConfigService := service.SystemInquiryConfigService{}
|
|
_, err = systemInquiryConfigService.PutSystemInquiryConfig(systemInquiryConfigId, req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// GetSystemInquiryConfigDetail 系统问诊配置详情-条件
|
|
func (r *InquiryConfig) GetSystemInquiryConfigDetail(c *gin.Context) {
|
|
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
|
req := inquiryConfigRequest.GetSystemInquiryConfigDetail
|
|
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
|
|
}
|
|
|
|
// 业务处理
|
|
systemInquiryConfigService := service.SystemInquiryConfigService{}
|
|
res, err := systemInquiryConfigService.GetSystemInquiryConfigDetail(req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(res, c)
|
|
}
|