患者根据医生编号完成绑定和解绑接口

news2025/4/17 17:49:20

医疗系统接口文档

一、Controller 层

1. InstitutionDoctorController

医疗机构和医生相关的控制器,提供机构查询、医生查询、绑定解绑医生等功能。

@RestController
@RequestMapping("/institution-doctor")
public class InstitutionDoctorController {

    @Autowired
    private InstitutionService institutionService;

    @Autowired
    private DoctorService doctorService;

    @Autowired
    private ClientService clientService;

    @GetMapping("/listInstitution/{institutionCategoryId}")
    public Result<List<Institution>> getInstitutionList(@PathVariable Long institutionCategoryId) {
        List<Institution> institutionList = institutionService.getInstitutionByInstitutionCategoryId(institutionCategoryId);
        return Result.success(institutionList);
    }

    @GetMapping("/listDoctor")
    public Result<List<User>> getDoctorList(@RequestParam String institution) {
        List<User> doctorList = doctorService.getDoctorByInstitutionName(institution);
        return Result.success(doctorList);
    }

    @PatchMapping("/bindDoctorByDoctorNumber")
    public Result<Boolean> bindDoctorByDoctorNumber(@PathVariable BindDoctorDto bindDoctorDto){
        boolean result = clientService.bindDoctorByDoctorNumber(bindDoctorDto);
        return Result.success(result);
    }

    @PatchMapping("/unbindDoctorByDoctorNumber")
    public Result<Boolean> unbindDoctorByDoctorNumber(@PathVariable BindDoctorDto bindDoctorDto){
        boolean result = clientService.unbindDoctorByDoctorNumber(bindDoctorDto);
        return Result.success(result);
    }

    @GetMapping("/getDoctorMsg/{doctorNumber}")
    public Result<UserVO> getDoctorMsg(@RequestParam int doctorNumber){
        UserVO doctorMsg = doctorService.getDoctorMsg(doctorNumber);
        return Result.success(doctorMsg);
    }
}

二、Service 接口

1. DoctorService

医生服务接口,提供获取医生信息的方法。

public interface DoctorService extends IService<User> {
    List<User> getDoctorByInstitutionName(String institution);

    UserVO getDoctorMsg(int doctorNumber);
}

2. ClientService

客户服务接口,提供客户与医生绑定和解绑的功能。

public interface ClientService extends IService<Client> {
    boolean bindDoctorByDoctorNumber(BindDoctorDto bindDoctorDto);

    boolean unbindDoctorByDoctorNumber(BindDoctorDto bindDoctorDto);
}

3. InstitutionService

医疗机构服务接口,提供获取机构列表的功能。

public interface InstitutionService extends IService<Institution>{
    List<Institution> getInstitutionByInstitutionCategoryId(Long institutionCategoryId);
}

三、Service 实现类

1. DoctorServiceImpl

@Service
public class DoctorServiceImpl extends ServiceImpl<UserMapper, User> implements DoctorService {

    @Autowired
    private UserMapper userMapper;

    private static final String Institution = "institution";
    @Override
    public List<User> getDoctorByInstitutionName(String institution) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Institution,institution);
        return userMapper.selectList(queryWrapper);
    }
    @Override
    public UserVO getDoctorMsg(int doctorNumber) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getNumber, doctorNumber);
        // 查询数据库
        User doctor = userMapper.selectOne(queryWrapper);
        if (doctor == null) {
            throw new BusinessException(
                    InstitutionDoctorEnum.DOCTOR_NOT_EXIST.getCode(),
                    InstitutionDoctorEnum.DOCTOR_NOT_EXIST.getMessage());
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(doctor, userVO);
        return userVO;
    }
}

2. ClientServiceImpl

