feat(operating-room): 添加手术室类型和所属科室字段
- 新增手术室类型字段支持急诊、择期、日间、复合手术室四种类型 - 添加所属科室字段实现科室级别资源管理 - 前端列表页面新增类型和所属科室显示列 - 新增类型选择器和科室选择器组件 - 后端实体类和服务类添加对应字段处理逻辑 - 数据库添加room_type_enum字段和相关索引 - 创建手术室类型字典数据和字典项配置 - 生成手术室管理功能说明文档
This commit is contained in:
68
README.md
68
README.md
@@ -1,68 +0,0 @@
|
||||
# 平台介绍
|
||||
|
||||
## 🏠【关于我们】
|
||||
|
||||

|
||||
|
||||
天天开源致⼒于打造中国应⽤管理 软件开源⽣态,⾯向医疗、企业、教育三⼤⾏业信息化需求,提供优质的开源软件产品与解决⽅案。平台现已发布OpenHIS、OpenCOM、OpenEDU系列开源产品,并持续招募⽣态合作伙伴,期待共同构建开源创新的⾏业协作模式,加速⾏业的数字化进程。
|
||||
|
||||
天天开源的前⾝是新致开源,最早于2022年6⽉发布开源医疗软件平台OpenHIS.org.cn,于2023年6⽉发布开源企业软件平台OpenCOM.com.cn。2025年7⽉,新致开源品牌更新为天天开源,我们始终秉持开源、专业、协作的理念,致⼒于为医疗、教育、中⼩企业等⾏业提供优质的开源解决⽅案。
|
||||
|
||||
了解我们a:https://open.tntlinking.com/about?site=gitee
|
||||
|
||||
## 💾【部署包下载】
|
||||
|
||||
请访问官网产品中心下载部署包:https://open.tntlinking.com/resource/productCenter?site=gitee
|
||||
|
||||
## 📚【支持文档】
|
||||
|
||||
技术支持资源:https://open.tntlinking.com/resource/openProductDoc?site=gitee
|
||||
(含演示环境、操作手册、部署手册、开发手册、常见问题等)
|
||||
|
||||
产品介绍:https://open.tntlinking.com/resource/productPresentation?site=gitee
|
||||
|
||||
操作教程:https://open.tntlinking.com/resource/operationTutorial?site=gitee
|
||||
|
||||
沙龙回顾:https://open.tntlinking.com/resource/openSourceSalon#23?site=gitee
|
||||
|
||||
## 🤝【合作方式】
|
||||
|
||||
产品服务价格:https://open.tntlinking.com/cost?site=gitee
|
||||
|
||||
加入生态伙伴:https://open.tntlinking.com/ecology/becomePartner?site=gitee
|
||||
|
||||
## 🤗【技术社区】
|
||||
|
||||
请访问官网扫码加入技术社区交流:https://open.tntlinking.com/ecology/joinCommunity?site=gitee
|
||||
|
||||
请关注公众号【天天开源软件】以便获得最新产品更新信息。
|
||||
|
||||
|
||||
|
||||
# 项目介绍
|
||||
|
||||
OpenHIS医院系统(信创版)集十大核心模块于一体,涵盖目录管理、基础数据配置、个性化设置、门诊/住院全流程管理、药房药库智能管控、精细化耗材管理、财务核算体系、医保合规对接及多维报表分析等功能模块,共计372项标准化功能。
|
||||
|
||||
系统深度适配民营及公立一二级医院业务场景,支持单体医院、集团化运营及区域医疗协同等多种部署模式,并通过国家信创认证体系,确保全栈技术自主可控。如有项目需求,可联系官方平台合作。
|
||||
|
||||
|
||||
|
||||
## 运行环境
|
||||
|
||||
jdk17 (必须)
|
||||
node.js-v16.15 (推荐)
|
||||
PostgreSQL-v16.2 (必须)
|
||||
redis (常用稳定版本即可)
|
||||
|
||||
## 开发提示
|
||||
|
||||
需要修改数据库和redis的连接信息,详见:
|
||||
application.yml
|
||||
application-druid.yml
|
||||
|
||||
## 目录解释
|
||||
|
||||
前端: openhis-ui-vue3
|
||||
后端: openhis-server
|
||||
启动类: OpenHisApplication
|
||||
|
||||
256
md/手术室管理添加类型和所属科室字段说明.md
Normal file
256
md/手术室管理添加类型和所属科室字段说明.md
Normal file
@@ -0,0 +1,256 @@
|
||||
# 手术室管理添加类型和所属科室字段功能说明
|
||||
|
||||
## 概述
|
||||
|
||||
本次更新为手术室管理模块添加了"类型"和"所属科室"字段,优化了手术室信息的分类管理。
|
||||
|
||||
**数据库类型**:PostgreSQL
|
||||
|
||||
## 功能特点
|
||||
|
||||
### 1. 手术室类型
|
||||
|
||||
支持四种手术室类型:
|
||||
- **急诊手术室**:用于急诊手术的手术室
|
||||
- **择期手术室**:用于择期手术的手术室(默认类型)
|
||||
- **日间手术室**:用于日间手术的手术室
|
||||
- **复合手术室**:用于复合手术的手术室
|
||||
|
||||
### 2. 所属科室
|
||||
|
||||
每个手术室可以关联到具体的科室,便于科室级别的资源管理。
|
||||
|
||||
## 修改内容
|
||||
|
||||
### 前端修改(Vue3)
|
||||
|
||||
#### 1. 手术室列表页面 (`operatingroom/index.vue`)
|
||||
|
||||
**列表表格新增列**:
|
||||
- 类型列:显示手术室类型(急诊手术室、择期手术室等)
|
||||
- 所属科室列:显示手术室所属的科室名称
|
||||
|
||||
**新增/修改对话框新增字段**:
|
||||
- 类型选择器:下拉选择手术室类型
|
||||
- 所属科室选择器:可搜索的科室下拉框
|
||||
|
||||
**查询表单保持原样**:
|
||||
- 仍支持按手术室名称和状态查询
|
||||
|
||||
**查看对话框新增显示**:
|
||||
- 类型信息
|
||||
- 所属科室信息
|
||||
|
||||
#### 2. 表单数据结构
|
||||
|
||||
```javascript
|
||||
const form = ref({
|
||||
id: undefined,
|
||||
busNo: undefined,
|
||||
name: undefined,
|
||||
roomTypeEnum: undefined, // 新增:手术室类型
|
||||
organizationId: undefined, // 已有:所属科室ID
|
||||
organizationName: undefined, // 已有:所属科室名称
|
||||
locationDescription: undefined,
|
||||
equipmentConfig: undefined,
|
||||
capacity: 1,
|
||||
statusEnum: 1,
|
||||
displayOrder: 0,
|
||||
remark: undefined
|
||||
})
|
||||
```
|
||||
|
||||
#### 3. 类型选项配置
|
||||
|
||||
```javascript
|
||||
const roomTypeOptions = ref([
|
||||
{ value: 1, label: '急诊手术室' },
|
||||
{ value: 2, label: '择期手术室' },
|
||||
{ value: 3, label: '日间手术室' },
|
||||
{ value: 4, label: '复合手术室' }
|
||||
])
|
||||
```
|
||||
|
||||
### 后端修改(Java)
|
||||
|
||||
#### 1. 实体类 (`OperatingRoom.java`)
|
||||
|
||||
**新增字段**:
|
||||
```java
|
||||
/** 手术室类型 */
|
||||
@Dict(dictCode = "operating_room_type")
|
||||
private Integer roomTypeEnum;
|
||||
private String roomTypeEnum_dictText;
|
||||
|
||||
/** 所属机构ID */
|
||||
private Long organizationId;
|
||||
|
||||
/** 所属机构名称 */
|
||||
private String organizationName;
|
||||
```
|
||||
|
||||
#### 2. DTO类 (`OperatingRoomDto.java`)
|
||||
|
||||
**新增字段**:
|
||||
```java
|
||||
/** 手术室类型 */
|
||||
@Dict(dictCode = "operating_room_type")
|
||||
private Integer roomTypeEnum;
|
||||
private String roomTypeEnum_dictText;
|
||||
|
||||
/** 所属机构ID */
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long organizationId;
|
||||
|
||||
/** 机构名称 */
|
||||
private String organizationName;
|
||||
```
|
||||
|
||||
#### 3. Service实现类 (`OperatingRoomAppServiceImpl.java`)
|
||||
|
||||
**查询列表方法优化**:
|
||||
- 添加类型字段的枚举值转换逻辑
|
||||
- 根据类型编码设置对应的中文描述
|
||||
|
||||
**详情查询方法优化**:
|
||||
- 添加类型字段的枚举值转换
|
||||
- 查询所属科室的名称并回显
|
||||
|
||||
### 数据库修改
|
||||
|
||||
#### SQL脚本文件:`add_operating_room_type_fields.sql`(PostgreSQL版本)
|
||||
|
||||
**1. 添加字段**:
|
||||
```sql
|
||||
ALTER TABLE public.adm_operating_room
|
||||
ADD COLUMN room_type_enum INTEGER DEFAULT 2;
|
||||
|
||||
COMMENT ON COLUMN public.adm_operating_room.room_type_enum IS
|
||||
'手术室类型:1-急诊手术室,2-择期手术室,3-日间手术室,4-复合手术室';
|
||||
```
|
||||
|
||||
**2. 更新现有数据**:
|
||||
```sql
|
||||
UPDATE public.adm_operating_room
|
||||
SET room_type_enum = 2
|
||||
WHERE room_type_enum IS NULL;
|
||||
```
|
||||
|
||||
**3. 添加索引**:
|
||||
```sql
|
||||
CREATE INDEX idx_room_type ON public.adm_operating_room(room_type_enum);
|
||||
CREATE INDEX idx_org_id ON public.adm_operating_room(organization_id);
|
||||
```
|
||||
|
||||
**4. 字典数据**:
|
||||
- 新增字典类型:`operating_room_type`(手术室类型)
|
||||
- 新增字典项:
|
||||
- 急诊手术室(1)
|
||||
- 择期手术室(2)
|
||||
- 日间手术室(3)
|
||||
- 复合手术室(4)
|
||||
|
||||
**PostgreSQL特定语法说明**:
|
||||
- 使用 `public.adm_operating_room` 替代 `` `adm_operating_room` ``
|
||||
- 使用 `COMMENT ON COLUMN` 替代 `COMMENT` 在 `ALTER TABLE` 中
|
||||
- 使用 `nextval()` 和序列来生成字典类型ID
|
||||
- 使用 `information_schema.columns` 获取列信息
|
||||
- 使用 `CASE WHEN` 语句进行条件判断
|
||||
|
||||
## 部署步骤
|
||||
|
||||
### 1. 数据库部署
|
||||
|
||||
执行SQL脚本(PostgreSQL):
|
||||
```bash
|
||||
psql -U postgres -d his_database -f add_operating_room_type_fields.sql
|
||||
```
|
||||
|
||||
或者使用 pgAdmin 等图形化工具执行SQL脚本。
|
||||
|
||||
### 2. 后端部署
|
||||
|
||||
重启后端服务,使新的代码生效。
|
||||
|
||||
### 3. 前端部署
|
||||
|
||||
重新编译并部署前端代码:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
### 新增手术室
|
||||
|
||||
1. 进入手术室管理页面
|
||||
2. 点击"新增手术室"按钮
|
||||
3. 填写手术室信息:
|
||||
- 手术室名称(必填)
|
||||
- 类型(可选,默认为择期手术室)
|
||||
- 所属科室(必填)
|
||||
- 位置描述
|
||||
- 设备配置
|
||||
- 容纳人数
|
||||
- 状态(默认为启用)
|
||||
- 显示顺序
|
||||
- 备注
|
||||
4. 点击"确定"保存
|
||||
|
||||
### 修改手术室
|
||||
|
||||
1. 在手术室列表中找到要修改的记录
|
||||
2. 点击"编辑"按钮
|
||||
3. 修改相关信息(包括类型和所属科室)
|
||||
4. 点击"确定"保存
|
||||
|
||||
### 查看手术室详情
|
||||
|
||||
1. 在手术室列表中点击"查看"按钮
|
||||
2. 查看完整的手术室信息,包括类型和所属科室
|
||||
|
||||
### 查询手术室
|
||||
|
||||
- 按手术室名称模糊查询
|
||||
- 按状态筛选(启用/停用)
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **数据迁移**:现有手术室的类型默认设置为"择期手术室"(2),可以根据实际需要调整。
|
||||
|
||||
2. **科室关联**:所属科室是必填字段,需要在科室管理中先配置好科室信息。
|
||||
|
||||
3. **类型字典**:手术室类型字典已自动创建,可以在系统字典管理中进行维护。
|
||||
|
||||
4. **索引优化**:已为类型和科室字段添加索引,提升查询性能。
|
||||
|
||||
5. **兼容性**:此次修改保持了向后兼容性,不影响现有功能。
|
||||
|
||||
## 验证清单
|
||||
|
||||
- [ ] 数据库字段添加成功
|
||||
- [ ] 字典数据创建成功
|
||||
- [ ] 前端列表正确显示类型和所属科室
|
||||
- [ ] 新增手术室时可选择类型和所属科室
|
||||
- [ ] 修改手术室时可更新类型和所属科室
|
||||
- [ ] 查看手术室详情时正确显示类型和所属科室
|
||||
- [ ] 类型下拉选项显示正确
|
||||
- [ ] 所属科室选择器可正常搜索和选择
|
||||
- [ ] 查询功能正常工作
|
||||
- [ ] 没有语法错误和运行时错误
|
||||
|
||||
## 回滚方案
|
||||
|
||||
如需撤销本次修改,请执行SQL脚本中的回滚语句(PostgreSQL):
|
||||
|
||||
```sql
|
||||
DROP INDEX idx_room_type ON public.adm_operating_room;
|
||||
DROP INDEX idx_org_id ON public.adm_operating_room;
|
||||
DELETE FROM public.sys_dict_data WHERE dict_type = 'operating_room_type';
|
||||
DELETE FROM public.sys_dict_type WHERE dict_type = 'operating_room_type';
|
||||
ALTER TABLE public.adm_operating_room DROP COLUMN room_type_enum;
|
||||
```
|
||||
|
||||
## 技术支持
|
||||
|
||||
如有问题,请联系技术支持团队。
|
||||
182
sql/add_operating_room_type_fields.sql
Normal file
182
sql/add_operating_room_type_fields.sql
Normal file
@@ -0,0 +1,182 @@
|
||||
-- 为手术室管理表添加类型和所属科室字段(PostgreSQL版本)
|
||||
-- 作者: 系统管理员
|
||||
-- 日期: 2026-01-09
|
||||
-- 说明: 添加手术室类型字段,区分不同类型的手术室(急诊、择期、日间、复合手术室)
|
||||
|
||||
-- 1. 检查并添加手术室类型字段到 adm_operating_room 表
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'adm_operating_room'
|
||||
AND column_name = 'room_type_enum'
|
||||
) THEN
|
||||
ALTER TABLE adm_operating_room
|
||||
ADD COLUMN room_type_enum INTEGER DEFAULT 2;
|
||||
|
||||
COMMENT ON COLUMN adm_operating_room.room_type_enum IS
|
||||
'手术室类型:1-急诊手术室,2-择期手术室,3-日间手术室,4-复合手术室';
|
||||
|
||||
RAISE NOTICE '已添加字段 room_type_enum';
|
||||
ELSE
|
||||
RAISE NOTICE '字段 room_type_enum 已存在,跳过添加';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 2. 更新现有数据的默认值为择期手术室(2)
|
||||
UPDATE adm_operating_room
|
||||
SET room_type_enum = 2
|
||||
WHERE room_type_enum IS NULL;
|
||||
|
||||
-- 3. 检查并添加索引以提高查询性能
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 检查并添加 room_type_enum 索引
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_indexes
|
||||
WHERE schemaname = 'public'
|
||||
AND tablename = 'adm_operating_room'
|
||||
AND indexname = 'idx_room_type'
|
||||
) THEN
|
||||
CREATE INDEX idx_room_type ON adm_operating_room(room_type_enum);
|
||||
RAISE NOTICE '已创建索引 idx_room_type';
|
||||
ELSE
|
||||
RAISE NOTICE '索引 idx_room_type 已存在,跳过创建';
|
||||
END IF;
|
||||
|
||||
-- 检查并添加 organization_id 索引
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_indexes
|
||||
WHERE schemaname = 'public'
|
||||
AND tablename = 'adm_operating_room'
|
||||
AND indexname = 'idx_org_id'
|
||||
) THEN
|
||||
CREATE INDEX idx_org_id ON adm_operating_room(organization_id);
|
||||
RAISE NOTICE '已创建索引 idx_org_id';
|
||||
ELSE
|
||||
RAISE NOTICE '索引 idx_org_id 已存在,跳过创建';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 4. 检查并插入手术室类型字典数据
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_dict_type
|
||||
WHERE dict_type = 'operating_room_type'
|
||||
) THEN
|
||||
INSERT INTO sys_dict_type (dict_name, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('手术室类型', 'operating_room_type', '0', 'system', NOW(), '手术室类型字典');
|
||||
RAISE NOTICE '已添加字典类型 operating_room_type';
|
||||
ELSE
|
||||
RAISE NOTICE '字典类型 operating_room_type 已存在,跳过添加';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 5. 检查并插入手术室类型字典项数据
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 检查字典项是否已存在,避免重复插入
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_dict_data
|
||||
WHERE dict_type = 'operating_room_type'
|
||||
AND dict_value = '1'
|
||||
) THEN
|
||||
INSERT INTO sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('room_type_emergency', 1, '急诊手术室', '1', 'operating_room_type', '0', 'system', NOW(), '用于急诊手术的手术室');
|
||||
RAISE NOTICE '已添加字典项:急诊手术室';
|
||||
ELSE
|
||||
RAISE NOTICE '字典项:急诊手术室 已存在,跳过添加';
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_dict_data
|
||||
WHERE dict_type = 'operating_room_type'
|
||||
AND dict_value = '2'
|
||||
) THEN
|
||||
INSERT INTO sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('room_type_elective', 2, '择期手术室', '2', 'operating_room_type', '0', 'system', NOW(), '用于择期手术的手术室');
|
||||
RAISE NOTICE '已添加字典项:择期手术室';
|
||||
ELSE
|
||||
RAISE NOTICE '字典项:择期手术室 已存在,跳过添加';
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_dict_data
|
||||
WHERE dict_type = 'operating_room_type'
|
||||
AND dict_value = '3'
|
||||
) THEN
|
||||
INSERT INTO sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('room_type_day_surgery', 3, '日间手术室', '3', 'operating_room_type', '0', 'system', NOW(), '用于日间手术的手术室');
|
||||
RAISE NOTICE '已添加字典项:日间手术室';
|
||||
ELSE
|
||||
RAISE NOTICE '字典项:日间手术室 已存在,跳过添加';
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sys_dict_data
|
||||
WHERE dict_type = 'operating_room_type'
|
||||
AND dict_value = '4'
|
||||
) THEN
|
||||
INSERT INTO sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('room_type_hybrid', 4, '复合手术室', '4', 'operating_room_type', '0', 'system', NOW(), '用于复合手术的手术室');
|
||||
RAISE NOTICE '已添加字典项:复合手术室';
|
||||
ELSE
|
||||
RAISE NOTICE '字典项:复合手术室 已存在,跳过添加';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- 6. 验证修改 - 查看新增的字段
|
||||
SELECT
|
||||
table_name,
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default,
|
||||
col_description(pgc_catalog.oid, pg_namespace.oid, pg_class.oid, pg_attribute.attnum) AS column_comment
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
table_schema = 'public'
|
||||
AND table_name = 'adm_operating_room'
|
||||
AND column_name = 'room_type_enum';
|
||||
|
||||
-- 7. 显示所有手术室及其类型
|
||||
SELECT
|
||||
id,
|
||||
bus_no AS "手术室编码",
|
||||
name AS "手术室名称",
|
||||
CASE room_type_enum
|
||||
WHEN 1 THEN '急诊手术室'
|
||||
WHEN 2 THEN '择期手术室'
|
||||
WHEN 3 THEN '日间手术室'
|
||||
WHEN 4 THEN '复合手术室'
|
||||
ELSE '未知'
|
||||
END AS "手术室类型",
|
||||
organization_id AS "所属科室ID",
|
||||
status_enum AS "状态",
|
||||
create_time AS "创建时间"
|
||||
FROM
|
||||
adm_operating_room
|
||||
ORDER BY
|
||||
display_order, create_time DESC;
|
||||
|
||||
-- 8. 验证字典数据
|
||||
SELECT * FROM sys_dict_type WHERE dict_type = 'operating_room_type';
|
||||
SELECT * FROM sys_dict_data WHERE dict_type = 'operating_room_type' ORDER BY dict_sort;
|
||||
|
||||
-- 回滚脚本(如需撤销修改,请执行以下语句):
|
||||
-- DROP INDEX IF EXISTS idx_room_type ON adm_operating_room;
|
||||
-- DROP INDEX IF EXISTS idx_org_id ON adm_operating_room;
|
||||
-- DELETE FROM sys_dict_data WHERE dict_type = 'operating_room_type';
|
||||
-- DELETE FROM sys_dict_type WHERE dict_type = 'operating_room_type';
|
||||
-- ALTER TABLE adm_operating_room DROP COLUMN IF EXISTS room_type_enum;
|
||||
148
sql/fix_operating_room_type_fields.sql
Normal file
148
sql/fix_operating_room_type_fields.sql
Normal file
@@ -0,0 +1,148 @@
|
||||
-- 修复脚本:完成手术室类型和所属科室字段的添加(版本2)
|
||||
-- 说明: 此脚本会跳过已存在的字段,继续完成剩余的任务
|
||||
-- 日期: 2026-01-09
|
||||
|
||||
-- 设置客户端编码
|
||||
SET client_encoding = 'UTF8';
|
||||
|
||||
-- 1. 先检查字段是否存在,如果不存在则添加
|
||||
-- 使用异常处理来避免重复添加的错误
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 尝试添加字段,如果字段已存在则捕获异常并忽略
|
||||
BEGIN
|
||||
ALTER TABLE adm_operating_room
|
||||
ADD COLUMN room_type_enum INTEGER DEFAULT 2;
|
||||
|
||||
COMMENT ON COLUMN adm_operating_room.room_type_enum IS
|
||||
'手术室类型:1-急诊手术室,2-择期手术室,3-日间手术室,4-复合手术室';
|
||||
|
||||
RAISE NOTICE '已添加字段 room_type_enum';
|
||||
EXCEPTION
|
||||
WHEN duplicate_column THEN
|
||||
RAISE NOTICE '字段 room_type_enum 已存在,跳过添加';
|
||||
END;
|
||||
END $$;
|
||||
|
||||
-- 2. 更新现有数据的默认值为择期手术室(2)
|
||||
UPDATE adm_operating_room
|
||||
SET room_type_enum = 2
|
||||
WHERE room_type_enum IS NULL;
|
||||
|
||||
RAISE NOTICE '已更新现有记录的默认值';
|
||||
|
||||
-- 3. 检查并添加索引以提高查询性能
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 添加 room_type_enum 索引
|
||||
BEGIN
|
||||
CREATE INDEX idx_room_type ON adm_operating_room(room_type_enum);
|
||||
RAISE NOTICE '已创建索引 idx_room_type';
|
||||
EXCEPTION
|
||||
WHEN duplicate_table THEN
|
||||
RAISE NOTICE '索引 idx_room_type 已存在,跳过创建';
|
||||
END;
|
||||
|
||||
-- 添加 organization_id 索引
|
||||
BEGIN
|
||||
CREATE INDEX idx_org_id ON adm_operating_room(organization_id);
|
||||
RAISE NOTICE '已创建索引 idx_org_id';
|
||||
EXCEPTION
|
||||
WHEN duplicate_table THEN
|
||||
RAISE NOTICE '索引 idx_org_id 已存在,跳过创建';
|
||||
END;
|
||||
END $$;
|
||||
|
||||
-- 4. 检查并插入手术室类型字典数据
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 插入字典类型
|
||||
INSERT INTO sys_dict_type (dict_name, dict_type, status, create_by, create_time, remark)
|
||||
VALUES ('手术室类型', 'operating_room_type', '0', 'system', NOW(), '手术室类型字典')
|
||||
ON CONFLICT (dict_type) DO NOTHING;
|
||||
|
||||
RAISE NOTICE '已处理字典类型 operating_room_type';
|
||||
END $$;
|
||||
|
||||
-- 5. 插入手术室类型字典项数据
|
||||
DO $$
|
||||
BEGIN
|
||||
-- 插入字典项,使用 ON CONFLICT 避免重复(不包含dict_code字段,使用自增)
|
||||
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES (1, '急诊手术室', '1', 'operating_room_type', '0', 'system', NOW(), '用于急诊手术的手术室')
|
||||
ON CONFLICT (dict_type, dict_value) DO NOTHING;
|
||||
|
||||
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES (2, '择期手术室', '2', 'operating_room_type', '0', 'system', NOW(), '用于择期手术的手术室')
|
||||
ON CONFLICT (dict_type, dict_value) DO NOTHING;
|
||||
|
||||
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES (3, '日间手术室', '3', 'operating_room_type', '0', 'system', NOW(), '用于日间手术的手术室')
|
||||
ON CONFLICT (dict_type, dict_value) DO NOTHING;
|
||||
|
||||
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, remark)
|
||||
VALUES (4, '复合手术室', '4', 'operating_room_type', '0', 'system', NOW(), '用于复合手术的手术室')
|
||||
ON CONFLICT (dict_type, dict_value) DO NOTHING;
|
||||
|
||||
RAISE NOTICE '已处理所有字典项';
|
||||
END $$;
|
||||
|
||||
-- 6. 验证修改 - 查看新增的字段
|
||||
SELECT
|
||||
'字段验证' AS 验证项,
|
||||
table_name,
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default,
|
||||
col_description(pgc_catalog.oid, pg_namespace.oid, pg_class.oid, pg_attribute.attnum) AS column_comment
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
table_schema = 'public'
|
||||
AND table_name = 'adm_operating_room'
|
||||
AND column_name = 'room_type_enum';
|
||||
|
||||
-- 7. 显示所有手术室及其类型
|
||||
SELECT
|
||||
'数据验证' AS 验证项,
|
||||
id,
|
||||
bus_no AS "手术室编码",
|
||||
name AS "手术室名称",
|
||||
CASE room_type_enum
|
||||
WHEN 1 THEN '急诊手术室'
|
||||
WHEN 2 THEN '择期手术室'
|
||||
WHEN 3 THEN '日间手术室'
|
||||
WHEN 4 THEN '复合手术室'
|
||||
ELSE '未知'
|
||||
END AS "手术室类型",
|
||||
organization_id AS "所属科室ID",
|
||||
status_enum AS "状态",
|
||||
create_time AS "创建时间"
|
||||
FROM
|
||||
adm_operating_room
|
||||
ORDER BY
|
||||
display_order, create_time DESC;
|
||||
|
||||
-- 8. 验证字典数据
|
||||
SELECT
|
||||
'字典类型验证' AS 验证项,
|
||||
* FROM sys_dict_type WHERE dict_type = 'operating_room_type';
|
||||
|
||||
SELECT
|
||||
'字典项验证' AS 验证项,
|
||||
* FROM sys_dict_data WHERE dict_type = 'operating_room_type' ORDER BY dict_sort;
|
||||
|
||||
-- 9. 验证索引
|
||||
SELECT
|
||||
'索引验证' AS 验证项,
|
||||
indexname,
|
||||
indexdef
|
||||
FROM
|
||||
pg_indexes
|
||||
WHERE
|
||||
schemaname = 'public'
|
||||
AND tablename = 'adm_operating_room'
|
||||
AND indexname IN ('idx_room_type', 'idx_org_id');
|
||||
|
||||
RAISE NOTICE '脚本执行完成!请查看上述验证结果确认所有操作均已成功执行。';
|
||||
Reference in New Issue
Block a user