尚医通-医院AIP业务1
service模块\service_hosp子模块
医院设置主要是用来保存开通医院的一些基本信息,每个医院一条信息,保存了医院编号(平台分配,全局唯一)和接口调用相关的签名key等信息,是整个流程的第一步,只有开通了医院设置信息,才可以上传医院相关信息。
我们所开发的功能就是基于单表的一个CRUD、锁定/解锁和发送签名信息这些基本功能。
查询的表为yygh_hosp库下的hospital_set
表结构:
医院AIP业务01
位置:
controller包\HospitalSetController.java
01 查询医院设置表所有信息
前端请求:
前提:首先该类注入了hospitalSetService接口,该接口继承了IService接口,可以使用mybatisplus包中封装好的方法
后端处理:
1 2 3 4
| public Result findAllHospitalSet() { List<HospitalSet> list = hospitalSetService.list(); return Result.ok(list); }
|
直接调用已封装好方法得到医院设置的list集合,并通过同一返回规范生成json返回list集合。
02 逻辑删除医院设置
所谓逻辑删除并不是把数据从表中移除而是把is_deleted字段设为0
前端请求:
后端处理:
1 2 3 4 5 6 7
| public Result removeHospSet(@PathVariable Long id) { boolean flag = hospitalSetService.removeById(id); if(flag) { return Result.ok(); } return Result.fail(); }
|
03 条件查询带分页
前端请求:
1
| @PostMapping("findPageHospSet/{current}/{limit}")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public Result findPageHospSet(@PathVariable long current, @PathVariable long limit, @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo) { Page<HospitalSet> page = new Page<>(current,limit); QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>(); String hosname = hospitalSetQueryVo.getHosname(); String hoscode = hospitalSetQueryVo.getHoscode(); if(!StringUtils.isEmpty(hosname)) { wrapper.like("hosname",hospitalSetQueryVo.getHosname()); } if(!StringUtils.isEmpty(hoscode)) { wrapper.eq("hoscode",hospitalSetQueryVo.getHoscode()); } IPage<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper); return Result.ok(pageHospitalSet); }
|
04 添加医院设置
前端请求:
1
| @PostMapping("saveHospitalSet")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12
| public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet) { hospitalSet.setStatus(1); Random random = new Random(); hospitalSet.setSignKey(MD5.encrypt(System.currentTimeMillis()+""+random.nextInt(1000))); boolean save = hospitalSetService.save(hospitalSet); if(save) { return Result.ok(); } return Result.fail(); }
|
05 根据id获取医院设置
前端发请求:
1
| @GetMapping("getHospSet/{id}")
|
后端处理:
1 2 3 4
| public Result getHospSet(@PathVariable Long id) { HospitalSet hospitalSet = hospitalSetService.getById(id); return Result.ok(hospitalSet); }
|
06 修改医院设置
前端请求:
1
| @PostMapping("updateHospitalSet")
|
后端处理:
1 2 3 4 5 6 7
| public Result updateHospitalSet(@RequestBody HospitalSet hospitalSet) { boolean flag = hospitalSetService.updateById(hospitalSet); if(flag) { return Result.ok(); } return Result.fail(); }
|
07 批量删除医院设置
前端请求:
1
| @DeleteMapping("batchRemove")
|
后端处理:
1 2 3 4
| public Result batchRemoveHospitalSet(@RequestBody List<Long> idList) { hospitalSetService.removeByIds(idList); return Result.ok(); }
|
08 医院设置锁定和解锁
前端请求:
1
| @PutMapping("lockHospitalSet/{id}/{status}")
|
后端处理:
1 2 3 4 5 6 7 8 9 10
| public Result lockHospitalSet(@PathVariable Long id, @PathVariable Integer status) { HospitalSet hospitalSet = hospitalSetService.getById(id); hospitalSet.setStatus(status); hospitalSetService.updateById(hospitalSet); return Result.ok(); }
|
09 发送签名秘钥
暂时没用上,说是短信服务会用但也没用上
医院AIP业务02
位置:
controller包\api包\ApiController.java
01 上传医院
上传后的数据存储在mongodb中
前端请求:
1
| @PostMapping("saveHospital")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public Result saveHosp(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
String hospSign = (String)paramMap.get("sign");
String hoscode = (String)paramMap.get("hoscode"); String signKey = hospitalSetService.getSignKey(hoscode);
String signKeyMd5 = MD5.encrypt(signKey);
if(!hospSign.equals(signKeyMd5)) { throw new YyghException(ResultCodeEnum.SIGN_ERROR); }
String logoData = (String)paramMap.get("logoData"); logoData = logoData.replaceAll(" ","+"); paramMap.put("logoData",logoData);
hospitalService.save(paramMap); return Result.ok(); }
|
save方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public void save(Map<String, Object> paramMap) { String mapString = JSONObject.toJSONString(paramMap); Hospital hospital = JSONObject.parseObject(mapString, Hospital.class);
String hoscode = hospital.getHoscode(); Hospital hospitalExist = hospitalRepository.getHospitalByHoscode(hoscode);
if(hospitalExist != null) { hospital.setStatus(hospitalExist.getStatus()); hospital.setCreateTime(hospitalExist.getCreateTime()); hospital.setUpdateTime(new Date()); hospital.setIsDeleted(0); hospitalRepository.save(hospital); } else { hospital.setStatus(0); hospital.setCreateTime(new Date()); hospital.setUpdateTime(new Date()); hospital.setIsDeleted(0); hospitalRepository.save(hospital); }
|
02 查询医院
前端请求:
1
| @PostMapping("hospital/show")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public Result getHospital(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap); String hoscode = (String)paramMap.get("hoscode"); String hospSign = (String)paramMap.get("sign");
String signKey = hospitalSetService.getSignKey(hoscode);
String signKeyMd5 = MD5.encrypt(signKey);
if(!hospSign.equals(signKeyMd5)) { throw new YyghException(ResultCodeEnum.SIGN_ERROR); }
Hospital hospital = hospitalService.getByHoscode(hoscode); return Result.ok(hospital); }
|
getByHoscode方法具体实现
1 2 3 4
| public Hospital getByHoscode(String hoscode) { Hospital hospital = hospitalRepository.getHospitalByHoscode(hoscode); return hospital; }
|
所用到的加密方法在common模块\service_util子模块\helper包\HttpRequestHelper.java
03 上传科室
前端请求:
1
| @PostMapping("saveDepartment")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public Result saveDepartment(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
String hoscode = (String)paramMap.get("hoscode"); String hospSign = (String)paramMap.get("sign");
String signKey = hospitalSetService.getSignKey(hoscode);
String signKeyMd5 = MD5.encrypt(signKey);
if(!hospSign.equals(signKeyMd5)) { throw new YyghException(ResultCodeEnum.SIGN_ERROR); }
departmentService.save(paramMap); return Result.ok(); }
|
save方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void save(Map<String, Object> paramMap) { String paramMapString = JSONObject.toJSONString(paramMap); Department department = JSONObject.parseObject(paramMapString,Department.class);
Department departmentExist = departmentRepository. getDepartmentByHoscodeAndDepcode(department.getHoscode(),department.getDepcode()); if(departmentExist!=null) { departmentExist.setUpdateTime(new Date()); departmentExist.setIsDeleted(0); departmentRepository.save(departmentExist); } else { department.setCreateTime(new Date()); department.setUpdateTime(new Date()); department.setIsDeleted(0); departmentRepository.save(department); } }
|
04 查询科室
前端请求:
1
| @PostMapping("department/list")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public Result findDepartment(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);
String hoscode = (String)paramMap.get("hoscode"); int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page")); int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));
DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo(); departmentQueryVo.setHoscode(hoscode); Page<Department> pageModel = departmentService.findPageDepartment(page,limit,departmentQueryVo); return Result.ok(pageModel); }
|
findPageDepartment方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public Page<Department> findPageDepartment(int page, int limit, DepartmentQueryVo departmentQueryVo) { Pageable pageable = PageRequest.of(page-1,limit); Department department = new Department(); BeanUtils.copyProperties(departmentQueryVo,department); department.setIsDeleted(0);
ExampleMatcher matcher = ExampleMatcher.matching() .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) .withIgnoreCase(true); Example<Department> example = Example.of(department,matcher);
Page<Department> all = departmentRepository.findAll(example, pageable); return all; }
|
05 删除科室
前端请求:
1
| @PostMapping("department/remove")
|
后端处理:
1 2 3 4 5 6 7 8 9 10
| public Result removeDepartment(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap); String hoscode = (String)paramMap.get("hoscode"); String depcode = (String)paramMap.get("depcode"); departmentService.remove(hoscode,depcode); return Result.ok(); }
|
remove方法具体实现
1 2 3 4 5 6 7
| public void remove(String hoscode, String depcode) { Department department = departmentRepository.getDepartmentByHoscodeAndDepcode(hoscode, depcode); if(department != null) { departmentRepository.deleteById(department.getId()); } }
|
06 上传排班
前端请求:
1
| @PostMapping("saveSchedule")
|
后端处理:
1 2 3 4 5 6 7
| public Result saveSchedule(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap); scheduleService.save(paramMap); return Result.ok(); }
|
save方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public void save(Map<String, Object> paramMap) { String paramMapString = JSONObject.toJSONString(paramMap); Schedule schedule = JSONObject.parseObject(paramMapString,Schedule.class);
Schedule scheduleExist = scheduleRepository. getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(),schedule.getHosScheduleId());
if(scheduleExist!=null) { scheduleExist.setUpdateTime(new Date()); scheduleExist.setIsDeleted(0); scheduleExist.setStatus(1); scheduleRepository.save(scheduleExist); } else { schedule.setCreateTime(new Date()); schedule.setUpdateTime(new Date()); schedule.setIsDeleted(0); schedule.setStatus(1); scheduleRepository.save(schedule); } }
|
07 查询排班
前端请求:
1
| @PostMapping("schedule/list")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public Result findSchedule(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap); String hoscode = (String)paramMap.get("hoscode"); String depcode = (String)paramMap.get("depcode"); int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page")); int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));
ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo(); scheduleQueryVo.setHoscode(hoscode); scheduleQueryVo.setDepcode(depcode); Page<Schedule> pageModel = scheduleService.findPageSchedule(page,limit,scheduleQueryVo); return Result.ok(pageModel); }
|
findPageSchedule方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public Page<Schedule> findPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo) { Pageable pageable = PageRequest.of(page-1,limit); Schedule schedule = new Schedule(); BeanUtils.copyProperties(scheduleQueryVo,schedule); schedule.setIsDeleted(0); schedule.setStatus(1);
ExampleMatcher matcher = ExampleMatcher.matching() .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) .withIgnoreCase(true); Example<Schedule> example = Example.of(schedule,matcher);
Page<Schedule> all = scheduleRepository.findAll(example, pageable); return all; }
|
08 删除排班
前端请求:
1
| @PostMapping("schedule/remove")
|
后端处理:
1 2 3 4 5 6 7 8 9 10 11
| public Result remove(HttpServletRequest request) { Map<String, String[]> requestMap = request.getParameterMap(); Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap); String hoscode = (String)paramMap.get("hoscode"); String hosScheduleId = (String)paramMap.get("hosScheduleId");
scheduleService.remove(hoscode,hosScheduleId); return Result.ok(); }
|
remove方法具体实现
1 2 3 4 5 6 7
| public void remove(String hoscode, String hosScheduleId) { Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId); if(schedule != null) { scheduleRepository.deleteById(schedule.getId()); } }
|
医院AIP业务03
位置:
controller包\HospitalController.java
01 查询医院列表(条件查询分页)
前端请求:
1
| @GetMapping("list/{page}/{limit}")
|
后端处理:
1 2 3 4 5 6
| public Result listHosp(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) { Page<Hospital> pageModel = hospitalService.selectHospPage(page,limit,hospitalQueryVo); return Result.ok(pageModel); }
|
selectHospPage方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public Page<Hospital> selectHospPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo) { Pageable pageable = PageRequest.of(page-1,limit); ExampleMatcher matcher = ExampleMatcher.matching() .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) .withIgnoreCase(true); Hospital hospital = new Hospital(); BeanUtils.copyProperties(hospitalQueryVo,hospital); Example<Hospital> example = Example.of(hospital,matcher); Page<Hospital> pages = hospitalRepository.findAll(example, pageable);
pages.getContent().stream().forEach(item -> { this.setHospitalHosType(item); }); return pages; }
|
02 更新医院上线状态
前端请求:
1
| @GetMapping("updateHospStatus/{id}/{status}")
|
后端处理:
1 2 3 4
| public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status) { hospitalService.updateStatus(id,status); return Result.ok(); }
|
updateStatus方法具体实现
1 2 3 4 5 6 7 8
| public void updateStatus(String id, Integer status) { Hospital hospital = hospitalRepository.findById(id).get(); hospital.setStatus(status); hospital.setUpdateTime(new Date()); hospitalRepository.save(hospital); }
|
03 医院详情信息
前端请求:
1
| @GetMapping("showHospDetail/{id}")
|
后端处理:
1 2 3 4
| public Result showHospDetail(@PathVariable String id) { Map<String, Object> map = hospitalService.getHospById(id); return Result.ok(map); }
|
getHospById方法具体实现
1 2 3 4 5 6 7 8 9 10 11
| public Map<String, Object> getHospById(String id) { Map<String, Object> result = new HashMap<>(); Hospital hospital = this.setHospitalHosType(hospitalRepository.findById(id).get()); result.put("hospital",hospital); result.put("bookingRule", hospital.getBookingRule()); hospital.setBookingRule(null); return result; }
|
setHospitalHosType方法:遍历医院等级进行封装
1 2 3 4 5 6 7 8 9 10 11 12
| private Hospital setHospitalHosType(Hospital hospital) { String hostypeString = dictFeignClient.getName("Hostype", hospital.getHostype()); String provinceString = dictFeignClient.getName(hospital.getProvinceCode()); String cityString = dictFeignClient.getName(hospital.getCityCode()); String districtString = dictFeignClient.getName(hospital.getDistrictCode());
hospital.getParam().put("fullAddress",provinceString+cityString+districtString); hospital.getParam().put("hostypeString",hostypeString); return hospital; }
|
医院AIP业务04
位置:
controller包\DepartmentController.java
01 根据医院编号,查询医院所有科室列表
前端请求:
1
| @GetMapping("getDeptList/{hoscode}")
|
后端处理:
1 2 3 4
| public Result getDeptList(@PathVariable String hoscode) { List<DepartmentVo> list = departmentService.findDeptTree(hoscode); return Result.ok(list); }
|
findDeptTree方法具体实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public List<DepartmentVo> findDeptTree(String hoscode) { List<DepartmentVo> result = new ArrayList<>();
Department departmentQuery = new Department(); departmentQuery.setHoscode(hoscode); Example example = Example.of(departmentQuery); List<Department> departmentList = departmentRepository.findAll(example);
Map<String, List<Department>> deparmentMap = departmentList.stream().collect(Collectors.groupingBy(Department::getBigcode)); for(Map.Entry<String,List<Department>> entry : deparmentMap.entrySet()) { String bigcode = entry.getKey(); List<Department> deparment1List = entry.getValue(); DepartmentVo departmentVo1 = new DepartmentVo(); departmentVo1.setDepcode(bigcode); departmentVo1.setDepname(deparment1List.get(0).getBigname());
List<DepartmentVo> children = new ArrayList<>(); for(Department department: deparment1List) { DepartmentVo departmentVo2 = new DepartmentVo(); departmentVo2.setDepcode(department.getDepcode()); departmentVo2.setDepname(department.getDepname()); children.add(departmentVo2); } departmentVo1.setChildren(children); result.add(departmentVo1); } return result; }
|