5.1 KiB
5.1 KiB
HIS 使用说明(自动生成目录文档)
此文档直接来自代码分析,优先参考 include/core、src/*、include/models、src/models 及 include/utils。
1. 项目概述
- 名称:HIS(Hospital 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::loadWardListFromFilesaveToFile(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_- 常用命令:
helpexit/quitpath <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. 运行步骤
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 适配