BookingController.java 42 KB

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