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