新增了用户病例处理
This commit is contained in:
parent
bc13339355
commit
702e482659
@ -7,6 +7,7 @@ type Api struct {
|
|||||||
BaseClass // 分类
|
BaseClass // 分类
|
||||||
Question // 问题
|
Question // 问题
|
||||||
User // 用户
|
User // 用户
|
||||||
|
UserCase // 用户病例
|
||||||
UserCoupon // 用户优惠卷
|
UserCoupon // 用户优惠卷
|
||||||
UserCollection // 用户收藏
|
UserCollection // 用户收藏
|
||||||
OrderSingle // 订单-单项
|
OrderSingle // 订单-单项
|
||||||
|
|||||||
@ -86,63 +86,6 @@ func (r *User) PutUser(c *gin.Context) {
|
|||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutBindUserName 绑定用户数据-昵称
|
|
||||||
func (r *User) PutBindUserName(c *gin.Context) {
|
|
||||||
userRequest := requests.UserRequest{}
|
|
||||||
req := userRequest.PutBindUserName
|
|
||||||
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.Nickname == "" {
|
|
||||||
responses.FailWithMessage("参数错误", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userId := c.GetInt64("UserId")
|
|
||||||
|
|
||||||
// 获取用户数据
|
|
||||||
userDao := dao.UserDao{}
|
|
||||||
user, err := userDao.GetUserById(userId)
|
|
||||||
if err != nil {
|
|
||||||
responses.FailWithMessage("用户数据错误", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.UserName != "" {
|
|
||||||
responses.Ok(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userData := make(map[string]interface{})
|
|
||||||
userData["user_name"] = req.Nickname
|
|
||||||
|
|
||||||
// 开始事务
|
|
||||||
tx := global.Db.Begin()
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
err = userDao.EditUserById(tx, user.UserId, userData)
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.Commit()
|
|
||||||
responses.Ok(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUserCheck 检测用户数据绑定状态
|
// GetUserCheck 检测用户数据绑定状态
|
||||||
func (r *User) GetUserCheck(c *gin.Context) {
|
func (r *User) GetUserCheck(c *gin.Context) {
|
||||||
userRequest := requests.UserRequest{}
|
userRequest := requests.UserRequest{}
|
||||||
|
|||||||
229
api/controller/UserCase.go
Normal file
229
api/controller/UserCase.go
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"hepa-calc-api/api/dao"
|
||||||
|
"hepa-calc-api/api/dto"
|
||||||
|
"hepa-calc-api/api/model"
|
||||||
|
"hepa-calc-api/api/requests"
|
||||||
|
"hepa-calc-api/api/responses"
|
||||||
|
"hepa-calc-api/extend/app"
|
||||||
|
"hepa-calc-api/global"
|
||||||
|
"hepa-calc-api/utils"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserCase struct{}
|
||||||
|
|
||||||
|
// GetUserCase 获取用户数据-病例
|
||||||
|
func (r *UserCase) GetUserCase(c *gin.Context) {
|
||||||
|
userId := c.GetInt64("UserId")
|
||||||
|
|
||||||
|
// 获取用户数据-病例
|
||||||
|
userCaseDao := dao.UserCaseDao{}
|
||||||
|
userCase, err := userCaseDao.GetUserCaseByUserId(userId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("用户数据错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取疾病列表
|
||||||
|
userCaseDiseaseItemDao := dao.UserCaseDiseaseItemDao{}
|
||||||
|
userCaseDiseaseItems, err := userCaseDiseaseItemDao.GetUserCaseDiseaseItemListPreloadByUserCaseId(userCase.UserCaseId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("用户数据错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回数据
|
||||||
|
g := dto.GetUserCaseDto(userCase)
|
||||||
|
|
||||||
|
// 加载数据-疾病列表
|
||||||
|
g.LoadUserCaseDiseaseItem(userCaseDiseaseItems)
|
||||||
|
|
||||||
|
responses.OkWithData(g, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutUserCase 修改用户数据-病例
|
||||||
|
func (r *UserCase) PutUserCase(c *gin.Context) {
|
||||||
|
userCaseRequest := requests.UserCaseRequest{}
|
||||||
|
req := userCaseRequest.PutUserCase
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
userId := c.GetInt64("UserId")
|
||||||
|
|
||||||
|
// 获取用户数据
|
||||||
|
userDao := dao.UserDao{}
|
||||||
|
user, err := userDao.GetUserById(userId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("用户数据错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户数据-病例
|
||||||
|
userCaseDao := dao.UserCaseDao{}
|
||||||
|
userCase, err := userCaseDao.GetUserCaseByUserId(userId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("用户数据错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userCaseData := make(map[string]interface{})
|
||||||
|
appData := app.UpdateUserCaseRequest{
|
||||||
|
IsAllergy: req.IsAllergyHistory,
|
||||||
|
AllergyInfo: req.AllergyHistory,
|
||||||
|
IsHospital: req.IsHospital,
|
||||||
|
IsMedication: req.IsMedication,
|
||||||
|
MedicationInfo: req.Medication,
|
||||||
|
LiverStatus: req.LiverStatus,
|
||||||
|
OtherDisease: req.ChronicDisease,
|
||||||
|
PatientUuid: user.AppIden,
|
||||||
|
DiseasesList: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否医院就诊
|
||||||
|
if req.IsHospital != nil {
|
||||||
|
userCaseData["is_hospital"] = *req.IsHospital
|
||||||
|
} else {
|
||||||
|
userCaseData["is_hospital"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 肝脏状态
|
||||||
|
userCaseData["liver_status"] = req.LiverStatus
|
||||||
|
|
||||||
|
// 是否服药
|
||||||
|
if req.IsMedication != nil {
|
||||||
|
userCaseData["is_medication"] = *req.IsMedication
|
||||||
|
|
||||||
|
// 服药名称
|
||||||
|
if *req.IsMedication == 1 {
|
||||||
|
if req.Medication == "" {
|
||||||
|
responses.FailWithMessage("请填写正在服用药品名称", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userCaseData["medication"] = req.Medication
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userCaseData["is_medication"] = nil
|
||||||
|
userCaseData["medication"] = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// 慢性疾病名称(逗号分隔)
|
||||||
|
userCaseData["chronic_disease"] = req.ChronicDisease
|
||||||
|
|
||||||
|
// 过敏史
|
||||||
|
if req.IsAllergyHistory != nil {
|
||||||
|
userCaseData["is_allergy_history"] = *req.IsAllergyHistory
|
||||||
|
|
||||||
|
// 过敏史描述
|
||||||
|
if *req.IsAllergyHistory == 1 {
|
||||||
|
if req.AllergyHistory == "" {
|
||||||
|
responses.FailWithMessage("请填写过敏史描述", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userCaseData["allergy_history"] = req.AllergyHistory
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userCaseData["is_allergy_history"] = nil
|
||||||
|
userCaseData["allergy_history"] = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 删除疾病列表
|
||||||
|
userCaseDiseaseItemDao := dao.UserCaseDiseaseItemDao{}
|
||||||
|
err = userCaseDiseaseItemDao.DeleteUserCaseDiseaseItemByUserCaseIdId(tx, userCase.UserCaseId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("操作失败", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所患疾病列表
|
||||||
|
if len(req.UserCaseDiseaseItem) > 0 {
|
||||||
|
baseDiseaseClassDao := dao.BaseDiseaseClassDao{}
|
||||||
|
diseasesLists := make([]*app.DiseasesListRequest, len(req.UserCaseDiseaseItem))
|
||||||
|
|
||||||
|
for i, item := range req.UserCaseDiseaseItem {
|
||||||
|
diseaseClassId, err := strconv.ParseInt(item.DiseaseClassId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取疾病分类数据
|
||||||
|
baseDiseaseClass, err := baseDiseaseClassDao.GetBaseDiseaseClassById(diseaseClassId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userCaseDiseaseItem := &model.UserCaseDiseaseItem{
|
||||||
|
UserCaseId: userCase.UserCaseId,
|
||||||
|
DiseaseClassId: diseaseClassId,
|
||||||
|
AppIden: baseDiseaseClass.AppIden,
|
||||||
|
Duration: &item.Duration,
|
||||||
|
Genotype: item.Genotype,
|
||||||
|
}
|
||||||
|
|
||||||
|
userCaseDiseaseItem, err = userCaseDiseaseItemDao.AddUserCaseDiseaseItem(tx, userCaseDiseaseItem)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// app请求数据
|
||||||
|
diseasesList := &app.DiseasesListRequest{
|
||||||
|
Uuid: baseDiseaseClass.AppIden,
|
||||||
|
Year: &item.Duration,
|
||||||
|
Info: "",
|
||||||
|
Name: baseDiseaseClass.DiseaseClassName,
|
||||||
|
}
|
||||||
|
diseasesLists[i] = diseasesList
|
||||||
|
}
|
||||||
|
|
||||||
|
appData.DiseasesList = diseasesLists
|
||||||
|
}
|
||||||
|
|
||||||
|
// 病例数据
|
||||||
|
if len(userCaseData) > 0 {
|
||||||
|
err := userCaseDao.EditUserCaseById(tx, userCase.UserCaseId, userCaseData)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// app数据
|
||||||
|
appData.PatientUuid = user.AppIden
|
||||||
|
_, err = app.UpdateUserCase(appData)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
@ -37,6 +37,15 @@ func (r *UserCaseDao) GetUserCaseByUserId(userId int64) (m *model.UserCase, err
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserCasePreloadByUserId 获取数据-user_id
|
||||||
|
func (r *UserCaseDao) GetUserCasePreloadByUserId(userId int64) (m *model.UserCase, err error) {
|
||||||
|
err = global.Db.Preload(clause.Associations).Where("user_id = ?", userId).First(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteUserCase 删除
|
// DeleteUserCase 删除
|
||||||
func (r *UserCaseDao) DeleteUserCase(tx *gorm.DB, maps interface{}) error {
|
func (r *UserCaseDao) DeleteUserCase(tx *gorm.DB, maps interface{}) error {
|
||||||
err := tx.Where(maps).Delete(&model.UserCase{}).Error
|
err := tx.Where(maps).Delete(&model.UserCase{}).Error
|
||||||
|
|||||||
@ -37,6 +37,15 @@ func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemByUserCaseId(userCaseId i
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserCaseDiseaseItemListPreloadByUserCaseId 获取数据-user_case_id
|
||||||
|
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemListPreloadByUserCaseId(userCaseId int64) (m []*model.UserCaseDiseaseItem, err error) {
|
||||||
|
err = global.Db.Preload(clause.Associations).Where("user_case_id = ?", userCaseId).Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteUserCaseDiseaseItem 删除
|
// DeleteUserCaseDiseaseItem 删除
|
||||||
func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItem(tx *gorm.DB, maps interface{}) error {
|
func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItem(tx *gorm.DB, maps interface{}) error {
|
||||||
err := tx.Where(maps).Delete(&model.UserCaseDiseaseItem{}).Error
|
err := tx.Where(maps).Delete(&model.UserCaseDiseaseItem{}).Error
|
||||||
@ -54,6 +63,14 @@ func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItemById(tx *gorm.DB, User
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteUserCaseDiseaseItemByUserCaseIdId 删除-id
|
||||||
|
func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItemByUserCaseIdId(tx *gorm.DB, userCaseId int64) error {
|
||||||
|
if err := tx.Where("user_case_id = ?", userCaseId).Delete(&model.UserCaseDiseaseItem{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// EditUserCaseDiseaseItem 修改
|
// EditUserCaseDiseaseItem 修改
|
||||||
func (r *UserCaseDiseaseItemDao) EditUserCaseDiseaseItem(tx *gorm.DB, maps interface{}, data interface{}) error {
|
func (r *UserCaseDiseaseItemDao) EditUserCaseDiseaseItem(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||||
err := tx.Model(&model.UserCaseDiseaseItem{}).Where(maps).Updates(data).Error
|
err := tx.Model(&model.UserCaseDiseaseItem{}).Where(maps).Updates(data).Error
|
||||||
|
|||||||
48
api/dto/UserCase.go
Normal file
48
api/dto/UserCase.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"hepa-calc-api/api/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserCaseDto 用户表-病例
|
||||||
|
type UserCaseDto struct {
|
||||||
|
UserCaseId string `json:"user_case_id"` // 主键id
|
||||||
|
UserId string `json:"user_id"` // 用户id
|
||||||
|
IsHospital *int `json:"is_hospital"` // 是否医院就诊(0:否 1:是)
|
||||||
|
LiverStatus string `json:"liver_status"` // 肝脏状态
|
||||||
|
IsMedication *int `json:"is_medication"` // 是否服药(0:否 1:是)
|
||||||
|
Medication string `json:"medication"` // 服药名称
|
||||||
|
ChronicDisease string `json:"chronic_disease"` // 慢性疾病名称(逗号分隔)
|
||||||
|
IsAllergyHistory *int `json:"is_allergy_history"` // 过敏史(0:否 1:是)
|
||||||
|
AllergyHistory string `json:"allergy_history"` // 过敏史描述
|
||||||
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||||
|
UserCaseDiseaseItem []*UserCaseDiseaseItemDto `json:"user_case_disease_item"` // 所患疾病列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserCaseDto 详情
|
||||||
|
func GetUserCaseDto(m *model.UserCase) *UserCaseDto {
|
||||||
|
return &UserCaseDto{
|
||||||
|
UserCaseId: fmt.Sprintf("%d", m.UserCaseId),
|
||||||
|
UserId: fmt.Sprintf("%d", m.UserId),
|
||||||
|
IsHospital: m.IsHospital,
|
||||||
|
LiverStatus: m.LiverStatus,
|
||||||
|
IsMedication: m.IsMedication,
|
||||||
|
Medication: m.Medication,
|
||||||
|
ChronicDisease: m.ChronicDisease,
|
||||||
|
IsAllergyHistory: m.IsAllergyHistory,
|
||||||
|
AllergyHistory: m.AllergyHistory,
|
||||||
|
CreatedAt: m.CreatedAt,
|
||||||
|
UpdatedAt: m.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadUserCaseDiseaseItem 加载数据-疾病列表
|
||||||
|
func (r *UserCaseDto) LoadUserCaseDiseaseItem(m []*model.UserCaseDiseaseItem) *UserCaseDto {
|
||||||
|
if len(m) > 0 {
|
||||||
|
r.UserCaseDiseaseItem = GetUserCaseDiseaseItemListDto(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
59
api/dto/UserCaseDiseaseItem.go
Normal file
59
api/dto/UserCaseDiseaseItem.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"hepa-calc-api/api/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserCaseDiseaseItemDto 用户-病例-所患疾病列表
|
||||||
|
type UserCaseDiseaseItemDto struct {
|
||||||
|
ItemId string `json:"item_id"` // 主键id
|
||||||
|
UserCaseId string `json:"user_case_id"` // 用户病例id
|
||||||
|
DiseaseClassId string `json:"disease_class_id"` // 疾病分类id
|
||||||
|
DiseaseClassName string `json:"disease_class_name"` // 疾病分类名称
|
||||||
|
AppIden string `json:"app_iden"` // app唯一标识
|
||||||
|
Duration *int `json:"duration"` // 患病时长(年)
|
||||||
|
Genotype string `json:"genotype"` // 基因型(仅丙肝存在)
|
||||||
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserCaseDiseaseItemListDto 列表-分页
|
||||||
|
func GetUserCaseDiseaseItemListDto(m []*model.UserCaseDiseaseItem) []*UserCaseDiseaseItemDto {
|
||||||
|
// 处理返回值
|
||||||
|
responses := make([]*UserCaseDiseaseItemDto, len(m))
|
||||||
|
|
||||||
|
if len(m) > 0 {
|
||||||
|
for i, v := range m {
|
||||||
|
response := &UserCaseDiseaseItemDto{
|
||||||
|
ItemId: fmt.Sprintf("%d", v.ItemId),
|
||||||
|
UserCaseId: fmt.Sprintf("%d", v.UserCaseId),
|
||||||
|
DiseaseClassId: fmt.Sprintf("%d", v.DiseaseClassId),
|
||||||
|
AppIden: v.AppIden,
|
||||||
|
Duration: v.Duration,
|
||||||
|
Genotype: v.Genotype,
|
||||||
|
CreatedAt: v.CreatedAt,
|
||||||
|
UpdatedAt: v.UpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载数据-疾病名称
|
||||||
|
if v.BaseDiseaseClass != nil {
|
||||||
|
response = response.LoadDiseaseClassName(v.BaseDiseaseClass)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将转换后的结构体添加到新切片中
|
||||||
|
responses[i] = response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return responses
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadDiseaseClassName 加载数据-疾病名称
|
||||||
|
func (r *UserCaseDiseaseItemDto) LoadDiseaseClassName(m *model.BaseDiseaseClass) *UserCaseDiseaseItemDto {
|
||||||
|
if m != nil {
|
||||||
|
r.DiseaseClassName = m.DiseaseClassName
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@ type UserCase struct {
|
|||||||
IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:过敏史(0:否 1:是)" json:"is_allergy_history"`
|
IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:过敏史(0:否 1:是)" json:"is_allergy_history"`
|
||||||
AllergyHistory string `gorm:"column:allergy_history;type:varchar(100);comment:过敏史描述" json:"allergy_history"`
|
AllergyHistory string `gorm:"column:allergy_history;type:varchar(100);comment:过敏史描述" json:"allergy_history"`
|
||||||
Model
|
Model
|
||||||
|
UserCaseDiseaseItem []*UserCaseDiseaseItem `gorm:"foreignKey:UserCaseId;references:user_case_id" json:"user_case_disease_item"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserCase) TableName() string {
|
func (m *UserCase) TableName() string {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ type UserCaseDiseaseItem struct {
|
|||||||
Duration *int `gorm:"column:duration;type:int(5);comment:患病时长(年)" json:"duration"`
|
Duration *int `gorm:"column:duration;type:int(5);comment:患病时长(年)" json:"duration"`
|
||||||
Genotype string `gorm:"column:genotype;type:varchar(20);comment:基因型(仅丙肝存在)" json:"genotype"`
|
Genotype string `gorm:"column:genotype;type:varchar(20);comment:基因型(仅丙肝存在)" json:"genotype"`
|
||||||
Model
|
Model
|
||||||
|
BaseDiseaseClass *BaseDiseaseClass `gorm:"foreignKey:DiseaseClassId;references:disease_class_id" json:"disease_class"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserCaseDiseaseItem) TableName() string {
|
func (m *UserCaseDiseaseItem) TableName() string {
|
||||||
|
|||||||
24
api/requests/UserCase.go
Normal file
24
api/requests/UserCase.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package requests
|
||||||
|
|
||||||
|
type UserCaseRequest struct {
|
||||||
|
PutUserCase // 修改用户数据-病例
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutUserCase 修改用户数据-病例
|
||||||
|
type PutUserCase struct {
|
||||||
|
IsHospital *int `json:"is_hospital" form:"is_hospital" label:"是否医院就诊"`
|
||||||
|
LiverStatus string `json:"liver_status" form:"liver_status" label:"肝脏状态"`
|
||||||
|
IsMedication *int `json:"is_medication" form:"is_medication" label:"是否服药"`
|
||||||
|
Medication string `json:"medication" form:"medication" label:"服药名称"`
|
||||||
|
ChronicDisease string `json:"chronic_disease" form:"chronic_disease" label:"慢性疾病名称(逗号分隔)"`
|
||||||
|
IsAllergyHistory *int `json:"is_allergy_history" form:"is_allergy_history" label:"过敏史"`
|
||||||
|
AllergyHistory string `json:"allergy_history" form:"allergy_history" label:"过敏史描述"`
|
||||||
|
UserCaseDiseaseItem []*PutUserCaseUserCaseDiseaseItem `json:"user_case_disease_item" form:"user_case_disease_item" label:"所患疾病列表"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutUserCaseUserCaseDiseaseItem 修改用户数据-病例-所患疾病列表
|
||||||
|
type PutUserCaseUserCaseDiseaseItem struct {
|
||||||
|
DiseaseClassId string `json:"disease_class_id" form:"disease_class_id" label:"疾病分类id" validate:"required"` // 疾病分类id
|
||||||
|
Duration int `json:"duration" form:"duration" label:"患病时长" validate:"required"` // 患病时长(年)
|
||||||
|
Genotype string `json:"genotype" form:"genotype" label:"基因型(仅丙肝存在)"` // 基因型(仅丙肝存在)
|
||||||
|
}
|
||||||
@ -184,6 +184,16 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
|
|
||||||
// 修改用户数据-基本信息
|
// 修改用户数据-基本信息
|
||||||
centerGroup.PUT("", api.User.PutUser)
|
centerGroup.PUT("", api.User.PutUser)
|
||||||
|
|
||||||
|
// 用户病例
|
||||||
|
caseGroup := centerGroup.Group("/case")
|
||||||
|
{
|
||||||
|
// 获取用户数据-病例
|
||||||
|
caseGroup.GET("", api.UserCase.GetUserCase)
|
||||||
|
|
||||||
|
// 修改用户数据-病例
|
||||||
|
caseGroup.PUT("", api.UserCase.PutUserCase)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优惠卷
|
// 优惠卷
|
||||||
|
|||||||
@ -686,6 +686,18 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error)
|
|||||||
userData["sex"] = req.Sex
|
userData["sex"] = req.Sex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 头像
|
||||||
|
if req.Avatar != "" {
|
||||||
|
avatar := utils.RemoveOssDomain(req.Avatar)
|
||||||
|
if avatar != user.Avatar {
|
||||||
|
userData["avatar"] = req.Avatar
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if user.Avatar != "" {
|
||||||
|
userData["avatar"] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 身高
|
// 身高
|
||||||
if req.Height != nil {
|
if req.Height != nil {
|
||||||
height := fmt.Sprintf("%d", *req.Height)
|
height := fmt.Sprintf("%d", *req.Height)
|
||||||
@ -693,7 +705,9 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error)
|
|||||||
userInfoData["height"] = req.Height
|
userInfoData["height"] = req.Height
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
userInfoData["height"] = nil
|
if userInfo.Height != "" {
|
||||||
|
userInfoData["height"] = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 体重
|
// 体重
|
||||||
@ -703,7 +717,9 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error)
|
|||||||
userInfoData["weight"] = req.Weight
|
userInfoData["weight"] = req.Weight
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
userInfoData["weight"] = nil
|
if userInfo.Weight != "" {
|
||||||
|
userInfoData["weight"] = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 民族id
|
// 民族id
|
||||||
|
|||||||
@ -18,6 +18,28 @@ type GetUserCaseByAppIdenRequest struct {
|
|||||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateUserCaseRequest 修改疾病信息-请求数据
|
||||||
|
type UpdateUserCaseRequest struct {
|
||||||
|
IsAllergy *int `json:"isAllergy"` // 是否过敏史 0否 1是
|
||||||
|
AllergyInfo string `json:"allergyInfo"` // 过敏史详情
|
||||||
|
IsHospital *int `json:"isHospital"` // 是否去医院 0否 1是
|
||||||
|
IsMedication *int `json:"isMedication"` // 是否服药 0否 1是
|
||||||
|
MedicationInfo string `json:"medicationInfo"` // 正在服用的药物
|
||||||
|
LiverStatus string `json:"liverStatus"` // 目前肝脏状态
|
||||||
|
OtherDisease string `json:"otherDisease"` // 合并其他慢性疾病 (多个英文逗号分隔拼接)
|
||||||
|
DiseasesList []*DiseasesListRequest `json:"diseasesList"` // 所患疾病列表
|
||||||
|
PatientUuid string `json:"patientUuid"` // 患者 uuid
|
||||||
|
Platform string `json:"platform"` // 所属平台
|
||||||
|
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DiseasesListRequest struct {
|
||||||
|
Uuid string `json:"uuid"` // 疾病 uuid
|
||||||
|
Year *int `json:"year"` // 患病时长
|
||||||
|
Info string `json:"info"` // 丙肝基因型(仅针对丙肝)
|
||||||
|
Name string `json:"name"` // 疾病名称
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserCaseByAppIdenResponse 根据app唯一标识获取用户病例信息-返回数据
|
// GetUserCaseByAppIdenResponse 根据app唯一标识获取用户病例信息-返回数据
|
||||||
type GetUserCaseByAppIdenResponse struct {
|
type GetUserCaseByAppIdenResponse struct {
|
||||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||||
@ -27,21 +49,30 @@ type GetUserCaseByAppIdenResponse struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserCaseByAppIdenData 根据app唯一标识获取用户病例信息-data详细数据
|
// UpdateUserCaseResponse 修改用户病例-返回数据
|
||||||
type GetUserCaseByAppIdenData struct {
|
type UpdateUserCaseResponse struct {
|
||||||
AllergyInfo string `json:"allergyInfo" description:"过敏史详情"`
|
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||||
DiseasesList []*DiseaseData `json:"diseasesList" description:"所患疾病列表"`
|
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||||
MedicationInfo string `json:"medicationInfo" description:"正在服用的药物"`
|
Success bool `json:"success"`
|
||||||
OtherDisease string `json:"otherDisease" description:"合并其他慢性疾病 (多个英文逗号分隔拼接)"`
|
Message string `json:"message"`
|
||||||
IsMedication *int `json:"isMedication" description:"是否服药 0否 1是"`
|
|
||||||
IsHospital *int `json:"isHospital" description:"是否去医院 0否 1是"`
|
|
||||||
IsAllergy *int `json:"isAllergy" description:"是否过敏史 0否 1是"`
|
|
||||||
LiverStatus string `json:"liverStatus" description:"目前肝脏状态"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiseaseData 所患疾病数据
|
// GetUserCaseByAppIdenData 根据app唯一标识获取用户病例信息-data详细数据
|
||||||
type DiseaseData struct {
|
type GetUserCaseByAppIdenData struct {
|
||||||
|
AllergyInfo string `json:"allergyInfo" description:"过敏史详情"`
|
||||||
|
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||||
|
DiseasesList []*DiseasesListData `json:"diseasesList" description:"所患疾病列表"`
|
||||||
|
MedicationInfo string `json:"medicationInfo" description:"正在服用的药物"`
|
||||||
|
OtherDisease string `json:"otherDisease" description:"合并其他慢性疾病 (多个英文逗号分隔拼接)"`
|
||||||
|
IsMedication *int `json:"isMedication" description:"是否服药 0否 1是"`
|
||||||
|
IsHospital *int `json:"isHospital" description:"是否去医院 0否 1是"`
|
||||||
|
IsAllergy *int `json:"isAllergy" description:"是否过敏史 0否 1是"`
|
||||||
|
LiverStatus string `json:"liverStatus" description:"目前肝脏状态"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DiseasesListData 根据app唯一标识获取用户病例信息-data详细数据-所患疾病数据
|
||||||
|
type DiseasesListData struct {
|
||||||
UUID string `json:"uuid" description:"疾病 uuid"`
|
UUID string `json:"uuid" description:"疾病 uuid"`
|
||||||
Year *int `json:"year" description:"患病时长"`
|
Year *int `json:"year" description:"患病时长"`
|
||||||
Info string `json:"info" description:"丙肝基因型(仅针对丙肝)"`
|
Info string `json:"info" description:"丙肝基因型(仅针对丙肝)"`
|
||||||
@ -130,3 +161,82 @@ func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err
|
|||||||
|
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateUserCase 修改用户病例
|
||||||
|
func UpdateUserCase(reqData UpdateUserCaseRequest) (g *UpdateUserCaseResponse, err error) {
|
||||||
|
reqData.Platform = platform
|
||||||
|
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
|
|
||||||
|
// 将 JSON 数据编码为字节数组
|
||||||
|
jsonData, err := json.Marshal(reqData)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
err = json.Unmarshal(jsonData, &maps)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取请求签名
|
||||||
|
sign, err := GenSignature(maps)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 准备请求体
|
||||||
|
requestBody := bytes.NewBuffer(jsonData)
|
||||||
|
|
||||||
|
// 设置请求 URL
|
||||||
|
url := apiUrl + "/patient-api/upDiseaseInfo"
|
||||||
|
|
||||||
|
// 创建 POST 请求
|
||||||
|
req, err := http.NewRequest("POST", url, requestBody)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("sign", sign)
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func(Body io.ReadCloser) {
|
||||||
|
_ = Body.Close()
|
||||||
|
}(resp.Body)
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查响应状态码
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return g, errors.New("失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(body, &g)
|
||||||
|
if err != nil {
|
||||||
|
// json解析失败
|
||||||
|
return g, err
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.LogJsonInfo("修改app数据返回", g)
|
||||||
|
|
||||||
|
if g.Code != 200 {
|
||||||
|
if g.Msg != "" {
|
||||||
|
return g, errors.New(g.Msg)
|
||||||
|
} else {
|
||||||
|
return g, errors.New("失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return g, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -48,11 +48,11 @@ type GetInfoByMobileResponse struct {
|
|||||||
|
|
||||||
// UpdateInfoResponse 修改用户信息-返回数据
|
// UpdateInfoResponse 修改用户信息-返回数据
|
||||||
type UpdateInfoResponse struct {
|
type UpdateInfoResponse struct {
|
||||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||||
Data GetInfoByMobileData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInfoByMobileData 根据手机号获取用户信息-data详细数据
|
// GetInfoByMobileData 根据手机号获取用户信息-data详细数据
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user