Files
HIS-GUI/docs/usage/readme.md
2026-03-31 10:51:39 +08:00

169 lines
5.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HIS 使用说明(自动生成目录文档)
此文档直接来自代码分析,优先参考 `include/core``src/*``include/models``src/models``include/utils`
## 1. 项目概述
- 名称HISHospital Information System
- 语言C++C++17+
- 构建CMake
- 目标:小型医院病房管理(病房、床位、住院患者分配与释放),模块化可扩展
- 数据结构:链表(`LinkedList`))、并以 JSON 文件持久化
## 2. 目录结构
```
HIS/
CMakeLists.txt # 构建配置
README.md # 简要项目名
build/ # 构建输出
data/ # 默认数据存放示例wards_bed
demo/ # 演示
docs/ # 文档(此处新建 usage
include/ # 头文件
cli/
repl_shell.h # 交互式命令行类
core/
his_core.h
his_context.h
patient_service.h
report_service.h
ward_service.h
models/
ward.h
utils/
linkedlist.hpp
file_manager.h
src/ # 源码实现
cli/
repl_shell.cpp
core/
core.cpp (空实现)
models/
ward.cpp
utils/
file_manager.cpp
main_shell.cpp
main_noshell.cpp
tests/ # 测试(见项目现有内容)
```
## 3. 核心架构Core
### 3.1 `include/core/his_core.h`
- `core::HisCore` 作为组合根
- `HisContext ctx_` 持有全局内存状态
- 初始化: `WardService ctx_``PatientService ctx_``ReportService ctx_`
### 3.2 `include/core/his_context.h`
- `core::HisContext` 包含:
- `LinkedList<std::string, Ward> wards;`(基于 `utils::LinkedList`
### 3.3 `include/core/ward_service.h`
- 核心 CRUD + 文件同步:
- `wardCount()`
- `findWard(wardId)`
- `for_eachWard(visitor)`
- `addWard(Ward)``removeWard(wardId)`
- `loadFromFile(path, outError)` => 使用 `FileManager::loadWardListFromFile`
- `saveToFile(path, outError, indent)` => 使用 `FileManager::saveWardListToFile`
### 3.4 `include/core/patient_service.h`
- 住院/出院逻辑:
- `admitPatient(wardId, patientId, outBedId)`
- `releaseBed(wardId, bedId)`
- `releasePatient(wardId, patientId)`
- 依赖 `Ward::admitPatient/releaseBed/releasePatient`
### 3.5 `include/core/report_service.h`
- 报表简化:
- `wardOccupancyRate(wardId)` => `Ward::occupancyRate()`
## 4. 模型病房与床位Ward
### 4.1 `include/models/ward.h` + `src/models/ward.cpp`
`WardType {Normal, Special, ICU}``BedStatus {Free, Occupied}`
`Bed` 功能:
- `isFree()`
- `assignPatient(patientId)`
- `release()`
- JSON`toJson()` / `fromJson()`
`Ward` 功能:
- 构造时创建 `MaxBeds` 个床位ID 生成 `wardID_B1`...
- `getFreeBedID(outBedId)`:查询首个空闲床位
- `admitPatient(patientId, outBedId)`:分配患者
- `releaseBed(bedId)`
- `releasePatient(patientId)`
- `freeBedCount()`, `occupiedBedCount()`, `occupancyRate()`
- JSON`toJson()` / `fromJson()` 包括 beds 数据
## 5. 工具:链表与文件
### 5.1 `include/utils/linkedlist.hpp`
- `LinkedList<Key,Value>`:双向链表 + HashMap 索引
- 节点:`ListNode<Key,Value>`
- 核心操作:`insert_front`, `remove`, `find`, `move_to_front`, `remove_tail`, `size`, `for_each`
### 5.2 `include/utils/file_manager.h` + `src/utils/file_manager.cpp`
- 文件基本:`readTextFile`, `writeTextFile`, `createFile`, `deleteFile`
- JSON 辅助:`deleteJsonField`
- Ward 文件:`loadWardListFromFile`, `saveWardListToFile`
- 指定 `data/wards_bed/wards.json` 默认路径CLI
## 6. CLI命令行操作
### 6.1 `include/cli/repl_shell.h` + `src/cli/repl_shell.cpp`
- `ReplShell` 使用 `core::HisCore` 对象 `core_`
- 常用命令:
- `help`
- `exit/quit`
- `path <file>`
- `load [file]`, `save [file]`
- `file create/delete`, `file rm-field <file> <field>`
- `list wards`, `show ward <wardId>`
- `add ward <wardId> <departmentId> <Normal|Special|ICU> <maxBeds>`
- `rm ward <wardId>`
- `admit <wardId> <patientId>`
- `release bed <wardId> <bedId>`
- `release patient <wardId> <patientId>`
### 6.2 交互输出
- `list wards`: 表格展示病房概览
- `show ward <wardId>`: 床位详情
## 7. 入口
- `src/main_shell.cpp`:启动 `ReplShell`(交互式)
- `src/main_noshell.cpp`:无交互入口(可能预留为脚本/测试调用)
## 8. 数据文件路径
- 默认 `data/wards_bed/wards.json`
- 通过 `path` 命令或 `load/save` 命令可替换为任意文件路径
## 9. 运行步骤
```bash
cd /home/e2hang/code/HIS
mkdir -p build && cd build
cmake ..
make -j
./his_shell # 或/可能为可执行名
```
## 10. 测试
- `tests/` 目录(源码未详细列出)
- 可用 `ctest --output-on-failure` 执行(若 cmake 生成测试目标)
## 11. 代码要点
- 无数据库,全部基于内存 `LinkedList` + JSON 持久化
- `Ward` 负责床位状态;`WardService` 负责病房列表维护/持久化;`PatientService` 负责入出院工单;`ReportService` 负责占用率查询
- 前后端交互仅命令行,后续可做 API / GUI 适配