@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper, Client> implements ClientService {

    @Autowired
    private ClientMapper clientMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PatientMapper patientMapper;

    private static final String NUMBER = "number";

    private static final String UUID = "uuid";

    private static final int DEFAULT_DOCTOR_NUMBER = 887375;


    // 绑定医生
    @Override
    public boolean bindDoctorByDoctorNumber(BindDoctorDto bindDoctorDto){
        String clientUuid = bindDoctorDto.getUuid();
        int doctorNumber = bindDoctorDto.getDoctorNumber();

        // 1. 查询医生
        User doctor = userMapper.selectOne(
                new QueryWrapper<User>().eq(NUMBER, doctorNumber)
        );
        if (doctor == null) {
            throw new BusinessException(
                    InstitutionDoctorEnum.DOCTOR_NOT_EXIST.getCode(),
                    InstitutionDoctorEnum.DOCTOR_NOT_EXIST.getMessage());
        }

        // 2. 查询 client
        Client client = clientMapper.selectOne(
                new QueryWrapper<Client>().eq(UUID, clientUuid)
        );
        if (client == null) {
            throw new BusinessException(
                    InstitutionDoctorEnum.CLIENT_NOT_EXIST.getCode(),
                    InstitutionDoctorEnum.CLIENT_NOT_EXIST.getMessage());
        }

        // 3. 查询 patient
        Patient patient = patientMapper.selectOne(
                new QueryWrapper<Patient>().eq(UUID, clientUuid)
        );
        if (patient == null) {
            throw new BusinessException(
                    InstitutionDoctorEnum.Patient_NOT_EXIST.getCode(),
                    InstitutionDoctorEnum.Patient_NOT_EXIST.getMessage());
        }

        // 4. 校验当前医生是否可覆盖
        Integer currentDoctorNumber = patient.getDoctorNumber();
        if (currentDoctorNumber != null) {
            User currentDoctor = userMapper.selectOne(
                    new QueryWrapper<User>().eq(NUMBER, currentDoctorNumber)
            );
            if (currentDoctor != null && currentDoctor.getRole() != 1) {
                throw new BusinessException(
                        InstitutionDoctorEnum.DOCTOR_ALREADY_BOUND.getCode(),
                        InstitutionDoctorEnum.DOCTOR_ALREADY_BOUND.getMessage()
                );
            }
        }

        // 5. 更新绑定
        patient.setDoctorNumber(doctorNumber);
        int update = patientMapper.update(
                patient,
                new UpdateWrapper<Patient>().eq(UUID, patient.getUuid())
        );

        if (update <= 0) {
            throw new BusinessException(
                    InstitutionDoctorEnum.BIND_UPDATE_FAILED.getCode(),
                    InstitutionDoctorEnum.BIND_UPDATE_FAILED.getMessage()
            );
        }

        return true;
    }

    @Override
    public boolean unbindDoctorByDoctorNumber(BindDoctorDto bindDoctorDto) {
        String clientUuid = bindDoctorDto.getUuid();

        Patient patient = patientMapper.selectOne(
                new QueryWrapper<Patient>().eq(UUID, clientUuid)
        );

        if (patient == null) {
            throw new BusinessException(
                    InstitutionDoctorEnum.Patient_NOT_EXIST.getCode(),
                    InstitutionDoctorEnum.Patient_NOT_EXIST.getMessage()
            );
        }

        patient.setDoctorNumber(DEFAULT_DOCTOR_NUMBER);

        int update = patientMapper.update(
                patient,
                new UpdateWrapper<Patient>().eq(UUID, clientUuid)
        );

        if (update <= 0) {
            throw new BusinessException(
                    InstitutionDoctorEnum.BIND_UPDATE_FAILED.getCode(),
                    InstitutionDoctorEnum.BIND_UPDATE_FAILED.getMessage()
            );
        }

        return true;
    }
}

3. InstitutionServiceImpl

@Service
public class InstitutionServiceImpl extends ServiceImpl<InstitutionMapper, Institution> implements InstitutionService {

    @Autowired
    private InstitutionMapper institutionMapper;

    @Autowired
    private UserMapper userMapper;

    public static final String CATEGORY_ID = "category_id";


    @Override
    public List<Institution> getInstitutionByInstitutionCategoryId(Long institutionCategoryId) {
        // 使用QueryWrapper构建查询条件
        QueryWrapper<Institution> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(CATEGORY_ID, institutionCategoryId);
        // 查询符合条件的所有机构
        return institutionMapper.selectList(queryWrapper);
    }
}

四、枚举类

InstitutionDoctorEnum

定义了医生和机构相关的业务异常枚举。

public enum InstitutionDoctorEnum {

    DOCTOR_NOT_EXIST(4031,"医生不存在"),
    CLIENT_NOT_EXIST(4032,"患者不存在"),
    Patient_NOT_EXIST(4033,"患者未绑定,请前往绑定"),
    DOCTOR_ALREADY_BOUND(4034,"用户已绑定医生"),
    BIND_UPDATE_FAILED(4035,"其它绑定错误");


    private Integer code;

    private String message;

    InstitutionDoctorEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}

五、接口功能说明

  1. getInstitutionList:根据机构分类ID获取机构列表
  2. getDoctorList:根据机构名称获取该机构的医生列表
  3. bindDoctorByDoctorNumber:通过医生编号为用户绑定医生
  4. unbindDoctorByDoctorNumber:解除用户与医生的绑定关系
  5. getDoctorMsg:根据医生编号获取医生详细信息

