diff --git a/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql b/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql index f2253a22c..a7a158d1c 100755 --- a/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql +++ b/openhis-server-new/sql/20260115_add_table_triage_queue_item.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS triage_queue_item ( patient_name VARCHAR(255), healthcare_name VARCHAR(255), practitioner_name VARCHAR(255), - status VARCHAR(50) NOT NULL, -- WAITING/CALLING/SKIPPED/COMPLETED + status INTEGER NOT NULL DEFAULT 0, -- 分诊队列状态: 0=WAITING(等待), 10=CALLING(叫号中), 20=IN_CLINIC(诊中), 30=COMPLETED(已完成), 40=SKIPPED(已跳过) queue_order INTEGER NOT NULL, create_time TIMESTAMP, update_time TIMESTAMP, diff --git a/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql b/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql new file mode 100644 index 000000000..7289a8241 --- /dev/null +++ b/openhis-server-new/sql/bug_400_fix_triage_queue_item_status_type.sql @@ -0,0 +1,30 @@ +-- Bug #400 修复:triage_queue_item.status 字段类型修正 +-- 原 DDL 将 status 定义为 VARCHAR(50),但 Java 实体 TriageQueueItem.status 为 Integer 类型, +-- 应用层使用 TriageQueueStatus 枚举值(0/10/20/30/40)写入,类型不匹配导致 MyBatis-Plus +-- 无法正确映射 status 字段,完诊时 status 更新为 30 失败。 +-- +-- 注意:必须在后端实际连接的 schema 中执行(dev=hisdev, test=histest, prd=hisprd) +-- 执行前请先确认:SET search_path TO hisdev; (或对应的 schema) + +-- 1. 先将已有的字符串值转换为对应的整数值 +-- 如果之前写入的是枚举 code(如 'waiting'、'completed'),需要先转换 +UPDATE triage_queue_item +SET status = CASE + WHEN status IN ('0', 'waiting', 'WAITING') THEN 0 + WHEN status IN ('10', 'calling', 'CALLING') THEN 10 + WHEN status IN ('20', 'in-clinic', 'IN_CLINIC', 'in-clinic') THEN 20 + WHEN status IN ('30', 'completed', 'COMPLETED') THEN 30 + WHEN status IN ('40', 'skipped', 'SKIPPED') THEN 40 + WHEN status IN ('50', 'refunded', 'REFUNDED') THEN 50 + WHEN status IN ('60', 'follow', 'FOLLOW') THEN 60 + ELSE 0 +END +WHERE status IS NOT NULL AND status !~ '^[0-9]+$'; + +-- 2. 修改字段类型为 INTEGER +ALTER TABLE triage_queue_item + ALTER COLUMN status TYPE INTEGER USING status::INTEGER; + +-- 3. 设置默认值 +ALTER TABLE triage_queue_item + ALTER COLUMN status SET DEFAULT 0;