BookingController.java 41 KB

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