基于SSM框架的医院就诊预约与病历管理系统 - 源码深度解析

JavaJavaScriptHTMLCSSSSM框架MavenMySQL
2026-02-0711 浏览

文章摘要

本项目是一款基于SSM(Spring+Spring MVC+MyBatis)框架构建的医院就诊预约与病历管理系统,旨在解决传统医院线下服务模式下患者挂号排队时间长、纸质病历易丢失难追溯、医患信息同步效率低等核心痛点。系统通过数字化的业务流程整合,将预约挂号和病历管理两大核心环节线上化,显著提升了医院...

在当今医疗信息化快速发展的背景下,传统医院管理模式面临着诸多挑战。患者挂号排队时间长、纸质病历管理困难、医患信息同步效率低等问题日益突出。针对这些痛点,我们设计并实现了一套智能医疗服务平台,采用成熟的SSM框架技术栈,为医院提供完整的就诊预约与病历管理解决方案。

系统架构与技术栈

该平台采用经典的三层架构设计,前端使用JSP动态页面技术,结合jQuery库实现丰富的用户交互体验。后端基于Spring+Spring MVC+MyBatis框架组合,通过Maven进行项目依赖管理,MySQL作为数据存储方案。

Spring框架负责整个应用的Bean管理和依赖注入,确保业务组件之间的松耦合。Spring MVC作为Web层框架,清晰地区分控制器、模型与视图,有效处理用户请求的路由与响应。MyBatis作为数据持久层解决方案,通过灵活的XML配置实现Java对象与数据库表的映射关系。

@Controller
public class AdminController {
    
    @Autowired
    private AdminService adminService;
    
    @ResponseBody
    @RequestMapping(value = "/getSections")
    public Result getSections(Integer pageNum, Integer pageSize){
        return adminService.getAllSections(pageNum,pageSize);
    }
}

数据库设计亮点分析

预约信息表设计

预约信息表(appointment_info)是整个系统的核心业务表,其设计体现了对医疗预约业务复杂性的充分考虑:

