医疗系统接口文档
一、Controller 层
1. InstitutionDoctorController
医疗机构和医生相关的控制器,提供机构查询、医生查询、绑定解绑医生等功能。
@RestController
@RequestMapping("/institution-doctor")
public class InstitutionDoctorController {@Autowiredprivate InstitutionService institutionService;@Autowiredprivate DoctorService doctorService;@Autowiredprivate 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 {@Autowiredprivate UserMapper userMapper;private static final String Institution = "institution";@Overridepublic List<User> getDoctorByInstitutionName(String institution) {QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.eq(Institution,institution);return userMapper.selectList(queryWrapper);}@Overridepublic 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 {@Autowiredprivate ClientMapper clientMapper;@Autowiredprivate UserMapper userMapper;@Autowiredprivate PatientMapper patientMapper;private static final String NUMBER = "number";private static final String UUID = "uuid";private static final int DEFAULT_DOCTOR_NUMBER = 887375;// 绑定医生@Overridepublic 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. 查询 clientClient 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. 查询 patientPatient 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;}@Overridepublic 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 {@Autowiredprivate InstitutionMapper institutionMapper;@Autowiredprivate UserMapper userMapper;public static final String CATEGORY_ID = "category_id";@Overridepublic 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;}
}
五、接口功能说明
getInstitutionList
:根据机构分类ID获取机构列表getDoctorList
:根据机构名称获取该机构的医生列表bindDoctorByDoctorNumber
:通过医生编号为用户绑定医生unbindDoctorByDoctorNumber
:解除用户与医生的绑定关系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
其它问题思考:
- pathVariable和requestparam的使用场景
- 唯一标识在用户量不大的情况下使用INT和String哪个效率高
- 用uuid完全代替id是否合理