BookingController.java 38 KB

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