From dae6c14ae4f0eb5e47040e6dd484e26973244956 Mon Sep 17 00:00:00 2001 From: chenqi Date: Mon, 22 Jun 2026 09:54:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E6=89=B9=E9=87=8F=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=84=9A=E6=9C=AC=20-=20V85/V87/V91/V99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - V85: 添加DO块处理不存在的表 - V87: 移除MySQL COMMENT语法,添加IF NOT EXISTS - V91: 移除MySQL COMMENT语法 - V99: 移除healthlink_his schema前缀,添加ON CONFLICT --- .../db/migration/V85__insert_test_data.sql | 32 +++++++++------- .../db/migration/V87__ai_diagnosis.sql | 18 ++------- .../db/migration/V91__miniprogram_nursing.sql | 38 ------------------- .../V99__seed_mr_management_test_data.sql | 11 +++--- 4 files changed, 28 insertions(+), 71 deletions(-) diff --git a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V85__insert_test_data.sql b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V85__insert_test_data.sql index 0ad62c054..a717dff41 100644 --- a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V85__insert_test_data.sql +++ b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V85__insert_test_data.sql @@ -1,16 +1,20 @@ -- 插入测试数据供移动端使用 --- 1. 测试患者数据(假设已有基础数据,这里添加护理任务) -INSERT INTO nurse_order_execute_record (encounter_id, patient_id, order_type, order_name, execute_status, create_time) -VALUES -(1, 1, '医嘱执行', '测量体温 bid', 'PENDING', CURRENT_TIMESTAMP), -(1, 1, '医嘱执行', '测量血压 qd', 'PENDING', CURRENT_TIMESTAMP), -(1, 1, '生命体征', '录入生命体征', 'PENDING', CURRENT_TIMESTAMP), -(1, 2, '医嘱执行', '更换敷料 qd', 'PENDING', CURRENT_TIMESTAMP), -(1, 2, '护理评估', 'Braden压疮评估', 'PENDING', CURRENT_TIMESTAMP), -(2, 3, '医嘱执行', '测量血糖 tid', 'PENDING', CURRENT_TIMESTAMP), -(2, 3, '医嘱执行', '胰岛素注射', 'PENDING', CURRENT_TIMESTAMP), -(2, 4, '生命体征', '录入生命体征', 'PENDING', CURRENT_TIMESTAMP), -(2, 4, '护理评估', 'Morse跌倒评估', 'PENDING', CURRENT_TIMESTAMP), -(3, 5, '医嘱执行', '雾化吸入 bid', 'PENDING', CURRENT_TIMESTAMP) -ON CONFLICT DO NOTHING; +-- 1. 测试患者数据(仅当表存在时插入) +DO $$ BEGIN + INSERT INTO nurse_order_execute_record (encounter_id, patient_id, order_type, order_name, execute_status, create_time) + VALUES + (1, 1, '医嘱执行', '测量体温 bid', 'PENDING', CURRENT_TIMESTAMP), + (1, 1, '医嘱执行', '测量血压 qd', 'PENDING', CURRENT_TIMESTAMP), + (1, 1, '生命体征', '录入生命体征', 'PENDING', CURRENT_TIMESTAMP), + (1, 2, '医嘱执行', '更换敷料 qd', 'PENDING', CURRENT_TIMESTAMP), + (1, 2, '护理评估', 'Braden压疮评估', 'PENDING', CURRENT_TIMESTAMP), + (2, 3, '医嘱执行', '测量血糖 tid', 'PENDING', CURRENT_TIMESTAMP), + (2, 3, '医嘱执行', '胰岛素注射', 'PENDING', CURRENT_TIMESTAMP), + (2, 4, '生命体征', '录入生命体征', 'PENDING', CURRENT_TIMESTAMP), + (2, 4, '护理评估', 'Morse跌倒评估', 'PENDING', CURRENT_TIMESTAMP), + (3, 5, '医嘱执行', '雾化吸入 bid', 'PENDING', CURRENT_TIMESTAMP) + ON CONFLICT DO NOTHING; +EXCEPTION WHEN undefined_table THEN + RAISE NOTICE 'nurse_order_execute_record table does not exist, skipping insert'; +END $$; diff --git a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V87__ai_diagnosis.sql b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V87__ai_diagnosis.sql index d58771a63..5903d8c32 100644 --- a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V87__ai_diagnosis.sql +++ b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V87__ai_diagnosis.sql @@ -1,6 +1,6 @@ -- V87: AI辅助诊疗 - AI诊断建议表 -CREATE TABLE ai_diagnosis_suggestion ( +CREATE TABLE IF NOT EXISTS ai_diagnosis_suggestion ( id BIGSERIAL PRIMARY KEY, encounter_id BIGINT NOT NULL, patient_id BIGINT NOT NULL, @@ -17,16 +17,6 @@ CREATE TABLE ai_diagnosis_suggestion ( update_by VARCHAR(64) ); -COMMENT ON TABLE ai_diagnosis_suggestion IS 'AI辅助诊疗建议'; -COMMENT ON COLUMN ai_diagnosis_suggestion.id IS '建议ID'; -COMMENT ON COLUMN ai_diagnosis_suggestion.encounter_id IS '就诊ID'; -COMMENT ON COLUMN ai_diagnosis_suggestion.patient_id IS '患者ID'; -COMMENT ON COLUMN ai_diagnosis_suggestion.symptom_text IS '症状描述'; -COMMENT ON COLUMN ai_diagnosis_suggestion.diagnosis_suggestions IS '诊断建议'; -COMMENT ON COLUMN ai_diagnosis_suggestion.confidence_score IS '置信度(0-100)'; -COMMENT ON COLUMN ai_diagnosis_suggestion.suggestion_source IS '建议来源(llm/rule/manual)'; -COMMENT ON COLUMN ai_diagnosis_suggestion.accepted IS '是否采纳'; - -CREATE INDEX idx_ai_diag_encounter ON ai_diagnosis_suggestion(encounter_id); -CREATE INDEX idx_ai_diag_patient ON ai_diagnosis_suggestion(patient_id); -CREATE INDEX idx_ai_diag_source ON ai_diagnosis_suggestion(suggestion_source); +CREATE INDEX IF NOT EXISTS idx_ai_diag_encounter ON ai_diagnosis_suggestion(encounter_id); +CREATE INDEX IF NOT EXISTS idx_ai_diag_patient ON ai_diagnosis_suggestion(patient_id); +CREATE INDEX IF NOT EXISTS idx_ai_diag_source ON ai_diagnosis_suggestion(suggestion_source); diff --git a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V91__miniprogram_nursing.sql b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V91__miniprogram_nursing.sql index d9c9b2a33..382acfe67 100644 --- a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V91__miniprogram_nursing.sql +++ b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V91__miniprogram_nursing.sql @@ -15,17 +15,6 @@ CREATE TABLE IF NOT EXISTS mp_nursing_task ( create_by VARCHAR(64) ); -COMMENT ON TABLE mp_nursing_task IS '移动护理-护理任务'; -COMMENT ON COLUMN mp_nursing_task.id IS '主键ID'; -COMMENT ON COLUMN mp_nursing_task.patient_id IS '患者ID'; -COMMENT ON COLUMN mp_nursing_task.encounter_id IS '就诊ID'; -COMMENT ON COLUMN mp_nursing_task.nurse_id IS '护士ID'; -COMMENT ON COLUMN mp_nursing_task.task_type IS '任务类型'; -COMMENT ON COLUMN mp_nursing_task.task_content IS '任务内容'; -COMMENT ON COLUMN mp_nursing_task.task_status IS '任务状态: PENDING/IN_PROGRESS/COMPLETED/CANCELLED'; -COMMENT ON COLUMN mp_nursing_task.due_time IS '截止时间'; -COMMENT ON COLUMN mp_nursing_task.complete_time IS '完成时间'; - -- 移动护理小程序 - 生命体征记录表 CREATE TABLE IF NOT EXISTS mp_vital_sign_record ( id BIGSERIAL PRIMARY KEY, @@ -47,21 +36,6 @@ CREATE TABLE IF NOT EXISTS mp_vital_sign_record ( create_by VARCHAR(64) ); -COMMENT ON TABLE mp_vital_sign_record IS '移动护理-生命体征记录'; -COMMENT ON COLUMN mp_vital_sign_record.id IS '主键ID'; -COMMENT ON COLUMN mp_vital_sign_record.patient_id IS '患者ID'; -COMMENT ON COLUMN mp_vital_sign_record.encounter_id IS '就诊ID'; -COMMENT ON COLUMN mp_vital_sign_record.nurse_id IS '记录护士ID'; -COMMENT ON COLUMN mp_vital_sign_record.record_time IS '记录时间'; -COMMENT ON COLUMN mp_vital_sign_record.temperature IS '体温(℃)'; -COMMENT ON COLUMN mp_vital_sign_record.pulse IS '脉搏(次/分)'; -COMMENT ON COLUMN mp_vital_sign_record.respiration IS '呼吸(次/分)'; -COMMENT ON COLUMN mp_vital_sign_record.systolic_bp IS '收缩压(mmHg)'; -COMMENT ON COLUMN mp_vital_sign_record.diastolic_bp IS '舒张压(mmHg)'; -COMMENT ON COLUMN mp_vital_sign_record.blood_oxygen IS '血氧饱和度(%)'; -COMMENT ON COLUMN mp_vital_sign_record.height IS '身高(cm)'; -COMMENT ON COLUMN mp_vital_sign_record.weight IS '体重(kg)'; - -- 移动护理小程序 - 护理评估记录表 CREATE TABLE IF NOT EXISTS mp_assessment_record ( id BIGSERIAL PRIMARY KEY, @@ -79,15 +53,3 @@ CREATE TABLE IF NOT EXISTS mp_assessment_record ( create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, create_by VARCHAR(64) ); - -COMMENT ON TABLE mp_assessment_record IS '移动护理-护理评估记录'; -COMMENT ON COLUMN mp_assessment_record.id IS '主键ID'; -COMMENT ON COLUMN mp_assessment_record.patient_id IS '患者ID'; -COMMENT ON COLUMN mp_assessment_record.encounter_id IS '就诊ID'; -COMMENT ON COLUMN mp_assessment_record.nurse_id IS '评估护士ID'; -COMMENT ON COLUMN mp_assessment_record.assessment_type IS '评估类型'; -COMMENT ON COLUMN mp_assessment_record.assessment_content IS '评估内容'; -COMMENT ON COLUMN mp_assessment_record.assessment_result IS '评估结果'; -COMMENT ON COLUMN mp_assessment_record.score IS '评分'; -COMMENT ON COLUMN mp_assessment_record.risk_level IS '风险等级'; -COMMENT ON COLUMN mp_assessment_record.record_time IS '评估时间'; diff --git a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V99__seed_mr_management_test_data.sql b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V99__seed_mr_management_test_data.sql index ef7323bfa..cef0dd243 100644 --- a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V99__seed_mr_management_test_data.sql +++ b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V99__seed_mr_management_test_data.sql @@ -2,7 +2,7 @@ -- 生成时间: 2026-06-19 -- ==================== 1. mr_borrowing 病案借阅 ==================== -INSERT INTO healthlink_his.mr_borrowing (id, medical_record_id, patient_name, mr_number, borrower_name, borrower_dept, borrow_reason, borrow_date, expected_return_date, actual_return_date, status, approver_name, approve_time, tenant_id, delete_flag, create_by, create_time) +INSERT INTO mr_borrowing (id, medical_record_id, patient_name, mr_number, borrower_name, borrower_dept, borrow_reason, borrow_date, expected_return_date, actual_return_date, status, approver_name, approve_time, tenant_id, delete_flag, create_by, create_time) VALUES -- 待审批(0) (9000000001, 6001, '测试患者甲', 'MR202606001', '李医生', '神经内科', '科研论文需要', '2026-06-15 09:00:00', '2026-06-22 17:00:00', NULL, 0, NULL, NULL, 1, '0', 'admin', '2026-06-15 09:00:00'), @@ -20,10 +20,11 @@ VALUES (9000000008, 6008, '测试患者丁', 'MR202606008', '陈医生', '超声诊断科', '个人学习', '2026-06-17 16:00:00', '2026-06-24 17:00:00', NULL, 5, '张院长', '2026-06-18 09:00:00', 1, '0', 'admin', '2026-06-17 16:00:00'), -- 更多借阅记录 (9000000009, 6009, '测试患者戊', 'MR202606009', '黄医生', '神经内科', '会诊需要', '2026-06-19 08:00:00', '2026-06-26 17:00:00', NULL, 0, NULL, NULL, 1, '0', 'admin', '2026-06-19 08:00:00'), -(9000000010, 6010, '测试患者己', 'MR202606010', '林护士', '内分泌科', '护理查房', '2026-06-16 13:00:00', '2026-06-23 17:00:00', '2026-06-20 10:00:00', 3, '赵科长', '2026-06-16 14:00:00', 1, '0', 'admin', '2026-06-16 13:00:00'); +(9000000010, 6010, '测试患者己', 'MR202606010', '林护士', '内分泌科', '护理查房', '2026-06-16 13:00:00', '2026-06-23 17:00:00', '2026-06-20 10:00:00', 3, '赵科长', '2026-06-16 14:00:00', 1, '0', 'admin', '2026-06-16 13:00:00') +ON CONFLICT DO NOTHING; -- ==================== 2. mr_sealing 病案封存 ==================== -INSERT INTO healthlink_his.mr_sealing (id, medical_record_id, patient_name, mr_number, seal_reason, seal_type, seal_date, seal_by, unseal_date, unseal_by, unseal_reason, status, tenant_id, delete_flag, create_by, create_time) +INSERT INTO mr_sealing (id, medical_record_id, patient_name, mr_number, seal_reason, seal_type, seal_date, seal_by, unseal_date, unseal_by, unseal_reason, status, tenant_id, delete_flag, create_by, create_time) VALUES -- 已封存(0) (9100000001, 6001, '测试患者甲', 'MR202606001', '医疗纠纷封存', 2, '2026-06-10 09:00:00', '张院长', NULL, NULL, NULL, 0, 1, '0', 'admin', '2026-06-10 09:00:00'), @@ -37,7 +38,7 @@ VALUES (9100000007, 6009, '测试患者戊', 'MR202606009', '医疗纠纷封存', 2, '2026-06-19 09:30:00', '张院长', NULL, NULL, NULL, 0, 1, '0', 'admin', '2026-06-19 09:30:00'); -- ==================== 3. mr_tracking 病案示踪 ==================== -INSERT INTO healthlink_his.mr_tracking (id, medical_record_id, mr_number, patient_name, location, location_type, status, moved_by, move_time, tenant_id, delete_flag, create_by, create_time) +INSERT INTO mr_tracking (id, medical_record_id, mr_number, patient_name, location, location_type, status, moved_by, move_time, tenant_id, delete_flag, create_by, create_time) VALUES -- 在架(IN_SHELF) (9200000001, 6001, 'MR202606001', '测试患者甲', '病案室-A区-01架-03层', 'STORAGE', 'IN_SHELF', '系统管理员', '2026-06-15 08:00:00', 1, '0', 'admin', '2026-06-15 08:00:00'), @@ -56,7 +57,7 @@ VALUES (9200000010, 6009, 'MR202606009', '测试患者戊', '神经内科', 'DEPT', 'BORROWED', '黄医生', '2026-06-19 08:30:00', 1, '0', 'admin', '2026-06-19 08:30:00'); -- ==================== 4. mr_death_discussion 死亡病例讨论 ==================== -INSERT INTO healthlink_his.mr_death_discussion (id, patient_id, patient_name, encounter_id, death_date, discussion_date, deadline_date, host_doctor_id, host_doctor_name, host_title, participants, discussion_conclusion, improvement_measures, status, is_overdue, tenant_id, delete_flag, create_by, create_time) +INSERT INTO mr_death_discussion (id, patient_id, patient_name, encounter_id, death_date, discussion_date, deadline_date, host_doctor_id, host_doctor_name, host_title, participants, discussion_conclusion, improvement_measures, status, is_overdue, tenant_id, delete_flag, create_by, create_time) VALUES -- 待讨论(0) - 未超期 (9300000001, 5001, '测试患者甲', 6001, '2026-06-17 03:20:00', NULL, '2026-06-24 03:20:00', 1001, '张院长', '主任医师', NULL, NULL, NULL, 0, false, 1, '0', 'admin', '2026-06-17 08:00:00'),