53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
package model
|
||
|
||
import (
|
||
"encoding/json"
|
||
"time"
|
||
)
|
||
|
||
// Consultation 专家会诊单
|
||
type Consultation struct {
|
||
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
|
||
RoomID *string `gorm:"column:room_id;type:uuid;index" json:"roomId,omitempty"`
|
||
BatchID *string `gorm:"column:batch_id;type:uuid;index" json:"batchId,omitempty"`
|
||
LampTestID *string `gorm:"column:lamp_test_id;type:uuid;index" json:"lampTestId,omitempty"`
|
||
Title string `gorm:"size:128" json:"title"`
|
||
Summary *string `gorm:"type:text" json:"summary,omitempty"`
|
||
Snapshot json.RawMessage `gorm:"type:jsonb" json:"snapshot,omitempty"`
|
||
Status string `gorm:"size:16;default:pending" json:"status"` // pending/consulting/resolved/archived
|
||
ExpertID *string `gorm:"column:expert_id;type:uuid" json:"expertId,omitempty"`
|
||
Opinion *string `gorm:"type:text" json:"opinion,omitempty"`
|
||
Plan *string `gorm:"type:text" json:"plan,omitempty"`
|
||
ResolvedAt *time.Time `gorm:"column:resolved_at;type:timestamptz" json:"resolvedAt,omitempty"`
|
||
ArchivedAt *time.Time `gorm:"column:archived_at;type:timestamptz" json:"archivedAt,omitempty"`
|
||
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
|
||
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
|
||
RoomName *string `gorm:"-" json:"roomName,omitempty"`
|
||
}
|
||
|
||
func (Consultation) TableName() string { return "consultations" }
|
||
|
||
// ValidConsultationTransition 状态流转规则:pending→consulting/resolved;consulting→resolved;resolved→archived
|
||
func ValidConsultationTransition(from, to string) bool {
|
||
switch from {
|
||
case "pending":
|
||
return to == "consulting" || to == "resolved"
|
||
case "consulting":
|
||
return to == "resolved"
|
||
case "resolved":
|
||
return to == "archived"
|
||
default:
|
||
return false
|
||
}
|
||
}
|
||
|
||
// ConsultationSnapshot 病例快照(会诊时打包,避免引用数据变化)
|
||
type ConsultationSnapshot struct {
|
||
RoomName string `json:"roomName,omitempty"`
|
||
LampTest *LampTest `json:"lampTest,omitempty"`
|
||
Inspection *InspectionRecord `json:"inspection,omitempty"`
|
||
Batch *Batch `json:"batch,omitempty"`
|
||
WeatherAlerts []WeatherAlert `json:"weatherAlerts,omitempty"`
|
||
CreatedAt time.Time `json:"createdAt"`
|
||
}
|