RehabilitationPlanService.java 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. package com.yihu.rehabilitation.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.fasterxml.jackson.core.type.TypeReference;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.yihu.fastdfs.FastDFSUtil;
  6. import com.yihu.jw.doctor.dao.BaseDoctorDao;
  7. import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
  8. import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
  9. import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
  10. import com.yihu.jw.entity.base.patient.BasePatientDO;
  11. import com.yihu.jw.entity.base.team.BaseTeamMemberDO;
  12. import com.yihu.jw.entity.base.wx.WxWechatDO;
  13. import com.yihu.jw.entity.door.SignFamily;
  14. import com.yihu.jw.entity.hospital.doctor.Frequency;
  15. import com.yihu.jw.entity.patient.Message;
  16. import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
  17. import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
  18. import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationOperateRecordsDO;
  19. import com.yihu.jw.entity.util.TransforSqlUtl;
  20. import com.yihu.jw.file_upload.FileUploadService;
  21. import com.yihu.jw.org.dao.BaseOrgDao;
  22. import com.yihu.jw.patient.dao.BasePatientDao;
  23. import com.yihu.jw.rehabilitation.RehabilitationOperateRecordsDao;
  24. import com.yihu.jw.restmodel.iot.common.UploadVO;
  25. import com.yihu.jw.restmodel.web.Envelop;
  26. import com.yihu.jw.restmodel.web.MixEnvelop;
  27. import com.yihu.jw.restmodel.web.ObjEnvelop;
  28. import com.yihu.jw.rm.specialist.SpecialistMapping;
  29. import com.yihu.jw.sign.dao.MessagesDao;
  30. import com.yihu.jw.team.BaseDoctorTeamMemberDao;
  31. import com.yihu.jw.util.common.QrcodeUtil;
  32. import com.yihu.jw.util.date.DateUtil;
  33. import com.yihu.jw.utils.hibernate.HibenateUtils;
  34. import com.yihu.jw.wechat.dao.WechatDao;
  35. import com.yihu.mysql.query.BaseJpaService;
  36. import com.yihu.rehabilitation.dao.FrequencyDao;
  37. import com.yihu.rehabilitation.dao.PatientRehabilitationPlanDao;
  38. import com.yihu.rehabilitation.dao.RehabilitationDetailDao;
  39. import com.yihu.rehabilitation.dao.SignFamilyDao;
  40. import com.yihu.utils.network.HttpResponse;
  41. import com.yihu.utils.network.HttpUtils;
  42. import com.yihu.utils.security.MD5;
  43. import org.apache.commons.collections.map.HashedMap;
  44. import org.apache.commons.lang3.StringUtils;
  45. import org.json.JSONArray;
  46. import org.json.JSONObject;
  47. import org.springframework.beans.factory.annotation.Autowired;
  48. import org.springframework.beans.factory.annotation.Value;
  49. import org.springframework.jdbc.core.JdbcTemplate;
  50. import org.springframework.mock.web.MockMultipartFile;
  51. import org.springframework.stereotype.Service;
  52. import org.springframework.transaction.annotation.Transactional;
  53. import java.io.InputStream;
  54. import java.text.ParseException;
  55. import java.text.SimpleDateFormat;
  56. import java.util.*;
  57. /**
  58. * Created by humingfen on 2018/8/22.
  59. */
  60. @Service
  61. @Transactional
  62. public class RehabilitationPlanService extends BaseJpaService<PatientRehabilitationPlanDO, PatientRehabilitationPlanDao> {
  63. @Value("${specialist.url}")
  64. private String specialistUrl;
  65. @Autowired
  66. private SpecialistEvaluateSevice specialistEvaluateSevice;
  67. @Autowired
  68. private SignFamilyDao signFamilyDao;
  69. @Autowired
  70. private MessagesDao messageDao;
  71. @Autowired
  72. private BasePatientDao patientDao;
  73. @Autowired
  74. private JdbcTemplate jdbcTemplate;
  75. @Autowired
  76. private FrequencyDao frequencyDao;
  77. @Autowired
  78. private BaseDoctorDao doctorDao;
  79. @Autowired
  80. private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
  81. @Autowired
  82. private ObjectMapper objectMapper;
  83. @Autowired
  84. private RehabilitationDetailDao rehabilitationDetailDao;
  85. @Value("${neiwang.enable}")
  86. private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传
  87. @Autowired
  88. private FastDFSUtil fastDFSUtil;
  89. @Value("${fastDFS.fastdfs_file_url}")
  90. private String fastdfs_file_url;
  91. @Autowired
  92. FileUploadService fileUploadService;
  93. @Value("${testPattern.sign}")
  94. private String isClose;
  95. @Value("${testPattern.remote_inner_url}")
  96. private String remote_inner_url;
  97. @Autowired
  98. private WechatDao wechatDao;
  99. @Value("${wechat.id}")
  100. private String wxId;
  101. @Autowired
  102. private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
  103. @Autowired
  104. private BaseOrgDao baseOrgDao;
  105. @Autowired
  106. private BaseDoctorTeamMemberDao baseDoctorTeamMemberDao;
  107. @Autowired
  108. private BaseDoctorHospitalDao baseDoctorHospitalDao;
  109. @Autowired
  110. private HibenateUtils hibenateUtils;
  111. public Envelop updatePatientImgById(String planId, String patientImg) {
  112. if(patientRehabilitationPlanDao.updatePatientImgById(planId,patientImg) > 0){
  113. return Envelop.getSuccess(SpecialistMapping.api_success);
  114. }
  115. return Envelop.getError("更新失败!");
  116. }
  117. /*public JSONArray findTemplateInfo(String doctor, String patient) throws Exception {
  118. Map<String, Object> param = new HashedMap();
  119. Long adminTeamId = null;
  120. AdminTeam team = teamService.findByLeaderCode(doctor);
  121. if(StringUtils.isBlank(patient)){
  122. adminTeamId = team.getId();
  123. param.put("adminTeamCode", adminTeamId);
  124. }else {
  125. param.put("doctor", doctor);
  126. param.put("patient", patient);
  127. }
  128. HttpResponse response = null;
  129. try {
  130. response = HttpUtils.doGet(specialistUrl + "svr-specialist/findRehabilitationPlanTemplate", param);
  131. } catch (Exception e) {
  132. e.printStackTrace();
  133. }
  134. JSONObject rs = new JSONObject(response.getContent());
  135. if ("success".equals(rs.getString("message"))) {
  136. return rs.getJSONArray("detailModelList");
  137. }
  138. throw new Exception("请求获取模板列表失败!");
  139. }*/
  140. public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId,String createUser,String createUserName) {
  141. for(RehabilitationDetailDO detail : details) {
  142. /*List<String> list = new ArrayList<>();
  143. list.add(detail.getHospitalServiceItemId());
  144. HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0);
  145. detail.setHospital(hospitalServiceItemDO.getHospital());
  146. detail.setHospitalName(hospitalServiceItemDO.getHospitalName());
  147. detail.setExpense(hospitalServiceItemDO.getExpense());*/
  148. detail.setPlanId(planId);
  149. detail.setCreateTime(new Date());
  150. detail.setStatus(0);
  151. detail.setUpdateTime(new Date());
  152. detail.setCreateUser(createUser);
  153. detail.setCreateUserName(createUserName);
  154. }
  155. return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
  156. }
  157. //code,timeType,executeTimes
  158. public String createRehabilitationPlan(String json, BaseDoctorDO doctor) throws Exception {
  159. JSONObject object = new JSONObject(json);
  160. String patient = object.getString("patient");
  161. BasePatientDO patientDo = null;
  162. if (!StringUtils.isNoneBlank(patient)){
  163. BasePatientDO basePatientDO = new BasePatientDO();
  164. basePatientDO.setName(object.getString("patientName"));
  165. basePatientDO.setIdcard(object.getString("idCard"));
  166. basePatientDO.setMobile(object.getString("mobile"));
  167. patientDo = saveUnSignPatient(basePatientDO);
  168. }else {
  169. patientDo = patientDao.findById(patient);
  170. }
  171. String patientName="";
  172. if(patientDo!=null){
  173. patientName = patientDo.getName();
  174. }
  175. JSONArray array = object.getJSONArray("detail");
  176. for (int z=0;z<array.length();z++){
  177. JSONObject jsonObject = array.getJSONObject(z);
  178. Long timeType = jsonObject.getLong("timeType");
  179. Frequency frequency = frequencyDao.findByCode(jsonObject.getString("frequencyCode"));
  180. String executeTimes = jsonObject.getString("executeTimes");
  181. String[] executeTime = executeTimes.split(",");
  182. List<String> list = new ArrayList<>();
  183. if (StringUtils.isNoneBlank(executeTimes)){
  184. for (int i=0;i<executeTime.length;i++){
  185. List<String> times = getFrequencyDate(frequency.getCode(),executeTime[i],frequency.getUnit(),frequency.getTime(),timeType);
  186. for (int j=0;j<times.size();j++){
  187. if (list!=null&&list.size()!=0){
  188. if (!list.contains(times.get(j))){
  189. list.add(times.get(j));
  190. }
  191. }else {
  192. list.add(times.get(j));
  193. }
  194. }
  195. }
  196. StringBuffer buffer = new StringBuffer();
  197. if(list!=null&&list.size()!=0){
  198. for (int i=0;i<list.size();i++){
  199. buffer.append(list.get(i)+",");
  200. }
  201. if (StringUtils.isNoneBlank(buffer)){
  202. buffer.deleteCharAt(buffer.length()-1);
  203. }
  204. }
  205. jsonObject.put("executeTime",buffer);
  206. }
  207. jsonObject.remove("executeTimes");
  208. }
  209. object.put("createUser", doctor.getId());
  210. object.put("createUserName", doctor.getName());
  211. String planDetails = array.toString();
  212. objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm"));
  213. List<RehabilitationDetailDO> details = objectMapper.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
  214. PatientRehabilitationPlanDO planDO = objectMapper.readValue(json.toString(), PatientRehabilitationPlanDO.class);
  215. planDO.setCreateUser(doctor.getId());
  216. planDO.setCreateUserName(doctor.getName());
  217. planDO = createPatientRehabilitationPlan(planDO);
  218. details = createRehabilitationDetail(details, planDO.getId(),doctor.getId(),doctor.getName());
  219. //康复计划创建完给执行者发送消息
  220. String planId = null;
  221. HashSet set = new HashSet();
  222. for ( RehabilitationDetailDO rehabilitationDetailDO : details) {
  223. if (!set.contains(rehabilitationDetailDO.getDoctor())) {
  224. set.add(rehabilitationDetailDO.getDoctor());
  225. planId = rehabilitationDetailDO.getPlanId();
  226. Message message = new Message();
  227. message.setSender(doctor.getId());
  228. message.setType(19);
  229. message.setRelationCode(rehabilitationDetailDO.getPlanId());
  230. message.setReceiver(rehabilitationDetailDO.getDoctor());
  231. message.setReason(doctor.getName());
  232. specialistEvaluateSevice.sendMessage(message, rehabilitationDetailDO.getHospital(), patient, null,null);
  233. //pushMsgTask.put(rehabilitationDetailDO.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", "");
  234. }
  235. }
  236. SignFamily signFamily = signFamilyDao.findByPatient(patient);
  237. //推送消息到IM
  238. if (signFamily != null && !set.contains(signFamily.getDoctor())) {
  239. //pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", "");
  240. }
  241. return planId;
  242. }
  243. public MixEnvelop<String,String> createServiceQrCode(String planDetailId, String doctorCode) throws Exception{
  244. //更新到康复计划居民关系表中
  245. Map<String, Object> param = new HashedMap();
  246. String fileUrl = "";
  247. String sql ="SELECT service_qr_code FROM wlyy_specialist.wlyy_rehabilitation_plan_detail where id='"+planDetailId+"'";
  248. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  249. if(list!=null && list.size()>0){
  250. fileUrl = String.valueOf(list.get(0).get("service_qr_code"));
  251. }
  252. if (StringUtils.isEmpty(fileUrl) || "null".equals(fileUrl)){
  253. //生成二维码图片
  254. WxWechatDO wxWechatDO = wechatDao.findById(wxId);
  255. String appId="";
  256. String wechat_base_url="";
  257. if (wxWechatDO!=null){
  258. appId=wxWechatDO.getAppId();
  259. wechat_base_url=wxWechatDO.getBaseUrl();
  260. }
  261. String contentJsonStr="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wechat_base_url+"/wx/html/kfgl/html/confirm-service.html"+"?paramStr="+planDetailId+","+doctorCode+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  262. InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
  263. UploadVO uploadVO = new UploadVO();
  264. String originalFilename ="plan_service_qrcode" + System.currentTimeMillis()+".png";
  265. if (isClose.equalsIgnoreCase("1")){
  266. Map<String, Object> map = fileUploadService.uploadImg(new MockMultipartFile(originalFilename,originalFilename,"", ipt));
  267. uploadVO.setFullUri(map.get("accessory").toString());
  268. }else if(isClose.equals("2")){
  269. //内网上传
  270. String rs = fileUploadService.request(remote_inner_url,new MockMultipartFile(originalFilename,originalFilename,"", ipt),null);
  271. com.alibaba.fastjson.JSONObject json = JSON.parseObject(rs);
  272. uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
  273. }else {
  274. // 得到文件的完整名称 xxx.txt
  275. /*InputStream inputStream = ipt;*/
  276. uploadVO = fileUploadService.uploadStream(ipt,originalFilename,fastdfs_file_url);
  277. }
  278. fileUrl = uploadVO.getFullUri();
  279. }
  280. System.out.println("服务码-----------1"+fileUrl);
  281. String sqlUpdate = "update wlyy_rehabilitation_plan_detail set service_qr_code='" + fileUrl + "' where id='" + planDetailId + "'";
  282. jdbcTemplate.update(sqlUpdate);
  283. return MixEnvelop.getSuccess("获取二维码成功!",fileUrl);
  284. }
  285. public Map<String,Object> checkAfterQrCode(String planDetailId,String patietCode)throws Exception{
  286. Map<String,Object> map = new HashedMap();
  287. int result = 0;
  288. String name= "";
  289. String sql ="SELECT p.patient,p.name FROM `wlyy_rehabilitation_plan_detail` pd LEFT JOIN wlyy_patient_rehabilitation_plan p ON pd.plan_id = p.id WHERE pd.id='"+planDetailId+"'";
  290. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  291. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  292. if (list!=null && list.size()>0){
  293. if (String.valueOf(list.get(0).get("patient")).equals(patietCode)){
  294. result =200;
  295. }else {
  296. result = -1;
  297. name=String.valueOf(list.get(0).get("name"));
  298. }
  299. }else {
  300. result = -10000;
  301. }
  302. map.put("code",result);
  303. if (StringUtils.isNotBlank(name)){
  304. map.put("name",name);
  305. }
  306. return map;
  307. }
  308. public PatientRehabilitationPlanDO createPatientRehabilitationPlan(PatientRehabilitationPlanDO planDO) {
  309. planDO.setCreateTime(new Date());
  310. planDO.setStatus(1);
  311. planDO.setUpdateTime(new Date());
  312. return patientRehabilitationPlanDao.save(planDO);
  313. }
  314. public List<String> getFrequencyDate(String code,String date,String unit,String time,Long timeType) throws ParseException {
  315. List<String> list = new ArrayList<>();
  316. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  317. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  318. String nowDate = date+":00";
  319. Date date6 = DateUtil.strToDateLong(nowDate);
  320. String date9 = sdf.format(date6)+" 09:00:00";//白天
  321. String date21 = sdf.format(date6)+" 21:00:00";//白天
  322. String date9s = DateUtil.getNextDay(date6,1)+" 09:00:00";//晚上
  323. Calendar calendar = Calendar.getInstance();
  324. if (unit.equalsIgnoreCase("D")&&!code.equalsIgnoreCase("qod")){
  325. String[] str = time.split(",");
  326. for (int i=0;i<str.length;i++){
  327. Date date1 = sdf.parse(date);
  328. calendar.setTime(date1);
  329. String lastDay = sdf.format(calendar.getTime()) + " "+str[i];
  330. list.add(lastDay);
  331. }
  332. }else if (unit.equalsIgnoreCase("D")&&code.equalsIgnoreCase("qod")){
  333. Date date1 = sdf.parse(date);
  334. calendar.setTime(date1);
  335. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) +1);
  336. String lastDay = sdf.format(calendar.getTime()) + " "+time;
  337. list.add(lastDay);
  338. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q0.5h")){
  339. Date date1 = sdf.parse(date);
  340. calendar.setTime(date1);
  341. String endTime = null;
  342. String lastDay = null;
  343. if (timeType == 0){
  344. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  345. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  346. }else if ( timeType == 1){
  347. lastDay = date9;
  348. endTime = date21;
  349. }else if (timeType == 2){
  350. lastDay = date21;
  351. endTime = date9s;
  352. }
  353. Date date2 = sdf1.parse(lastDay);
  354. Date date3 = sdf1.parse(endTime);
  355. Long time1 = date2.getTime();
  356. for (int i=0;i<47;i++){
  357. time1 += 30*60*1000;
  358. String day = sdf1.format(time1);
  359. Date date4 = sdf1.parse(day);
  360. if (date4.compareTo(date3)==-1 || date4.compareTo(date3) == 0){
  361. list.add(day);
  362. }
  363. }
  364. }else if (unit.equalsIgnoreCase("H")&& code.equalsIgnoreCase("q2h")){
  365. Date date1 = sdf.parse(date);
  366. calendar.setTime(date1);
  367. /* String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";*/
  368. String endTime = null;
  369. String lastDay = null;
  370. if (timeType == 0){
  371. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  372. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  373. }else if ( timeType == 1){
  374. lastDay = date9;
  375. endTime = date21;
  376. }else if (timeType == 2){
  377. lastDay = date21;
  378. endTime = date9s;
  379. }
  380. Date date2 = sdf1.parse(lastDay);
  381. Date date3 = sdf1.parse(endTime);
  382. calendar.setTime(date2);
  383. for (int i=0;i<11;i++){
  384. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+2);
  385. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  386. System.out.print(sdf1.format(calendar.getTime()));
  387. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  388. list.add(sdf1.format(calendar.getTime()));
  389. }
  390. }
  391. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q3h")){
  392. Date date1 = sdf.parse(date);
  393. calendar.setTime(date1);
  394. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  395. String endTime = null;
  396. String lastDay = null;
  397. if (timeType == 0){
  398. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  399. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  400. }else if ( timeType == 1){
  401. lastDay = date9;
  402. endTime = date21;
  403. }else if (timeType == 2){
  404. lastDay = date21;
  405. endTime = date9s;
  406. }
  407. Date date2 = sdf1.parse(lastDay);
  408. Date date3 = sdf1.parse(endTime);
  409. calendar.setTime(date2);
  410. for (int i=0;i<7;i++){
  411. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+3);
  412. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  413. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  414. list.add(sdf1.format(calendar.getTime()));
  415. }
  416. }
  417. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q4h")){
  418. Date date1 = sdf.parse(date);
  419. calendar.setTime(date1);
  420. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  421. String endTime = null;
  422. String lastDay = null;
  423. if (timeType == 0){
  424. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  425. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  426. }else if ( timeType == 1){
  427. lastDay = date9;
  428. endTime = date21;
  429. }else if (timeType == 2){
  430. lastDay = date21;
  431. endTime = date9s;
  432. }
  433. Date date2 = sdf1.parse(lastDay);
  434. Date date3 = sdf1.parse(endTime);
  435. calendar.setTime(date2);
  436. for (int i=0;i<5;i++){
  437. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+4);
  438. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  439. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  440. list.add(sdf1.format(calendar.getTime()));
  441. }
  442. }
  443. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("qh")){
  444. Date date1 = sdf.parse(date);
  445. calendar.setTime(date1);
  446. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  447. String endTime = null;
  448. String lastDay = null;
  449. if (timeType == 0){
  450. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  451. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  452. }else if ( timeType == 1){
  453. lastDay = date9;
  454. endTime = date21;
  455. }else if (timeType == 2){
  456. lastDay = date21;
  457. endTime = date9s;
  458. }
  459. Date date2 = sdf1.parse(lastDay);
  460. Date date3 = sdf1.parse(endTime);
  461. calendar.setTime(date2);
  462. for (int i=0;i<23;i++){
  463. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+1);
  464. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  465. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  466. list.add(sdf1.format(calendar.getTime()));
  467. }
  468. }
  469. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_1")){
  470. String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
  471. Date date1 = new Date();
  472. String date3 = sdf1.format(date1);
  473. if (date2.compareTo(date3)==1){
  474. list.add(date2);
  475. }
  476. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_2")){
  477. String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
  478. Date date1 = new Date();
  479. String date3 = sdf1.format(date1);
  480. if (date2.compareTo(date3)==1){
  481. list.add(date2);
  482. }
  483. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_3")){
  484. String date2 = DateUtil.getWeek(date,"3")+" 08:00:00";
  485. Date date1 = new Date();
  486. String date3 = sdf1.format(date1);
  487. if (date2.compareTo(date3)==1){
  488. list.add(date2);
  489. }
  490. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_4")){
  491. String date2 = DateUtil.getWeek(date,"4")+" 08:00:00";
  492. Date date1 = new Date();
  493. String date3 = sdf1.format(date1);
  494. if (date2.compareTo(date3)==1){
  495. list.add(date2);
  496. }
  497. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_5")){
  498. String date2 = DateUtil.getWeek(date,"5")+" 08:00:00";
  499. Date date1 = new Date();
  500. String date3 = sdf1.format(date1);
  501. if (date2.compareTo(date3)==1){
  502. list.add(date2);
  503. }
  504. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_6")){
  505. String date2 = DateUtil.getWeek(date,"6")+" 08:00:00";
  506. Date date1 = new Date();
  507. String date3 = sdf1.format(date1);
  508. if (date2.compareTo(date3)==1){
  509. list.add(date2);
  510. }
  511. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_7")){
  512. String date2 = DateUtil.getWeek(date,"7")+" 08:00:00";
  513. Date date1 = new Date();
  514. String date3 = sdf1.format(date1);
  515. if (date2.compareTo(date3)==1){
  516. list.add(date2);
  517. }
  518. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw135")){
  519. String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
  520. String date4 = DateUtil.getWeek(date,"3")+" 08:00:00";
  521. String date5 = DateUtil.getWeek(date,"5")+" 08:00:00";
  522. Date date1 = new Date();
  523. String date3 = sdf1.format(date1);
  524. if (date2.compareTo(date3)==1){
  525. list.add(date2);
  526. }
  527. if (date4.compareTo(date3)==1){
  528. list.add(date2);
  529. }
  530. if (date5.compareTo(date3) == 1){
  531. list.add(date2);
  532. }
  533. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw246")){
  534. String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
  535. String date4 = DateUtil.getWeek(date,"4")+" 08:00:00";
  536. String date5 = DateUtil.getWeek(date,"6")+" 08:00:00";
  537. Date date1 = new Date();
  538. String date3 = sdf1.format(date1);
  539. if (date2.compareTo(date3)==1){
  540. list.add(date2);
  541. }
  542. if (date4.compareTo(date3)==1){
  543. list.add(date2);
  544. }
  545. if (date5.compareTo(date3) == 1){
  546. list.add(date2);
  547. }
  548. }
  549. return list;
  550. }
  551. public String deleteTemplate(String templateId) {
  552. Map<String, Object> param = new HashedMap();
  553. param.put("id", templateId);
  554. HttpResponse response = null;
  555. try {
  556. response = HttpUtils.doPost(specialistUrl + "svr-specialist/deleteRehabilitationPlanTemplate", param);
  557. } catch (Exception e) {
  558. e.printStackTrace();
  559. }
  560. JSONObject rs = new JSONObject(response.getContent());
  561. return rs.getString("message");
  562. }
  563. /**
  564. * 更新计划的状态
  565. * @param planId
  566. * @param status
  567. * @throws Exception
  568. */
  569. public void updatePlanStatusById(String planId, Integer status,String abortReason) throws Exception{
  570. Map<String, Object> param = new HashedMap();
  571. param.put("planId", planId);
  572. param.put("status", status);
  573. param.put("abortReason",abortReason);
  574. HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePlanStatusById", param);
  575. JSONObject result = new JSONObject(response.getContent());
  576. if (result.getInt("status")==200 && status==0){
  577. List<Message> messageList = new ArrayList<>();
  578. Map<String,String> recieveMap = new HashMap<>();
  579. JSONObject jsonObject =result.getJSONObject("obj");
  580. String patientCode = jsonObject.getString("patient");
  581. String patientName = jsonObject.getString("name");
  582. String diseaseName = jsonObject.getString("diseaseName");
  583. String createDoctorCode = jsonObject.getString("createUser");
  584. JSONArray detailModelList = result.getJSONArray("detailModelList");
  585. for (Object obj : detailModelList) {
  586. JSONObject detail = (JSONObject) obj;
  587. String doctor = detail.getString("doctor");
  588. if (!createDoctorCode.equals(doctor)){
  589. if (!recieveMap.containsKey(doctor)){
  590. recieveMap.put(doctor,detail.getString("doctorName"));
  591. }
  592. }
  593. }
  594. SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
  595. if (signFamily!=null){
  596. if (!recieveMap.containsKey(signFamily.getDoctor())){
  597. recieveMap.put(signFamily.getDoctor(),signFamily.getDoctorName());
  598. }
  599. }
  600. for (Map.Entry<String,String> entry : recieveMap.entrySet()){
  601. //推送消息到IM
  602. //pushMsgTask.put(entry.getKey(),"20", "康复计划中止消息", "您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因", "");
  603. Message message = initMessage(patientName,entry.getKey(),entry.getValue(),"system","system","康复计划-中止提醒","您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因。",planId,29);
  604. messageList.add(message);
  605. }
  606. messageDao.save(messageList);
  607. /*Message message = new Message();
  608. message.setCzrq(new Date());
  609. message.setCreateTime(new Date());
  610. message.setContent("您的"+patientName+"签约居民,已中止康复计划,点击查看原因。");
  611. message.setRead(1);//设置未读
  612. if (signFamily!=null){
  613. message.setReceiver(signFamily.getDoctor());//设置接受医生的code
  614. message.setReceiverName(signFamily.getDoctorName());
  615. }
  616. message.setSender("system");//设置发送的用户
  617. message.setSenderName("system");
  618. message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
  619. message.setSenderPhoto("");
  620. message.setTitle("康复计划-中止提醒");
  621. message.setType(29);//康复计划中止消息提醒
  622. message.setReadonly(1);//是否只读消息
  623. message.setRelationCode(planId);
  624. message.setOver("1");//未处理
  625. message.setState(1);
  626. message.setData("");
  627. message.setDel("1");*/
  628. //推送消息到IM
  629. // pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划中止消息", "您的"+patientName+"签约居民,已中止康复计划,点击查看原因", "");
  630. }
  631. if(result.getInt("status")!=200){
  632. throw new Exception("请求微服务失败!");
  633. }
  634. }
  635. private Message initMessage(String patientName,String doctor,String doctorName,String sender,String senderName,String title,String content,String relatioenCode,int type){
  636. Message message = new Message();
  637. message.setCzrq(new Date());
  638. message.setCreateTime(new Date());
  639. message.setContent("您的服务居民"+patientName+",已中止康复计划,点击查看原因。");
  640. message.setRead(1);//设置未读
  641. message.setReceiver(doctor);//设置接受医生的code
  642. message.setReceiverName(doctorName);
  643. message.setSender(sender);//设置发送的用户
  644. message.setSenderName(senderName);
  645. message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
  646. message.setSenderPhoto("");
  647. message.setTitle(title);
  648. message.setType(type);//康复计划中止消息提醒
  649. message.setReadonly(1);//是否只读消息
  650. message.setRelationCode(relatioenCode);
  651. message.setOver("0");//未处理
  652. message.setState(1);
  653. message.setData("");
  654. message.setDel("1");
  655. return message;
  656. }
  657. public JSONObject getServiceItemsAfterStop(String planId)throws Exception{
  658. Map<String, Object> param = new HashedMap();
  659. param.put("planId", planId);
  660. HttpResponse response = HttpUtils.doGet(specialistUrl + "svr-specialist/getServiceItemsAfterStop", param);
  661. JSONObject result = new JSONObject(response.getContent());
  662. JSONObject jsonObject = new JSONObject();
  663. if(result.getInt("status")!=200){
  664. throw new Exception("请求微服务失败!");
  665. }
  666. if (result.getInt("status")==200){
  667. jsonObject = result.getJSONObject("obj");
  668. JSONArray jsonArray = jsonObject.getJSONArray("serviceList");
  669. if (jsonArray!=null && jsonArray.length()>0){
  670. jsonObject.put("patientName",jsonArray.getJSONObject(0).get("name"));
  671. jsonObject.put("abortTime",jsonArray.getJSONObject(0).get("abort_time"));
  672. jsonObject.put("hospitalName",jsonArray.getJSONObject(0).get("hospital_name"));
  673. jsonObject.put("abortReason",jsonArray.getJSONObject(0).get("abort_reason"));
  674. String patientCode = String.valueOf(jsonArray.getJSONObject(0).get("patient"));
  675. jsonObject.put("patientCode", patientCode);
  676. jsonObject.put("disease_name", jsonArray.getJSONObject(0).get("disease_name"));
  677. jsonObject.put("create_time", jsonArray.getJSONObject(0).get("create_time"));
  678. jsonObject.put("patient_img", jsonArray.getJSONObject(0).get("patient_img"));
  679. BasePatientDO patient = patientDao.findById(patientCode);
  680. if (patient!=null){
  681. jsonObject.put("openid", patient.getOpenid());
  682. jsonObject.put("ssc",patient.getSsc());
  683. jsonObject.put("mobile",patient.getMobile());
  684. }
  685. }
  686. }
  687. return jsonObject;
  688. }
  689. /**
  690. * 更新居民签名照/证件照
  691. * @param planId
  692. * @throws Exception
  693. *//*
  694. public void updatePatientImgById(String planId, String patientImg) throws Exception {
  695. Map<String, Object> param = new HashedMap();
  696. param.put("planId", planId);
  697. param.put("patientImg", patientImg);
  698. HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePatientImgById", param);
  699. JSONObject result = new JSONObject(response.getContent());
  700. if(result.getInt("status")!=200){
  701. throw new Exception("请求微服务失败!");
  702. }
  703. }*/
  704. public void sendWxTemplate(String accessToken, String planId, String doctorCode, JSONObject jsonObject) {
  705. BaseDoctorDO d = doctorDao.findById(doctorCode);
  706. JSONObject json = new JSONObject();
  707. String patient = jsonObject.getString("patientCode");
  708. String patientName = jsonObject.get("patientName") + "";
  709. json.put("first", patientName + "您好,您有一个康复计划已完成,请确认接收。");
  710. json.put("toUser", patient);
  711. json.put("represented", patient);//被代理人
  712. json.put("keyword1", jsonObject.get("disease_name") + "康复计划");
  713. json.put("keyword2", d.getName());
  714. json.put("keyword3", DateUtil.dateToStr(new Date ((Long) jsonObject.get("create_time")), "yyyy/MM/dd") + "-" + DateUtil.dateToStr(new Date(), "yyyy/MM/dd"));
  715. json.put("remark", "完成的康复项清单已发送给您,点击此消息可查看。");
  716. json.put("planId", planId);
  717. if (!jsonObject.isNull("openid")) {
  718. //pushMsgTask.putWxMsg(accessToken, 27, jsonObject.get("openid") + "", patientName, json);
  719. }/*else {
  720. try {
  721. //发送代理人
  722. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
  723. if (jsonArray != null && jsonArray.length() > 0) {
  724. Patient p = patientDao.findByCode(patient);
  725. for (int i = 0; i < jsonArray.length(); i++) {
  726. JSONObject j = jsonArray.getJSONObject(i);
  727. Patient member = (Patient) j.get("member");
  728. JSONObject data = json;
  729. data.remove("toUser");
  730. data.put("toUser", member.getCode());
  731. data.remove("first");
  732. json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()));
  733. pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 27, member.getOpenid(), p.getName(), data);
  734. }
  735. }
  736. } catch (Exception e) {
  737. e.printStackTrace();
  738. }
  739. }*/
  740. }
  741. public BasePatientDO saveUnSignPatient(BasePatientDO basepatientDO){
  742. basepatientDO.setDel("1");
  743. basepatientDO.setLocked(0);
  744. basepatientDO.setEnabled(1);
  745. String salt = randomString(5);
  746. basepatientDO.setSalt(salt);
  747. basepatientDO.setPassword(MD5.md5Hex(basepatientDO.getIdcard().substring(12,18) + "{" + salt + "}"));
  748. basepatientDO=patientDao.save(basepatientDO);
  749. return basepatientDO;
  750. }
  751. public RehabilitationOperateRecordsDO saveRehabilitationRecord(RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO){
  752. RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(rehabilitationOperateRecordsDO.getRehabilitationDetailId());
  753. if (!StringUtils.isNoneBlank(rehabilitationOperateRecordsDO.getId())){
  754. rehabilitationOperateRecordsDO.setId(getCode());
  755. }
  756. if (rehabilitationDetailDO.getExecuteTime()!=null){
  757. rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
  758. }
  759. rehabilitationOperateRecordsDO.setCompleteTime(new Date());
  760. rehabilitationOperateRecordsDO.setCreateTime(new Date());
  761. rehabilitationOperateRecordsDO.setUpdateTime(new Date());
  762. rehabilitationOperateRecordsDO.setStatus(rehabilitationOperateRecordsDO.getStatus());
  763. if (StringUtils.isEmpty(rehabilitationOperateRecordsDO.getPatientName())){
  764. String sql ="select name from base_patient where id='"+rehabilitationOperateRecordsDO.getPatientCode()+"'";
  765. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  766. if (list!=null && list.size()>0){
  767. rehabilitationOperateRecordsDO.setPatientName(String.valueOf(list.get(0).get("name")));
  768. }
  769. }
  770. return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
  771. }
  772. /**
  773. * 更新康复计划项目状态
  774. * @param status
  775. * @param planId
  776. * @return
  777. */
  778. public MixEnvelop updatePlanStatusById(Integer status, String planId) throws Exception{
  779. if(status == 1) {
  780. if (patientRehabilitationPlanDao.updateStatusById(status, planId) > 0) {
  781. return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
  782. }
  783. }else if(status == 2){
  784. if (patientRehabilitationPlanDao.updateStatusAndTimeById(2,planId, new Date()) > 0) {
  785. return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
  786. }
  787. }
  788. return MixEnvelop.getError("更新失败!");
  789. }
  790. public MixEnvelop abortPlanById(String planId,String abortReason){
  791. PatientRehabilitationPlanDO patientRehabilitationPlanDO=patientRehabilitationPlanDao.findById(planId);
  792. List<RehabilitationDetailDO> detailDOList = rehabilitationDetailDao.findByPlanIdAndStatus(planId,0);
  793. if(null!=patientRehabilitationPlanDO){
  794. patientRehabilitationPlanDO.setAbortReason(abortReason);
  795. patientRehabilitationPlanDO.setAbortTime(new Date());
  796. patientRehabilitationPlanDO.setStatus(0);
  797. patientRehabilitationPlanDO.setUpdateTime(new Date());
  798. patientRehabilitationPlanDao.save(patientRehabilitationPlanDO);
  799. return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRehabilitationPlanDO,detailDOList);
  800. }
  801. return MixEnvelop.getError("更新失败!");
  802. }
  803. public ObjEnvelop findServiceItemByDoctor(String doctor){
  804. String teamCode="";
  805. String orgCode="";
  806. List<BaseTeamMemberDO> baseTeamMemberDO = baseDoctorTeamMemberDao.findUseDoctorCode(doctor);
  807. if (baseTeamMemberDO!=null&&baseTeamMemberDO.size()>0){
  808. teamCode= baseTeamMemberDO.get(0).getTeamCode();
  809. }
  810. List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctor);
  811. if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
  812. orgCode= baseDoctorHospitalDO.get(0).getOrgCode();
  813. }
  814. String packageSql = "select m.service_package_id as \"servicePackageId\"," +
  815. " n.name as \"name\"" +
  816. "from base_service_package_item m left join base_service_package_item n on" +
  817. " m.service_package_id = n.id where 1=1 and m.service_package_id !='system' ";
  818. if(StringUtils.isNoneBlank(teamCode)){
  819. packageSql+= " and m.team_code ='"+teamCode+"'";
  820. }else {
  821. return null;
  822. }
  823. if(StringUtils.isNoneBlank(orgCode)){
  824. packageSql+= " and m.org_code ='"+orgCode+"'";
  825. }else {
  826. return null;
  827. }
  828. packageSql+=" group by m.service_package_id,n.name ";
  829. List<Map<String,Object>> listPackage = hibenateUtils.createSQLQuery(packageSql);
  830. for (Map<String,Object> map:listPackage){
  831. if (map.get("servicePackageId")!=null){
  832. String sql = "select t.id as \"id\"," +
  833. " t.code as \"code\"," +
  834. " t.name as \"name\"," +
  835. " t.service_package_id as \"servicePackageId\"," +
  836. " t.price as \"price\"," +
  837. " t.fee_type as \"feeType\"," +
  838. " t.org_code as \"orgCode\"," +
  839. " t.org_name as \"orgName\"," +
  840. " t.introduce as \"introduce\"," +
  841. " t.del as \"del\"," +
  842. " t.team_code as \"teamCode\"," +
  843. " t.team_name as \"teamName\"," +
  844. " t.create_time as \"createTime\"," +
  845. " t.dict_id as \"dictId\"" +
  846. " from base_service_package_item t where 1=1 and t.service_package_id !='system' ";
  847. if (StringUtils.isNoneBlank(teamCode)) {
  848. sql += " and t.team_code ='" + teamCode + "'";
  849. }
  850. if (StringUtils.isNoneBlank(orgCode)) {
  851. sql += " and t.org_code ='" + orgCode + "'";
  852. }
  853. sql+=" and t.service_package_id = '"+map.get("servicePackageId").toString()+"'";
  854. List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
  855. map.put("itemList",list);
  856. }
  857. }
  858. return ObjEnvelop.getSuccess("操作成功",listPackage);
  859. }
  860. public List<Map<String, Object>> findServiceItemInBase(String code,String name,String teamCode){
  861. String sql = "select t.id as \"id\"," +
  862. " t.code as \"code\"," +
  863. " t.name as \"name\"," +
  864. " t.service_package_id as \"servicePackageId\"," +
  865. " t.price as \"price\"," +
  866. " t.fee_type as \"feeType\"," +
  867. " t.org_code as \"orgCode\"," +
  868. " t.org_name as \"orgName\"," +
  869. " t.introduce as \"introduce\"," +
  870. " t.del as \"del\"," +
  871. " t.team_code as \"teamCode\"," +
  872. " t.team_name as \"teamName\"," +
  873. " t.create_time as \"createTime\"," +
  874. " t.dict_id as \"dictId\"" +
  875. " from base_service_package_item t where 1=1 and t.service_package_id ='system' and t.del ='1'";
  876. if (StringUtils.isNoneBlank(teamCode)) {
  877. sql += " and t.team_code ='" + teamCode + "'";
  878. }
  879. if (StringUtils.isNoneBlank(code)) {
  880. sql += " and t.code ='" + code + "'";
  881. }
  882. if (StringUtils.isNoneBlank(name)) {
  883. sql += " and t.name ='" + name + "'";
  884. }
  885. List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
  886. return list;
  887. }
  888. }