BookingController.java 35 KB

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