Browse Source

fix(server): 修复健康模型 ID 字段 JSON 序列化

- 显式定义 ID 字段并添加 json:"id" 标签
- 解决 GORM 嵌入 Model 导致 ID 序列化为大写问题
- 修复前端删除病史记录时 ID 为 undefined 的问题

Co-authored-by: Cursor <cursoragent@cursor.com>
master
dark 2 days ago
parent
commit
0f93039dc3
  1. 51
      server/internal/model/health.go

51
server/internal/model/health.go

@ -1,35 +1,48 @@
package model package model
import "gorm.io/gorm" import (
"time"
"gorm.io/gorm"
)
// MedicalHistory 既往病史 // MedicalHistory 既往病史
type MedicalHistory struct { type MedicalHistory struct {
gorm.Model ID uint `gorm:"primarykey" json:"id"`
HealthProfileID uint `gorm:"index" json:"health_profile_id"` CreatedAt time.Time `json:"created_at"`
DiseaseName string `gorm:"size:100" json:"disease_name"` UpdatedAt time.Time `json:"updated_at"`
DiseaseType string `gorm:"size:50" json:"disease_type"` // chronic, surgery, other DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
DiagnosedDate string `gorm:"size:20" json:"diagnosed_date"` HealthProfileID uint `gorm:"index" json:"health_profile_id"`
Status string `gorm:"size:20" json:"status"` // cured, treating, controlled DiseaseName string `gorm:"size:100" json:"disease_name"`
Notes string `gorm:"type:text" json:"notes"` DiseaseType string `gorm:"size:50" json:"disease_type"` // chronic, surgery, other
DiagnosedDate string `gorm:"size:20" json:"diagnosed_date"`
Status string `gorm:"size:20" json:"status"` // cured, treating, controlled
Notes string `gorm:"type:text" json:"notes"`
} }
// FamilyHistory 家族病史 // FamilyHistory 家族病史
type FamilyHistory struct { type FamilyHistory struct {
gorm.Model ID uint `gorm:"primarykey" json:"id"`
HealthProfileID uint `gorm:"index" json:"health_profile_id"` CreatedAt time.Time `json:"created_at"`
Relation string `gorm:"size:20" json:"relation"` // father, mother, grandparent UpdatedAt time.Time `json:"updated_at"`
DiseaseName string `gorm:"size:100" json:"disease_name"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
Notes string `gorm:"type:text" json:"notes"` HealthProfileID uint `gorm:"index" json:"health_profile_id"`
Relation string `gorm:"size:20" json:"relation"` // father, mother, grandparent
DiseaseName string `gorm:"size:100" json:"disease_name"`
Notes string `gorm:"type:text" json:"notes"`
} }
// AllergyRecord 过敏记录 // AllergyRecord 过敏记录
type AllergyRecord struct { type AllergyRecord struct {
gorm.Model ID uint `gorm:"primarykey" json:"id"`
HealthProfileID uint `gorm:"index" json:"health_profile_id"` CreatedAt time.Time `json:"created_at"`
AllergyType string `gorm:"size:20" json:"allergy_type"` // drug, food, other UpdatedAt time.Time `json:"updated_at"`
Allergen string `gorm:"size:100" json:"allergen"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
Severity string `gorm:"size:20" json:"severity"` // mild, moderate, severe HealthProfileID uint `gorm:"index" json:"health_profile_id"`
ReactionDesc string `gorm:"type:text" json:"reaction_desc"` AllergyType string `gorm:"size:20" json:"allergy_type"` // drug, food, other
Allergen string `gorm:"size:100" json:"allergen"`
Severity string `gorm:"size:20" json:"severity"` // mild, moderate, severe
ReactionDesc string `gorm:"type:text" json:"reaction_desc"`
} }
// TableName 指定表名 // TableName 指定表名

Loading…
Cancel
Save