BookingController.java 38 KB

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