BookingController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. package com.yihu.wlyy.web.third;
  2. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  3. import com.yihu.wlyy.entity.patient.Patient;
  4. import com.yihu.wlyy.entity.patient.PatientReservation;
  5. import com.yihu.wlyy.service.app.reservation.PatientReservationService;
  6. import com.yihu.wlyy.service.common.account.DoctorService;
  7. import com.yihu.wlyy.service.common.account.PatientService;
  8. import com.yihu.wlyy.service.third.guahao.GuahaoDoctor;
  9. import com.yihu.wlyy.service.third.guahao.GuahaoXMService;
  10. import com.yihu.wlyy.service.third.guahao.GuahaoYihuService;
  11. import com.yihu.wlyy.service.third.guahao.IGuahaoService;
  12. import com.yihu.wlyy.task.PushMsgTask;
  13. import com.yihu.wlyy.util.HttpClientUtil;
  14. import com.yihu.wlyy.util.SystemConf;
  15. import com.yihu.wlyy.web.WeixinBaseController;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import io.swagger.annotations.ApiParam;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.apache.http.NameValuePair;
  21. import org.apache.http.message.BasicNameValuePair;
  22. import org.json.JSONArray;
  23. import org.json.JSONObject;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.http.MediaType;
  26. import org.springframework.stereotype.Controller;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RequestMethod;
  29. import org.springframework.web.bind.annotation.RequestParam;
  30. import org.springframework.web.bind.annotation.ResponseBody;
  31. import java.lang.reflect.Field;
  32. import java.text.SimpleDateFormat;
  33. import java.util.*;
  34. /**
  35. * 预约挂号
  36. *
  37. * @author hzp at 2016-08-30
  38. */
  39. @Controller
  40. @RequestMapping(value = "/third/guahao")
  41. @Api(description = "预约挂号接口")
  42. public class BookingController extends WeixinBaseController {
  43. @Autowired
  44. private GuahaoXMService guahaoXM;
  45. @Autowired
  46. private GuahaoYihuService guahaoYihu;
  47. @Autowired
  48. private PatientReservationService patientReservationService;
  49. @Autowired
  50. private PatientService patientService;
  51. @Autowired
  52. private DoctorService doctorService;
  53. /**
  54. * 根据城市编码获取相应挂号服务
  55. *
  56. * @return
  57. */
  58. private IGuahaoService getService(String city) {
  59. IGuahaoService re = guahaoYihu;
  60. if (city != null && city.equals("350200")) {
  61. re = guahaoXM;
  62. }
  63. return re;
  64. }
  65. /**
  66. * 发送短信参数
  67. */
  68. private static List<NameValuePair> buildSmsParams(String content, String mobile) {
  69. List<NameValuePair> params = new ArrayList<NameValuePair>();
  70. params.add(new BasicNameValuePair("SpCode", SystemConf.getInstance().getSmsCode()));
  71. params.add(new BasicNameValuePair("LoginName", SystemConf.getInstance().getSmsName()));
  72. params.add(new BasicNameValuePair("Password", SystemConf.getInstance().getSmsPassword()));
  73. params.add(new BasicNameValuePair("MessageContent", content));
  74. params.add(new BasicNameValuePair("UserNumber", mobile));
  75. params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
  76. params.add(new BasicNameValuePair("ScheduleTime", ""));
  77. params.add(new BasicNameValuePair("f", "1"));
  78. return params;
  79. }
  80. /**
  81. * 获取时间
  82. */
  83. private static Date getMonthBefore(Date d, int month) {
  84. Calendar now = Calendar.getInstance();
  85. now.setTime(d);
  86. now.set(Calendar.MONTH, now.get(Calendar.MONTH) - month);
  87. return now.getTime();
  88. }
  89. @RequestMapping(value = "GetOrgList", method = RequestMethod.POST)
  90. @ResponseBody
  91. @ApiOperation("获取机构列表")
  92. public String GetOrgList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  93. @RequestParam(value = "city", required = true) String city,
  94. @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
  95. @RequestParam(value = "filter", required = false) String filter,
  96. @ApiParam(name = "type", value = "类型", defaultValue = "1")
  97. @RequestParam(value = "type", required = false) String type,
  98. @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
  99. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  100. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
  101. @RequestParam(value = "pageSize", required = false) Integer pageSize) {
  102. try {
  103. List<Map<String, String>> list = getService(city).GetOrgList(city, filter, type, pageIndex, pageSize);
  104. return write(200, "获取机构列表成功!", "data", list);
  105. } catch (Exception e) {
  106. return error(-1, e.getMessage());
  107. }
  108. }
  109. @RequestMapping(value = "GetOrgDepList", method = RequestMethod.POST)
  110. @ResponseBody
  111. @ApiOperation("获取科室接口")
  112. public String GetOrgDepList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  113. @RequestParam(value = "city", required = true) String city,
  114. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  115. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  116. @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
  117. @RequestParam(value = "filter", required = false) String filter,
  118. @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
  119. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  120. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
  121. @RequestParam(value = "pageSize", required = false) Integer pageSize) {
  122. try {
  123. List<Map<String, String>> list = getService(city).GetOrgDepList(hospitalId, filter, pageIndex, pageSize);
  124. return write(200, "获取科室列表成功!", "data", list);
  125. } catch (Exception e) {
  126. return error(-1, e.getMessage());
  127. }
  128. }
  129. @RequestMapping(value = "GetDoctorList", method = RequestMethod.POST)
  130. @ResponseBody
  131. @ApiOperation("获取医生接口")
  132. public String GetDoctorList(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  133. @RequestParam(value = "city", required = true) String city,
  134. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  135. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  136. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1040610")
  137. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  138. @ApiParam(name = "filter", value = "过滤条件", defaultValue = "")
  139. @RequestParam(value = "filter", required = false) String filter,
  140. @ApiParam(name = "pageIndex", value = "第几页", defaultValue = "")
  141. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  142. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "")
  143. @RequestParam(value = "pageSize", required = false) Integer pageSize) {
  144. try {
  145. List<GuahaoDoctor> list = getService(city).GetDoctorList(hospitalId, hosDeptId, filter, pageIndex, pageSize);
  146. return write(200, "获取医生列表成功!", "data", list);
  147. } catch (Exception e) {
  148. return error(-1, e.getMessage());
  149. }
  150. }
  151. @RequestMapping(value = "GetDoctorArrange", method = RequestMethod.POST)
  152. @ResponseBody
  153. @ApiOperation("获取医生排班接口(包含排班详细)")
  154. public String GetDoctorArrange(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  155. @RequestParam(value = "city", required = true) String city,
  156. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211G1102")
  157. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  158. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "3020001")
  159. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  160. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "AA2")
  161. @RequestParam(value = "doctorId", required = true) String doctorId) {
  162. try {
  163. List<Map<String, Object>> list = getService(city).GetDoctorArrange(hospitalId, hosDeptId, doctorId);
  164. return write(200, "获取医生排班成功!", "data", list);
  165. } catch (Exception e) {
  166. return error(-1, e.getMessage());
  167. }
  168. }
  169. @RequestMapping(value = "GetDoctorArrangeSimple", method = RequestMethod.POST)
  170. @ResponseBody
  171. @ApiOperation("获取医生排班接口(一级)")
  172. public String GetDoctorArrangeSimple(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  173. @RequestParam(value = "city", required = true) String city,
  174. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  175. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  176. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1010210")
  177. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  178. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "03101")
  179. @RequestParam(value = "doctorId", required = true) String doctorId) {
  180. try {
  181. List<Map<String, String>> list = getService(city).GetDoctorArrangeSimple(hospitalId, hosDeptId, doctorId);
  182. return write(200, "获取医生排班成功!", "data", list);
  183. } catch (Exception e) {
  184. return error(-1, e.getMessage());
  185. }
  186. }
  187. @RequestMapping(value = "GetDoctorInfo", method = RequestMethod.POST)
  188. @ResponseBody
  189. @ApiOperation("根据医生编码获取医生详细信息")
  190. public String GetDoctorInfo(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  191. @RequestParam(value = "city", required = true) String city,
  192. @ApiParam(name = "doctorId", value = "医生id", defaultValue = "07101")
  193. @RequestParam(value = "doctorId", required = true) String doctorId,
  194. @ApiParam(name = "hospitalId", value = "医院id", defaultValue = "350211A1001")
  195. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  196. @ApiParam(name = "hosDeptId", value = "科室id", defaultValue = "1040610")
  197. @RequestParam(value = "hosDeptId", required = true) String hosDeptId) {
  198. try {
  199. GuahaoDoctor doctor = getService(city).GetDoctorInfo(doctorId, hospitalId, hosDeptId);
  200. return write(200, "获取医生信息成功!", "data", doctor);
  201. } catch (Exception e) {
  202. return error(-1, e.getMessage());
  203. }
  204. }
  205. @RequestMapping(value = "CreateOrder", method = RequestMethod.POST)
  206. @ResponseBody
  207. @ApiOperation("创建挂号单")
  208. public String CreateOrder(@ApiParam(name = "city", value = "城市编码", defaultValue = "350200")
  209. @RequestParam(value = "city", required = true) String city,
  210. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  211. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  212. @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "厦门大学附属第一医院")
  213. @RequestParam(value = "hospitalName", required = true) String hospitalName,
  214. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1040610")
  215. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  216. @ApiParam(name = "hosDeptName", value = "医院科室名称", defaultValue = "儿二科")
  217. @RequestParam(value = "hosDeptName", required = true) String hosDeptName,
  218. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "07101")
  219. @RequestParam(value = "doctorId", required = true) String doctorId,
  220. @ApiParam(name = "doctorName", value = "医生姓名", defaultValue = "林素莲")
  221. @RequestParam(value = "doctorName", required = true) String doctorName,
  222. @ApiParam(name = "arrangeDate", value = "排班信息", defaultValue = "{\"sectionType\":\"a\",\"startTime\":\"2016-09-02 08:20:00\",\"endTime\":\"2016-09-02 08:30:00\"}")
  223. @RequestParam(value = "arrangeDate", required = true) String arrangeDate,
  224. @ApiParam(name = "patient", value = "患者代码", defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
  225. @RequestParam(value = "patient", required = true) String patient,
  226. @ApiParam(name = "patientName", value = "患者姓名", defaultValue = "张锦川")
  227. @RequestParam(value = "patientName", required = true) String patientName,
  228. @ApiParam(name = "cardNo", value = "身份证号码", defaultValue = "35052419880511553X")
  229. @RequestParam(value = "cardNo", required = true) String cardNo,
  230. @ApiParam(name = "clinicCard", value = "市民卡号", defaultValue = "D57117706")
  231. @RequestParam(value = "clinicCard", required = true) String clinicCard,
  232. @ApiParam(name = "patientPhone", value = "患者手机", defaultValue = "13950116510")
  233. @RequestParam(value = "patientPhone", required = true) String patientPhone) {
  234. try {
  235. if (StringUtils.isEmpty(patientName)) {
  236. return error(-1, "未设置姓名!");
  237. }
  238. if (StringUtils.isEmpty(cardNo)) {
  239. return error(-1, "未设置身份证号!");
  240. }
  241. if (StringUtils.isEmpty(clinicCard)) {
  242. return error(-1, "未设置社保卡号!");
  243. }
  244. if (StringUtils.isEmpty(patientPhone)) {
  245. return error(-1, "未设置手机号码!");
  246. }
  247. String orderCode = getService(city).CreateOrder(hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, arrangeDate, patient, patientName, cardNo, clinicCard, patientPhone);
  248. //预约发送微信消息
  249. PatientReservation obj = patientReservationService.findByCode(orderCode);
  250. if (obj != null) {
  251. Patient p = patientService.findByCode(obj.getPatient());
  252. String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
  253. if (StringUtils.isNotEmpty(p.getOpenid())) {
  254. // 推送消息给微信端
  255. JSONObject json = new JSONObject();
  256. json.put("first", "");
  257. json.put("toUser", p.getCode());
  258. json.put("id", obj.getCode());
  259. json.put("date", obj.getStartTime());
  260. json.put("orgCode", obj.getOrgCode());
  261. json.put("orgName", obj.getOrgName());
  262. json.put("doctorName", obj.getDoctorName());
  263. json.put("deptName", obj.getDeptName());
  264. json.put("remark", p.getName() + ",您好!" + msg);
  265. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
  266. }
  267. //发送短信小时
  268. // 调用总部发送信息的接口
  269. //String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
  270. //JSONObject json = toJson(result);
  271. // if (json == null) {
  272. // // 发送失败
  273. // throw new Exception("短信发送失败!");
  274. // } else if (json.getInt("result") != 0) {
  275. // return json.getString("description");
  276. // } else {
  277. // //发送成功,保存到数据库
  278. // }
  279. return write(200, "创建挂号单成功!");
  280. } else {
  281. return error(-1, "创建挂号单失败!");
  282. }
  283. } catch (Exception e) {
  284. return error(-1, e.getMessage());
  285. }
  286. }
  287. @RequestMapping(value = "CreateOrderByDoctor", method = RequestMethod.POST)
  288. @ResponseBody
  289. @ApiOperation("(内网)转诊预约挂号")
  290. public String CreateOrderByDoctor(@ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  291. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  292. @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "厦门大学附属第一医院")
  293. @RequestParam(value = "hospitalName", required = true) String hospitalName,
  294. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1011610")
  295. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  296. @ApiParam(name = "hosDeptName", value = "医院科室名称", defaultValue = "内分泌糖尿病科门诊")
  297. @RequestParam(value = "hosDeptName", required = true) String hosDeptName,
  298. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
  299. @RequestParam(value = "doctorId", required = true) String doctorId,
  300. @ApiParam(name = "doctorName", value = "医生姓名", defaultValue = "杨叔禹")
  301. @RequestParam(value = "doctorName", required = true) String doctorName,
  302. @ApiParam(name = "arrangeDate", value = "排班信息", defaultValue = "{\"sectionType\":\"p\",\"startTime\":\"2016-12-29 14:00:00\",\"endTime\":\"2016-12-29 14:08:00\"}")
  303. @RequestParam(value = "arrangeDate", required = true) String arrangeDate,
  304. @ApiParam(name = "patient", value = "患者代码", defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
  305. @RequestParam(value = "patient", required = true) String patient,
  306. @ApiParam(name = "patientName", value = "患者姓名", defaultValue = "张锦川")
  307. @RequestParam(value = "patientName", required = true) String patientName,
  308. @ApiParam(name = "cardNo", value = "身份证号码", defaultValue = "35052419880511553X")
  309. @RequestParam(value = "cardNo", required = true) String cardNo,
  310. @ApiParam(name = "clinicCard", value = "市民卡号", defaultValue = "A0601003595X")
  311. @RequestParam(value = "clinicCard", required = true) String clinicCard,
  312. @ApiParam(name = "patientPhone", value = "患者手机", defaultValue = "13950116510")
  313. @RequestParam(value = "patientPhone", required = true) String patientPhone,
  314. @ApiParam(name = "dcode", value = "代预约医生编号", defaultValue = "test00000000005")
  315. @RequestParam(value = "dcode", required = true) String dcode,
  316. @ApiParam(name = "dname", value = "代预约医生名称", defaultValue = "组2全科医生")
  317. @RequestParam(value = "dname", required = true) String dname) {
  318. try {
  319. if (StringUtils.isEmpty(patientName)) {
  320. return error(-1, "未设置姓名!");
  321. }
  322. if (StringUtils.isEmpty(cardNo)) {
  323. return error(-1, "未设置身份证号!");
  324. }
  325. if (StringUtils.isEmpty(clinicCard)) {
  326. return error(-1, "未设置社保卡号!");
  327. }
  328. if (StringUtils.isEmpty(patientPhone)) {
  329. return error(-1, "未设置手机号码!");
  330. }
  331. String orderCode = guahaoXM.CreateOrderByDoctor(hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, arrangeDate, patient, patientName, cardNo, clinicCard, patientPhone, dname, dcode);
  332. //获取预约信息查询是否挂号成功
  333. PatientReservation obj = patientReservationService.findByCode(orderCode);
  334. if (obj != null) {
  335. Patient p = patientService.findByCode(obj.getPatient());
  336. Doctor d = doctorService.findDoctorByCode(getUID());
  337. String msg = d.getName() + "医生已成功为您预约:" + obj.getStartTime() + "," + obj.getOrgName() +
  338. obj.getDeptName() + obj.getDeptName() + "医生的号源。您可直接前往医院就诊。";
  339. if (StringUtils.isNotEmpty(p.getOpenid())) {
  340. // 推送消息给微信端
  341. JSONObject json = new JSONObject();
  342. json.put("first", "");
  343. json.put("toUser", p.getCode());
  344. json.put("id", obj.getCode());
  345. json.put("date", obj.getStartTime());
  346. json.put("orgName", obj.getOrgName());
  347. json.put("orgCode", obj.getOrgCode());
  348. json.put("doctorName", obj.getDeptName());
  349. json.put("deptName", obj.getDeptName());
  350. json.put("remark", p.getName() + ",您好!\n" + msg);
  351. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
  352. }
  353. //发送短信小时
  354. // 调用总部发送信息的接口
  355. String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
  356. return write(200, "创建挂号单成功!");
  357. } else {
  358. return error(-1, "创建挂号单失败!");
  359. }
  360. } catch (Exception e) {
  361. return error(-1, e.getMessage());
  362. }
  363. }
  364. @RequestMapping(value = "GetDoctorArrangeTenDay", method = RequestMethod.POST)
  365. @ResponseBody
  366. @ApiOperation("(内网)获取医生排班接口")
  367. public String GetDoctorArrangeTenDay(
  368. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  369. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  370. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1011610")
  371. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  372. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
  373. @RequestParam(value = "doctorId", required = true) String doctorId) {
  374. try {
  375. List<Map<String, Object>> list = guahaoXM.GetDoctorArrangeTenDay(hospitalId, hosDeptId, doctorId);
  376. return write(200, "获取医生排班成功!", "data", list);
  377. } catch (Exception e) {
  378. return error(-1, e.getMessage());
  379. }
  380. }
  381. @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
  382. @ResponseBody
  383. @ApiOperation("取消挂号单")
  384. public String CancelOrder(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
  385. @RequestParam(value = "orderId", required = true) String orderId) {
  386. try {
  387. //获取订单信息
  388. PatientReservation obj = patientReservationService.findById(orderId);
  389. boolean re = false;
  390. if (obj != null) {
  391. String type = obj.getType();
  392. String code = obj.getCode();
  393. if (type.equals("0")) { //医护网接口
  394. re = guahaoYihu.CancelOrder(code);
  395. } else if (type.equals("1")) //厦门市民健康预约接口
  396. {
  397. re = guahaoXM.CancelOrder(code, obj.getSsc());
  398. }
  399. }
  400. if (re) {
  401. //更新状态
  402. patientReservationService.updateStatus(obj.getCode(), 0);
  403. //微信消息
  404. Patient p = patientService.findByCode(obj.getPatient());
  405. if (StringUtils.isNotEmpty(p.getOpenid())) {
  406. JSONObject json = new JSONObject();
  407. json.put("first", "");
  408. json.put("toUser", p.getCode());
  409. json.put("name", obj.getName());
  410. json.put("date", obj.getStartTime());
  411. json.put("doctorName", obj.getDoctorName());
  412. json.put("orgName", obj.getOrgName());
  413. json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
  414. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
  415. }
  416. return write(200, "取消挂号单成功!");
  417. } else {
  418. return error(-1, "取消挂号单失败!");
  419. }
  420. } catch (Exception e) {
  421. return error(-1, e.getMessage());
  422. }
  423. }
  424. /********************************************* 医生端查询 **************************************************************************/
  425. @RequestMapping(value = "GetPatientReservationList", method = RequestMethod.POST)
  426. @ResponseBody
  427. @ApiOperation("获取患者预约信息列表接口-医生端")
  428. public String GetPatientReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
  429. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  430. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
  431. @RequestParam(value = "pageSize", required = false) Integer pageSize,
  432. @ApiParam(name = "patient", value = "患者编号", defaultValue = "10")
  433. @RequestParam(value = "patient", required = false) String patient,
  434. @ApiParam(name = "doctor", value = "医生编号", defaultValue = "10")
  435. @RequestParam(value = "doctor", required = false) String doctor) {
  436. try {
  437. List<PatientReservation> list = patientReservationService.getReservationByPatient(patient, doctor, pageIndex, pageSize);
  438. //遍历更新预约状态
  439. for (PatientReservation item : list) {
  440. String type = item.getType();
  441. String code = item.getCode();
  442. if (type.equals("0")) { //医护网接口
  443. }
  444. else if (type.equals("1")) //厦门市民健康预约接口
  445. {
  446. Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
  447. //更新状态
  448. if (status != null) {
  449. patientReservationService.updateStatus(item.getCode(), 0);
  450. item.setStatus(status);
  451. }
  452. }
  453. }
  454. return write(200, "获取患者预约信息列表成功!", "data", list);
  455. } catch (Exception e) {
  456. return error(-1, e.getMessage());
  457. }
  458. }
  459. @RequestMapping(value = "GetDoctorReservationList", method = RequestMethod.POST)
  460. @ResponseBody
  461. @ApiOperation("获取医生代预约信息列表接口-医生端")
  462. public String GetDoctorReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
  463. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  464. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
  465. @RequestParam(value = "pageSize", required = false) Integer pageSize,
  466. @ApiParam(name = "doctor", value = "医生编号", defaultValue = "10")
  467. @RequestParam(value = "doctor", required = false) String doctor) {
  468. try {
  469. List<PatientReservation> list = patientReservationService.getReservationByDoctor(doctor, pageIndex, pageSize);
  470. //遍历更新预约状态
  471. JSONArray array = new JSONArray();
  472. for (PatientReservation item : list) {
  473. String type = item.getType();
  474. String code = item.getCode();
  475. JSONObject object = new JSONObject();
  476. Class pClass = (Class) item.getClass();
  477. for(Field field : pClass.getDeclaredFields()){
  478. field.setAccessible(true);
  479. object.put(field.getName(),field.get(item));
  480. }
  481. Patient patient = patientService.findByCode(item.getPatient());
  482. if(patient!=null){
  483. object.put("photo",patient.getPhoto());
  484. }
  485. array.put(object);
  486. if (type.equals("0")) { //医护网接口
  487. } else if (type.equals("1")) //厦门市民健康预约接口
  488. {
  489. Integer status = guahaoXM.GetOrderStatus(item.getOrgCode(), code, item.getSsc());
  490. //更新状态
  491. if (status != null) {
  492. patientReservationService.updateStatus(item.getCode(), 0);
  493. item.setStatus(status);
  494. }
  495. }
  496. }
  497. return write(200, "获取患者预约信息列表成功!", "data", array);
  498. } catch (Exception e) {
  499. return error(-1, e.getMessage());
  500. }
  501. }
  502. @RequestMapping(value = "GetPatientReservation", method = RequestMethod.POST)
  503. @ResponseBody
  504. @ApiOperation("获取患者预约信息单条-医生端")
  505. public String GetPatientReservation(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
  506. @RequestParam(value = "orderId", required = true) String orderId) {
  507. try {
  508. PatientReservation obj = null;
  509. try {
  510. obj = patientReservationService.findById(orderId);
  511. } catch (Exception e) {
  512. obj = patientReservationService.findByCode(orderId);
  513. }
  514. if (obj != null) {
  515. String type = obj.getType();
  516. String code = obj.getCode();
  517. Integer status = null;
  518. if (type.equals("0")) { //医护网接口
  519. } else if (type.equals("1")) //厦门市民健康预约接口
  520. {
  521. status = guahaoXM.GetOrderStatus(obj.getOrgCode(), code, obj.getSsc());
  522. }
  523. //更新状态
  524. if (status != null) {
  525. patientReservationService.updateStatus(obj.getCode(), 0);
  526. obj.setStatus(status);
  527. }
  528. return write(200, "获取患者预约信息成功!", "data", obj);
  529. } else {
  530. return error(-1, "不存在该条预约信息!");
  531. }
  532. } catch (Exception e) {
  533. return error(-1, e.getMessage());
  534. }
  535. }
  536. @RequestMapping(value = "CountReservationByDoctorForPatient", method = RequestMethod.POST)
  537. @ResponseBody
  538. @ApiOperation("获取医生为患者预约的总数")
  539. public String CountReservationByDoctorForPatient(@ApiParam(name = "doctor", value = "医生编号")
  540. @RequestParam(value = "doctor", required = true) String doctor,
  541. @ApiParam(name = "patient", value = "患者编号")
  542. @RequestParam(value = "patient", required = true) String patient) {
  543. try {
  544. Long obj = patientReservationService.countReservationByDoctorForPatient(doctor, patient);
  545. return write(200, "获取患者预约信息成功!", "data", obj);
  546. } catch (Exception e) {
  547. return error(-1, e.getMessage());
  548. }
  549. }
  550. /*************************************** 患者端查询 ******************************************************************/
  551. @RequestMapping(value = "GetRegList", method = RequestMethod.POST)
  552. @ResponseBody
  553. @ApiOperation("获取患者预约信息列表接口--患者端")
  554. public String GetRegList(@ApiParam(name = "patient", value = "患者编号", defaultValue = "0cc6e4562de2437ab2dbbf51a9fc3b49")
  555. @RequestParam(value = "patient", required = false) String patient) {
  556. try {
  557. SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
  558. Date nowDate = new Date();
  559. Date oneMonthAfter = getMonthBefore(nowDate, -1);
  560. Date threeMonthBefore = getMonthBefore(nowDate, 3); //三个月历史记录
  561. List<PatientReservation> list = guahaoXM.GetRegList(patient, sm.format(threeMonthBefore), sm.format(oneMonthAfter));
  562. return write(200, "获取患者预约信息列表成功!", "data", list);
  563. } catch (Exception e) {
  564. return error(-1, e.getMessage());
  565. }
  566. }
  567. @RequestMapping(value = "GetPatientReservationXm", method = RequestMethod.POST)
  568. @ResponseBody
  569. @ApiOperation("获取患者预约信息单条-患者端")
  570. public String GetPatientReservationXm(@ApiParam(name = "patientCode", value = "患者编号",defaultValue = "0cc6e4562de2437ab2dbbf51a9fc3b49")
  571. @RequestParam(value = "patientCode", required = true) String patientCode,
  572. @ApiParam(name = "orgCode", value = "机构编码",defaultValue = "350211A1002")
  573. @RequestParam(value = "orgCode", required = true) String orgCode,
  574. @ApiParam(name = "regCode", value = "挂号单号",defaultValue = "9c34e255-5984-43f0-8ecf-3bbf160e3c58")
  575. @RequestParam(value = "regCode", required = true) String regCode) {
  576. try {
  577. PatientReservation obj = guahaoXM.getRegDetail(patientCode, orgCode, regCode);
  578. return write(200, "获取患者预约信息成功!", "data", obj);
  579. } catch (Exception e) {
  580. return error(-1, e.getMessage());
  581. }
  582. }
  583. }