六、接口调用示例

1. 获取机构列表

GET /institution-doctor/listInstitution/1

2. 获取医生列表

GET /institution-doctor/listDoctor?institution=某医院

3. 绑定医生

PATCH /institution-doctor/bindDoctorByDoctorNumber
请求体: {"uuid": "用户UUID", "doctorNumber": 12345}

4. 解绑医生

PATCH /institution-doctor/unbindDoctorByDoctorNumber
请求体: {"uuid": "用户UUID", "doctorNumber": 12345}

5. 获取医生信息

GET /institution-doctor/getDoctorMsg/12345

其它问题思考:

  1. pathVariable和requestparam的使用场景
  2. 唯一标识在用户量不大的情况下使用INT和String哪个效率高
  3. 用uuid完全代替id是否合理

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2331519.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Navicat 17 for Mac 数据库管理

Navicat 17 for Mac 数据库管理 一、介绍 Navicat Premium 17 for Mac是一款专业的数据库管理工具&#xff0c;适用于开发人员、数据库管理员和分析师等用户。它提供了强大的数据管理功能和丰富的工具&#xff0c;使用户能够轻松地管理和维护数据库&#xff0c;提高数据处理效…

grok 驱动级键盘按键记录器分析

grok是一个驱动模块&#xff0c;其主要功能就行进行键盘按键及剪切板数据的记录&#xff0c;也就是一个键盘记录器。实现原理是通过对shadow-ssdt的相关函数进行hook,和r3对GetUserMessage进行hook的原理差不多。 关键部分如下&#xff1a; 查找csrss.exe进程是否已经启动&…

MyBatis中特殊符号处理总结

前言 MyBatis 是一款流行的Java持久层框架&#xff0c;广泛应用于各种类型的项目中。因为我们在日常代码 MyBatis 动态拼接语句时&#xff0c;会经常使用到 大于(>,>)、小于(<,<)、不等于(<>、!)操作符号。由于此符号包含了尖括号&#xff0c;而 MyBatis 使用…

MYSQL——SQL语句到底怎么执行

查询语句执行流程 MySQL 查询语句执行流程 查询缓存&#xff08;Query Cache&#xff09; MySQL内部自带了一个缓存模块&#xff0c;默认是关闭的。主要是因为MySQL自带的缓存应用场景有限。 它要求SQL语句必须一摸一样表里面的任何一条数据发生变化时&#xff0c;该表所有缓…

智能血压计WT2801芯片方案-BLE 5.0无线传输、高保真语音交互、LED显示驱动、低功耗待机四大技术赋能

在智能健康设备飞速发展的今天&#xff0c;血压计早已不再是简单的“测量工具”&#xff0c;而是家庭健康的“智能管家”。然而&#xff0c;一台真正可靠、易用、功能全面的血压计&#xff0c;离不开一颗强大的“核心芯片”。 今天&#xff0c;我们揭秘医疗级芯片WT2801的硬核实…

基于51单片机的智能火灾报警系统—温度烟雾检测、数码管显示、手动报警

基于51单片机的火灾报警系统 &#xff08;仿真&#xff0b;程序&#xff0b;原理图&#xff0b;设计报告&#xff09; 功能介绍 具体功能&#xff1a; 由51单片机MQ-2烟雾传感ADC0832模数转换芯片DS18B20温度传感器数码管显示按键模块声光报警模块构成 具体功能&#xff1a;…

指定运行级别

linux系统下有7种运行级别,我们需要来了解一下常用的运行级别,方便我们熟悉以后的部署环境,话不多说,来看. 开机流程&#xff1a; 指定数级别 基本介绍 运行级别说明: 0:关机 相当于shutdown -h now ⭐️默认参数不能设置为0,否则系统无法正常启动 1:单用户(用于找回丢…

Python标准库:sys模块深入解析

sys模块是Python标准库中一个非常重要的内置模块&#xff0c;它提供了与Python解释器及其环境交互的多种功能。本文将深入探讨sys模块的各个方面&#xff0c;帮助开发者更好地理解和利用这个强大的工具。 1. sys模块概述 sys模块提供了对由解释器使用或维护的变量的访问&…

加油站小程序实战教程10开通会员

