package model import ( "time" "gorm.io/datatypes" ) // ScriptPackage is the scenario-level script package. It replaces the legacy // knowledge graph for the consultation scenario. A package owns dimensions, // dimension values, stages, scripts, options, linkages and entry adapters. type ScriptPackage struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` ScenarioID uint64 `json:"scenario_id" gorm:"not null;uniqueIndex"` Name string `json:"name" gorm:"size:128;not null"` Status string `json:"status" gorm:"size:24;not null"` StartStageKey string `json:"start_stage_key" gorm:"size:64;not null"` CreatedBy uint64 `json:"created_by" gorm:"not null"` } // PackageDimension is a quantifiable dimension (symptom, disease, plan, ...). type PackageDimension struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` DimKey string `json:"dim_key" gorm:"size:64;not null"` Name string `json:"name" gorm:"size:128;not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // DimensionValue is one value of a dimension and carries a runtime weight. type DimensionValue struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` DimensionID uint64 `json:"dimension_id" gorm:"not null;index"` ValueKey string `json:"value_key" gorm:"size:64;not null"` Name string `json:"name" gorm:"size:128;not null"` InitialWeight int `json:"initial_weight" gorm:"not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // PackageStage is a SOP stage inside a script package. Each stage has a primary // dimension that drives script matching. type PackageStage struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` StageKey string `json:"stage_key" gorm:"size:64;not null"` Name string `json:"name" gorm:"size:128;not null"` Purpose string `json:"purpose" gorm:"type:text;not null"` PrimaryDimensionID uint64 `json:"primary_dimension_id" gorm:"not null;index"` SortOrder int `json:"sort_order" gorm:"not null"` } // StageScript is a script shown inside a stage. ScriptType is one of // confirm / info / choice / template / fallback / message. Products is the // static product list attached to recommendation scripts. Multiple marks a // choice script whose options can be selected together. type StageScript struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` StageID uint64 `json:"stage_id" gorm:"not null;index"` ScriptKey string `json:"script_key" gorm:"size:64;not null"` Name string `json:"name" gorm:"size:128;not null"` ScriptType string `json:"script_type" gorm:"size:32;not null"` Content string `json:"content" gorm:"type:text;not null"` DimensionValueID *uint64 `json:"dimension_value_id" gorm:"index"` ShowThreshold int `json:"show_threshold" gorm:"not null"` ConfirmThreshold int `json:"confirm_threshold" gorm:"not null"` CollectFieldKey string `json:"collect_field_key" gorm:"size:64;not null"` Required bool `json:"required" gorm:"not null"` Multiple bool `json:"multiple" gorm:"not null"` Products datatypes.JSON `json:"products" gorm:"type:json;not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // ScriptOption is one answer option of a script. Effect is set/add/subtract/zero // and targets a dimension value. type ScriptOption struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` ScriptID uint64 `json:"script_id" gorm:"not null;index"` OptionKey string `json:"option_key" gorm:"size:64;not null"` Label string `json:"label" gorm:"size:128;not null"` TargetDimensionValueID *uint64 `json:"target_dimension_value_id" gorm:"index"` Effect string `json:"effect" gorm:"size:16;not null"` EffectValue int `json:"effect_value" gorm:"not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // DimensionLinkage propagates a confirmed source dimension value weight into // a target dimension value (for example symptom -> disease). A source counts // as confirmed only when its weight reaches ActivationThreshold (engine // default 5 when the value is zero). type DimensionLinkage struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` FromDimensionValueID uint64 `json:"from_dimension_value_id" gorm:"not null;index"` ToDimensionValueID uint64 `json:"to_dimension_value_id" gorm:"not null;index"` RelationType string `json:"relation_type" gorm:"size:64;not null"` Contribution int `json:"contribution" gorm:"not null"` ActivationThreshold int `json:"activation_threshold" gorm:"not null"` Condition datatypes.JSON `json:"condition" gorm:"type:json;not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // PackageAdapter initializes a dimension value weight from an incoming or // derived field value (for example an order product id or symptom tag). type PackageAdapter struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` SourceField string `json:"source_field" gorm:"size:128;not null"` MatchValue string `json:"match_value" gorm:"size:191;not null"` TargetDimensionValueID uint64 `json:"target_dimension_value_id" gorm:"not null;index"` Weight int `json:"weight" gorm:"not null"` SortOrder int `json:"sort_order" gorm:"not null"` } // RunDimension is the materialized current weight of one dimension value in a // run. It is recomputed deterministically after every mutation. type RunDimension struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` RunID uint64 `json:"run_id" gorm:"not null;index"` PackageID uint64 `json:"package_id" gorm:"not null;index"` DimensionID uint64 `json:"dimension_id" gorm:"not null;index"` ValueKey string `json:"value_key" gorm:"size:64;not null"` Weight int `json:"weight" gorm:"not null"` UpdatedAt time.Time `json:"updated_at"` } // ScriptFeedback records like/report/unreasonable feedback on a script. type ScriptFeedback struct { Base TenantID uint64 `json:"tenant_id" gorm:"not null;index"` RunID uint64 `json:"run_id" gorm:"not null;index"` StageID uint64 `json:"stage_id" gorm:"not null;index"` ScriptID uint64 `json:"script_id" gorm:"not null;index"` FeedbackType string `json:"feedback_type" gorm:"size:32;not null"` OperatorID uint64 `json:"operator_id" gorm:"not null;index"` Note string `json:"note" gorm:"type:text;not null"` }