尚医通-医院AIP业务1

尚医通-医院AIP业务1

service模块\service_hosp子模块

医院设置主要是用来保存开通医院的一些基本信息,每个医院一条信息,保存了医院编号(平台分配,全局唯一)和接口调用相关的签名key等信息,是整个流程的第一步,只有开通了医院设置信息,才可以上传医院相关信息。

我们所开发的功能就是基于单表的一个CRUD、锁定/解锁和发送签名信息这些基本功能。

查询的表为yygh_hosp库下的hospital_set

表结构:

医院AIP业务01

位置:

controller包\HospitalSetController.java

01 查询医院设置表所有信息

前端请求:
1
@GetMapping("findAll")

前提:首先该类注入了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
@DeleteMapping("{id}")
后端处理:
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对象,传递当前页,每页记录数
Page<HospitalSet> page = new Page<>(current,limit);
//构建条件,queryWrapper是mybatis plus中实现查询的对象封装操作类
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) {
//设置状态 1 使用 0 不能使用
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) {
//根据id查询医院设置信息
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);

//1 获取医院系统传递过来的签名,签名进行MD5加密
String hospSign = (String)paramMap.get("sign");

//2 根据传递过来医院编码,查询数据库,查询签名
String hoscode = (String)paramMap.get("hoscode");
String signKey = hospitalSetService.getSignKey(hoscode);

//3 把数据库查询签名进行MD5加密
String signKeyMd5 = MD5.encrypt(signKey);

//4 判断签名是否一致
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) {
//把参数map集合转换对象 Hospital
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) {
//1 获取传递过来医院信息
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");

//2 根据传递过来医院编号,查询数据库中是否存在签名
String signKey = hospitalSetService.getSignKey(hoscode);

//3 把数据库查询签名进行MD5加密
String signKeyMd5 = MD5.encrypt(signKey);

//4 判断签名是否一致
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");

//2 根据传递过来医院编码,查询数据库中是否存在签名
String signKey = hospitalSetService.getSignKey(hoscode);

//3 把数据库查询签名进行MD5加密
String signKeyMd5 = MD5.encrypt(signKey);

//4 判断签名是否一致
if(!hospSign.equals(signKeyMd5)) {
throw new YyghException(ResultCodeEnum.SIGN_ERROR);
}

//调用service的方法
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) {
//paramMap 转换department对象
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);
//调用service方法
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对象,设置当前页和每页记录数
//0是第一页
Pageable pageable = PageRequest.of(page-1,limit);
Department department = new Department();
BeanUtils.copyProperties(departmentQueryVo,department);
department.setIsDeleted(0);

// 创建Example对象
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) {
//paramMap 转换department对象
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);
//调用service方法
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对象,设置当前页和每页记录数
//0是第一页
Pageable pageable = PageRequest.of(page-1,limit);
Schedule schedule = new Schedule();
BeanUtils.copyProperties(scheduleQueryVo,schedule);
schedule.setIsDeleted(0);
schedule.setStatus(1);

// 创建Example对象
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 pageable = PageRequest.of(page-1,limit);
//创建条件匹配器
ExampleMatcher matcher = ExampleMatcher.matching()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase(true);
//hospitalSetQueryVo转换Hospital对象
Hospital hospital = new Hospital();
BeanUtils.copyProperties(hospitalQueryVo,hospital);
//创建对象
Example<Hospital> example = Example.of(hospital,matcher);
//调用方法实现查询
Page<Hospital> pages = hospitalRepository.findAll(example, pageable);

//获取查询list集合,遍历进行医院等级封装
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) {
//根据id查询医院信息
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) {
//根据dictCode和value获取医院等级名称
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集合,用于最终数据封装
List<DepartmentVo> result = new ArrayList<>();

//根据医院编号,查询医院所有科室信息
Department departmentQuery = new Department();
departmentQuery.setHoscode(hoscode);
Example example = Example.of(departmentQuery);
//所有科室列表 departmentList
List<Department> departmentList = departmentRepository.findAll(example);

//根据大科室编号 bigcode 分组,获取每个大科室里面下级子科室
Map<String, List<Department>> deparmentMap =
departmentList.stream().collect(Collectors.groupingBy(Department::getBigcode));
//遍历map集合 deparmentMap
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());
//封装到list集合
children.add(departmentVo2);
}
//把小科室list集合放到大科室children里面
departmentVo1.setChildren(children);
//放到最终result里面
result.add(departmentVo1);
}
return result;
}

尚医通-医院AIP业务1
https://yztldxdz.top/2022/10/04/尚医通-医院AIP业务1/
发布于
2022年10月4日
许可协议