CombinationEndPoint.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package com.yihu.ehr.basic.appointment.controller;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.ehr.basic.appointment.service.CombinationService;
  4. import com.yihu.ehr.basic.fzopen.service.OpenService;
  5. import com.yihu.ehr.constants.ApiVersion;
  6. import com.yihu.ehr.constants.ServiceApi;
  7. import com.yihu.ehr.util.rest.Envelop;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.util.*;
  19. /**
  20. * 组合福州总部的预约挂号接口为我方需要的数据结构
  21. *
  22. * @author 张进军
  23. * @date 2018/4/17 17:05
  24. */
  25. @RestController
  26. @RequestMapping(value = ApiVersion.Version1_0)
  27. @Api(description = "组合福州总部的预约挂号接口为我方需要的数据结构", tags = {"预约挂号--组合福州总部的预约挂号接口为我方需要的数据结构"})
  28. public class CombinationEndPoint {
  29. @Value("${fz-gateway.url}")
  30. private String fzGatewayUrl;
  31. @Value("${fz-gateway.clientId}")
  32. private String fzClientId;
  33. @Value("${fz-gateway.clientVersion}")
  34. private String fzClientVersion;
  35. @Autowired
  36. private ObjectMapper objectMapper;
  37. @Autowired
  38. private OpenService openService;
  39. @Autowired
  40. private CombinationService combinationService;
  41. /**
  42. * 由于总部开放平台的医生列表接口,没有就诊日期筛选条件,所以不满足于医疗云PC端预约挂号的原型设计。
  43. * 另求他法,先从医生列表接口获取医生,再从排班接口获取医生sn,对比去掉没有排班的医生,再获取医生详情,最后获取每个医生的排班。
  44. */
  45. @ApiOperation("有排班的医生列表")
  46. @RequestMapping(value = ServiceApi.FzCombination.FindDoctorList, method = RequestMethod.GET)
  47. public Envelop findDoctorList(
  48. @ApiParam(value = "医生列表分页参数,起始页,从1开始", required = true)
  49. @RequestParam int pageIndex,
  50. @ApiParam(value = "医生列表分页参数,每页条数,不能超过100", required = true)
  51. @RequestParam int pageSize,
  52. @ApiParam(value = "医生总数,头次为 0,后续后台返回", required = true)
  53. @RequestParam int total,
  54. @ApiParam(value = "标记医生列表上次查询到第几页,头次为 0,后续后台返回", required = true)
  55. @RequestParam int lastPageIndex,
  56. @ApiParam(value = "标记医生列表上次那页遍历到第几条,头次为 0,后续后台返回", required = true)
  57. @RequestParam int lastPageNo,
  58. @ApiParam(value = "医院ID", required = true)
  59. @RequestParam String hospitalId,
  60. @ApiParam(value = "科室ID", required = true)
  61. @RequestParam String hosDeptId,
  62. @ApiParam(value = "就诊日期,yyyy-MM-dd")
  63. @RequestParam(required = false) String registerDate) {
  64. Envelop envelop = new Envelop();
  65. envelop.setSuccessFlg(false);
  66. try {
  67. Map<String, Object> result = new HashMap<>();
  68. Map<String, Object> params = new HashMap<>();
  69. List<Map<String, Object>> doctorList = new ArrayList<>();
  70. // 获取一页数量有排班的医生,及其详情、排班列表
  71. params.clear();
  72. params.put("pageIndex", pageIndex);
  73. params.put("pageSize", pageSize);
  74. params.put("hospitalId", hospitalId);
  75. params.put("hosDeptId", hosDeptId);
  76. if (StringUtils.isNotEmpty(registerDate)) {
  77. params.put("registerDate", registerDate);
  78. }
  79. Map<String, Integer> flagMap = new HashMap<>();
  80. flagMap.put("lastPageIndex", lastPageIndex);
  81. flagMap.put("lastPageNo", lastPageNo);
  82. combinationService.getOnePageDoctorList(doctorList, flagMap, params);
  83. result.put("doctorList", doctorList);
  84. result.put("lastPageIndex", flagMap.get("lastPageIndex"));
  85. result.put("lastPageNo", flagMap.get("lastPageNo"));
  86. // 获取有排班的医生总数
  87. if (total == 0) {
  88. params.clear();
  89. params.put("pageIndex", 1);
  90. params.put("pageSize", 100);
  91. params.put("hospitalId", hospitalId);
  92. params.put("hosDeptId", hosDeptId);
  93. params.put("registerDate", registerDate);
  94. result.put("total", combinationService.getTotalDoctors(params));
  95. } else {
  96. result.put("total", total);
  97. }
  98. envelop.setObj(result);
  99. envelop.setSuccessFlg(true);
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. envelop.setErrorMsg(e.getMessage());
  103. }
  104. return envelop;
  105. }
  106. @ApiOperation("医院列表")
  107. @RequestMapping(value = ServiceApi.FzCombination.FindHospitalList, method = RequestMethod.GET)
  108. public Envelop findHospitalList(
  109. @ApiParam(value = "分页参数,起始页,从1开始", required = true)
  110. @RequestParam int pageIndex,
  111. @ApiParam(value = "分页参数,每页条数,不能超过100", required = true)
  112. @RequestParam int pageSize,
  113. @ApiParam(value = "省份行政编码", required = true)
  114. @RequestParam String provinceCode,
  115. @ApiParam(value = "城市行政编码,如果是直辖市,则此字段可以不用传递,表示查询该市下全部的区域", required = true)
  116. @RequestParam Integer cityCode,
  117. @ApiParam(value = "医院名称模块查询")
  118. @RequestParam(required = false) String hosNameLike,
  119. @ApiParam(value = "是否提供预约,2有提供预约的医院")
  120. @RequestParam(required = false) Integer state,
  121. @ApiParam(value = "医院等级")
  122. @RequestParam(required = false) Integer levelId,
  123. @ApiParam(value = "医院性质,(1公立,2民营,其他数字为尚未配置)")
  124. @RequestParam(required = false) Integer nature) {
  125. Envelop envelop = new Envelop();
  126. envelop.setSuccessFlg(false);
  127. try {
  128. // 从总部获取医院列表
  129. String hosApi = "baseinfo/HospitalApi/querySimpleHospitalList";
  130. Map<String, Object> hosParams = new HashMap<>();
  131. hosParams.put("pageIndex", pageIndex);
  132. hosParams.put("pageSize", 100);
  133. hosParams.put("provinceCode", provinceCode);
  134. hosParams.put("cityCode", cityCode);
  135. if (StringUtils.isNotEmpty(hosNameLike)) {
  136. hosParams.put("hosNameLike", hosNameLike);
  137. }
  138. if (state != null) {
  139. hosParams.put("state", state);
  140. }
  141. if (levelId != null) {
  142. hosParams.put("levelId", levelId);
  143. }
  144. if (nature != null) {
  145. hosParams.put("nature", nature);
  146. }
  147. /* //region 正式线测试用
  148. List<Map<String, Object>> allHosList = new ArrayList<>();
  149. // 获取上饶医院
  150. // hosParams.put("provinceCode", "360000");
  151. // hosParams.put("cityCode", "361100");
  152. Map<String, Object> hosResMapSr = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
  153. if (!"10000".equals(hosResMapSr.get("Code").toString())) {
  154. envelop.setErrorMsg("获取福州总部医院列表," + hosResMapSr.get("Message").toString());
  155. return envelop;
  156. }
  157. List<Map<String, Object>> hosListSr = (ArrayList) hosResMapSr.get("Result");
  158. int totalSr = (int) hosResMapSr.get("Total");
  159. allHosList.addAll(hosListSr);
  160. // 获取林芝医院
  161. *//*hosParams.put("provinceCode", "540000");
  162. hosParams.put("cityCode", "540400");*//*
  163. Map<String, Object> hosResMapLz = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
  164. if (!"10000".equals(hosResMapLz.get("Code").toString())) {
  165. envelop.setErrorMsg("获取福州总部医院列表," + hosResMapLz.get("Message").toString());
  166. return envelop;
  167. }
  168. List<Map<String, Object>> hosListLz = (ArrayList) hosResMapLz.get("Result");
  169. int totalLz = (int) hosResMapLz.get("Total");
  170. allHosList.addAll(hosListLz);
  171. String hosInfoApi = "baseinfo/HospitalApi/querySimpleHospitalById";
  172. Map<String, Object> hosInfoParams = new HashMap<>();
  173. for (int i = 0, size = allHosList.size(); i < size; i++) {
  174. // 获取医院详情
  175. hosInfoParams.clear();
  176. hosInfoParams.put("hospitalId", allHosList.get(i).get("hospitalId").toString());
  177. Map<String, Object> hosInfoResultMap = objectMapper.readValue(openService.callFzOpenApi(hosInfoApi, hosInfoParams), Map.class);
  178. if (!"10000".equals(hosInfoResultMap.get("Code").toString())) {
  179. envelop.setErrorMsg("获取福州总部医院详情," + hosInfoResultMap.get("Message").toString());
  180. return envelop;
  181. }
  182. // 医生数
  183. allHosList.get(i).put("doctorCount", hosInfoResultMap.get("doctorCount"));
  184. }
  185. hosResMapLz.put("Result", allHosList);
  186. hosResMapLz.put("Total", totalLz + totalSr);
  187. envelop.setObj(hosResMapLz);
  188. envelop.setSuccessFlg(true);
  189. //endregion 正式线测试用
  190. */
  191. Map<String, Object> hosResMap = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
  192. if (!"10000".equals(hosResMap.get("Code").toString())) {
  193. envelop.setErrorMsg("获取福州总部医院列表," + hosResMap.get("Message").toString());
  194. return envelop;
  195. }
  196. List<Map<String, Object>> hosList = (ArrayList) hosResMap.get("Result");
  197. String hosInfoApi = "baseinfo/HospitalApi/querySimpleHospitalById";
  198. Map<String, Object> hosInfoParams = new HashMap<>();
  199. for (int i = 0, size = hosList.size(); i < size; i++) {
  200. // 获取医院详情
  201. hosInfoParams.clear();
  202. hosInfoParams.put("hospitalId", hosList.get(i).get("hospitalId").toString());
  203. Map<String, Object> hosInfoResultMap = objectMapper.readValue(openService.callFzOpenApi(hosInfoApi, hosInfoParams), Map.class);
  204. if (!"10000".equals(hosInfoResultMap.get("Code").toString())) {
  205. envelop.setErrorMsg("获取福州总部医院详情," + hosInfoResultMap.get("Message").toString());
  206. return envelop;
  207. }
  208. // 医生数
  209. hosList.get(i).put("doctorCount", hosInfoResultMap.get("doctorCount"));
  210. }
  211. hosResMap.put("Result", hosList);
  212. envelop.setObj(hosResMap);
  213. envelop.setSuccessFlg(true);
  214. } catch (Exception e) {
  215. e.printStackTrace();
  216. envelop.setErrorMsg(e.getMessage());
  217. }
  218. return envelop;
  219. }
  220. }