60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
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
|
|
}
|