CREATE TABLE `appointment_info` (
  `appointment_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '预约ID',
  `appointment_time` timestamp NULL DEFAULT NULL COMMENT '预约时间',
  `appointment_description` varchar(255) DEFAULT NULL COMMENT '预约描述',
  `appointment_state` int(255) DEFAULT 0 COMMENT '0预约中,1成功,2失败 3取消预约 4就诊完成',
  `appointment_fail_reason` varchar(255) DEFAULT NULL COMMENT '预约失败原因',
  `appointment_create_time` timestamp NULL DEFAULT current_timestamp() COMMENT '预约创建时间',
  `appointment_oper_time` timestamp NULL DEFAULT NULL COMMENT '预约操作时间',
  `section_id` int(11) DEFAULT NULL COMMENT '科室ID',
  `user_id` int(11) DEFAULT NULL COMMENT '用户ID',
  `doctor_id` int(11) DEFAULT NULL COMMENT '医生ID',
  PRIMARY KEY (`appointment_id`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='预约信息表'

该表设计的亮点在于:

  • 状态机设计:appointment_state字段采用枚举值设计,清晰定义了预约的完整生命周期
  • 时间维度完整:包含创建时间、操作时间、预约时间三个关键时间戳,便于业务追溯
  • 外键关联合理:通过section_id、user_id、doctor_id关联科室、用户和医生信息
  • 失败原因记录:appointment_fail_reason字段记录操作失败的具体原因,提升系统可维护性

预约管理界面

就诊信息表设计

就诊信息表(treatment_info)的设计充分考虑了医疗业务的特殊性:

CREATE TABLE `treatment_info` (
  `treatment_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '就诊ID',
  `treatment_description` varchar(255) DEFAULT NULL COMMENT '就诊描述',
  `treatment_time` timestamp NULL DEFAULT current_timestamp() COMMENT '就诊时间',
  `treatment_state` varchar(255) DEFAULT '0' COMMENT '0待就诊 1就诊完成',
  `appointment_id` int(11) DEFAULT NULL COMMENT '预约ID',
  `patient_id` int(11) DEFAULT NULL COMMENT '患者ID',
  `doctor_id` int(255) DEFAULT NULL COMMENT '医生ID',
  `medicine_infos` varchar(255) DEFAULT '' COMMENT '药物信息,自动生成 (药名,数量)',
  `room_infos` varchar(255) DEFAULT '无' COMMENT '住院信息',
  PRIMARY KEY (`treatment_id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='就诊信息表'

该表的关键设计特点:

  • 药品信息结构化存储:medicine_infos字段采用特定格式存储处方信息,便于后续统计分析
  • 住院信息扩展性:room_infos字段为后续住院管理功能预留了扩展空间
  • 就诊状态跟踪:treatment_state字段实时跟踪就诊进度,确保业务流程连贯性

用户表设计的角色权限体系

用户表(user)采用单表多角色的设计模式,通过user_role字段实现权限控制:

CREATE TABLE `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
  `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
  `user_pwd` varchar(255) DEFAULT NULL COMMENT '用户密码',
  `user_role` int(255) DEFAULT 1 COMMENT '1病人 2医师 3管理员',
  `user_phone` varchar(255) DEFAULT NULL COMMENT '用户电话',
  `user_address` varchar(255) DEFAULT NULL COMMENT '用户地址',
  `user_create_time` timestamp NULL DEFAULT current_timestamp() COMMENT '用户创建时间',
  `user_rank` varchar(255) DEFAULT NULL COMMENT '职称',
  `user_real_name` varchar(255) DEFAULT NULL COMMENT '用户真实姓名',
  `user_age` int(255) DEFAULT NULL COMMENT '用户年龄',
  `section_id` int(11) DEFAULT NULL COMMENT '科室ID',
  `is_ban` int(11) DEFAULT 0 COMMENT '是否禁用',
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户信息表'

这种设计的优势在于:

  • 统一的身份管理:所有用户类型在同一表中管理,简化了权限控制逻辑
  • 灵活的权限分配:通过user_role字段实现细粒度的权限控制
  • 账户状态管理:is_ban字段支持账户的启用和禁用操作
  • 医生专业信息:user_rank和section_id字段存储医生的专业属性

医生管理界面

核心功能实现深度解析

智能预约管理模块

预约管理是系统的核心功能,实现了从号源分配、预约申请到状态管理的完整流程。系统通过精确的时间冲突检测和资源分配算法,确保医疗资源的高效利用。

@Service
public class AppointmentService {
    
    public Result createAppointment(AppointmentInfo appointment) {
        // 检查时间冲突
        if (checkTimeConflict(appointment)) {
            return Result.error("该时间段已有预约");
        }
        
        // 检查医生可用性
        if (!checkDoctorAvailability(appointment.getDoctorId(), 
                                   appointment.getAppointmentTime())) {
            return Result.error("医生该时间段不可用");
        }
        
        // 保存预约信息
        appointment.setAppointmentState(0); // 预约中状态
        appointment.setAppointmentCreateTime(new Date());
        appointmentMapper.insert(appointment);
        
        return Result.success("预约申请提交成功");
    }
    
    private boolean checkTimeConflict(AppointmentInfo newAppointment) {
        // 实现时间冲突检测逻辑
        List<AppointmentInfo> existingAppointments = 
            appointmentMapper.selectByDoctorAndTime(
                newAppointment.getDoctorId(), 
                newAppointment.getAppointmentTime());
        return !existingAppointments.isEmpty();
    }
}

患者预约界面

电子病历管理功能

电子病历管理模块实现了患者就诊记录的数字化存储和快速检索。系统采用结构化数据存储方案,支持病历信息的快速查询和统计分析。

@Controller
@RequestMapping("/medicalRecord")
public class MedicalRecordController {
    
    @Autowired
    private TreatmentService treatmentService;
    
    @ResponseBody
    @RequestMapping("/getPatientRecords")
    public Result getPatientRecords(Integer patientId, 
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<TreatmentInfo> records = treatmentService.getByPatientId(patientId);
            PageInfo<TreatmentInfo> pageInfo = new PageInfo<>(records);
            return Result.success(pageInfo);
        } catch (Exception e) {
            return Result.error("查询病历失败");
        }
    }
    
    @ResponseBody
    @RequestMapping("/updateTreatment")
    public Result updateTreatment(@RequestBody TreatmentInfo treatment) {
        // 更新就诊信息,包括药品信息和诊断结果
        treatment.setTreatmentTime(new Date());
        treatment.setTreatmentState("1"); // 就诊完成
        
        // 更新药品库存
        updateMedicineStock(treatment.getMedicineInfos());
        
        treatmentService.update(treatment);
        return Result.success("就诊信息更新成功");
    }
}

就诊记录查看

药品库存管理

药品管理模块实现了药品信息的全生命周期管理,包括入库、出库、库存预警等功能。

@Service
public class MedicineService {
    
    @Autowired
    private MedicineMapper medicineMapper;
    
    public Result getAllMedicine(Integer pageNum, Integer pageSize, 
                               Map<String, String> queryMap) {
        PageHelper.startPage(pageNum, pageSize);
        
        // 构建查询条件
        MedicineExample example = new MedicineExample();
        MedicineExample.Criteria criteria = example.createCriteria();
        
        if (queryMap.containsKey("medicineName")) {
            criteria.andMedicineNameLike("%" + queryMap.get("medicineName") + "%");
        }
        
        List<Medicine> medicines = medicineMapper.selectByExample(example);
        PageInfo<Medicine> pageInfo = new PageInfo<>(medicines);
        
        return Result.success(pageInfo);
    }
    
    public Result updateStock(Integer medicineId, Integer quantity) {
        Medicine medicine = medicineMapper.selectByPrimaryKey(medicineId);
        if (medicine == null) {
            return Result.error("药品不存在");
        }
        
        int newStock = medicine.getMedicineStock() + quantity;
        if (newStock < 0) {
            return Result.error("库存不足");
        }
        
        medicine.setMedicineStock(newStock);
        medicineMapper.updateByPrimaryKey(medicine);
        
        // 库存预警检查
        checkStockWarning(medicine);
        
        return Result.success("库存更新成功");
    }
}

药品管理界面

多角色权限控制

系统通过统一的用户表设计和角色权限控制,实现了患者、医生、管理员三种角色的功能隔离。

@Component
public class SecurityInterceptor implements HandlerInterceptor {
    
    @Override
    public boolean preHandle(HttpServletRequest request, 
                           HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("currentUser");
        
        if (user == null) {
            response.sendRedirect("/login");
            return false;
        }
        
        // 检查角色权限
        String requestURI = request.getRequestURI();
        if (!hasPermission(user.getUserRole(), requestURI)) {
            response.sendError(403, "权限不足");
            return false;
        }
        
        return true;
    }
    
    private boolean hasPermission(Integer userRole, String requestURI) {
        // 根据角色和请求路径判断权限
        if (userRole == 3) { // 管理员
            return true; // 管理员拥有所有权限
        } else if (userRole == 2) { // 医生
            return requestURI.startsWith("/doctor/") || 
                   requestURI.startsWith("/patient/");
        } else { // 患者
            return requestURI.startsWith("/patient/");
        }
    }
}

实体模型设计

系统采用面向对象的设计思想,通过实体类精确映射数据库表结构。以下是一个典型的实体类设计:

package entity;

import java.util.Date;

public class AppointmentHistory {
    private Integer appointmentId;
    private String appointmentHistoryContent;
    private Date appointmentHistoryCreateTime;
    private Integer userId;
    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Integer getAppointmentId() {
        return appointmentId;
    }

    public void setAppointmentId(Integer appointmentId) {
        this.appointmentId = appointmentId;
    }

    public String getAppointmentHistoryContent() {
        return appointmentHistoryContent;
    }

    public void setAppointmentHistoryContent(String appointmentHistoryContent) {
        this.appointmentHistoryContent = appointmentHistoryContent == null ? 
            null : appointmentHistoryContent.trim();
    }

    public Date getAppointmentHistoryCreateTime() {
        return appointmentHistoryCreateTime;
    }

    public void setAppointmentHistoryCreateTime(Date appointmentHistoryCreateTime) {
        this.appointmentHistoryCreateTime = appointmentHistoryCreateTime;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
}

这种实体类设计的特点包括:

  • 属性封装完整:所有字段都提供getter和setter方法
  • 数据类型匹配:Java类型与数据库字段类型精确对应
  • 关联关系处理:包含关联实体对象,支持复杂查询结果映射
  • 空值安全处理:在setter方法中进行空值检查和trim处理

功能展望与优化方向

1. 引入Redis缓存提升性能

当前系统在频繁查询操作(如科室列表、医生信息等)中存在性能优化空间。建议引入Redis作为缓存层:

@Service
public class SectionServiceWithCache {
    
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    
    private static final String SECTION_CACHE_KEY = "sections:all";
    
    public List<Section> getAllSections() {
        // 先查缓存
        List<Section> sections = (List<Section>) redisTemplate.opsForValue()
            .get(SECTION_CACHE_KEY);
        
        if (sections == null) {
            // 缓存未命中,查询数据库
            sections = sectionMapper.selectAll();
            // 写入缓存,设置过期时间
            redisTemplate.opsForValue().set(SECTION_CACHE_KEY, sections, 30, TimeUnit.MINUTES);
        }
        
        return sections;
    }
}

2. 消息队列实现异步处理

对于预约成功通知、药品库存预警等场景,可以引入消息队列实现异步处理:

@Component
public class NotificationService {
    
    @Autowired
    private AmqpTemplate rabbitTemplate;
    
    public void sendAppointmentSuccessNotification(AppointmentInfo appointment) {
        AppointmentNotification notification = new AppointmentNotification();
        notification.setPatientId(appointment.getUserId());
        notification.setAppointmentTime(appointment.getAppointmentTime());
        notification.setDoctorId(appointment.getDoctorId());
        
        rabbitTemplate.convertAndSend("appointment.exchange", 
                                    "appointment.success", notification);
    }
}

3. 微服务架构改造

随着业务复杂度的增加,可以考虑将系统拆分为多个微服务:

  • 用户服务:负责用户管理和认证授权
  • 预约服务:处理预约相关的核心业务逻辑
  • 病历服务:管理电子病历和就诊记录
  • 药品服务:负责药品库存管理和处方处理

4. 移动端适配与小程序开发

开发微信小程序或移动App,为患者提供更便捷的预约和查询体验:

// 小程序端预约功能示例
Page({
  data: {
    departments: [],
    doctors: []
  },
  
  onLoad() {
    this.loadDepartments();
  },
  
  loadDepartments() {
    wx.request({
      url: 'https://api.hospital.com/miniapp/departments',
      success: (res) => {
        this.setData({ departments: res.data });
      }
    });
  }
});

5. 大数据分析与智能推荐

利用历史就诊数据构建推荐算法,为患者智能推荐合适的科室和医生:

# Python数据分析示例
import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity

def recommend_doctors(patient_history, all_doctors):
    # 基于协同过滤的医生推荐算法
    patient_vector = build_patient_vector(patient_history)
    doctor_vectors = build_doctor_vectors(all_doctors)
    
    similarities = cosine_similarity([patient_vector], doctor_vectors)
    recommended_indices = similarities.argsort()[0][-5:][::-1]
    
    return [all_doctors[i] for i in recommended_indices]

总结

该智能医疗服务平台通过合理的架构设计和细致的功能实现,为医疗机构提供了完整的数字化解决方案。系统采用成熟的SSM技术栈,确保了系统的稳定性和可维护性。数据库设计充分考虑了医疗业务的特殊性,实体模型设计体现了面向对象的设计原则。

在核心功能方面,系统实现了智能预约管理、电子病历管理、药品库存管理和多角色权限控制等关键模块。每个模块都经过精心设计,确保了业务流程的顺畅和数据的准确性。

面向未来,系统在缓存优化、异步处理、微服务架构、移动端适配和智能推荐等方面都有很大的扩展空间。这些优化方向将进一步提升系统的性能和用户体验,为医疗信息化建设提供更加完善的技术支撑。

系统登录界面

通过持续的技术迭代和功能优化,该平台有望成为中小型医疗机构信息化建设的标准解决方案,为提升医疗服务质量和管理效率做出重要贡献。

本文关键词
SSM框架医院预约系统病历管理系统源码解析数据库设计

上下篇

上一篇
没有更多文章
下一篇
没有更多文章