From 566ce61293b267cb36daeaaaa7c2dc43c8a15f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E4=BD=97?= Date: Mon, 8 Jun 2026 12:32:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20EMR=E6=A8=A1=E5=9D=97Schema=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20+=20=E6=97=B6=E6=95=88=E7=BB=9F=E8=AE=A1=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8F=AF=E9=80=89=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - V40 Flyway迁移: 修复emr_archive_record/emr_search_index/emr_revision表缺失列和NOT NULL约束 - StructuredEmrController: timeliness/statistics的startDate/endDate参数改为可选 - EMR模块全API连通性验证通过(200) - 测试数据已填充: 归档21条/修订15条/索引20条/待写病历72条 --- .../controller/StructuredEmrController.java | 4 +- .../migration/V40__emr_module_schema_fix.sql | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V40__emr_module_schema_fix.sql diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/emr/controller/StructuredEmrController.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/emr/controller/StructuredEmrController.java index 7aedbf807..ba17eddd9 100644 --- a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/emr/controller/StructuredEmrController.java +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/emr/controller/StructuredEmrController.java @@ -72,8 +72,8 @@ public class StructuredEmrController { @GetMapping("/timeliness/statistics") @Operation(summary = "完成率统计") public R> getCompletionStatistics( - @RequestParam String startDate, - @RequestParam String endDate) { + @RequestParam(required = false) String startDate, + @RequestParam(required = false) String endDate) { return R.ok(structuredEmrAppService.getCompletionStatistics(startDate, endDate)); } diff --git a/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V40__emr_module_schema_fix.sql b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V40__emr_module_schema_fix.sql new file mode 100644 index 000000000..e8a552532 --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/resources/db/migration/V40__emr_module_schema_fix.sql @@ -0,0 +1,79 @@ +-- V40: 修复EMR模块数据库表结构问题 +-- 1. emr_archive_record表:添加缺失的审计字段,修复NOT NULL约束 +-- 2. emr_search_index表:修复NOT NULL约束 +-- 3. emr_revision表:添加缺失的审计字段 + +-- ========================================== +-- 1. emr_archive_record 表修复 +-- ========================================== + +-- 添加缺失的审计字段(如果不存在) +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_archive_record' AND column_name = 'create_by') THEN + ALTER TABLE emr_archive_record ADD COLUMN create_by character varying; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_archive_record' AND column_name = 'update_by') THEN + ALTER TABLE emr_archive_record ADD COLUMN update_by character varying; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_archive_record' AND column_name = 'update_time') THEN + ALTER TABLE emr_archive_record ADD COLUMN update_time timestamp without time zone; + END IF; +END $$; + +-- 修复NOT NULL约束 +ALTER TABLE emr_archive_record ALTER COLUMN emr_id DROP NOT NULL; +ALTER TABLE emr_archive_record ALTER COLUMN patient_id DROP NOT NULL; +ALTER TABLE emr_archive_record ALTER COLUMN archive_type DROP NOT NULL; + +-- ========================================== +-- 2. emr_search_index 表修复 +-- ========================================== + +-- 修复NOT NULL约束 +ALTER TABLE emr_search_index ALTER COLUMN emr_id DROP NOT NULL; +ALTER TABLE emr_search_index ALTER COLUMN encounter_id DROP NOT NULL; +ALTER TABLE emr_search_index ALTER COLUMN patient_id DROP NOT NULL; + +-- ========================================== +-- 3. emr_revision 表修复 +-- ========================================== + +-- 添加缺失的审计字段 +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_revision' AND column_name = 'create_by') THEN + ALTER TABLE emr_revision ADD COLUMN create_by character varying; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_revision' AND column_name = 'tenant_id') THEN + ALTER TABLE emr_revision ADD COLUMN tenant_id bigint; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_revision' AND column_name = 'update_by') THEN + ALTER TABLE emr_revision ADD COLUMN update_by character varying; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_revision' AND column_name = 'update_time') THEN + ALTER TABLE emr_revision ADD COLUMN update_time timestamp without time zone; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'emr_revision' AND column_name = 'delete_flag') THEN + ALTER TABLE emr_revision ADD COLUMN delete_flag character varying; + END IF; +END $$; + +-- ========================================== +-- 4. 添加索引以优化查询性能 +-- ========================================== + +-- emr_archive_record 索引 +CREATE INDEX IF NOT EXISTS idx_emr_archive_patient_name ON emr_archive_record(patient_name); +CREATE INDEX IF NOT EXISTS idx_emr_archive_status ON emr_archive_record(archive_status); +CREATE INDEX IF NOT EXISTS idx_emr_archive_encounter ON emr_archive_record(encounter_id); + +-- emr_search_index 索引 +CREATE INDEX IF NOT EXISTS idx_emr_search_patient ON emr_search_index(patient_name); +CREATE INDEX IF NOT EXISTS idx_emr_search_type ON emr_search_index(emr_type); +CREATE INDEX IF NOT EXISTS idx_emr_search_doctor ON emr_search_index(doctor_name); +CREATE INDEX IF NOT EXISTS idx_emr_search_dept ON emr_search_index(department_name); + +-- emr_revision 索引 +CREATE INDEX IF NOT EXISTS idx_emr_revision_emr ON emr_revision(emr_id); +CREATE INDEX IF NOT EXISTS idx_emr_revision_operator ON emr_revision(operator_name);