RehabilitationPlanService.java 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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.hospital.message.SystemMessageDO;
  16. import com.yihu.jw.entity.patient.Message;
  17. import com.yihu.jw.entity.specialist.DoctorPatientRelationDO;
  18. import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
  19. import com.yihu.jw.entity.specialist.RehabilitationServiceItemDO;
  20. import com.yihu.jw.entity.specialist.rehabilitation.*;
  21. import com.yihu.jw.entity.util.TransforSqlUtl;
  22. import com.yihu.jw.file_upload.FileUploadService;
  23. import com.yihu.jw.hospital.message.dao.SystemMessageDao;
  24. import com.yihu.jw.org.dao.BaseOrgDao;
  25. import com.yihu.jw.patient.dao.BasePatientDao;
  26. import com.yihu.jw.rehabilitation.DoctorPatientRelationDao;
  27. import com.yihu.jw.rehabilitation.RehabilitationOperateRecordsDao;
  28. import com.yihu.jw.restmodel.iot.common.UploadVO;
  29. import com.yihu.jw.restmodel.specialist.PatientSignInfoVO;
  30. import com.yihu.jw.restmodel.web.Envelop;
  31. import com.yihu.jw.restmodel.web.ListEnvelop;
  32. import com.yihu.jw.restmodel.web.MixEnvelop;
  33. import com.yihu.jw.restmodel.web.ObjEnvelop;
  34. import com.yihu.jw.rm.specialist.SpecialistMapping;
  35. import com.yihu.jw.sign.dao.MessagesDao;
  36. import com.yihu.jw.team.BaseDoctorTeamMemberDao;
  37. import com.yihu.jw.util.common.IdCardUtil;
  38. import com.yihu.jw.util.common.QrcodeUtil;
  39. import com.yihu.jw.util.date.DateUtil;
  40. import com.yihu.jw.utils.hibernate.HibenateUtils;
  41. import com.yihu.jw.wechat.dao.WechatDao;
  42. import com.yihu.mysql.query.BaseJpaService;
  43. import com.yihu.rehabilitation.dao.*;
  44. import com.yihu.rehabilitation.vo.TemplateDetailVo;
  45. import com.yihu.utils.network.HttpResponse;
  46. import com.yihu.utils.network.HttpUtils;
  47. import com.yihu.utils.security.MD5;
  48. import org.apache.commons.collections.map.HashedMap;
  49. import org.apache.commons.lang3.StringUtils;
  50. import org.json.JSONArray;
  51. import org.json.JSONObject;
  52. import org.springframework.beans.factory.annotation.Autowired;
  53. import org.springframework.beans.factory.annotation.Value;
  54. import org.springframework.data.redis.core.StringRedisTemplate;
  55. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  56. import org.springframework.jdbc.core.JdbcTemplate;
  57. import org.springframework.mock.web.MockMultipartFile;
  58. import org.springframework.stereotype.Service;
  59. import org.springframework.transaction.annotation.Transactional;
  60. import java.io.InputStream;
  61. import java.text.ParseException;
  62. import java.text.SimpleDateFormat;
  63. import java.util.*;
  64. import java.util.stream.Collectors;
  65. /**
  66. * Created by humingfen on 2018/8/22.
  67. */
  68. @Service
  69. @Transactional
  70. public class RehabilitationPlanService extends BaseJpaService<PatientRehabilitationPlanDO, PatientRehabilitationPlanDao> {
  71. @Value("${specialist.url}")
  72. private String specialistUrl;
  73. @Autowired
  74. private SpecialistEvaluateSevice specialistEvaluateSevice;
  75. @Autowired
  76. private SignFamilyDao signFamilyDao;
  77. @Autowired
  78. private SystemMessageDao messageDao;
  79. @Autowired
  80. private BasePatientDao patientDao;
  81. @Autowired
  82. private JdbcTemplate jdbcTemplate;
  83. @Autowired
  84. private FrequencyDao frequencyDao;
  85. @Autowired
  86. private BaseDoctorDao doctorDao;
  87. @Autowired
  88. private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
  89. @Autowired
  90. private ObjectMapper objectMapper;
  91. @Autowired
  92. private RehabilitationDetailDao rehabilitationDetailDao;
  93. @Value("${neiwang.enable}")
  94. private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传
  95. @Autowired
  96. private FastDFSUtil fastDFSUtil;
  97. @Value("${fastDFS.fastdfs_file_url}")
  98. private String fastdfs_file_url;
  99. @Autowired
  100. FileUploadService fileUploadService;
  101. @Value("${testPattern.sign}")
  102. private String isClose;
  103. @Value("${testPattern.remote_inner_url}")
  104. private String remote_inner_url;
  105. @Autowired
  106. private WechatDao wechatDao;
  107. @Value("${wechat.id}")
  108. private String wxId;
  109. @Autowired
  110. private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
  111. @Autowired
  112. private BaseOrgDao baseOrgDao;
  113. @Autowired
  114. private BaseDoctorTeamMemberDao baseDoctorTeamMemberDao;
  115. @Autowired
  116. private BaseDoctorHospitalDao baseDoctorHospitalDao;
  117. @Autowired
  118. private HibenateUtils hibenateUtils;
  119. @Autowired
  120. private DoctorPatientRelationDao doctorPatientRelationDao;
  121. @Autowired
  122. private RehabilitationPlanTemplateDao templateDao;
  123. @Autowired
  124. private RehabilitationTemplateDetailDao templateDetailDao;
  125. @Autowired
  126. private RehabilitationServiceItemDao serviceItemDao;
  127. @Autowired
  128. StringRedisTemplate redisTemplate;
  129. public Envelop updatePatientImgById(String planId, String patientImg) {
  130. if(patientRehabilitationPlanDao.updatePatientImgById(planId,patientImg) > 0){
  131. return Envelop.getSuccess(SpecialistMapping.api_success);
  132. }
  133. return Envelop.getError("更新失败!");
  134. }
  135. /*public JSONArray findTemplateInfo(String doctor, String patient) throws Exception {
  136. Map<String, Object> param = new HashedMap();
  137. Long adminTeamId = null;
  138. AdminTeam team = teamService.findByLeaderCode(doctor);
  139. if(StringUtils.isBlank(patient)){
  140. adminTeamId = team.getId();
  141. param.put("adminTeamCode", adminTeamId);
  142. }else {
  143. param.put("doctor", doctor);
  144. param.put("patient", patient);
  145. }
  146. HttpResponse response = null;
  147. try {
  148. response = HttpUtils.doGet(specialistUrl + "svr-specialist/findRehabilitationPlanTemplate", param);
  149. } catch (Exception e) {
  150. e.printStackTrace();
  151. }
  152. JSONObject rs = new JSONObject(response.getContent());
  153. if ("success".equals(rs.getString("message"))) {
  154. return rs.getJSONArray("detailModelList");
  155. }
  156. throw new Exception("请求获取模板列表失败!");
  157. }*/
  158. public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId,String createUser,String createUserName) {
  159. for(RehabilitationDetailDO detail : details) {
  160. /*List<String> list = new ArrayList<>();
  161. list.add(detail.getHospitalServiceItemId());
  162. HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0);
  163. detail.setHospital(hospitalServiceItemDO.getHospital());
  164. detail.setHospitalName(hospitalServiceItemDO.getHospitalName());
  165. detail.setExpense(hospitalServiceItemDO.getExpense());*/
  166. detail.setPlanId(planId);
  167. detail.setCreateTime(new Date());
  168. detail.setStatus(0);
  169. detail.setUpdateTime(new Date());
  170. detail.setCreateUser(createUser);
  171. detail.setCreateUserName(createUserName);
  172. }
  173. return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
  174. }
  175. //code,timeType,executeTimes
  176. public String createRehabilitationPlan(String json, BaseDoctorDO doctor) throws Exception {
  177. JSONObject object = new JSONObject(json);
  178. String patient = object.getString("patient");
  179. String relationId=object.getString("relationId");
  180. String teamCode=object.getString("teamCode");
  181. BasePatientDO patientDo = patientDao.findById(patient);
  182. if (patientDo==null){
  183. BasePatientDO basePatientDO = new BasePatientDO();
  184. basePatientDO.setName(object.getString("patientName"));
  185. basePatientDO.setIdcard(object.getString("idCard"));
  186. basePatientDO.setMobile(object.getString("mobile"));
  187. patientDo = saveUnSignPatient(basePatientDO);
  188. }
  189. String patientName="";
  190. if(patientDo!=null){
  191. patientName = patientDo.getName();
  192. }
  193. JSONArray array = object.getJSONArray("detail");
  194. for (int z=0;z<array.length();z++){
  195. JSONObject jsonObject = array.getJSONObject(z);
  196. Long timeType = jsonObject.getLong("timeType");
  197. Frequency frequency = frequencyDao.findByCode(jsonObject.getString("frequencyCode"));
  198. String executeTimes = jsonObject.getString("executeTimes");
  199. String[] executeTime = executeTimes.split(",");
  200. List<String> list = new ArrayList<>();
  201. if (StringUtils.isNoneBlank(executeTimes)){
  202. for (int i=0;i<executeTime.length;i++){
  203. List<String> times = getFrequencyDate(frequency.getCode(),executeTime[i],frequency.getUnit(),frequency.getTime(),timeType);
  204. for (int j=0;j<times.size();j++){
  205. if (list!=null&&list.size()!=0){
  206. if (!list.contains(times.get(j))){
  207. list.add(times.get(j));
  208. }
  209. }else {
  210. list.add(times.get(j));
  211. }
  212. }
  213. }
  214. StringBuffer buffer = new StringBuffer();
  215. if(list!=null&&list.size()!=0){
  216. for (int i=0;i<list.size();i++){
  217. buffer.append(list.get(i)+",");
  218. }
  219. if (StringUtils.isNoneBlank(buffer)){
  220. buffer.deleteCharAt(buffer.length()-1);
  221. }
  222. }
  223. jsonObject.put("executeTime",buffer);
  224. }
  225. jsonObject.remove("executeTimes");
  226. }
  227. object.put("createUser", doctor.getId());
  228. object.put("createUserName", doctor.getName());
  229. String planDetails = array.toString();
  230. objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm"));
  231. List<RehabilitationDetailDO> details = objectMapper.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
  232. PatientRehabilitationPlanDO planDO = objectMapper.readValue(json.toString(), PatientRehabilitationPlanDO.class);
  233. planDO.setCreateUser(doctor.getId());
  234. planDO.setCreateUserName(doctor.getName());
  235. planDO = createPatientRehabilitationPlan(planDO);
  236. details = createRehabilitationDetail(details, planDO.getId(),doctor.getId(),doctor.getName());
  237. //康复计划创建完给执行者发送消息
  238. String planId = null;
  239. if (planDO!=null){
  240. planId=planDO.getId();
  241. }
  242. HashSet set = new HashSet();
  243. for ( RehabilitationDetailDO rehabilitationDetailDO : details) {
  244. if (!set.contains(rehabilitationDetailDO.getDoctor())) {
  245. set.add(rehabilitationDetailDO.getDoctor());
  246. SystemMessageDO message = new SystemMessageDO();
  247. message.setSender(doctor.getId());
  248. message.setType("19");
  249. message.setRelationCode(rehabilitationDetailDO.getPlanId());
  250. message.setReceiver(rehabilitationDetailDO.getDoctor());
  251. message.setReason(doctor.getName());
  252. specialistEvaluateSevice.sendMessage(message, rehabilitationDetailDO.getHospital(), patient, null,null);
  253. //pushMsgTask.put(rehabilitationDetailDO.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", "");
  254. }
  255. }
  256. DoctorPatientRelationDO doctorPatientRelationDO = doctorPatientRelationDao.findOne(relationId);
  257. if (null!=doctorPatientRelationDO){
  258. if (doctorPatientRelationDO.getIsManage()==null||doctorPatientRelationDO.getIsManage()==0){
  259. doctorPatientRelationDO.setDoctor(doctor.getId());
  260. doctorPatientRelationDO.setDoctorName(doctor.getName());
  261. doctorPatientRelationDO.setIsManage(0);
  262. }
  263. doctorPatientRelationDO.setTeamCode(teamCode);
  264. doctorPatientRelationDO.setIsdeal("1");
  265. doctorPatientRelationDao.save(doctorPatientRelationDO);
  266. }
  267. SignFamily signFamily = signFamilyDao.findByPatient(patient);
  268. //推送消息到IM
  269. if (signFamily != null && !set.contains(signFamily.getDoctor())) {
  270. //pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划创建消息", "您的居民"+patientName+"的康复计划已配置完成,点击查看", "");
  271. }
  272. return planId;
  273. }
  274. public MixEnvelop<String,String> createServiceQrCode(String planDetailId, String doctorCode) throws Exception{
  275. //更新到康复计划居民关系表中
  276. Map<String, Object> param = new HashedMap();
  277. String fileUrl = "";
  278. String sql ="SELECT service_qr_code FROM wlyy_specialist.wlyy_rehabilitation_plan_detail where id='"+planDetailId+"'";
  279. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  280. if(list!=null && list.size()>0){
  281. fileUrl = String.valueOf(list.get(0).get("service_qr_code"));
  282. }
  283. if (StringUtils.isEmpty(fileUrl) || "null".equals(fileUrl)){
  284. //生成二维码图片
  285. WxWechatDO wxWechatDO = wechatDao.findById(wxId);
  286. String appId="";
  287. String wechat_base_url="";
  288. if (wxWechatDO!=null){
  289. appId=wxWechatDO.getAppId();
  290. wechat_base_url=wxWechatDO.getBaseUrl();
  291. }
  292. 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";
  293. InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
  294. UploadVO uploadVO = new UploadVO();
  295. String originalFilename ="plan_service_qrcode" + System.currentTimeMillis()+".png";
  296. if (isClose.equalsIgnoreCase("1")){
  297. Map<String, Object> map = fileUploadService.uploadImg(new MockMultipartFile(originalFilename,originalFilename,"", ipt));
  298. uploadVO.setFullUri(map.get("accessory").toString());
  299. }else if(isClose.equals("2")){
  300. //内网上传
  301. String rs = fileUploadService.request(remote_inner_url,new MockMultipartFile(originalFilename,originalFilename,"", ipt),null);
  302. com.alibaba.fastjson.JSONObject json = JSON.parseObject(rs);
  303. uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
  304. }else {
  305. // 得到文件的完整名称 xxx.txt
  306. /*InputStream inputStream = ipt;*/
  307. uploadVO = fileUploadService.uploadStream(ipt,originalFilename,fastdfs_file_url);
  308. }
  309. fileUrl = uploadVO.getFullUri();
  310. }
  311. System.out.println("服务码-----------1"+fileUrl);
  312. String sqlUpdate = "update wlyy_rehabilitation_plan_detail set service_qr_code='" + fileUrl + "' where id='" + planDetailId + "'";
  313. jdbcTemplate.update(sqlUpdate);
  314. return MixEnvelop.getSuccess("获取二维码成功!",fileUrl);
  315. }
  316. public Map<String,Object> checkAfterQrCode(String planDetailId,String patietCode)throws Exception{
  317. Map<String,Object> map = new HashedMap();
  318. int result = 0;
  319. String name= "";
  320. 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+"'";
  321. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  322. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  323. if (list!=null && list.size()>0){
  324. if (String.valueOf(list.get(0).get("patient")).equals(patietCode)){
  325. result =200;
  326. }else {
  327. result = -1;
  328. name=String.valueOf(list.get(0).get("name"));
  329. }
  330. }else {
  331. result = -10000;
  332. }
  333. map.put("code",result);
  334. if (StringUtils.isNotBlank(name)){
  335. map.put("name",name);
  336. }
  337. return map;
  338. }
  339. public PatientRehabilitationPlanDO createPatientRehabilitationPlan(PatientRehabilitationPlanDO planDO) {
  340. planDO.setCreateTime(new Date());
  341. planDO.setStatus(1);
  342. planDO.setIsVerify("0");
  343. planDO.setUpdateTime(new Date());
  344. return patientRehabilitationPlanDao.save(planDO);
  345. }
  346. public List<String> getFrequencyDate(String code,String date,String unit,String time,Long timeType) throws ParseException {
  347. List<String> list = new ArrayList<>();
  348. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  349. SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  350. String nowDate = date+":00";
  351. Date date6 = DateUtil.strToDateLong(nowDate);
  352. String date9 = sdf.format(date6)+" 09:00:00";//白天
  353. String date21 = sdf.format(date6)+" 21:00:00";//白天
  354. String date9s = DateUtil.getNextDay(date6,1)+" 09:00:00";//晚上
  355. Calendar calendar = Calendar.getInstance();
  356. if (unit.equalsIgnoreCase("D")&&!code.equalsIgnoreCase("qod")){
  357. String[] str = time.split(",");
  358. for (int i=0;i<str.length;i++){
  359. Date date1 = sdf.parse(date);
  360. calendar.setTime(date1);
  361. String lastDay = sdf.format(calendar.getTime()) + " "+str[i];
  362. list.add(lastDay);
  363. }
  364. }else if (unit.equalsIgnoreCase("D")&&code.equalsIgnoreCase("qod")){
  365. Date date1 = sdf.parse(date);
  366. calendar.setTime(date1);
  367. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) +1);
  368. String lastDay = sdf.format(calendar.getTime()) + " "+time;
  369. list.add(lastDay);
  370. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q0.5h")){
  371. Date date1 = sdf.parse(date);
  372. calendar.setTime(date1);
  373. String endTime = null;
  374. String lastDay = null;
  375. if (timeType == 0){
  376. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  377. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  378. }else if ( timeType == 1){
  379. lastDay = date9;
  380. endTime = date21;
  381. }else if (timeType == 2){
  382. lastDay = date21;
  383. endTime = date9s;
  384. }
  385. Date date2 = sdf1.parse(lastDay);
  386. Date date3 = sdf1.parse(endTime);
  387. Long time1 = date2.getTime();
  388. for (int i=0;i<47;i++){
  389. time1 += 30*60*1000;
  390. String day = sdf1.format(time1);
  391. Date date4 = sdf1.parse(day);
  392. if (date4.compareTo(date3)==-1 || date4.compareTo(date3) == 0){
  393. list.add(day);
  394. }
  395. }
  396. }else if (unit.equalsIgnoreCase("H")&& code.equalsIgnoreCase("q2h")){
  397. Date date1 = sdf.parse(date);
  398. calendar.setTime(date1);
  399. /* String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";*/
  400. String endTime = null;
  401. String lastDay = null;
  402. if (timeType == 0){
  403. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  404. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  405. }else if ( timeType == 1){
  406. lastDay = date9;
  407. endTime = date21;
  408. }else if (timeType == 2){
  409. lastDay = date21;
  410. endTime = date9s;
  411. }
  412. Date date2 = sdf1.parse(lastDay);
  413. Date date3 = sdf1.parse(endTime);
  414. calendar.setTime(date2);
  415. for (int i=0;i<11;i++){
  416. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+2);
  417. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  418. System.out.print(sdf1.format(calendar.getTime()));
  419. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  420. list.add(sdf1.format(calendar.getTime()));
  421. }
  422. }
  423. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q3h")){
  424. Date date1 = sdf.parse(date);
  425. calendar.setTime(date1);
  426. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  427. String endTime = null;
  428. String lastDay = null;
  429. if (timeType == 0){
  430. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  431. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  432. }else if ( timeType == 1){
  433. lastDay = date9;
  434. endTime = date21;
  435. }else if (timeType == 2){
  436. lastDay = date21;
  437. endTime = date9s;
  438. }
  439. Date date2 = sdf1.parse(lastDay);
  440. Date date3 = sdf1.parse(endTime);
  441. calendar.setTime(date2);
  442. for (int i=0;i<7;i++){
  443. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+3);
  444. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  445. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  446. list.add(sdf1.format(calendar.getTime()));
  447. }
  448. }
  449. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("q4h")){
  450. Date date1 = sdf.parse(date);
  451. calendar.setTime(date1);
  452. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  453. String endTime = null;
  454. String lastDay = null;
  455. if (timeType == 0){
  456. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  457. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  458. }else if ( timeType == 1){
  459. lastDay = date9;
  460. endTime = date21;
  461. }else if (timeType == 2){
  462. lastDay = date21;
  463. endTime = date9s;
  464. }
  465. Date date2 = sdf1.parse(lastDay);
  466. Date date3 = sdf1.parse(endTime);
  467. calendar.setTime(date2);
  468. for (int i=0;i<5;i++){
  469. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+4);
  470. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  471. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  472. list.add(sdf1.format(calendar.getTime()));
  473. }
  474. }
  475. }else if (unit.equalsIgnoreCase("H")&&code.equalsIgnoreCase("qh")){
  476. Date date1 = sdf.parse(date);
  477. calendar.setTime(date1);
  478. //String lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  479. String endTime = null;
  480. String lastDay = null;
  481. if (timeType == 0){
  482. lastDay = sdf.format(calendar.getTime()) + " 00:00:00";
  483. endTime = sdf.format(calendar.getTime()) + " 23:59:59";
  484. }else if ( timeType == 1){
  485. lastDay = date9;
  486. endTime = date21;
  487. }else if (timeType == 2){
  488. lastDay = date21;
  489. endTime = date9s;
  490. }
  491. Date date2 = sdf1.parse(lastDay);
  492. Date date3 = sdf1.parse(endTime);
  493. calendar.setTime(date2);
  494. for (int i=0;i<23;i++){
  495. calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR)+1);
  496. Date date4 = sdf1.parse(sdf1.format(calendar.getTime()));
  497. if (date4.compareTo(date3)==-1||date4.compareTo(date3) == 0){
  498. list.add(sdf1.format(calendar.getTime()));
  499. }
  500. }
  501. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_1")){
  502. String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
  503. Date date1 = new Date();
  504. String date3 = sdf1.format(date1);
  505. if (date2.compareTo(date3)==1){
  506. list.add(date2);
  507. }
  508. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_2")){
  509. String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
  510. Date date1 = new Date();
  511. String date3 = sdf1.format(date1);
  512. if (date2.compareTo(date3)==1){
  513. list.add(date2);
  514. }
  515. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_3")){
  516. String date2 = DateUtil.getWeek(date,"3")+" 08:00:00";
  517. Date date1 = new Date();
  518. String date3 = sdf1.format(date1);
  519. if (date2.compareTo(date3)==1){
  520. list.add(date2);
  521. }
  522. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_4")){
  523. String date2 = DateUtil.getWeek(date,"4")+" 08:00:00";
  524. Date date1 = new Date();
  525. String date3 = sdf1.format(date1);
  526. if (date2.compareTo(date3)==1){
  527. list.add(date2);
  528. }
  529. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_5")){
  530. String date2 = DateUtil.getWeek(date,"5")+" 08:00:00";
  531. Date date1 = new Date();
  532. String date3 = sdf1.format(date1);
  533. if (date2.compareTo(date3)==1){
  534. list.add(date2);
  535. }
  536. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_6")){
  537. String date2 = DateUtil.getWeek(date,"6")+" 08:00:00";
  538. Date date1 = new Date();
  539. String date3 = sdf1.format(date1);
  540. if (date2.compareTo(date3)==1){
  541. list.add(date2);
  542. }
  543. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("qw_7")){
  544. String date2 = DateUtil.getWeek(date,"7")+" 08:00:00";
  545. Date date1 = new Date();
  546. String date3 = sdf1.format(date1);
  547. if (date2.compareTo(date3)==1){
  548. list.add(date2);
  549. }
  550. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw135")){
  551. String date2 = DateUtil.getWeek(date,"1")+" 08:00:00";
  552. String date4 = DateUtil.getWeek(date,"3")+" 08:00:00";
  553. String date5 = DateUtil.getWeek(date,"5")+" 08:00:00";
  554. Date date1 = new Date();
  555. String date3 = sdf1.format(date1);
  556. if (date2.compareTo(date3)==1){
  557. list.add(date2);
  558. }
  559. if (date4.compareTo(date3)==1){
  560. list.add(date2);
  561. }
  562. if (date5.compareTo(date3) == 1){
  563. list.add(date2);
  564. }
  565. }else if (unit.equalsIgnoreCase("W")&&code.equalsIgnoreCase("tiw246")){
  566. String date2 = DateUtil.getWeek(date,"2")+" 08:00:00";
  567. String date4 = DateUtil.getWeek(date,"4")+" 08:00:00";
  568. String date5 = DateUtil.getWeek(date,"6")+" 08:00:00";
  569. Date date1 = new Date();
  570. String date3 = sdf1.format(date1);
  571. if (date2.compareTo(date3)==1){
  572. list.add(date2);
  573. }
  574. if (date4.compareTo(date3)==1){
  575. list.add(date2);
  576. }
  577. if (date5.compareTo(date3) == 1){
  578. list.add(date2);
  579. }
  580. }
  581. return list;
  582. }
  583. public String deleteTemplate(String templateId) {
  584. Map<String, Object> param = new HashedMap();
  585. param.put("id", templateId);
  586. HttpResponse response = null;
  587. try {
  588. response = HttpUtils.doPost(specialistUrl + "svr-specialist/deleteRehabilitationPlanTemplate", param);
  589. } catch (Exception e) {
  590. e.printStackTrace();
  591. }
  592. JSONObject rs = new JSONObject(response.getContent());
  593. return rs.getString("message");
  594. }
  595. /**
  596. * 更新计划的状态
  597. * @param planId
  598. * @param status
  599. * @throws Exception
  600. */
  601. public void updatePlanStatusById(String planId, Integer status,String abortReason) throws Exception{
  602. Map<String, Object> param = new HashedMap();
  603. param.put("planId", planId);
  604. param.put("status", status);
  605. param.put("abortReason",abortReason);
  606. HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePlanStatusById", param);
  607. JSONObject result = new JSONObject(response.getContent());
  608. if (result.getInt("status")==200 && status==0){
  609. List<SystemMessageDO> messageList = new ArrayList<>();
  610. Map<String,String> recieveMap = new HashMap<>();
  611. JSONObject jsonObject =result.getJSONObject("obj");
  612. String patientCode = jsonObject.getString("patient");
  613. String patientName = jsonObject.getString("name");
  614. String diseaseName = jsonObject.getString("diseaseName");
  615. String createDoctorCode = jsonObject.getString("createUser");
  616. JSONArray detailModelList = result.getJSONArray("detailModelList");
  617. for (Object obj : detailModelList) {
  618. JSONObject detail = (JSONObject) obj;
  619. String doctor = detail.getString("doctor");
  620. if (!createDoctorCode.equals(doctor)){
  621. if (!recieveMap.containsKey(doctor)){
  622. recieveMap.put(doctor,detail.getString("doctorName"));
  623. }
  624. }
  625. }
  626. SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
  627. if (signFamily!=null){
  628. if (!recieveMap.containsKey(signFamily.getDoctor())){
  629. recieveMap.put(signFamily.getDoctor(),signFamily.getDoctorName());
  630. }
  631. }
  632. for (Map.Entry<String,String> entry : recieveMap.entrySet()){
  633. //推送消息到IM
  634. //pushMsgTask.put(entry.getKey(),"20", "康复计划中止消息", "您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因", "");
  635. SystemMessageDO message = initMessage(patientName,entry.getKey(),entry.getValue(),"system","system","康复计划-中止提醒","您的居民"+patientName+",已中止"+diseaseName+"康复计划,点击查看原因。",planId,29);
  636. messageList.add(message);
  637. }
  638. messageDao.save(messageList);
  639. /*Message message = new Message();
  640. message.setCzrq(new Date());
  641. message.setCreateTime(new Date());
  642. message.setContent("您的"+patientName+"签约居民,已中止康复计划,点击查看原因。");
  643. message.setRead(1);//设置未读
  644. if (signFamily!=null){
  645. message.setReceiver(signFamily.getDoctor());//设置接受医生的code
  646. message.setReceiverName(signFamily.getDoctorName());
  647. }
  648. message.setSender("system");//设置发送的用户
  649. message.setSenderName("system");
  650. message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
  651. message.setSenderPhoto("");
  652. message.setTitle("康复计划-中止提醒");
  653. message.setType(29);//康复计划中止消息提醒
  654. message.setReadonly(1);//是否只读消息
  655. message.setRelationCode(planId);
  656. message.setOver("1");//未处理
  657. message.setState(1);
  658. message.setData("");
  659. message.setDel("1");*/
  660. //推送消息到IM
  661. // pushMsgTask.put(signFamily.getDoctor(),"20", "康复计划中止消息", "您的"+patientName+"签约居民,已中止康复计划,点击查看原因", "");
  662. }
  663. if(result.getInt("status")!=200){
  664. throw new Exception("请求微服务失败!");
  665. }
  666. }
  667. private SystemMessageDO initMessage(String patientName, String doctor, String doctorName, String sender, String senderName, String title, String content, String relatioenCode, int type){
  668. SystemMessageDO message = new SystemMessageDO();
  669. message.setCreateTime(new Date());
  670. message.setContent("您的服务居民"+patientName+",已中止康复计划,点击查看原因。");
  671. message.setIsRead("1");//设置未读
  672. message.setReceiver(doctor);//设置接受医生的code
  673. message.setReceiverName(doctorName);
  674. message.setSender(sender);//设置发送的用户
  675. message.setSenderName(senderName);
  676. message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
  677. message.setSenderPhoto("");
  678. message.setTitle(title);
  679. message.setType(String.valueOf(type));//康复计划中止消息提醒
  680. message.setReadonly(1);//是否只读消息
  681. message.setRelationCode(relatioenCode);
  682. message.setOver("0");//未处理
  683. message.setState(1);
  684. message.setData("");
  685. message.setDel("1");
  686. return message;
  687. }
  688. public JSONObject getServiceItemsAfterStop(String planId)throws Exception{
  689. Map<String, Object> param = new HashedMap();
  690. param.put("planId", planId);
  691. HttpResponse response = HttpUtils.doGet(specialistUrl + "svr-specialist/getServiceItemsAfterStop", param);
  692. JSONObject result = new JSONObject(response.getContent());
  693. JSONObject jsonObject = new JSONObject();
  694. if(result.getInt("status")!=200){
  695. throw new Exception("请求微服务失败!");
  696. }
  697. if (result.getInt("status")==200){
  698. jsonObject = result.getJSONObject("obj");
  699. JSONArray jsonArray = jsonObject.getJSONArray("serviceList");
  700. if (jsonArray!=null && jsonArray.length()>0){
  701. jsonObject.put("patientName",jsonArray.getJSONObject(0).get("name"));
  702. jsonObject.put("abortTime",jsonArray.getJSONObject(0).get("abort_time"));
  703. jsonObject.put("hospitalName",jsonArray.getJSONObject(0).get("hospital_name"));
  704. jsonObject.put("abortReason",jsonArray.getJSONObject(0).get("abort_reason"));
  705. String patientCode = String.valueOf(jsonArray.getJSONObject(0).get("patient"));
  706. jsonObject.put("patientCode", patientCode);
  707. jsonObject.put("disease_name", jsonArray.getJSONObject(0).get("disease_name"));
  708. jsonObject.put("create_time", jsonArray.getJSONObject(0).get("create_time"));
  709. jsonObject.put("patient_img", jsonArray.getJSONObject(0).get("patient_img"));
  710. BasePatientDO patient = patientDao.findById(patientCode);
  711. if (patient!=null){
  712. jsonObject.put("openid", patient.getOpenid());
  713. jsonObject.put("ssc",patient.getSsc());
  714. jsonObject.put("mobile",patient.getMobile());
  715. }
  716. }
  717. }
  718. return jsonObject;
  719. }
  720. /**
  721. * 更新居民签名照/证件照
  722. * @param planId
  723. * @throws Exception
  724. *//*
  725. public void updatePatientImgById(String planId, String patientImg) throws Exception {
  726. Map<String, Object> param = new HashedMap();
  727. param.put("planId", planId);
  728. param.put("patientImg", patientImg);
  729. HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePatientImgById", param);
  730. JSONObject result = new JSONObject(response.getContent());
  731. if(result.getInt("status")!=200){
  732. throw new Exception("请求微服务失败!");
  733. }
  734. }*/
  735. public void sendWxTemplate(String accessToken, String planId, String doctorCode, JSONObject jsonObject) {
  736. BaseDoctorDO d = doctorDao.findById(doctorCode);
  737. JSONObject json = new JSONObject();
  738. String patient = jsonObject.getString("patientCode");
  739. String patientName = jsonObject.get("patientName") + "";
  740. json.put("first", patientName + "您好,您有一个康复计划已完成,请确认接收。");
  741. json.put("toUser", patient);
  742. json.put("represented", patient);//被代理人
  743. json.put("keyword1", jsonObject.get("disease_name") + "康复计划");
  744. json.put("keyword2", d.getName());
  745. json.put("keyword3", DateUtil.dateToStr(new Date ((Long) jsonObject.get("create_time")), "yyyy/MM/dd") + "-" + DateUtil.dateToStr(new Date(), "yyyy/MM/dd"));
  746. json.put("remark", "完成的康复项清单已发送给您,点击此消息可查看。");
  747. json.put("planId", planId);
  748. if (!jsonObject.isNull("openid")) {
  749. //pushMsgTask.putWxMsg(accessToken, 27, jsonObject.get("openid") + "", patientName, json);
  750. }/*else {
  751. try {
  752. //发送代理人
  753. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
  754. if (jsonArray != null && jsonArray.length() > 0) {
  755. Patient p = patientDao.findByCode(patient);
  756. for (int i = 0; i < jsonArray.length(); i++) {
  757. JSONObject j = jsonArray.getJSONObject(i);
  758. Patient member = (Patient) j.get("member");
  759. JSONObject data = json;
  760. data.remove("toUser");
  761. data.put("toUser", member.getCode());
  762. data.remove("first");
  763. json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()));
  764. pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 27, member.getOpenid(), p.getName(), data);
  765. }
  766. }
  767. } catch (Exception e) {
  768. e.printStackTrace();
  769. }
  770. }*/
  771. }
  772. public BasePatientDO saveUnSignPatient(BasePatientDO basepatientDO){
  773. basepatientDO.setDel("1");
  774. basepatientDO.setLocked(0);
  775. basepatientDO.setEnabled(1);
  776. String salt = randomString(5);
  777. basepatientDO.setSalt(salt);
  778. basepatientDO.setPassword(MD5.md5Hex(basepatientDO.getIdcard().substring(12,18) + "{" + salt + "}"));
  779. basepatientDO=patientDao.save(basepatientDO);
  780. return basepatientDO;
  781. }
  782. public RehabilitationOperateRecordsDO saveRehabilitationRecord(RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO){
  783. RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(rehabilitationOperateRecordsDO.getRehabilitationDetailId());
  784. if (!StringUtils.isNoneBlank(rehabilitationOperateRecordsDO.getId())){
  785. rehabilitationOperateRecordsDO.setId(getCode());
  786. }
  787. if (rehabilitationDetailDO.getExecuteTime()!=null){
  788. rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
  789. }
  790. rehabilitationOperateRecordsDO.setCompleteTime(new Date());
  791. rehabilitationOperateRecordsDO.setCreateTime(new Date());
  792. rehabilitationOperateRecordsDO.setUpdateTime(new Date());
  793. rehabilitationOperateRecordsDO.setStatus(rehabilitationOperateRecordsDO.getStatus());
  794. if (StringUtils.isEmpty(rehabilitationOperateRecordsDO.getPatientName())){
  795. String sql ="select name from base_patient where id='"+rehabilitationOperateRecordsDO.getPatientCode()+"'";
  796. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  797. if (list!=null && list.size()>0){
  798. rehabilitationOperateRecordsDO.setPatientName(String.valueOf(list.get(0).get("name")));
  799. }
  800. }
  801. return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
  802. }
  803. /**
  804. * 更新康复计划项目状态
  805. * @param status
  806. * @param planId
  807. * @return
  808. */
  809. public MixEnvelop updatePlanStatusById(Integer status, String planId) throws Exception{
  810. if(status == 1) {
  811. if (patientRehabilitationPlanDao.updateStatusById(status, planId) > 0) {
  812. return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
  813. }
  814. }else if(status == 2){
  815. if (patientRehabilitationPlanDao.updateStatusAndTimeById(2,planId, new Date()) > 0) {
  816. return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
  817. }
  818. }
  819. return MixEnvelop.getError("更新失败!");
  820. }
  821. public MixEnvelop abortPlanById(String planId,String abortReason){
  822. PatientRehabilitationPlanDO patientRehabilitationPlanDO=patientRehabilitationPlanDao.findById(planId);
  823. List<RehabilitationDetailDO> detailDOList = rehabilitationDetailDao.findByPlanIdAndStatus(planId,0);
  824. if(null!=patientRehabilitationPlanDO){
  825. patientRehabilitationPlanDO.setAbortReason(abortReason);
  826. patientRehabilitationPlanDO.setAbortTime(new Date());
  827. patientRehabilitationPlanDO.setStatus(0);
  828. patientRehabilitationPlanDO.setUpdateTime(new Date());
  829. patientRehabilitationPlanDao.save(patientRehabilitationPlanDO);
  830. return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRehabilitationPlanDO,detailDOList);
  831. }
  832. return MixEnvelop.getError("更新失败!");
  833. }
  834. public ObjEnvelop findServiceItemByDoctor(String doctor){
  835. String teamCode="";
  836. String orgCode="";
  837. List<BaseTeamMemberDO> baseTeamMemberDO = baseDoctorTeamMemberDao.findUseDoctorCode(doctor);
  838. if (baseTeamMemberDO!=null&&baseTeamMemberDO.size()>0){
  839. teamCode= baseTeamMemberDO.get(0).getTeamCode();
  840. }
  841. List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctor);
  842. if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
  843. orgCode= baseDoctorHospitalDO.get(0).getOrgCode();
  844. }
  845. String packageSql = "select m.service_package_id as \"servicePackageId\"," +
  846. " n.name as \"name\"" +
  847. "from base_service_package_item m left join base_service_package n on" +
  848. " m.service_package_id = n.id where 1=1 and m.service_package_id !='system' ";
  849. if(StringUtils.isNoneBlank(teamCode)){
  850. packageSql+= " and m.team_code ='"+teamCode+"'";
  851. }else {
  852. return null;
  853. }
  854. if(StringUtils.isNoneBlank(orgCode)){
  855. packageSql+= " and m.org_code ='"+orgCode+"'";
  856. }else {
  857. return null;
  858. }
  859. packageSql+=" group by m.service_package_id,n.name ";
  860. List<Map<String,Object>> listPackage = hibenateUtils.createSQLQuery(packageSql);
  861. for (Map<String,Object> map:listPackage){
  862. if (map.get("servicePackageId")!=null){
  863. String sql = "select t.id as \"id\"," +
  864. " t.code as \"code\"," +
  865. " t.name as \"name\"," +
  866. " t.service_package_id as \"servicePackageId\"," +
  867. " t.price as \"price\"," +
  868. " t.fee_type as \"feeType\"," +
  869. " t.org_code as \"orgCode\"," +
  870. " t.org_name as \"orgName\"," +
  871. " t.introduce as \"introduce\"," +
  872. " t.del as \"del\"," +
  873. " t.team_code as \"teamCode\"," +
  874. " t.team_name as \"teamName\"," +
  875. " t.create_time as \"createTime\"," +
  876. " t.dict_id as \"dictId\"" +
  877. " from base_service_package_item t where 1=1 and t.service_package_id !='system' ";
  878. if (StringUtils.isNoneBlank(teamCode)) {
  879. sql += " and t.team_code ='" + teamCode + "'";
  880. }
  881. if (StringUtils.isNoneBlank(orgCode)) {
  882. sql += " and t.org_code ='" + orgCode + "'";
  883. }
  884. sql+=" and t.service_package_id = '"+map.get("servicePackageId").toString()+"'";
  885. List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
  886. map.put("itemList",list);
  887. }
  888. }
  889. return ObjEnvelop.getSuccess("操作成功",listPackage);
  890. }
  891. public List<Map<String, Object>> findServiceItemInBase(String code,String name,String teamCode){
  892. String sql = "select t.id as \"id\"," +
  893. " t.code as \"code\"," +
  894. " t.name as \"name\"," +
  895. " t.service_package_id as \"servicePackageId\"," +
  896. " t.price as \"price\"," +
  897. " t.fee_type as \"feeType\"," +
  898. " t.org_code as \"orgCode\"," +
  899. " t.org_name as \"orgName\"," +
  900. " t.introduce as \"introduce\"," +
  901. " t.del as \"del\"," +
  902. " t.team_code as \"teamCode\"," +
  903. " t.team_name as \"teamName\"," +
  904. " t.create_time as \"createTime\"," +
  905. " t.dict_id as \"dictId\"" +
  906. " from base_service_package_item t where 1=1 and t.service_package_id ='system' and t.del ='1'";
  907. if (StringUtils.isNoneBlank(teamCode)) {
  908. sql += " and t.team_code ='" + teamCode + "'";
  909. }
  910. if (StringUtils.isNoneBlank(code)) {
  911. sql += " and t.code ='" + code + "'";
  912. }
  913. if (StringUtils.isNoneBlank(name)) {
  914. sql += " and t.name ='" + name + "'";
  915. }
  916. List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
  917. return list;
  918. }
  919. public List<Map<String,Object>> findDoctorTeams(String doctor){
  920. String sql = "select a.id as \"id\", " +
  921. " a.org_code as \"orgCode\"," +
  922. " a.org_name as \"orgName\"," +
  923. " a.name as \"name\"," +
  924. " a.leader_code as \"leaderCode\"," +
  925. " a.team_num as \"teamNum\"," +
  926. " a.qrcode as \"qrcode\"," +
  927. " a.del as \"del\"," +
  928. " a.create_time as \"createTime\"" +
  929. " from base_team a left join base_team_member b " +
  930. " on a.id = b.team_code where a.del ='1' ";
  931. if (StringUtils.isNotBlank(doctor)){
  932. sql+=" and b.doctor_code ='"+doctor+"'";
  933. }else{
  934. return null;
  935. }
  936. List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
  937. return list;
  938. }
  939. public List<Map<String,Object>> findDoctorByTeams(String teamCode){
  940. String sql = "select b.id as \"id\"," +
  941. " t.id as \"doctorId\"," +
  942. " t.name as \"doctorName\"," +
  943. " b.team_code as \"teamcode\"," +
  944. " b.org_code as \"orgcode\"" +
  945. "from base_team_member b left join base_doctor t on b.doctor_code = t.id" +
  946. " where b.del =1 ";
  947. if (StringUtils.isNotBlank(teamCode)){
  948. sql+=" and b.team_code ='"+teamCode+"'";
  949. }else{
  950. return null;
  951. }
  952. List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
  953. return list;
  954. }
  955. public ObjEnvelop createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) {
  956. templateDO.setCreateTime(new Date());
  957. templateDO.setDel(1);
  958. templateDO.setUpdateTime(new Date());
  959. templateDO = templateDao.save(templateDO);
  960. String templateId = templateDO.getId();
  961. String user = templateDO.getCreateUser();
  962. String userName = templateDO.getCreateUserName();
  963. //默认新增服务项
  964. String sql = "SELECT code from wlyy.system_dict WHERE `dict_name` = 'default_service_item_id'";
  965. List<String> list = jdbcTemplate.queryForList(sql,String.class);
  966. if(list!=null&&list.size()>0){
  967. list.stream().forEach(code->{
  968. RehabilitationTemplateDetailDO detailDO = new RehabilitationTemplateDetailDO();
  969. detailDO.setTemplateId(templateId);
  970. detailDO.setHospitalServiceItemId(code);
  971. detailDO.setCreateUser(user);
  972. detailDO.setCreateUserName(userName);
  973. detailDO.setCreateTime(new Date());
  974. detailDO.setUpdateTime(new Date());
  975. templateDetailDao.save(detailDO);
  976. });
  977. }
  978. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,templateDO.getId());
  979. }
  980. public ObjEnvelop createRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
  981. for(RehabilitationTemplateDetailDO detail : details){
  982. detail.setCreateTime(new Date());
  983. detail.setUpdateTime(new Date());
  984. templateDetailDao.save(detail);
  985. }
  986. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true);
  987. }
  988. public ObjEnvelop updateRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
  989. String templateId = details.get(0).getTemplateId();
  990. if(templateId != null && templateId.length() > 0){
  991. templateDetailDao.deleteByTemplateId(templateId);
  992. }
  993. for(RehabilitationTemplateDetailDO detail : details){
  994. detail.setCreateTime(new Date());
  995. detail.setUpdateTime(new Date());
  996. templateDetailDao.save(detail);
  997. }
  998. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true);
  999. }
  1000. public MixEnvelop findRehabilitationPlanTemplate(Long adminTeamCode, String doctor, String patient) {
  1001. List<RehabilitationPlanTemplateDO> list = templateDao.findByAdminTeamCode(adminTeamCode);
  1002. return MixEnvelop.getSuccessList(SpecialistMapping.api_success, list);
  1003. }
  1004. /**
  1005. * 根据模板id修改康复模板删除状态
  1006. * @param id
  1007. * @return
  1008. */
  1009. public ObjEnvelop deleteRehabilitationPlanTemplate(String id) {
  1010. templateDao.updateDelById(id);
  1011. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,true);
  1012. }
  1013. /**
  1014. * 根据模板id获取机构服务项目id,然后找出具体服务项目内容
  1015. * @param templateId
  1016. * @return
  1017. */
  1018. public ListEnvelop findTemplateDetailByTemplateId(String templateId) {
  1019. List<TemplateDetailVo> resultList = new ArrayList<>();
  1020. List<RehabilitationTemplateDetailDO> list = templateDetailDao.findTemplateDetailByTemplateId(templateId);
  1021. List<RehabilitationServiceItemDO> itemDOList = serviceItemDao.findList();
  1022. Map<String, List<RehabilitationTemplateDetailDO>> map = list.stream().collect(Collectors.groupingBy(RehabilitationTemplateDetailDO::getHospitalServiceItemId));
  1023. for (String code : map.keySet()){
  1024. TemplateDetailVo detailVo = new TemplateDetailVo();
  1025. detailVo.setCode(code);
  1026. detailVo.setId(code);
  1027. detailVo.setList(map.get(code));
  1028. for (RehabilitationServiceItemDO item:itemDOList){
  1029. if(code.equals(item.getCode())){
  1030. detailVo.setName(item.getName());
  1031. break;
  1032. }
  1033. }
  1034. resultList.add(detailVo);
  1035. }
  1036. return ListEnvelop.getSuccess(SpecialistMapping.api_success,resultList);
  1037. }
  1038. public List<RehabilitationServiceItemDO> findSystemTemplateList(){
  1039. List<RehabilitationServiceItemDO> itemDOList = serviceItemDao.findList();
  1040. return itemDOList;
  1041. }
  1042. public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId) {
  1043. for(RehabilitationDetailDO detail : details) {
  1044. /*List<String> list = new ArrayList<>();
  1045. list.add(detail.getHospitalServiceItemId());
  1046. HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0);
  1047. detail.setHospital(hospitalServiceItemDO.getHospital());
  1048. detail.setHospitalName(hospitalServiceItemDO.getHospitalName());
  1049. detail.setExpense(hospitalServiceItemDO.getExpense());*/
  1050. detail.setPlanId(planId);
  1051. detail.setCreateTime(new Date());
  1052. detail.setStatus(0);
  1053. detail.setUpdateTime(new Date());
  1054. }
  1055. return (List<RehabilitationDetailDO>)rehabilitationDetailDao.save(details);
  1056. }
  1057. public void deleteDetailByPlanIdAndHospitalServiceItemId(String planId, String hospitalServiceItemId, Date dateShort) {
  1058. rehabilitationDetailDao.deleteDetailByPlanIdAndHospitalServiceItemId(planId, hospitalServiceItemId, dateShort);
  1059. }
  1060. public void deleteDetailByPlanId(String planId, Date dateShort) {
  1061. rehabilitationDetailDao.deleteDetailByPlanId(planId, dateShort);
  1062. }
  1063. public List<RehabilitationDetailDO> updateRehabilitationPlan(String json, BaseDoctorDO doctor,String updateStatus) throws Exception {
  1064. JSONObject object = new JSONObject(json);
  1065. JSONArray array = object.getJSONArray("detail");
  1066. for (int z=0;z<array.length();z++){
  1067. JSONObject jsonObject = array.getJSONObject(z);
  1068. Long timeType = jsonObject.getLong("timeType");
  1069. Frequency frequency = frequencyDao.findByCode(jsonObject.getString("frequencyCode"));
  1070. String executeTimes = jsonObject.getString("executeTimes");
  1071. BaseDoctorDO doctor1 = doctorDao.findById(jsonObject.getString("doctor"));
  1072. if(StringUtils.isNotBlank(executeTimes)) {
  1073. List<String> list = new ArrayList<>();
  1074. String[] executeTime = executeTimes.split(",");
  1075. for (int i = 0; i < executeTime.length; i++) {
  1076. List<String> times = getFrequencyDate(frequency.getCode(), executeTime[i], frequency.getUnit(), frequency.getTime(), timeType);
  1077. for (int j = 0; j < times.size(); j++) {
  1078. if (list != null && list.size() != 0) {
  1079. if (!list.contains(times.get(j))) {
  1080. list.add(times.get(j));
  1081. }
  1082. } else {
  1083. list.add(times.get(j));
  1084. }
  1085. }
  1086. }
  1087. StringBuffer buffer = new StringBuffer();
  1088. if (list != null && list.size() != 0) {
  1089. for (int i = 0; i < list.size(); i++) {
  1090. buffer.append(list.get(i) + ",");
  1091. }
  1092. if (StringUtils.isNoneBlank(buffer)) {
  1093. buffer.deleteCharAt(buffer.length() - 1);
  1094. }
  1095. }
  1096. jsonObject.put("executeTime", buffer);
  1097. }
  1098. jsonObject.remove("executeTimes");
  1099. }
  1100. object.put("createUser", doctor.getId());
  1101. object.put("createUserName", doctor.getName());
  1102. String planId = object.getString("planId");
  1103. String hospitalServiceItemId = object.getString("hospitalServiceItemId");
  1104. //删除该服务项目今日之后未完成的计划
  1105. if(StringUtils.isBlank(updateStatus)||updateStatus.equals("0")){//单个服务的修改
  1106. deleteDetailByPlanIdAndHospitalServiceItemId(planId, hospitalServiceItemId, DateUtil.getDateShort(new Date()));
  1107. }
  1108. else{
  1109. deleteDetailByPlanId(planId, DateUtil.getDateShort(new Date()));
  1110. }
  1111. JSONArray array1 = new JSONArray();
  1112. for(Object planDetail : object.getJSONArray("detail")) {
  1113. String expense="";
  1114. JSONObject j = (JSONObject)planDetail;
  1115. if (j.get("expense") instanceof Integer){
  1116. expense= String.valueOf(j.getInt("expense"));
  1117. }
  1118. else{
  1119. expense = j.getString("expense");
  1120. if(expense.contains(".")){
  1121. int pointIndex = expense.indexOf(".");
  1122. expense = expense.substring(0,pointIndex);
  1123. }
  1124. }
  1125. j.put("expense",expense);
  1126. if(j.has("executeTime")) {
  1127. String executeTime = j.get("executeTime").toString();
  1128. String[] result = null;
  1129. if (executeTime.contains(",")) {
  1130. result = executeTime.split(",");
  1131. } else {
  1132. result = new String[1];
  1133. result[0] = executeTime;
  1134. }
  1135. int len = result.length;
  1136. while (len > 0) {
  1137. len--;
  1138. JSONObject temp = new JSONObject(j.toString());
  1139. temp.put("executeTime", result[len]);
  1140. temp.put("createUser", object.get("createUser"));
  1141. temp.put("createUserName", object.get("createUserName"));
  1142. array1.put(temp);
  1143. }
  1144. }else {
  1145. j.put("createUser", object.get("createUser"));
  1146. j.put("createUserName", object.get("createUserName"));
  1147. array1.put(j);
  1148. }
  1149. }
  1150. String planDetails = array1.toString();
  1151. ObjectMapper object1 = new ObjectMapper();
  1152. object1.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm"));
  1153. List<RehabilitationDetailDO> details = object1.readValue(planDetails, new TypeReference<List<RehabilitationDetailDO>>(){});
  1154. details = createRehabilitationDetail(details, planId);
  1155. String updateTime = DateUtil.dateToStr(details.get(0).getCreateTime(),"yyyy-MM-dd hh:mm:ss");
  1156. //康复计划修改 日志添加
  1157. String sql ="INSERT INTO wlyy_patient_rehabilitation_plan_log(id,plan_id,create_user,create_user_name,create_time) " +
  1158. "VALUES('"+getCode()+"','"+planId+"','"+doctor.getId()+"','"+ doctor.getName()+"','"+updateTime+"')";
  1159. jdbcTemplate.execute(sql);
  1160. return details;
  1161. }
  1162. /**
  1163. * 获取康复计划修改记录
  1164. * @param planId
  1165. * @return
  1166. */
  1167. public List<Map<String,Object>> getRehabilitationPlanLog(String planId){
  1168. String sql ="select * from wlyy_patient_rehabilitation_plan_log where plan_id = '"+planId+"' ORDER BY create_time DESC";
  1169. List<Map<String,Object>> planLogList = jdbcTemplate.queryForList(sql);
  1170. return planLogList;
  1171. }
  1172. /**
  1173. * 查询单个居民信息
  1174. *
  1175. * @param patient
  1176. * @return
  1177. * @throws Exception
  1178. */
  1179. public JSONObject getPatient(String patient,String doctor) throws Exception {
  1180. JSONObject json = new JSONObject();
  1181. // Patient p = patientDao.findByCode(patient);
  1182. BasePatientDO p = patientDao.findById(patient);
  1183. if (p == null) {
  1184. throw new Exception("patient info can not find");
  1185. }
  1186. // 设置患者标识
  1187. json.put("code", p.getId());
  1188. // 设置患者姓名
  1189. json.put("name", p.getName());
  1190. // 设置患者手机号
  1191. json.put("mobile", p.getMobile());
  1192. // 设置患者微信openid
  1193. json.put("openid", StringUtils.isNotEmpty(p.getOpenid()) ? p.getOpenid() : "");
  1194. json.put("openidTime",DateUtil.dateToStr(p.getOpenidTime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
  1195. // 设置患者联系电话
  1196. json.put("phone", p.getPhone());
  1197. // 设置患者头像
  1198. json.put("photo", p.getPhoto());
  1199. // 设置患者年龄
  1200. json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(),p.getBirthday()));
  1201. // 设置患者性别
  1202. json.put("sex", p.getSex());
  1203. // 身份证号
  1204. json.put("idcard", p.getIdcard());
  1205. //1.4.2新增medicareNumber
  1206. //json.put("medicareNumber", p.());
  1207. // 设置患者居住省份
  1208. json.put("provinceName", p.getProvinceName());
  1209. json.put("cityName", p.getCityName());
  1210. json.put("townName", p.getTownName());
  1211. json.put("streetName", p.getStreetName());
  1212. // 设置患者地址
  1213. json.put("address", p.getAddress());
  1214. // 社保号
  1215. json.put("ssc", p.getSsc());
  1216. //病情类型:0健康,1高血压,2糖尿病,(1,2)高血压+糖尿病
  1217. /* json.put("disease",p.getDisease());
  1218. // 病情:0绿标,1黄标,2红标,
  1219. json.put("diseaseCondition",p.getDiseaseCondition());*/
  1220. //预警状态
  1221. json.put("standardStatus",p.getStandardStatus());
  1222. //设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
  1223. /* json.put("deviceType",p.getDeviceType()==null?"":p.getDeviceType());
  1224. //20190719 增加返回字段:档案状态(-2冻结 1未管理 2死亡3 正常4 高危)
  1225. json.put("archiveStatus",p.getArchiveStatus() == null? "":p.getArchiveStatus().toString());
  1226. // 专病类型,专病名称
  1227. json.put("specialistDisease", p.getSpecialistDisease());
  1228. json.put("specialistDiseaseName", p.getSpecialistDiseaseName());
  1229. */
  1230. if (json.has("expensesStatus") && (StringUtils.isEmpty(String.valueOf(json.get("expensesStatus"))) || String.valueOf(json.get("expensesStatus")).equals("0"))) {
  1231. boolean epTime = false;
  1232. try {
  1233. epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getId());
  1234. } catch (Exception e) {
  1235. e.printStackTrace();
  1236. }
  1237. if (!epTime) {
  1238. json.put("expensesRemindStatus", 0);
  1239. } else {
  1240. json.put("expensesRemindStatus", 1);
  1241. }
  1242. }
  1243. boolean epTime = false;
  1244. try {
  1245. epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getId());
  1246. } catch (Exception e) {
  1247. e.printStackTrace();
  1248. }
  1249. if (!epTime) {
  1250. json.put("wechatFocusRemind", 0);
  1251. } else {
  1252. json.put("wechatFocusRemind", 1);
  1253. }
  1254. String timeKey = DateUtil.dateToStr(new Date(), "yyyyMMdd");
  1255. String flag = redisTemplate.opsForValue().get("renew:" + timeKey + ":" + patient);
  1256. if (StringUtils.isNotBlank(flag)) {
  1257. json.put("isRemindRenew", "1");
  1258. } else {
  1259. json.put("isRemindRenew", "0");
  1260. }
  1261. //1.4.9 是否专科医生服务
  1262. List<PatientSignInfoVO> patientSignInfoVOS =findPatientSignSpecialist(patient);
  1263. if(patientSignInfoVOS!=null&&patientSignInfoVOS.size()>0){
  1264. json.put("isSpecialist",1);
  1265. json.put("specialistArray", patientSignInfoVOS);
  1266. }else{
  1267. json.put("isSpecialist",0);
  1268. }
  1269. //1.5.0 是否有康复计划
  1270. List<PatientRehabilitationPlanDO> planList = planListByPatient(patient);
  1271. if(planList!=null&&planList.size()>0){
  1272. json.put("havePlan",1);
  1273. }else{
  1274. json.put("havePlan",0);
  1275. }
  1276. return json;
  1277. }
  1278. public List<PatientSignInfoVO> findPatientSignSpecialist(String patient){
  1279. String sql = "SELECT " +
  1280. " r.id AS relationCode, " +
  1281. " r.patient, " +
  1282. " r.team_code AS teamCode,r.patient_name as patientName" +
  1283. // AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
  1284. // " r.patient_name AS patientName, " +
  1285. // " d.name AS doctorName, " +
  1286. ",d.name as doctorName"+
  1287. // AesEncryptUtils.decryptMysql("d.name","doctorName") +
  1288. " ,d.id AS doctor, " +
  1289. " d.photo, " +
  1290. " d.job_title_name AS job, " +
  1291. " d.sex AS sex " +
  1292. " FROM " +
  1293. " wlyy_doctor_patient_relation r " +
  1294. " JOIN base_doctor d ON r.doctor = d.id " +
  1295. " WHERE " +
  1296. " r.patient ='"+patient+"' " +
  1297. " AND r.`status`>=0 " ;
  1298. //sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
  1299. List<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class));
  1300. return patientSignInfoVOs;
  1301. }
  1302. /**
  1303. * 根据居民获取康复计划
  1304. * @param patient
  1305. * @return
  1306. */
  1307. public List<PatientRehabilitationPlanDO> planListByPatient(String patient){
  1308. List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patient);
  1309. return list;
  1310. }
  1311. public JSONArray findTemplateDetailInfo(String templateId) throws Exception {
  1312. Map<String, Object> param = new HashedMap();
  1313. param.put("templateId", templateId);
  1314. HttpResponse response = null;
  1315. try {
  1316. response = HttpUtils.doGet(specialistUrl + "svr-specialist/findTemplateDetailByTemplateId", param);
  1317. } catch (Exception e) {
  1318. e.printStackTrace();
  1319. }
  1320. JSONObject rs = new JSONObject(response.getContent());
  1321. if (rs.getInt("status") == 200) {
  1322. JSONArray result = rs.getJSONArray("detailModelList");
  1323. for (int i=0;i<result.length();i++){
  1324. JSONObject obj = result.getJSONObject(i);
  1325. JSONObject reobj = obj.getJSONArray("list").getJSONObject(0);
  1326. if(!reobj.isNull("expense")){
  1327. Integer expense = reobj.getInt("expense");
  1328. obj.put("expense",expense);
  1329. }
  1330. else{
  1331. obj.put("expense",0);
  1332. }
  1333. }
  1334. return rs.getJSONArray("detailModelList");
  1335. }
  1336. throw new Exception("请求获取模板明细列表失败!");
  1337. }
  1338. }