BookingController.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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. // 推送消息给微信端
  278. JSONObject json = new JSONObject();
  279. json.put("first", "");
  280. json.put("toUser", p.getCode());
  281. json.put("represented",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. }
  294. // else{
  295. // JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
  296. // Patient member = (Patient) j.get("member");
  297. // if(StringUtils.isNotBlank(member.getOpenid())){
  298. // String first = (String) json.get("first");
  299. // json.remove("first");
  300. // json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
  301. // PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
  302. // }
  303. // }
  304. //发送代理人
  305. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
  306. if(jsonArray!=null&&jsonArray.length()>0){
  307. for (int i = 0;i<jsonArray.length();i++){
  308. JSONObject j = jsonArray.getJSONObject(i);
  309. Patient member = (Patient) j.get("member");
  310. if(StringUtils.isNotBlank(member.getOpenid())){
  311. JSONObject data = json;
  312. data.remove("toUser");
  313. data.put("toUser",member.getCode());
  314. String first = (String) json.get("first");
  315. data.remove("first");
  316. data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
  317. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), data);
  318. }
  319. }
  320. }
  321. //发送短信小时
  322. // 调用总部发送信息的接口
  323. //String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
  324. //JSONObject json = toJson(result);
  325. // if (json == null) {
  326. // // 发送失败
  327. // throw new Exception("短信发送失败!");
  328. // } else if (json.getInt("result") != 0) {
  329. // return json.getString("description");
  330. // } else {
  331. // //发送成功,保存到数据库
  332. // }
  333. BusinessLogs.info(BusinessLogs.BusinessType.appointment, getUID(), p.getCode(), new JSONObject(obj));
  334. return write(200, "创建挂号单成功!");
  335. } else {
  336. return error(-1, "创建挂号单失败!");
  337. }
  338. } catch (Exception e) {
  339. return error(-1, e.getMessage());
  340. }
  341. }
  342. @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
  343. @ResponseBody
  344. @ApiOperation("取消挂号单")
  345. public String CancelOrder(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
  346. @RequestParam(value = "orderId", required = true) Long orderId) {
  347. try {
  348. //获取订单信息
  349. PatientReservation obj = patientReservationService.findById(orderId);
  350. boolean re = false;
  351. if (obj != null) {
  352. String type = obj.getType();
  353. String code = obj.getCode();
  354. if (type.equals("0")) { //医护网接口
  355. re = guahaoYihu.CancelOrder(code);
  356. } else if (type.equals("1")) //厦门市民健康预约接口
  357. {
  358. re = guahaoXM.CancelOrder(code, obj.getSsc());
  359. }
  360. }
  361. if (re) {
  362. //更新状态
  363. patientReservationService.updateStatus(orderId, 0);
  364. //微信消息
  365. Patient p = patientService.findByCode(obj.getPatient());
  366. if (StringUtils.isNotEmpty(p.getOpenid())) {
  367. JSONObject json = new JSONObject();
  368. json.put("first", "");
  369. json.put("toUser", p.getCode());
  370. json.put("represented",p.getCode());//被代理人
  371. json.put("name", obj.getName());
  372. json.put("date", obj.getStartTime());
  373. json.put("doctorName", obj.getDoctorName());
  374. json.put("orgName", obj.getOrgName());
  375. json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
  376. //判断是否判定openId,有没有发则查找家人发送
  377. if(StringUtils.isNotBlank(p.getOpenid())){
  378. // 添加到发送队列
  379. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.getName(), json);
  380. }
  381. // else{
  382. // JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
  383. // Patient member = (Patient) j.get("member");
  384. // if(StringUtils.isNotBlank(member.getOpenid())){
  385. // String first = (String) json.get("first");
  386. // json.remove("first");
  387. // json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
  388. // PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
  389. // }
  390. // }
  391. //发送代理人
  392. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
  393. if(jsonArray!=null&&jsonArray.length()>0){
  394. for (int i = 0;i<jsonArray.length();i++){
  395. JSONObject j = jsonArray.getJSONObject(i);
  396. Patient member = (Patient) j.get("member");
  397. if(StringUtils.isNotBlank(member.getOpenid())){
  398. JSONObject data = json;
  399. data.remove("toUser");
  400. data.put("toUser",member.getCode());
  401. String first = (String) json.get("first");
  402. data.remove("first");
  403. data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
  404. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), data);
  405. }
  406. }
  407. }
  408. }
  409. return write(200, "取消挂号单成功!");
  410. } else {
  411. return error(-1, "取消挂号单失败!");
  412. }
  413. } catch (Exception e) {
  414. return error(-1, e.getMessage());
  415. }
  416. }
  417. /****************************************** 内网预约 ***************************************************************/
  418. /* @RequestMapping(value = "sendMessage", method = RequestMethod.POST)
  419. @ResponseBody
  420. @ApiOperation("发送短信测试")
  421. public String sendMessage()
  422. {
  423. try {
  424. //发送短信消息,调用总部发送信息的接口
  425. String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams("测试", "13559207522"), "GBK");
  426. System.out.print(result);
  427. *//*JSONObject json = toJson(result);
  428. JSONObject result = smsService.sendMsg("13559207522", "测试");
  429. if (result != null && result.getInt("result") != 0) {
  430. System.out.print("短信提醒失败!(原因:" + result.getString("description") + ")");
  431. }*//*
  432. return error(-1, "创建挂号单失败!"+result);
  433. }
  434. catch (Exception e) {
  435. return error(-1, e.getMessage());
  436. }
  437. }*/
  438. @RequestMapping(value = "CreateOrderByDoctor", method = RequestMethod.POST)
  439. @ResponseBody
  440. @ApiOperation("(内网)转诊预约挂号")
  441. public String CreateOrderByDoctor(@ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  442. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  443. @ApiParam(name = "hospitalName", value = "医院名称", defaultValue = "厦门大学附属第一医院")
  444. @RequestParam(value = "hospitalName", required = true) String hospitalName,
  445. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1011610")
  446. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  447. @ApiParam(name = "hosDeptName", value = "医院科室名称", defaultValue = "内分泌糖尿病科门诊")
  448. @RequestParam(value = "hosDeptName", required = true) String hosDeptName,
  449. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
  450. @RequestParam(value = "doctorId", required = true) String doctorId,
  451. @ApiParam(name = "doctorName", value = "医生姓名", defaultValue = "杨叔禹")
  452. @RequestParam(value = "doctorName", required = true) String doctorName,
  453. @ApiParam(name = "arrangeDate", value = "排班信息", defaultValue = "{\"sectionType\":\"p\",\"startTime\":\"2016-12-29 14:00:00\",\"endTime\":\"2016-12-29 14:08:00\"}")
  454. @RequestParam(value = "arrangeDate", required = true) String arrangeDate,
  455. @ApiParam(name = "patient", value = "患者代码", defaultValue = "01954b2ebbb24a40a05da9d2f5c94795")
  456. @RequestParam(value = "patient", required = true) String patient,
  457. @ApiParam(name = "patientName", value = "患者姓名", defaultValue = "张锦川")
  458. @RequestParam(value = "patientName", required = true) String patientName,
  459. @ApiParam(name = "cardNo", value = "身份证号码", defaultValue = "35052419880511553X")
  460. @RequestParam(value = "cardNo", required = true) String cardNo,
  461. @ApiParam(name = "clinicCard", value = "市民卡号", defaultValue = "A0601003595X")
  462. @RequestParam(value = "clinicCard", required = true) String clinicCard,
  463. @ApiParam(name = "patientPhone", value = "患者手机", defaultValue = "13559207522")
  464. @RequestParam(value = "patientPhone", required = true) String patientPhone,
  465. @ApiParam(name = "dcode", value = "代预约医生编号", defaultValue = "test00000000005")
  466. @RequestParam(value = "dcode", required = true) String dcode,
  467. @ApiParam(name = "dname", value = "代预约医生名称", defaultValue = "组2全科医生")
  468. @RequestParam(value = "dname", required = true) String dname) {
  469. try {
  470. String orderCode = guahaoXM.CreateOrderByDoctor(hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, arrangeDate, patient, patientName, cardNo, clinicCard, patientPhone, dname, dcode);
  471. //获取预约信息查询是否挂号成功
  472. PatientReservation obj = patientReservationService.findByCode(orderCode);
  473. if (obj != null) {
  474. String des = "";
  475. try {
  476. String msg = obj.getDname() + "医生已成功为您预约:" + DateUtil.dateToChinese(obj.getStartTime()) + "," + obj.getOrgName() +
  477. obj.getDeptName() + obj.getDeptName() + "医生的号源。您可直接前往医院就诊。";
  478. //发送短信消息,调用总部发送信息的接口
  479. String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, patientPhone), "GBK");
  480. System.out.print(result);
  481. JSONObject resultJson = toJson(result);
  482. if (resultJson != null && resultJson.getInt("result") != 0) {
  483. des = "短信提醒失败!(原因:"+resultJson.getString("description")+")";
  484. }
  485. //保存短信记录
  486. SMS sms = new SMS();
  487. sms.setContent(msg+des);
  488. sms.setCaptcha(null);
  489. Date date = new Date();
  490. sms.setDeadline(date);
  491. sms.setCzrq(date);
  492. sms.setMobile(patientPhone);
  493. sms.setIp(NetworkUtil.getIpAddress(request));
  494. sms.setType(6);
  495. sms.setStatus(1);
  496. smsDao.save(sms);
  497. // 推送消息给微信端
  498. Patient p = patientService.findByCode(patient);
  499. if (StringUtils.isNotEmpty(p.getOpenid())) {
  500. JSONObject json = new JSONObject();
  501. json.put("first", "");
  502. json.put("toUser", patient);
  503. json.put("represented",patient);//被代理人
  504. json.put("id", orderCode);
  505. json.put("date", obj.getStartTime());
  506. json.put("orgName", obj.getOrgName());
  507. json.put("orgCode", obj.getOrgCode());
  508. json.put("doctorName", obj.getDeptName());
  509. json.put("deptName", obj.getDeptName());
  510. json.put("remark", patientName + ",您好!\n" + msg);
  511. //判断是否判定openId,有没有发则查找家人发送
  512. if(StringUtils.isNotBlank(p.getOpenid())){
  513. // 添加到发送队列
  514. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, p.getOpenid(), patientName, json);
  515. }
  516. // else{
  517. // JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
  518. // Patient member = (Patient) j.get("member");
  519. // if(StringUtils.isNotBlank(member.getOpenid())){
  520. // String first = (String) json.get("first");
  521. // json.remove("first");
  522. // json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
  523. // PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
  524. // }
  525. // }
  526. //发送代理人
  527. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode());
  528. if(jsonArray!=null&&jsonArray.length()>0){
  529. for (int i = 0;i<jsonArray.length();i++){
  530. JSONObject j = jsonArray.getJSONObject(i);
  531. Patient member = (Patient) j.get("member");
  532. if(StringUtils.isNotBlank(member.getOpenid())){
  533. JSONObject data = json;
  534. data.remove("toUser");
  535. data.put("toUser",member.getCode());
  536. String first = (String) json.get("first");
  537. data.remove("first");
  538. data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
  539. PushMsgTask.getInstance().putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), data);
  540. }
  541. }
  542. }
  543. }
  544. else{
  545. des +=" 微信提醒失败,患者无绑定微信!";
  546. }
  547. BusinessLogs.info(BusinessLogs.BusinessType.appointment, getUID(), p.getCode(), new JSONObject(obj));
  548. }
  549. catch (Exception ex)
  550. {
  551. ex.printStackTrace();
  552. }
  553. return write(200, "创建挂号单成功!"+des,"data",obj.getId());
  554. } else {
  555. return error(-1, "创建挂号单失败!");
  556. }
  557. } catch (Exception e) {
  558. return error(-1, e.getMessage());
  559. }
  560. }
  561. @RequestMapping(value = "GetDoctorArrangeTenDay", method = RequestMethod.POST)
  562. @ResponseBody
  563. @ApiOperation("(内网)获取医生排班接口")
  564. public String GetDoctorArrangeTenDay(
  565. @ApiParam(name = "hospitalId", value = "医院ID", defaultValue = "350211A1001")
  566. @RequestParam(value = "hospitalId", required = true) String hospitalId,
  567. @ApiParam(name = "hosDeptId", value = "科室ID", defaultValue = "1011610")
  568. @RequestParam(value = "hosDeptId", required = true) String hosDeptId,
  569. @ApiParam(name = "doctorId", value = "医生ID", defaultValue = "50108")
  570. @RequestParam(value = "doctorId", required = true) String doctorId) {
  571. try {
  572. List<Map<String, Object>> list = guahaoXM.GetDoctorArrangeTenDay(hospitalId, hosDeptId, doctorId);
  573. return write(200, "获取医生排班成功!", "data", list);
  574. } catch (Exception e) {
  575. return error(-1, e.getMessage());
  576. }
  577. }
  578. /********************************************* 医生端查询 **************************************************************************/
  579. @RequestMapping(value = "GetPatientReservationList", method = {RequestMethod.POST,RequestMethod.GET})
  580. @ResponseBody
  581. @ApiOperation("获取患者预约信息列表接口-医生端")
  582. public String GetPatientReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
  583. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  584. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
  585. @RequestParam(value = "pageSize", required = false) Integer pageSize,
  586. @ApiParam(name = "patient", value = "患者编号", defaultValue = "4afdbce6194e412fbc770eb4dfbe7b00")
  587. @RequestParam(value = "patient", required = false) String patient,
  588. @ApiParam(name = "teamCode", value = "行政团队")
  589. @RequestParam(value = "teamCode", required = false) Long teamCode) {
  590. try {
  591. JSONArray list = patientReservationService.getReservationByPatient(patient, teamCode, pageIndex, pageSize);
  592. return write(200, "获取患者预约信息列表成功!", "data", list);
  593. } catch (Exception e) {
  594. return error(-1, e.getMessage());
  595. }
  596. }
  597. @RequestMapping(value = "GetDoctorReservationList", method = RequestMethod.POST)
  598. @ResponseBody
  599. @ApiOperation("获取医生代预约信息列表接口-医生端")
  600. public String GetDoctorReservation(@ApiParam(name = "pageIndex", value = "第几页", defaultValue = "1")
  601. @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
  602. @ApiParam(name = "pageSize", value = "每页记录数", defaultValue = "10")
  603. @RequestParam(value = "pageSize", required = false) Integer pageSize,
  604. @ApiParam(name = "doctor", value = "医生编号", defaultValue = "shiliuD20160926005")
  605. @RequestParam(value = "doctor", required = false) String doctor) {
  606. try {
  607. List<Map<String,String>> list = patientReservationService.getReservationByDoctor(doctor, pageIndex, pageSize);
  608. return write(200, "获取患者预约信息列表成功!", "data", list);
  609. } catch (Exception e) {
  610. return error(-1, e.getMessage());
  611. }
  612. }
  613. @RequestMapping(value = "GetPatientReservation", method = RequestMethod.POST)
  614. @ResponseBody
  615. @ApiOperation("获取患者预约信息单条-医生端")
  616. public String GetPatientReservation(@ApiParam(name = "orderId", value = "订单id", defaultValue = "9")
  617. @RequestParam(value = "orderId", required = true) Long orderId) {
  618. try {
  619. PatientReservation obj = patientReservationService.findById(orderId);
  620. return write(200, "获取患者预约信息成功!", "data", obj);
  621. }
  622. catch (Exception e) {
  623. return error(-1, e.getMessage());
  624. }
  625. }
  626. @RequestMapping(value = "CountReservationByDoctorForPatient", method = RequestMethod.POST)
  627. @ResponseBody
  628. @ApiOperation("获取医生为患者预约的总数")
  629. public String CountReservationByDoctorForPatient(@ApiParam(name = "doctor", value = "医生编号")
  630. @RequestParam(value = "doctor", required = true) String doctor,
  631. @ApiParam(name = "patient", value = "患者编号")
  632. @RequestParam(value = "patient", required = true) String patient) {
  633. try {
  634. Long obj = patientReservationService.countReservationByDoctorForPatient(doctor, patient);
  635. return write(200, "获取患者预约信息成功!", "data", obj);
  636. } catch (Exception e) {
  637. return error(-1, e.getMessage());
  638. }
  639. }
  640. /*************************************** 患者端查询 ******************************************************************/
  641. @RequestMapping(value = "GetRegList", method = RequestMethod.POST)
  642. @ResponseBody
  643. @ApiOperation("获取患者预约信息列表接口--患者端")
  644. public String GetRegList(@ApiParam(name = "patient", value = "患者编号", defaultValue = "0cc6e4562de2437ab2dbbf51a9fc3b49")
  645. @RequestParam(value = "patient", required = false) String patient) {
  646. try {
  647. SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
  648. Date nowDate = new Date();
  649. Date oneMonthAfter = getMonthBefore(nowDate, -1);
  650. Date threeMonthBefore = getMonthBefore(nowDate, 3); //三个月历史记录
  651. List<PatientReservation> list = guahaoXM.GetRegList(patient, sm.format(threeMonthBefore), sm.format(oneMonthAfter), threeMonthBefore, oneMonthAfter);
  652. return write(200, "获取患者预约信息列表成功!", "data", list);
  653. } catch (Exception e) {
  654. return error(-1, e.getMessage());
  655. }
  656. }
  657. @RequestMapping(value = "GetPatientReservationXm", method = RequestMethod.POST)
  658. @ResponseBody
  659. @ApiOperation("获取患者预约信息单条-患者端")
  660. public String GetPatientReservationXm(@ApiParam(name = "patientCode", value = "患者编号",defaultValue = "0cc6e4562de2437ab2dbbf51a9fc3b49")
  661. @RequestParam(value = "patientCode", required = true) String patientCode,
  662. @ApiParam(name = "orgCode", value = "机构编码",defaultValue = "350211A1002")
  663. @RequestParam(value = "orgCode", required = true) String orgCode,
  664. @ApiParam(name = "regCode", value = "挂号单号",defaultValue = "9c34e255-5984-43f0-8ecf-3bbf160e3c58")
  665. @RequestParam(value = "regCode", required = true) String regCode) {
  666. try {
  667. PatientReservation obj = guahaoXM.getRegDetail(patientCode, orgCode, regCode);
  668. return write(200, "获取患者预约信息成功!", "data", obj);
  669. } catch (Exception e) {
  670. return error(-1, e.getMessage());
  671. }
  672. }
  673. }