目录 1 修改用户登录逻辑2 创建变量3 调用API总结 我们上一篇搭建了开通会员的界面&#xff0c;有了界面的时候就需要加入一些逻辑来控制界面显示。我们的逻辑是当用户打开我的页面的时候&#xff0c;在页面加载完毕后调用API看用户是否已经开通会员了&#xff0c;如果未开通就…

没有他的“变换”,就没有今天的人工智能

从ChatGPT发布以来&#xff0c;大语言模型&#xff08;LLM&#xff09;是所有人追逐的方向&#xff0c;无论是将其看作“万能神”或是人工智能应用的基础构件&#xff0c;其重要性毋庸置疑。而随着大语言模型扩展到多模态领域&#xff0c;就需要更多的工具来帮助其进行处理。 例…

MCP 实战:实现server端,并在cline调用

本文动手实现一个简单的MCP服务端的编写&#xff0c;并通过MCP Server 实现成绩查询的调用。 一、配置环境 安装mcp和uv, mcp要求python版本 Python >3.10; pip install mcppip install uv 二、编写并启用服务端 # get_score.py from mcp.server.fastmcp import…

关于C++日志库spdlog

关于C日志库spdlog spdlog是一个高性能、易于使用的C日志库&#xff0c;广泛应用于现代C项目中。它支持多线程、异步日志记录、多种日志格式、以及灵活的输出方式&#xff08;如控制台、文件、甚至自定义输出&#xff09;。下面将就常用功能方面介绍spdlog的安装、配置和使用方…

回归预测 | Matlab实现RIME-CNN-GRU-Attention霜冰优化卷积门控循环单元注意力机制多变量回归预测

回归预测 | Matlab实现RIME-CNN-GRU-Attention霜冰优化卷积门控循环单元注意力机制多变量回归预测 目录 回归预测 | Matlab实现RIME-CNN-GRU-Attention霜冰优化卷积门控循环单元注意力机制多变量回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.Matlab实现RIME…

液氮恒温器是做什么的

‌液氮恒温器‌是一种利用液氮作为冷源的恒温装置&#xff0c;主要用于提供低温、恒温或变温环境&#xff0c;广泛应用于科研、工业和医疗等领域。液氮恒温器通过液氮的低温特性来实现降温效果&#xff0c;具有效率高、降温速度快、振动小、成本低等优点。 液氮恒温器应用场景和…

`mpi4py` 是什么; ModuleNotFoundError: No module named ‘mpi4py

mpi4py 是什么 目录 `mpi4py` 是什么ModuleNotFoundError: No module named mpi4pyModuleNotFoundError: No module named mpi4py mpi4py 是一个 Python 模块,它提供了对 MPI(Message Passing Interface)标准的接口,使得 Python 程序能够利用 MPI 进行并行计算。其作用主要…

大数据 - 1. 概述

早期的计算机&#xff08;上世纪70年代前&#xff09; 是相互独立的&#xff0c;各自处理各自的数据上世纪70年代后&#xff0c;出现了基于TCP/IP协议的小规模的计算机互联互通。上世纪90年代后&#xff0c;全球互联的互联网出现。当全球互联网逐步建成&#xff08;2000年左右&…

Java基础下

一、Map Map常用的API //map常用的api//1.添加 put: 如果map里边没有key&#xff0c;则会添加&#xff1b;如果有key&#xff0c;则会覆盖&#xff0c;并且返回被覆盖的值Map<String,String> mnew HashMap<>();m.put("品牌","dj");m.put("…

数据结构和算法(十二)--最小生成树

一、有向图 定义: 有向图是一副具有方向性的图&#xff0c;是由一组顶点和一组有方向的边组成的&#xff0c;每条方向的边都连着一对有序的顶点。 出度: 由某个顶点指出的边的个数称为该顶点的出度。 入度: 指向某个顶点的边的个数称为该顶点的入度。 有向路径: 由一系列顶点组…

TK广告素材优化:提升投放效果的核心策略

在广告投放领域&#xff0c;决定投放效果的三大关键要素是&#xff1a;产品、素材和人群。由于产品相对固定且人群多采用通投策略&#xff0c;因此素材质量成为影响投放效果的决定性因素。 为什么素材如此重要&#xff1f; 素材质量直接影响广告的点击率&#xff0c;进而影响…

8.3.1 MenuStrip(菜单)控件

版权声明&#xff1a;本文为博主原创文章&#xff0c;转载请在显著位置标明本文出处以及作者网名&#xff0c;未经作者允许不得用于商业目的 MenuStrip控件提供了程序窗体的主菜单&#xff0c;即显示于窗体顶端部分的菜单。 MenuStrip常用属性&#xff1a; ImageScalingSize…