RehabilitationManageService.java 178 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293
  1. package com.yihu.rehabilitation.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.fasterxml.jackson.databind.node.ObjectNode;
  6. import com.yihu.fastdfs.FastDFSUtil;
  7. import com.yihu.jw.doctor.dao.BaseDoctorDao;
  8. import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
  9. import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
  10. import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
  11. import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
  12. import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
  13. import com.yihu.jw.entity.base.patient.BasePatientDO;
  14. import com.yihu.jw.entity.door.SignFamily;
  15. import com.yihu.jw.entity.hospital.doctor.Frequency;
  16. import com.yihu.jw.entity.hospital.message.SystemMessageDO;
  17. import com.yihu.jw.entity.patient.Patient;
  18. import com.yihu.jw.entity.specialist.DoctorPatientRelationDO;
  19. import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
  20. import com.yihu.jw.entity.specialist.rehabilitation.*;
  21. import com.yihu.jw.entity.util.TransforSqlUtl;
  22. import com.yihu.jw.im.util.ImUtil;
  23. import com.yihu.jw.patient.dao.BasePatientDao;
  24. import com.yihu.jw.rehabilitation.*;
  25. import com.yihu.jw.restmodel.web.Envelop;
  26. import com.yihu.jw.restmodel.web.MixEnvelop;
  27. import com.yihu.jw.restmodel.web.ObjEnvelop;
  28. import com.yihu.jw.rm.base.BaseRequestMapping;
  29. import com.yihu.jw.rm.specialist.SpecialistMapping;
  30. import com.yihu.jw.util.common.IdCardUtil;
  31. import com.yihu.jw.util.common.QrcodeUtil;
  32. import com.yihu.jw.util.date.DateUtil;
  33. import com.yihu.jw.utils.hibernate.HibenateUtils;
  34. import com.yihu.rehabilitation.dao.*;
  35. import com.yihu.rehabilitation.util.HtmlUtil;
  36. import org.apache.commons.collections.map.HashedMap;
  37. import org.apache.commons.lang3.StringUtils;
  38. import org.json.JSONArray;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.beans.factory.annotation.Value;
  41. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  42. import org.springframework.jdbc.core.JdbcTemplate;
  43. import org.springframework.stereotype.Service;
  44. import org.springframework.transaction.annotation.Propagation;
  45. import org.springframework.transaction.annotation.Transactional;
  46. import java.io.InputStream;
  47. import java.sql.Timestamp;
  48. import java.text.DecimalFormat;
  49. import java.text.SimpleDateFormat;
  50. import java.util.*;
  51. /**
  52. * Created by 刘文彬 on 2018/8/16.
  53. */
  54. @Service
  55. @Transactional
  56. public class RehabilitationManageService {
  57. @Autowired
  58. private JdbcTemplate jdbcTemplate;
  59. @Autowired
  60. private RehabilitationDetailDao rehabilitationDetailDao;
  61. @Autowired
  62. private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
  63. @Autowired
  64. private GuidanceMessageLogDao guidanceMessageLogDao;
  65. @Autowired
  66. private SpecialistPatientRelationDao specialistPatientRelationDao;
  67. @Autowired
  68. private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
  69. @Autowired
  70. private RehabilitationDetailAppointmentDao rehabilitationDetailAppointmentDao;
  71. @Autowired
  72. private BaseDoctorDao baseDoctorDao;
  73. @Autowired
  74. private BaseDoctorRoleDao baseDoctorRoleDao;
  75. @Autowired
  76. private BasePatientDao basePatientDao;
  77. @Autowired
  78. private SignFamilyDao signFamilyDao;
  79. @Autowired
  80. private SpecialistEvaluateSevice specialistEvaluateSevice;
  81. @Autowired
  82. private FrequencyDao frequencyDao;
  83. @Autowired
  84. private ImUtil imUtil;
  85. @Autowired
  86. private PatientMedicalRecordsRehabilitationDao medicalRecordsRehabilitationDao;
  87. @Autowired
  88. private BaseDoctorHospitalDao baseDoctorHospitalDao;
  89. @Autowired
  90. private HibenateUtils hibenateUtils;
  91. @Autowired
  92. private DoctorPatientRelationDao doctorPatientRelationDao;
  93. @Autowired
  94. private FastDFSUtil fastDFSUtil;
  95. @Autowired
  96. private PatientMedicalRecordsRehabilitationDao patientMedicalRecordsDao;
  97. @Value("${im.data_base_name}")
  98. private String imDBName;
  99. @Value("${neiwang.enable}")
  100. private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传
  101. @Autowired
  102. private ZsRehabilitationInfoService zsRehabilitationInfoService;
  103. @Autowired
  104. private PatientRecordService patientRecordService;
  105. @Autowired
  106. private RehabilitationInfoService rehabilitationInfoService;
  107. @Autowired
  108. private ObjectMapper objectMapper;
  109. @Value("${demo.flag}")
  110. private Boolean demoFlag;
  111. /**
  112. * 预约协诊
  113. * @param doctor
  114. * @param doctorName
  115. * @param sendTime
  116. * @param planDetailId
  117. */
  118. public ObjEnvelop appointmentConsultation(String patient,String doctor, String doctorName,
  119. String appointmentDoctor,String appointmentDoctorName,String sendTime, String planDetailId){
  120. RehabilitationDetailAppointmentDO appointment = new RehabilitationDetailAppointmentDO();
  121. appointment.setAppointmentTime(sendTime+":00");
  122. appointment.setCreateTime(new Date());
  123. appointment.setDoctor(doctor);
  124. appointment.setDoctorName(doctorName);
  125. appointment.setAppointmentDoctor(appointmentDoctor);
  126. appointment.setAppointmentDoctorName(appointmentDoctorName);
  127. appointment.setIsSend(0);
  128. appointment.setRehabilitationPlanDetailId(planDetailId);
  129. appointment.setPatient(patient);
  130. rehabilitationDetailAppointmentDao.save(appointment);
  131. return ObjEnvelop.getSuccess("获取成功",appointment);
  132. }
  133. /**
  134. * 康复管理(专科)-- 计划列表
  135. * @param doctorCode
  136. * @param diseaseCode
  137. * @param planType
  138. * @param todaybacklog
  139. * @param page
  140. * @param pageSize
  141. * @return
  142. * @throws Exception
  143. */
  144. public MixEnvelop<Map<String,Object>, Map<String,Object>> findRehabilitationPlan(String doctorCode, String diseaseCode, Integer planType,Integer todaybacklog, String patientCondition,Integer page, Integer pageSize) throws Exception{
  145. Integer doctorType =null;
  146. BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
  147. List<BaseDoctorRoleDO> baseDoctorRoleDO = baseDoctorRoleDao.findByDoctorCode(doctor.getId());
  148. for(BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){
  149. if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){
  150. doctorType = 1;
  151. break;
  152. }else {
  153. doctorType = 2;
  154. }
  155. }
  156. String sql = " select DISTINCT p.* " +
  157. " from wlyy_rehabilitation_plan_detail a INNER JOIN wlyy_patient_rehabilitation_plan p " +
  158. " on a.plan_id = p.id " ;
  159. if(doctorType==2){//家医是根据签约关系过滤
  160. sql+=" INNER JOIN wlyy_sign_family f ON f.patient = p.patient \n" +
  161. "\tand f.expenses_status=1\n" +
  162. "\tAND f.STATUS >= 1 \n" +
  163. "\tAND ( f.doctor = '"+doctorCode+"' OR f.doctor_health = '"+doctorCode+"' ) ";
  164. }
  165. sql += " where 1=1 ";
  166. if(todaybacklog!=null&&todaybacklog==1){
  167. String todayStart = DateUtil.getStringDateShort()+" "+"00:00:00";
  168. String todayEnd = DateUtil.getStringDateShort()+" "+"23:59:59";
  169. sql += " and a.execute_time>='"+todayStart+"' and a.execute_time<='"+todayEnd+"'";
  170. }
  171. if(planType!=null){
  172. sql += " and p.plan_type="+planType;
  173. }
  174. if(StringUtils.isNotEmpty(diseaseCode)){
  175. sql+=" and p.disease='"+diseaseCode+"'";
  176. }
  177. if(StringUtils.isNotEmpty(patientCondition)){//姓名idcard模糊查询
  178. sql +=" AND EXISTS (select code from base_patient where `id` = p.patient and ( `name` LIKE '%"+patientCondition+"%' or idcard like '%"+patientCondition+"%') )";
  179. }
  180. if (doctorType==1){
  181. sql +=" AND (p.create_user = '"+doctorCode+"' \n" +
  182. "\tOR a.doctor = '"+doctorCode+"' ) ";
  183. }
  184. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planAll2(sql);
  185. List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
  186. int count = 0;
  187. if(rstotal!=null&&rstotal.size()>0&&rstotal.get(0).get("id")!=null){
  188. count = rstotal.size();
  189. }
  190. sql += " ORDER BY p.create_time DESC LIMIT "+(page-1)*pageSize+","+pageSize;
  191. System.out.println("sql==="+sql);
  192. List<Map<String,Object>> patientRehabilitationPlanDOList = jdbcTemplate.queryForList(sql);
  193. List<Map<String,Object>> resultList = new ArrayList<>();
  194. BasePatientDO patient =null;
  195. if(patientRehabilitationPlanDOList.size()>0&&patientRehabilitationPlanDOList.get(0).get("id")!=null){
  196. for(Map<String,Object> one:patientRehabilitationPlanDOList){
  197. Map<String,Object> resultMap = new HashMap<>();
  198. // Integer age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
  199. // String sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
  200. // resultMap.put("age",age);
  201. resultMap.put("hospitalName",one.get("hospital_name"));
  202. // resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
  203. resultMap.put("patientName",one.get("patientName"));
  204. resultMap.put("patientCode",one.get("patient"));
  205. patient = basePatientDao.findById(one.get("patient").toString());
  206. if (patient!=null){
  207. resultMap.put("photo",patient!=null?patient.getPhoto():"");
  208. Integer age = IdCardUtil.getAgeForIdcard(patient.getIdcard());
  209. String sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
  210. resultMap.put("age",age);
  211. resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
  212. SignFamily signFamily = signFamilyDao.findByPatient(one.get("patient").toString());
  213. if (signFamily != null){
  214. resultMap.put("hospitalName",signFamily.getHospitalName());
  215. }else {
  216. resultMap.put("hospitalName","");
  217. }
  218. }
  219. resultMap.put("id",one.get("id"));
  220. resultMap.put("status",one.get("status"));//康复计划状态
  221. //健康情况
  222. String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+one.get("patient")+"' and label_type=8";
  223. List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
  224. String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
  225. String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
  226. resultMap.put("healthyCondition",healthyCondition);
  227. resultMap.put("healthyConditionType",healthyConditionType);
  228. //安排类型
  229. String planTypeName = null;
  230. Integer planTypeTemp = (Integer)one.get("plan_type");
  231. switch (planTypeTemp){
  232. case 1:planTypeName="康复计划" ;break;
  233. case 2:planTypeName="(转)社区医院" ;break;
  234. case 3:planTypeName="(转)转家庭病床" ;break;
  235. }
  236. resultMap.put("planTypeName",planTypeName);
  237. resultMap.put("planCreateUser",one.get("create_user"));
  238. //今日待办(即今日全部的项目)
  239. Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"00:00:00");
  240. Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"23:59:59");
  241. Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.get("id").toString(),beginTime,endTime);
  242. resultMap.put("todayBacklogCount",todayBacklogCount);//今日待办总数
  243. //已完成
  244. Integer finishedCount = rehabilitationDetailDao.completenessCount(1,one.get("id").toString(),beginTime,endTime);
  245. resultMap.put("finishedCount",finishedCount);//已完成
  246. //未完成
  247. Integer notstartedCount = rehabilitationDetailDao.completenessCount(0,one.get("id").toString(),beginTime,endTime);//未开始
  248. Integer underwayCount = rehabilitationDetailDao.completenessCount(2,one.get("id").toString(),beginTime,endTime);//已预约
  249. Integer unfinishedCount = notstartedCount+underwayCount;
  250. resultMap.put("unfinishedCount",unfinishedCount);//未完成
  251. //完成度(已完成/(已完成+未完成))
  252. Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.get("id").toString());
  253. Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.get("id").toString());
  254. resultMap.put("allCount",allCount);//总数
  255. resultMap.put("allFinishCount",allFinishCount);//全部已完成数
  256. resultMap.put("createTime",one.get("create_time"));
  257. resultList.add(resultMap);
  258. }
  259. }
  260. return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,Long.valueOf(count));
  261. }
  262. /**
  263. * 康复管理更多计划
  264. * @param currentDoctorCode
  265. * @param patientCode
  266. * @return
  267. * @throws Exception
  268. */
  269. public ObjEnvelop findRehabilitationPlanDetailList(String currentDoctorCode,String patientCode) throws Exception{
  270. String sql = " select DISTINCT r.* from wlyy_doctor_patient_relation r join wlyy_patient_rehabilitation_plan p on r.patient=p.patient where r.status in('0','1') and r.patient='"+patientCode+"' ";
  271. //sql = TransforSqlUtl.specialistPatientRelationAll2(sql);
  272. List<Map<String,Object>> specialistPatientRelationList = jdbcTemplate.queryForList(sql);
  273. List<Map<String,Object>> resultList = new ArrayList<>();
  274. for(Map<String,Object> temp: specialistPatientRelationList){
  275. String doctorCode = temp.get("doctor")+"";
  276. Map<String,Object> resultMap = new HashMap<>();
  277. Integer isOperator = 0;
  278. resultMap.put("patientCode",patientCode);//居民code
  279. String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+patientCode+"' and label_type=8";
  280. List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
  281. String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
  282. String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
  283. resultMap.put("healthyCondition",healthyCondition);
  284. resultMap.put("healthyConditionType",healthyConditionType);
  285. //专科医生
  286. String specialistRelationSql = "select r.*,t.name as teamName,h.name as specialistHospitalName from wlyy_doctor_patient_relation r left join base_team t on r.team_code=t.id left join base_org h on t.org_code=h.code where r.status in('0','1') and r.patient='"+patientCode+"' and r.doctor='"+doctorCode+"'";
  287. specialistRelationSql = TransforSqlUtl.specialistPatientRelationAll2(specialistRelationSql);
  288. List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
  289. Map<String,Object> specialistMap = specialistRelationList.get(0);
  290. resultMap.put("specialistAdminTeamName",specialistMap.get("teamName"));
  291. resultMap.put("specialistHospitalName",specialistMap.get("specialistHospitalName"));//专科医生所在医院
  292. Integer specialistUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(doctorCode,patientCode,1);
  293. Integer specialistFinishCount1 = rehabilitationDetailDao.findItemByDoctor(doctorCode,patientCode);
  294. Integer specialistServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(doctorCode,patientCode,1);
  295. /*Integer specialistUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(specialistMap.get("health_assistant")+"",patientCode,1);
  296. Integer specialistFinishCount2 = rehabilitationDetailDao.findItemByDoctor(specialistMap.get("health_assistant")+"",patientCode);
  297. Integer specialistServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(specialistMap.get("health_assistant")+"",patientCode,1);*/
  298. resultMap.put("specialistFinishItemCount",specialistFinishCount1-specialistUnfinishCount1);//完成项目
  299. resultMap.put("specialistServiceRecordCount",specialistServiceCount1);//服务次数
  300. //家庭医生(包括全科医生、健管师)
  301. String signFamilySql = "SELECT f.*,t.name as teamName FROM wlyy_sign_family f LEFT JOIN wlyy_admin_team t on f.admin_team_code=t.id where f.status =1 and f.expenses_status='1' and f.patient='"+patientCode+"'";
  302. List<Map<String,Object>> signFamilyList = jdbcTemplate.queryForList(signFamilySql);
  303. if(signFamilyList != null && signFamilyList.size() >0 ) {
  304. Map<String, Object> signFamilyMap = signFamilyList.get(0);
  305. resultMap.put("signFamilyAdminTeamName", signFamilyMap.get("teamName"));
  306. resultMap.put("familyHospitalName", signFamilyMap.get("hospital_name"));//家庭医生所在医院
  307. Integer familyUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
  308. Integer familyFinishCount1 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor") + "", patientCode);
  309. Integer familyServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
  310. if ((signFamilyMap.get("doctor") + "").equals(signFamilyMap.get("doctor_health") + "")) {
  311. resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1);//完成项目
  312. resultMap.put("signFamilyServiceRecordCount", familyServiceCount1);//服务次数
  313. } else {
  314. Integer familyUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
  315. Integer familyFinishCount2 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode);
  316. Integer familyServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
  317. resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1 + familyFinishCount2 - familyUnfinishCount2);//完成项目
  318. resultMap.put("signFamilyServiceRecordCount", familyServiceCount1 + familyServiceCount2);//服务次数
  319. }
  320. //基础信息
  321. resultMap.put("hospitalName", signFamilyMap.get("hospital_name"));
  322. Integer age = IdCardUtil.getAgeForIdcard(signFamilyMap.get("idcard") + "");
  323. String sex = IdCardUtil.getSexForIdcard_new(signFamilyMap.get("idcard") + "");
  324. resultMap.put("age", age);
  325. resultMap.put("sex", "1".equals(sex) ? "男" : ("2".equals(sex) ? "女" : "未知"));
  326. resultMap.put("patientName", signFamilyMap.get("patientName"));
  327. }
  328. /* //疾病类型
  329. String diseaseSql = " select s.* from wlyy_patient_disease_server s where s.del=1 and s.patient='"+patientCode+"' and s.specialist_relation_code='"+specialistMap.get("id")+"' ";
  330. List<Map<String,Object>> diseaseList = jdbcTemplate.queryForList(diseaseSql);
  331. List<String> disease = new ArrayList<>();
  332. for(Map<String,Object> one2:diseaseList){
  333. disease.add(one2.get("disease_name")+"");
  334. }
  335. resultMap.put("diseaseList",disease);*/
  336. //计划列表
  337. List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatientAndCreateUser(patientCode,doctorCode);
  338. List<Map<String,Object>> rehabilitationPlanList = new ArrayList<>();
  339. for(PatientRehabilitationPlanDO one:list){
  340. Map<String,Object> planMap = new HashMap<>();
  341. planMap.put("planId",one.getId());
  342. //安排类型
  343. String planTypeName = null;
  344. Integer planTypeTemp = one.getPlanType();
  345. switch (planTypeTemp){
  346. case 1:planTypeName="康复计划" ;break;
  347. case 2:planTypeName="(转)社区医院" ;break;
  348. case 3:planTypeName="(转)转家庭病床" ;break;
  349. }
  350. planMap.put("planTypeName",planTypeName);
  351. planMap.put("status",one.getStatus());//0已中止,1进行中,2已完成
  352. if(currentDoctorCode.equals(doctorCode)){
  353. isOperator = 1;
  354. }
  355. planMap.put("isOperator",isOperator);
  356. //状态(0未完成,1已完成,2已预约)
  357. //今日待办
  358. Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"00:00:00");
  359. Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"23:59:59");
  360. Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.getId(),beginTime,endTime);
  361. planMap.put("todayBacklogCount",todayBacklogCount);
  362. //已完成
  363. Integer finishedCount = rehabilitationDetailDao.completenessCount(1,one.getId(),beginTime,endTime);
  364. planMap.put("finishedCount",finishedCount);//已完成
  365. //未完成
  366. Integer notstartedCount = rehabilitationDetailDao.completenessCount(0,one.getId(),beginTime,endTime);//未完成
  367. Integer underwayCount = rehabilitationDetailDao.completenessCount(2,one.getId(),beginTime,endTime);//已预约
  368. Integer unfinishedCount = notstartedCount+underwayCount;
  369. planMap.put("unfinishedCount",unfinishedCount);//未完成
  370. //完成度(已完成/(已完成+未完成))
  371. Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.getId());
  372. Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
  373. planMap.put("allCount",allCount);//总数
  374. planMap.put("allFinishCount",allFinishCount);//全部已完成数
  375. rehabilitationPlanList.add(planMap);
  376. }
  377. resultMap.put("rehabilitationPlanList",rehabilitationPlanList);
  378. BasePatientDO p = basePatientDao.findById(patientCode);
  379. resultMap.put("patientPhoto",p.getPhoto());
  380. resultList.add(resultMap);
  381. }
  382. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultList);
  383. }
  384. /**
  385. * 日历
  386. * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
  387. * @param status 任务状态(0未完成,1已完成,2已预约)
  388. * @param doctorCode 登陆医生
  389. * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
  390. */
  391. public ObjEnvelop calendarPlanDetailByPatient(String executeStartTime,String executeEndTime,String patient,Integer searchTask,Integer status,String doctorCode,String taskExecutor) throws Exception{
  392. List<Map<String,Object>> planList = getPatientAllRehabilitationPlan(patient);
  393. StringBuilder planCondition = new StringBuilder();
  394. planCondition .append("'"+planList.get(0).get("id").toString()+"'");
  395. for (int i=1;i<planList.size();i++){
  396. planCondition .append(",'"+planList.get(0).get("id").toString()+"'");
  397. }
  398. String sql = " select d.* from wlyy_rehabilitation_plan_detail d " +
  399. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  400. " where d.plan_id in ("+planCondition+") " +
  401. "" ;
  402. if(StringUtils.isNotBlank(executeStartTime)){
  403. sql += " and d.execute_time>='"+executeStartTime+"' ";
  404. }
  405. if(StringUtils.isNotBlank(executeEndTime)){
  406. sql += " and d.execute_time<='"+executeEndTime+"' ";
  407. }
  408. if(searchTask!=null){
  409. if(searchTask==8){
  410. sql+=" and d.doctor='"+doctorCode+"' " ;
  411. }else {
  412. sql+=" and i.code="+searchTask+" " ;
  413. }
  414. }
  415. if(taskExecutor.equals("1")){ //我的任务
  416. sql+="and d.doctor='"+doctorCode+"' ";
  417. }
  418. if(taskExecutor.equals("2")){//他人任务
  419. sql+="and d.doctor <>'"+doctorCode+"' ";
  420. }
  421. if(status!=null){
  422. sql+= " and d.status="+status;
  423. }
  424. sql += " ORDER BY d.execute_time ";
  425. List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
  426. // List<RehabilitationDetailDO> rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId);
  427. Map<String,Map<String,Object>> map = new LinkedHashMap<>();
  428. for(Map<String,Object> one:rehabilitationDetailList){
  429. String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD);
  430. Map<String,Object> m = null;
  431. if(map.containsKey(executeTime)){
  432. m = map.get(executeTime);
  433. Map<String,Integer> family = null;
  434. Map<String,Integer> specialist = null;
  435. if(one.get("type")!=null){
  436. if((Integer)one.get("type")==1){//家庭医生
  437. if(m.containsKey("family")){
  438. family = (Map<String,Integer>)m.get("family");
  439. }else{
  440. family = new HashMap<>();
  441. family.put("all",0);
  442. family.put("finish",0);
  443. }
  444. if((Integer)one.get("status")==1){
  445. family.put("finish",family.get("finish")+1);
  446. }
  447. family.put("all",family.get("all")+1);
  448. m.put("family",family);
  449. }else if((Integer)one.get("type")==2){//专科医生
  450. if(m.containsKey("specialist")){
  451. specialist = (Map<String,Integer>)m.get("specialist");
  452. }else{
  453. specialist = new HashMap<>();
  454. specialist.put("all",0);
  455. specialist.put("finish",0);
  456. }
  457. if((Integer)one.get("status")==1){
  458. specialist.put("finish",(specialist.get("finish"))+1);
  459. }
  460. specialist.put("all",(specialist.get("all"))+1);
  461. m.put("specialist",specialist);
  462. }
  463. }
  464. }else{
  465. m = new HashMap<>();
  466. // m.put("specialist",new HashMap<String,Object>());
  467. if(one.get("type")!=null){
  468. if((Integer)one.get("type")==1){//家庭医生
  469. Map<String,Integer> family = new HashMap<>();
  470. family.put("all",0);
  471. family.put("finish",0);
  472. if((Integer)one.get("status")==1){
  473. family.put("finish",family.get("finish")+1);
  474. }
  475. family.put("all",family.get("all")+1);
  476. m.put("family",family);
  477. }else if((Integer)one.get("type")==2){//专科医生
  478. Map<String,Integer> specialist = new HashMap<>();
  479. specialist.put("all",0);
  480. specialist.put("finish",0);
  481. if((Integer)one.get("status")==1){
  482. specialist.put("finish",specialist.get("finish")+1);
  483. }
  484. specialist.put("all",specialist.get("all")+1);
  485. m.put("specialist",specialist);
  486. }
  487. }
  488. }
  489. //myTaskFlag,1:有自己任务,0:没有自己任务
  490. if(StringUtils.isNotEmpty(doctorCode)){
  491. if(m.containsKey("myTaskFlag")){
  492. if((Integer)m.get("myTaskFlag")==0){
  493. if(doctorCode.equals(one.get("doctor").toString())){
  494. m.put("myTaskFlag",1);
  495. }else{
  496. m.put("myTaskFlag",0);
  497. }
  498. }
  499. }else{
  500. if(doctorCode.equals(one.get("doctor").toString())){
  501. m.put("myTaskFlag",1);
  502. }else{
  503. m.put("myTaskFlag",0);
  504. }
  505. }
  506. }
  507. if(m.containsKey("planDetailIds")){
  508. m.put("planDetailIds",m.get("planDetailIds")+","+one.get("id"));
  509. }else{
  510. m.put("planDetailIds",one.get("id")+"");
  511. }
  512. map.put(executeTime,m);
  513. }
  514. /*List list = new ArrayList();
  515. for(String key : map.keySet()){
  516. Map<String,Object> result = map.get(key);
  517. result.put("executeTime", key);
  518. list.add(result);
  519. }*/
  520. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
  521. }
  522. /**
  523. * 日历
  524. * @param planId 计划id
  525. * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
  526. * @param status 任务状态(0未完成,1已完成,2已预约)
  527. * @param doctorCode 登陆医生
  528. * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
  529. */
  530. public ObjEnvelop calendarPlanDetail(String executeStartTime,String executeEndTime,String planId,Integer searchTask,Integer status,String doctorCode,String taskExecutor) throws Exception{
  531. String[] planIdlist = planId.split(",");
  532. StringBuilder planCondition = new StringBuilder();
  533. planCondition .append("'"+planIdlist[0]+"'");
  534. for (int i=1;i<planIdlist.length;i++){
  535. planCondition .append(",'"+planIdlist[i]+"'");
  536. }
  537. String sql = " select d.* from wlyy_rehabilitation_plan_detail d " +
  538. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  539. " where d.plan_id in ("+planCondition+") " +
  540. " " ;
  541. if(StringUtils.isNotBlank(executeStartTime)){
  542. sql += " and d.execute_time>='"+executeStartTime+"' ";
  543. }
  544. if(StringUtils.isNotBlank(executeEndTime)){
  545. sql += " and d.execute_time<='"+executeEndTime+"' ";
  546. }
  547. if(searchTask!=null){
  548. if(searchTask==8){
  549. sql+=" and d.doctor='"+doctorCode+"' " ;
  550. }else {
  551. sql+=" and i.code="+searchTask+" " ;
  552. }
  553. }
  554. if(taskExecutor.equals("1")){ //我的任务
  555. sql+="and d.doctor='"+doctorCode+"' ";
  556. }
  557. if(taskExecutor.equals("2")){//他人任务
  558. sql+="and d.doctor <>'"+doctorCode+"' ";
  559. }
  560. if(status!=null){
  561. sql+= " and d.status="+status;
  562. }
  563. sql += " ORDER BY d.execute_time ";
  564. List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
  565. // List<RehabilitationDetailDO> rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId);
  566. Map<String,Map<String,Object>> map = new LinkedHashMap<>();
  567. for(Map<String,Object> one:rehabilitationDetailList){
  568. String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD);
  569. Map<String,Object> m = null;
  570. if(map.containsKey(executeTime)){
  571. m = map.get(executeTime);
  572. Map<String,Integer> family = null;
  573. Map<String,Integer> specialist = null;
  574. if(one.get("type")!=null){
  575. if((Integer)one.get("type")==1){//家庭医生
  576. if(m.containsKey("family")){
  577. family = (Map<String,Integer>)m.get("family");
  578. }else{
  579. family = new HashMap<>();
  580. family.put("all",0);
  581. family.put("finish",0);
  582. }
  583. if((Integer)one.get("status")==1){
  584. family.put("finish",family.get("finish")+1);
  585. }
  586. family.put("all",family.get("all")+1);
  587. m.put("family",family);
  588. }else if((Integer)one.get("type")==2){//专科医生
  589. if(m.containsKey("specialist")){
  590. specialist = (Map<String,Integer>)m.get("specialist");
  591. }else{
  592. specialist = new HashMap<>();
  593. specialist.put("all",0);
  594. specialist.put("finish",0);
  595. }
  596. if((Integer)one.get("status")==1){
  597. specialist.put("finish",(specialist.get("finish"))+1);
  598. }
  599. specialist.put("all",(specialist.get("all"))+1);
  600. m.put("specialist",specialist);
  601. }
  602. }
  603. }else{
  604. m = new HashMap<>();
  605. // m.put("specialist",new HashMap<String,Object>());
  606. if(one.get("type")!=null){
  607. if((Integer)one.get("type")==1){//家庭医生
  608. Map<String,Integer> family = new HashMap<>();
  609. family.put("all",0);
  610. family.put("finish",0);
  611. if((Integer)one.get("status")==1){
  612. family.put("finish",family.get("finish")+1);
  613. }
  614. family.put("all",family.get("all")+1);
  615. m.put("family",family);
  616. }else if((Integer)one.get("type")==2){//专科医生
  617. Map<String,Integer> specialist = new HashMap<>();
  618. specialist.put("all",0);
  619. specialist.put("finish",0);
  620. if((Integer)one.get("status")==1){
  621. specialist.put("finish",specialist.get("finish")+1);
  622. }
  623. specialist.put("all",specialist.get("all")+1);
  624. m.put("specialist",specialist);
  625. }
  626. }
  627. }
  628. //myTaskFlag,1:有自己任务,0:没有自己任务
  629. if(StringUtils.isNotEmpty(doctorCode)){
  630. if(m.containsKey("myTaskFlag")){
  631. if((Integer)m.get("myTaskFlag")==0){
  632. if(doctorCode.equals(one.get("doctor").toString())){
  633. m.put("myTaskFlag",1);
  634. }else{
  635. m.put("myTaskFlag",0);
  636. }
  637. }
  638. }else{
  639. if(doctorCode.equals(one.get("doctor").toString())){
  640. m.put("myTaskFlag",1);
  641. }else{
  642. m.put("myTaskFlag",0);
  643. }
  644. }
  645. }
  646. if(m.containsKey("planDetailIds")){
  647. m.put("planDetailIds",m.get("planDetailIds")+","+one.get("id"));
  648. }else{
  649. m.put("planDetailIds",one.get("id")+"");
  650. }
  651. map.put(executeTime,m);
  652. }
  653. /*List list = new ArrayList();
  654. for(String key : map.keySet()){
  655. Map<String,Object> result = map.get(key);
  656. result.put("executeTime", key);
  657. list.add(result);
  658. }*/
  659. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
  660. }
  661. /**
  662. * 日历列表
  663. * @param planId 计划id
  664. * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
  665. * @param status 任务状态(0未完成,1已完成,2已预约)
  666. * @param doctorCode 登陆医生
  667. * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
  668. */
  669. public ObjEnvelop calendarPlanDetailList(String planId,Integer searchTask,Integer status,String doctorCode,String executeStartTime,String executeEndTime,String taskExecutor){
  670. String[] planIdlist = planId.split(",");
  671. StringBuilder planCondition = new StringBuilder();
  672. planCondition .append("'"+planIdlist[0]+"'");
  673. for (int i=1;i<planIdlist.length;i++){
  674. planCondition .append(",'"+planIdlist[i]+"'");
  675. }
  676. String sql = " select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,i.name from wlyy_rehabilitation_plan_detail d " +
  677. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  678. " where d.plan_id in ("+planCondition+" )AND d.execute_time IS NOT NULL " +
  679. " and d.execute_time <>'' " ;
  680. if(searchTask!=null){
  681. if(searchTask==8){//
  682. sql+="and d.doctor='"+doctorCode+"' ";
  683. }else {
  684. sql+=" and i.code="+searchTask+" " ;
  685. }/*else if(searchTask==5){
  686. sql+=" and i.reserve=1 " ;
  687. }*/
  688. }
  689. if("1".equals(taskExecutor)){ //我的任务
  690. sql+="and d.doctor='"+doctorCode+"' ";
  691. }
  692. if("2".equals(taskExecutor)){//他人任务
  693. sql+="and d.doctor <>'"+doctorCode+"' ";
  694. }
  695. if (StringUtils.isNoneBlank(executeEndTime)&&StringUtils.isNoneBlank(executeStartTime)){
  696. sql+="and d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' ";
  697. }
  698. if(status!=null){
  699. sql+= "and d.status="+status;
  700. }
  701. sql +=" order by d.execute_time desc ";
  702. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
  703. List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
  704. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,rehabilitationDetailList);
  705. }
  706. /**
  707. * 日历列表
  708. * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
  709. * @param status 任务状态(0未完成,1已完成,2已预约)
  710. * @param doctorCode 登陆医生
  711. * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
  712. */
  713. public ObjEnvelop calendarPlanDetailListByPatient(String executeStartTime,String executeEndTime,String patient,Integer searchTask,Integer status,String doctorCode,String taskExecutor){
  714. List<Map<String,Object>> planList = getPatientAllRehabilitationPlan(patient);
  715. StringBuilder planCondition = new StringBuilder();
  716. planCondition .append("'"+planList.get(0).get("id").toString()+"'");
  717. for (int i=1;i<planList.size();i++){
  718. planCondition .append(",'"+planList.get(0).get("id").toString()+"'");
  719. }
  720. String sql = " select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,i.name from wlyy_rehabilitation_plan_detail d " +
  721. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  722. " where d.plan_id in ("+planCondition+" )AND d.execute_time IS NOT NULL and d.execute_time <>'' " ;
  723. if(searchTask!=null){
  724. if(searchTask==8){//
  725. sql+="and d.doctor='"+doctorCode+"' ";
  726. }else {
  727. sql+=" and i.code="+searchTask+" " ;
  728. }/*else if(searchTask==5){
  729. sql+=" and i.reserve=1 " ;
  730. }*/
  731. }
  732. if("1".equals(taskExecutor)){ //我的任务
  733. sql+="and d.doctor='"+doctorCode+"' ";
  734. }
  735. if("2".equals(taskExecutor)){//他人任务
  736. sql+="and d.doctor <>'"+doctorCode+"' ";
  737. }
  738. if (StringUtils.isNoneBlank(executeEndTime)&&StringUtils.isNoneBlank(executeStartTime)){
  739. sql+="and d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' ";
  740. }
  741. if(status!=null){
  742. sql+= "and d.status="+status;
  743. }
  744. sql +=" order by d.execute_time desc ";
  745. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
  746. List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
  747. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,rehabilitationDetailList);
  748. }
  749. /**
  750. * 多个康复计划服务项目内容列表
  751. * @param planDetailIds
  752. * @return
  753. * @throws Exception
  754. */
  755. public ObjEnvelop serviceItemList(String planDetailIds,String doctorCode) throws Exception{
  756. String[] s = planDetailIds.split(",");
  757. String planDetailList = "";
  758. for(String one:s){
  759. planDetailList +=",'"+one+"'";
  760. }
  761. String planDetailResult = StringUtils.isNotEmpty(planDetailList)?planDetailList.substring(1):"";
  762. String sql = "select i.name,i.code,i.introduce,d.execute_time,d.hospital_name,d.id,d.status,d.type as detailType,d.expense,d.doctor as executeDoctor," +
  763. " d.doctor_name as executeDoctorName,p.patient ,p.id AS planId,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus " +
  764. " from wlyy_rehabilitation_plan_detail d " +
  765. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  766. " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
  767. " where d.id in ("+planDetailResult+") order BY d.execute_time ASC";
  768. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
  769. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
  770. List<Map<String,Object>> serviceItemList = jdbcTemplate.queryForList(sql);
  771. // if(serviceItemList.size()>0){
  772. // Map<String,Object> serviceItem = serviceItemList.get(0);
  773. List<Map<String,Object>> resultList = new ArrayList<>();
  774. for(Map<String,Object> one:serviceItemList){
  775. Map<String,Object> resultMap = new HashMap<>();
  776. Integer isMyTask = 0;
  777. if(StringUtils.isNotEmpty(doctorCode)&&doctorCode.equals(one.get("executeDoctor")+"")){
  778. isMyTask=1;
  779. }
  780. resultMap.put("isMyTask",isMyTask);//0不是自己的任务,1是自己的任务
  781. // if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
  782. // executeDoctorList.add(one.get("create_user_name")+"");
  783. // }
  784. List<String> executeDoctorList = new ArrayList<>();
  785. executeDoctorList.add(one.get("executeDoctorName")+"");
  786. resultMap.put("executeDoctorList",executeDoctorList);//执行医生名称列表
  787. resultMap.put("executeDoctorCode",one.get("executeDoctor")+"");//执行医生code
  788. resultMap.put("executeDoctorName",one.get("executeDoctorName")+"");//执行医生code
  789. resultMap.put("specialistDoctorCode",one.get("createDoctor")+"");//创建人(专科)医生code
  790. resultMap.put("specialistDoctorName",one.get("createDoctorName")+"");//创建人(专科)医生名字
  791. resultMap.put("title",one.get("name"));//项目标题
  792. resultMap.put("planDetaiId",one.get("id"));//计划服务项目id
  793. resultMap.put("planId",one.get("planId"));//计划id
  794. resultMap.put("shortExecuteTime",DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.HH_MM));//项目标题
  795. resultMap.put("content",one.get("content"));//项目内容
  796. resultMap.put("hospitalName",one.get("hospital_name"));//地点
  797. resultMap.put("executeTime",one.get("execute_time"));//执行时间
  798. DecimalFormat df = new DecimalFormat("0.00");
  799. resultMap.put("expense", one.get("expense")!=null?df.format(((Integer)one.get("expense")*1.00)):0);//收费
  800. resultMap.put("reserve",null);//是否需要预约(1预约、0不预约)
  801. resultMap.put("planStatus",one.get("planStatus"));//计划的状态
  802. Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
  803. String statusName = "";
  804. switch (status){
  805. case 0:{statusName="未完成";break;}
  806. case 1:{statusName="已完成";break;}
  807. case 2:{statusName="已预约";break;}
  808. }
  809. resultMap.put("statusName",statusName);//状态
  810. //指导与汇报
  811. List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
  812. List<Map<String,Object>> messageMapList = new ArrayList<>();
  813. for(GuidanceMessageLogDO one2:messageList){
  814. Map<String,Object> map = new HashMap<>();
  815. map.put("doctorName",one2.getDoctorName());
  816. map.put("adminTeamName",one2.getAdminTeamName());
  817. map.put("content",one2.getContent());
  818. map.put("contentType",one2.getContentType());
  819. map.put("createTime",DateUtil.dateToStr(one2.getCreateTime(),"MM-dd HH:mm"));
  820. messageMapList.add(map);
  821. }
  822. /* Integer itemType = (Integer) one.get("itemType");*/
  823. resultMap.put("messageList",messageMapList);//指导与汇报记录
  824. resultMap.put("patient",one.get("patient"));
  825. resultMap.put("itemType",one.get("code"));
  826. resultMap.put("detaiType",one.get("detaiType"));
  827. resultMap.put("status",status);//状态
  828. //是否完成任务
  829. List<RehabilitationOperateRecordsDO> operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
  830. Integer operate = 0;
  831. if(operateList.size()>0){
  832. operate =1;
  833. RehabilitationOperateRecordsDO temp = operateList.get(0);
  834. operate =1;
  835. Date completeTime = temp.getCompleteTime();
  836. String completeTimeStr = DateUtil.dateToStr(completeTime,DateUtil.YYYY_MM_DD_HH_MM);
  837. resultMap.put("completeTime",completeTimeStr);//完成时间
  838. resultMap.put("operatorDoctorName",temp.getDoctorName());//执行医生名称
  839. resultMap.put("node",temp.getNode());
  840. resultMap.put("relationRecordImg",(temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg()))?(new JSONArray(temp.getRelationRecordImg())):null);//json格式
  841. resultMap.put("relationRecordCode",temp.getRelationRecordCode());
  842. resultMap.put("completeTimeShort",DateUtil.dateToStr(completeTime,"yyyy/MM/dd"));
  843. }
  844. resultMap.put("operate",operate);//是否完成任务(默认0:未完成,1:已完成)
  845. List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(one.get("patient").toString(),"1",1);
  846. if(list.size()>0){
  847. resultMap.put("familyDoctorCode",list.get(0).getDoctor());
  848. resultMap.put("familyDoctorName",list.get(0).getDoctorName());
  849. }else{
  850. resultMap.put("familyDoctorCode","");
  851. resultMap.put("familyDoctorName","");
  852. }
  853. resultList.add(resultMap);
  854. }
  855. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultList);
  856. // }
  857. // return MixEnvelop.getError("没有该服务项详情信息!");
  858. }
  859. /**
  860. * 康复计划服务项目确认页
  861. * @param planDetailId
  862. * @return
  863. * @throws Exception
  864. *
  865. */
  866. public ObjEnvelop serviceItem(String planDetailId,String doctorCode,String recordId) throws Exception{
  867. String sql = "select h.name as title,h.content as content,h.code as itemType,d.id,d.execute_time,d.hospital_name,d.status,d.type,d.expense,d.doctor as executeDoctor, " +
  868. " d.doctor_name as executeDoctorName,p.patient ,p.name as patientName,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus," +
  869. " p.disease,p.disease_name as diseaseName,p.title as planTitle,d.plan_id as planId,d.relation_code as relationCode,d.frequency_code as frequencyCode,d.remark "+
  870. " ,a.appointment_time appointmentTime,a.appointment_doctor appointmentDoctor,a.appointment_doctor_name appointmentDoctorName,d.reservation_type reservationType" +
  871. " from wlyy_rehabilitation_plan_detail d " +
  872. " LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id = h.code "+
  873. " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
  874. " LEFT JOIN wlyy_plan_detail_appointment a on d.id=.a.rehabilitation_plan_detail_id " +
  875. " where d.id = '"+planDetailId+"'";
  876. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName2(sql);
  877. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
  878. sql = TransforSqlUtl.wlyy_plan_detail_appointmentAppDoctorName(sql);
  879. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
  880. System.out.println("sql===="+sql);
  881. List<Map<String,Object>> serviceItemList = jdbcTemplate.queryForList(sql);
  882. if (serviceItemList.size()==0){
  883. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,new HashMap<>());
  884. }
  885. Map<String,Object> one = serviceItemList.get(0);
  886. Map<String,Object> resultMap = new HashMap<>();
  887. List<String> executeDoctorList = new ArrayList<>();
  888. Integer isMyTask = 0;
  889. //判断登陆者和执行医生是不是同一个人
  890. if(StringUtils.isNotEmpty(doctorCode)&&doctorCode.equals(one.get("executeDoctor")+"")){
  891. isMyTask=1;
  892. }
  893. // 协诊预约信息
  894. resultMap.put("appointmentTime",one.get("appointmentTime"));
  895. resultMap.put("appointmentDoctor",one.get("appointmentDoctor"));
  896. resultMap.put("appointmentDoctorName",one.get("appointmentDoctorName"));
  897. resultMap.put("reservationType",one.get("reservationType"));//复诊类型:1线上,2线下,3远程
  898. resultMap.put("frequencyCode",one.get("frequencyCode")+"");
  899. resultMap.put("isMyTask",isMyTask);//0不是自己的任务,1是自己的任务
  900. // if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
  901. // executeDoctorList.add(one.get("create_user_name")+"");
  902. // }
  903. List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(one.get("executeDoctor").toString());
  904. if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
  905. resultMap.put("executeDoctorDept",baseDoctorHospitalDO.get(0).getDeptCode());
  906. resultMap.put("executeDoctorDeptName",baseDoctorHospitalDO.get(0).getDeptName());
  907. }
  908. executeDoctorList.add(one.get("executeDoctorName")+"");//
  909. resultMap.put("remark",one.get("remark"));//备注
  910. resultMap.put("executeDoctorList",executeDoctorList);//执行医生名称列表
  911. resultMap.put("executeDoctorCode",one.get("executeDoctor")+"");//执行医生code
  912. resultMap.put("executeDoctorName",one.get("executeDoctorName")+"");//执行医生名称
  913. resultMap.put("specialistDoctorCode",one.get("createDoctor")+"");//创建人(专科)医生code
  914. resultMap.put("specialistDoctorName",one.get("createDoctorName")+"");//创建人(专科)医生名字
  915. resultMap.put("title",one.get("title"));//项目标题
  916. resultMap.put("shortExecuteTime",DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.HH_MM));//项目标题
  917. resultMap.put("content",one.get("content"));//项目内容
  918. resultMap.put("hospitalName",one.get("hospital_name"));//地点
  919. resultMap.put("executeTime",one.get("execute_time"));//执行时间
  920. DecimalFormat df = new DecimalFormat("0.00");
  921. resultMap.put("expense",one.get("expense")!=null?df.format(((Integer)one.get("expense")*1.00)):0);//收费
  922. resultMap.put("reserve",one.get("reserve"));//是否需要预约(1预约、0不预约)
  923. resultMap.put("planStatus",one.get("planStatus"));//计划的状态
  924. resultMap.put("relationCode",one.get("relationCode"));//业务关联code
  925. Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
  926. String statusName = "";
  927. switch (status){
  928. case 0:{statusName="未完成";break;}
  929. case 1:{statusName="已完成";break;}
  930. case 2:{statusName="已预约";break;}
  931. case 3:{statusName="待录入";break;}
  932. }
  933. resultMap.put("statusName",statusName);//状态名称
  934. resultMap.put("status",status);//状态
  935. resultMap.put("disease",one.get("disease"));
  936. resultMap.put("diseaseName",one.get("diseaseName"));
  937. resultMap.put("planTitle",one.get("planTitle"));
  938. resultMap.put("planId",one.get("planId"));
  939. //指导与汇报
  940. List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
  941. List<Map<String,Object>> messageMapList = new ArrayList<>();
  942. for(GuidanceMessageLogDO one2:messageList){
  943. Map<String,Object> map = new HashMap<>();
  944. map.put("doctorName",one2.getDoctorName());
  945. map.put("adminTeamName",one2.getAdminTeamName());
  946. map.put("content",one2.getContent());
  947. map.put("contentType",one2.getContentType());
  948. map.put("doctorType",one2.getDoctorType());//医生类型
  949. map.put("createTime",DateUtil.dateToStr(one2.getCreateTime(),"MM-dd HH:mm"));
  950. messageMapList.add(map);
  951. }
  952. resultMap.put("messageList",messageMapList);//指导与汇报记录
  953. resultMap.put("patient",one.get("patient"));
  954. resultMap.put("patientName",one.get("patientName"));
  955. resultMap.put("type",one.get("itemType"));//1扫码、0上传附件、2、健康教育,3、健康指导,4、随访
  956. //是否完成任务
  957. List<RehabilitationOperateRecordsDO> operateList = new ArrayList<>();
  958. if(StringUtils.isNoneBlank(recordId)){
  959. operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailIdAndId(one.get("id").toString(),recordId);
  960. }else {
  961. operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
  962. }
  963. Integer operate = 0;
  964. if(operateList.size()>0){
  965. RehabilitationOperateRecordsDO temp = operateList.get(0);
  966. operate =1;
  967. Date completeTime = temp.getCompleteTime();
  968. String completeTimeStr = DateUtil.dateToStr(completeTime,DateUtil.YYYY_MM_DD_HH_MM);
  969. resultMap.put("completeTime",completeTimeStr);//完成时间
  970. resultMap.put("operatorDoctorName",temp.getDoctorName());//执行医生名称
  971. resultMap.put("node",temp.getNode());
  972. resultMap.put("recordStatus",temp.getStatus());//操作记录
  973. resultMap.put("recordRelationCode",temp.getRelationCode());
  974. resultMap.put("recordFlag",temp.getFlag());
  975. resultMap.put("recordId",temp.getId());
  976. JSONArray imgs = new JSONArray();
  977. if (temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg())){
  978. resultMap.put("relationRecordImg",(temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg()))?(new JSONArray(temp.getRelationRecordImg())):null);//json格式
  979. }
  980. else{
  981. resultMap.put("relationRecordImg",imgs);
  982. }
  983. /* if(itemType!=1&&itemType!=0){*/
  984. resultMap.put("relationRecordCode",temp.getRelationRecordCode());
  985. resultMap.put("completeTimeShort",DateUtil.dateToStr(completeTime,"yyyy/MM/dd"));
  986. /* }*/
  987. }
  988. List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(one.get("patient").toString(),"1",1);
  989. if(list.size()>0){
  990. resultMap.put("familyDoctorCode",list.get(0).getDoctor());
  991. resultMap.put("familyDoctorName",list.get(0).getDoctorName());
  992. }else{
  993. resultMap.put("familyDoctorCode","");
  994. resultMap.put("familyDoctorName","");
  995. }
  996. resultMap.put("operate",operate);//是否完成任务(默认0:未完成,1:已完成)
  997. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
  998. }
  999. /**
  1000. * 康复管理居民详情页
  1001. * @param patientCode
  1002. * @return
  1003. */
  1004. public ObjEnvelop patientRehabilitationDetail(String patientCode){
  1005. Map<String,Object> resultMap = new HashMap<>();
  1006. List<SignFamily> listFamiluy = signFamilyDao.findByPatientAndExpensesStatusAndStatus(patientCode,"1",1);
  1007. String healthDoctor = null;
  1008. String healthDoctorName =null;
  1009. String generalDoctor = null;
  1010. String generalDoctorName = null;
  1011. String patientName = null;
  1012. Integer age = null;
  1013. String sex = null;
  1014. String signHospitalName = null;
  1015. org.json.JSONObject json = new org.json.JSONObject();
  1016. String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+patientCode+"' and label_type=8";
  1017. List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
  1018. String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
  1019. String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
  1020. BasePatientDO patient = basePatientDao.findById(patientCode);
  1021. if(listFamiluy.size()>0) {
  1022. SignFamily signFamily = listFamiluy.get(0);
  1023. healthDoctor = signFamily.getDoctorHealth();
  1024. healthDoctorName = signFamily.getDoctorHealthName();
  1025. generalDoctor = signFamily.getDoctor();
  1026. generalDoctorName = signFamily.getDoctorName();
  1027. patientName = signFamily.getName();
  1028. signHospitalName = signFamily.getHospitalName();
  1029. }
  1030. //个人基础信息(康复机构)
  1031. String patientInfoSql = " SELECT DISTINCT hospital_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
  1032. " where p.patient='"+patientCode+"' and p.status=1 ";
  1033. List<Map<String,Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
  1034. Map<String,Object> patientInfo = new HashMap<>();
  1035. String rehabilitationOrg = "";
  1036. for(Map<String,Object> one:patientInfoList){
  1037. rehabilitationOrg+=","+one.get("hospital_name");
  1038. }
  1039. patientInfo.put("rehabilitationOrg",StringUtils.isNotEmpty(rehabilitationOrg)?rehabilitationOrg.substring(1):"");
  1040. resultMap.put("patientInfo",patientInfo);
  1041. //服务医生
  1042. //完成项目=全部的服务项目-未完成的服务项目
  1043. List<Map<String,Object>> serviceDoctorList = new ArrayList<>();
  1044. //全科医生和健管师要是同一个人,就显示全科医生
  1045. /* if(!generalDoctor.equals(healthDoctor)){
  1046. */
  1047. if(StringUtils.isNotEmpty(healthDoctor)){
  1048. Map<String,Object> healthDoctorMap = new HashMap<>();
  1049. healthDoctorMap.put("type","健管师");
  1050. healthDoctorMap.put("doctorName",healthDoctorName);
  1051. healthDoctorMap.put("doctorCode",healthDoctor);
  1052. Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor,patientCode,1);
  1053. Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor,patientCode);
  1054. Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor,patientCode,1);
  1055. healthDoctorMap.put("finishedItem",healthFinishCount-healthUnfinishCount);
  1056. healthDoctorMap.put("serviceCount",healthServiceCount);
  1057. serviceDoctorList.add(healthDoctorMap);
  1058. }
  1059. /* }*/
  1060. if(StringUtils.isNotEmpty(generalDoctor)){
  1061. Map<String,Object> generalDoctorMap = new HashMap<>();
  1062. generalDoctorMap.put("type","全科医生");
  1063. generalDoctorMap.put("doctorName",generalDoctorName);
  1064. generalDoctorMap.put("doctorCode",generalDoctor);
  1065. Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor,patientCode,1);
  1066. Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor,patientCode);
  1067. Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor,patientCode,1);
  1068. generalDoctorMap.put("finishedItem",generalFinishCount-generalUnfinishCount);
  1069. generalDoctorMap.put("serviceCount",generalServiceCount);
  1070. serviceDoctorList.add(generalDoctorMap);
  1071. }
  1072. String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 and p.patient='"+patientCode+"'";
  1073. specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
  1074. List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
  1075. BaseDoctorDO baseDoctorDO = null;
  1076. for(Map<String,Object> one:specialistRelationList){
  1077. String doctor = one.get("doctor")+"";
  1078. String doctorName = one.get("doctor_name")+"";
  1079. Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor,patientCode,1);
  1080. Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor,patientCode);
  1081. Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor,patientCode,1);
  1082. Map<String,Object> map = new HashMap<>();
  1083. map.put("finishedItem",finishCount-unfinishCount);
  1084. map.put("serviceCount",serviceCount);
  1085. map.put("doctorName",doctorName);
  1086. map.put("doctorCode",doctor);
  1087. map.put("type","专科医生");
  1088. serviceDoctorList.add(map);
  1089. }
  1090. for (Map<String,Object> d:serviceDoctorList){
  1091. BaseDoctorDO baseDoctorDO1 = baseDoctorDao.findById(d.get("doctorCode").toString());
  1092. d.put("doctorPhoto",baseDoctorDO1!=null?baseDoctorDO1.getPhoto():"");
  1093. }
  1094. resultMap.put("serviceDoctorList",serviceDoctorList);
  1095. //康复计划
  1096. List<Map<String,Object>> planList = new ArrayList<>();
  1097. List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patientCode);
  1098. Integer planUnderway = 0;//进行中
  1099. Integer planFinish = 0;//已完成
  1100. for(PatientRehabilitationPlanDO one:list){
  1101. if(one.getStatus()==1){
  1102. planUnderway+=1;
  1103. }else if(one.getStatus()==2){
  1104. planFinish+=1;
  1105. }
  1106. Map<String,Object> map = new HashMap<>();
  1107. //安排类型
  1108. String planTypeName = null;
  1109. Integer planTypeTemp = one.getPlanType();
  1110. switch (planTypeTemp){
  1111. case 1:planTypeName="康复计划" ;break;
  1112. case 2:planTypeName="(转)社区医院" ;break;
  1113. case 3:planTypeName="(转)转家庭病床" ;break;
  1114. }
  1115. map.put("createUser",one.getCreateUser());
  1116. map.put("createUserName",one.getCreateUserName());
  1117. map.put("planId",one.getId());
  1118. map.put("planTypeName",planTypeName);
  1119. String statusName = "";
  1120. Integer status = one.getStatus();
  1121. switch (status){
  1122. case 0:{statusName="已中止";break;}
  1123. case 1:{statusName="进行中";break;}
  1124. case 2:{statusName="已完成";break;}
  1125. }
  1126. map.put("planTypeName",planTypeName);//安排类型名称
  1127. map.put("statusName",statusName);//状态名称
  1128. map.put("medicalRecordsCode",one.getMedicalRecordsCode());//住院code
  1129. map.put("adviceContent",one.getAdviceContent());//康复建议
  1130. //已完成
  1131. Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.getId());
  1132. map.put("allFinishCount",allFinishCount);//已完成
  1133. //完成度(已完成/(已完成+未完成))
  1134. Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
  1135. map.put("allCount",allCount);//总数
  1136. List<RehabilitationDetailDO> detailList = rehabilitationDetailDao.getAllRehabilitationDetail(one.getId());
  1137. if(detailList.size()>0){
  1138. Date executeTimeStart = detailList.get(0).getExecuteTime();
  1139. Date executeTimeEnd = detailList.get(detailList.size()-1).getExecuteTime();
  1140. String executeStart = DateUtil.dateToStr(executeTimeStart,"yyyy/MM/dd");
  1141. String executeEnd = DateUtil.dateToStr(executeTimeEnd,"yyyy/MM/dd");
  1142. map.put("time",executeStart+"-"+executeEnd);
  1143. }else{
  1144. map.put("time","");
  1145. }
  1146. planList.add(map);
  1147. }
  1148. resultMap.put("planList",planList);
  1149. //康复计划-已完成、进行中
  1150. resultMap.put("planUnderway",planUnderway);//进行中
  1151. resultMap.put("planFinish",planFinish);//已完成
  1152. resultMap.put("healthyCondition",healthyCondition);
  1153. resultMap.put("healthyConditionType",healthyConditionType);
  1154. resultMap.put("patientName",patientName);
  1155. resultMap.put("signHospitalName",signHospitalName);
  1156. age = IdCardUtil.getAgeForIdcard(patient.getIdcard());
  1157. sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
  1158. resultMap.put("patientCode", patientCode);
  1159. resultMap.put("patientName", patient.getName());
  1160. resultMap.put("age",age);
  1161. resultMap.put("sex",sex);
  1162. resultMap.put("photo",patient.getPhoto());
  1163. resultMap.put("mobile",patient.getMobile());
  1164. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
  1165. }
  1166. /**
  1167. * 居民康复计划详情页-近期康复相关记录
  1168. * @param patientCode
  1169. * @param startTime
  1170. * @param endTime
  1171. */
  1172. public ObjEnvelop recentPlanDetailRecord(String patientCode,String startTime,String endTime,Integer page, Integer pageSize) throws Exception{
  1173. Map<String,Object> resultMap = new HashMap<>();
  1174. //近期康复相关记录
  1175. // String currentTime = DateUtil.getStringDate();
  1176. String planDetailSql = " select d.*,h.name,h.code,s.complete_time from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code " +
  1177. " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id" +
  1178. " left join wlyy_rehabilitation_operate_records s on s.rehabilitation_detail_id=d.id " +
  1179. " where d.status=1 and p.patient='"+patientCode+"' and d.frequency_code IS NOT NULL AND d.frequency_code <>'' ";
  1180. if(StringUtils.isNotEmpty(startTime)){
  1181. planDetailSql += " and d.execute_Time>='"+startTime+"' ";
  1182. }
  1183. if(StringUtils.isNotEmpty(endTime)){
  1184. planDetailSql += " and d.execute_time<='"+endTime+"' ";
  1185. }
  1186. planDetailSql += " ORDER BY s.complete_time DESC LIMIT "+(page-1)*pageSize+","+pageSize;
  1187. planDetailSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(planDetailSql);
  1188. List<Map<String,Object>> planDetails = jdbcTemplate.queryForList(planDetailSql);
  1189. List<Map<String,Object>> planDetailList = new ArrayList<>();
  1190. for(Map<String,Object> one:planDetails){
  1191. Date executeTimeDate = (Date)one.get("complete_time");
  1192. String executeTime = DateUtil.dateToStr(executeTimeDate,"yyyy/MM/dd HH:mm");
  1193. String content = one.get("code")+"";
  1194. String title = one.get("name")+"";
  1195. Integer status = (Integer)one.get("status");
  1196. String statusName = "";
  1197. switch (status){
  1198. case 0:{statusName="未完成";break;}
  1199. case 1:{statusName="已完成";break;}
  1200. case 2:{statusName="已预约";break;}
  1201. }
  1202. String id = one.get("id").toString();
  1203. Map<String,Object> map = new HashMap<>();
  1204. map.put("id",id);//id
  1205. // List<RehabilitationOperateRecordsDO> rehabilitationOperateRecords = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(id);
  1206. // Date completeTime = rehabilitationOperateRecords!=null&&rehabilitationOperateRecords.size()>0?rehabilitationOperateRecords.get(0).getCompleteTime():null;
  1207. // String completeTimeStr = completeTime!=null?DateUtil.dateToStr(completeTime,"yyyy/MM/dd HH:mm"):"";
  1208. map.put("executeTime",executeTime);//执行时间
  1209. map.put("title",title);//项目标题
  1210. map.put("content",content);//项目内容
  1211. map.put("statusName",statusName);//状态名称
  1212. planDetailList.add(map);
  1213. }
  1214. resultMap.put("planDetailList",planDetailList);//康复相关记录列表
  1215. String planDetailCountSql = " select d.status as num from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code" +
  1216. " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where p.patient='"+patientCode+"' ";
  1217. List<Map<String,Object>> planDetailList2 = jdbcTemplate.queryForList(planDetailCountSql);
  1218. Integer planDetailFinish = 0;
  1219. Integer planDetailUnfinish = 0;
  1220. for(Map<String,Object> one:planDetailList2){
  1221. Integer status = (Integer)one.get("num");
  1222. if(status==1){
  1223. planDetailFinish+=1;
  1224. }else{
  1225. planDetailUnfinish+=1;
  1226. }
  1227. }
  1228. resultMap.put("planDetailFinish",planDetailFinish);//已完成
  1229. resultMap.put("planDetailUnfinish",planDetailUnfinish);//未完成
  1230. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
  1231. }
  1232. /**
  1233. * 保存康复管理指导留言信息
  1234. * @param messageId
  1235. * @param doctor
  1236. */
  1237. @Transactional
  1238. public Envelop saveGuidanceMessage(String messageId,String doctor,String content,String planDetailId,Integer contentType) throws Exception{
  1239. BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
  1240. Integer doctorType =null;
  1241. if (doctorDO!=null){
  1242. List<BaseDoctorRoleDO> baseDoctorRoleDO = baseDoctorRoleDao.findByDoctorCode(doctor);
  1243. if (baseDoctorRoleDO!=null){
  1244. for (BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){
  1245. if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){
  1246. doctorType=1;
  1247. break;
  1248. }else {
  1249. doctorType=2;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. List<String> patientList = rehabilitationDetailDao.findPatientById(planDetailId);
  1255. String patient = patientList.size()>0?patientList.get(0):"";
  1256. GuidanceMessageLogDO guidanceMessageLogDO = new GuidanceMessageLogDO();
  1257. guidanceMessageLogDO.setMessageId(messageId);
  1258. guidanceMessageLogDO.setPlanDetailId(planDetailId);
  1259. guidanceMessageLogDO.setContent(content);
  1260. guidanceMessageLogDO.setDoctor(doctor);
  1261. guidanceMessageLogDO.setContentType(contentType);
  1262. guidanceMessageLogDO.setDoctorType(doctorType);
  1263. Integer adminTeamCode = null;
  1264. String doctorName = null;
  1265. if(doctorType==1){
  1266. SpecialistPatientRelationDO specialistPatientRelationDO = specialistPatientRelationDao.findByPatientAndDoctor(doctor,patient);
  1267. adminTeamCode = specialistPatientRelationDO.getTeamCode();
  1268. doctorName = specialistPatientRelationDO.getDoctorName();
  1269. }else if(doctorType==2){
  1270. String signFamilySql = " select f.* from wlyy_sign_family f where f.status=1 and f.expenses_status='1' and f.patient='"+patient+"'";
  1271. List<Map<String,Object>> signFamily = jdbcTemplate.queryForList(signFamilySql);
  1272. adminTeamCode = (Integer)signFamily.get(0).get("admin_team_code");
  1273. doctorName = signFamily.get(0).get("doctor_name").toString();
  1274. }
  1275. String adminTeamSql = " select t.* from base_team t where t.del='1' and t.id="+adminTeamCode;
  1276. List<Map<String,Object>> adminTeam = jdbcTemplate.queryForList(adminTeamSql);
  1277. String adminTeamName = adminTeam.get(0).get("name").toString();
  1278. guidanceMessageLogDO.setAdminTeamCode(adminTeamCode);
  1279. guidanceMessageLogDO.setAdminTeamName(adminTeamName);
  1280. guidanceMessageLogDO.setDoctorName(doctorName);
  1281. guidanceMessageLogDO.setCreateTime(new Date());
  1282. guidanceMessageLogDO.setUpdateTime(new Date());
  1283. guidanceMessageLogDao.save(guidanceMessageLogDO);
  1284. return Envelop.getSuccess(SpecialistMapping.api_success);
  1285. }
  1286. /**
  1287. * 康复管理-更新康复计划操作完成日志状态
  1288. * @param planDetailId
  1289. * @param status
  1290. * @throws Exception
  1291. */
  1292. @Transactional
  1293. public Envelop updateStatusRehabilitationOperate(Integer status,String planDetailId){
  1294. if(rehabilitationOperateRecordsDao.updateStatus(status,planDetailId)>0){
  1295. return Envelop.getSuccess(SpecialistMapping.api_success);
  1296. }
  1297. return Envelop.getError("更新失败!");
  1298. }
  1299. /**
  1300. * app端居民详情服务医生列表
  1301. * @param patientCode
  1302. * @return
  1303. */
  1304. public ObjEnvelop serviceDoctorList(String patientCode){
  1305. List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(patientCode,"1",1);
  1306. String healthDoctor = null;
  1307. String healthDoctorName =null;
  1308. String generalDoctor = null;
  1309. String generalDoctorName = null;
  1310. if(list!=null&&list.size()>0){
  1311. SignFamily signFamily = list.get(0);
  1312. healthDoctor = signFamily.getDoctorHealth();
  1313. healthDoctorName = signFamily.getDoctorHealthName();
  1314. generalDoctor = signFamily.getDoctor();
  1315. generalDoctorName = signFamily.getDoctorName();
  1316. }
  1317. //服务医生
  1318. //完成项目=全部的服务项目-未完成的服务项目
  1319. List<Map<String,Object>> serviceDoctorList = new ArrayList<>();
  1320. if(StringUtils.isNotEmpty(generalDoctor)){
  1321. Map<String,Object> generalDoctorMap = new HashMap<>();
  1322. generalDoctorMap.put("type","全科医生");
  1323. generalDoctorMap.put("doctorName",generalDoctorName);
  1324. generalDoctorMap.put("doctorCode",generalDoctor);
  1325. Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor,patientCode,1);
  1326. Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor,patientCode);
  1327. Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor,patientCode,1);
  1328. generalDoctorMap.put("finishedItem",generalFinishCount-generalUnfinishCount);
  1329. generalDoctorMap.put("serviceCount",generalServiceCount);
  1330. serviceDoctorList.add(generalDoctorMap);
  1331. }
  1332. if(StringUtils.isNotEmpty(healthDoctor)){
  1333. Map<String,Object> healthDoctorMap = new HashMap<>();
  1334. healthDoctorMap.put("type","健管师");
  1335. healthDoctorMap.put("doctorName",healthDoctorName);
  1336. healthDoctorMap.put("doctorCode",healthDoctor);
  1337. Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor,patientCode,1);
  1338. Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor,patientCode);
  1339. Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor,patientCode,1);
  1340. healthDoctorMap.put("finishedItem",healthFinishCount-healthUnfinishCount);
  1341. healthDoctorMap.put("serviceCount",healthServiceCount);
  1342. serviceDoctorList.add(healthDoctorMap);
  1343. }
  1344. String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 AND d.doctor IS NOT NULL and d.doctor <> '' and p.patient='"+patientCode+"'";
  1345. specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
  1346. List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
  1347. for(Map<String,Object> one:specialistRelationList){
  1348. String doctor = one.get("doctor")+"";
  1349. String doctorName = one.get("doctor_name")+"";
  1350. Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor,patientCode,1);
  1351. Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor,patientCode);
  1352. Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor,patientCode,1);
  1353. Map<String,Object> map = new HashMap<>();
  1354. map.put("finishedItem",finishCount-unfinishCount);
  1355. map.put("serviceCount",serviceCount);
  1356. map.put("doctorName",doctorName);
  1357. map.put("doctorCode",doctor);
  1358. map.put("type","专科医生");
  1359. serviceDoctorList.add(map);
  1360. }
  1361. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,serviceDoctorList);
  1362. }
  1363. /**
  1364. * app端、微信端计划的服务项目列表
  1365. * @param planId
  1366. * @param searchTask
  1367. * @param status
  1368. * @param executeStartTime
  1369. * @param executeEndTime
  1370. * @return
  1371. */
  1372. public ObjEnvelop appCalendarPlanDetailList(String planId,Integer searchTask,Integer status,String executeStartTime,String executeEndTime){
  1373. Map<String,Object> resultMap = new HashMap<>();
  1374. ObjEnvelop objEnvelop = calendarPlanDetailList(planId,searchTask,status,null,executeStartTime,executeEndTime,"0");
  1375. Integer finishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId);
  1376. Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);
  1377. resultMap.put("planDetailList",objEnvelop.getObj());
  1378. resultMap.put("finishCount",finishCount);
  1379. resultMap.put("allCount",allCount);
  1380. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
  1381. }
  1382. /**
  1383. * 每日康复服务通知
  1384. * @param startTime
  1385. * @param endTime
  1386. * @return
  1387. */
  1388. public JSONArray dailyJob(String startTime,String endTime){
  1389. String sql = "select d.doctor,p.patient,count(1) as num from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and p.status=1 and d.execute_time>='"+startTime+"' and d.execute_time<='"+endTime+"' GROUP BY d.doctor,p.patient";
  1390. // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
  1391. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1392. String doctorCode = "";
  1393. String patientCode = "";
  1394. List<String> listMap = null;
  1395. for(Map<String,Object> one:list){
  1396. doctorCode = one.get("doctor")+"";
  1397. patientCode = one.get("patient")+"";
  1398. listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
  1399. String ids = "";
  1400. for(String one2 : listMap){
  1401. ids += ","+one2;
  1402. }
  1403. one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
  1404. }
  1405. return new JSONArray(list);
  1406. }
  1407. /**
  1408. * 明日康复计划提醒
  1409. *
  1410. * @param startTime
  1411. * @param endTime
  1412. * @return
  1413. */
  1414. public JSONArray tomorrowJob(String startTime,String endTime){
  1415. String sql = "select d.doctor,p.patient,count(1) as num,p.id from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and p.status=1 and d.execute_time>='"+startTime+"' and d.execute_time<='"+endTime+"' GROUP BY d.doctor,p.patient";
  1416. // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
  1417. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1418. String doctorCode = "";
  1419. String patientCode = "";
  1420. List<String> listMap = null;
  1421. for(Map<String,Object> one:list){
  1422. doctorCode = one.get("doctor")+"";
  1423. patientCode = one.get("patient")+"";
  1424. listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
  1425. String ids = "";
  1426. for(String one2 : listMap){
  1427. ids += ","+one2;
  1428. }
  1429. one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
  1430. }
  1431. return new JSONArray(list);
  1432. }
  1433. /**
  1434. * 每日康复计划提醒
  1435. *
  1436. * @param startTime
  1437. * @param endTime
  1438. * @return
  1439. */
  1440. public JSONArray dailyByJob(String startTime,String endTime){
  1441. String sql = "select d.doctor,p.patient,h.service_item_name AS serviceItemName,d.time_type AS timeType from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id left join wlyy_hospital_service_item h ON h.id=d.hospital_service_item_id where d.status!=1 and p.status=1 and d.execute_time>='"+startTime+"' and d.execute_time<='"+endTime+"' GROUP BY d.doctor,p.patient,d.execute_time";
  1442. // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
  1443. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1444. String doctorCode = "";
  1445. String patientCode = "";
  1446. List<String> listMap = null;
  1447. for(Map<String,Object> one:list){
  1448. doctorCode = one.get("doctor")+"";
  1449. patientCode = one.get("patient")+"";
  1450. listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
  1451. String ids = "";
  1452. for(String one2 : listMap){
  1453. ids += ","+one2;
  1454. }
  1455. one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
  1456. }
  1457. return new JSONArray(list);
  1458. }
  1459. /**
  1460. * 更新康复计划项目操作日志并且确认完成更新status.
  1461. * @param node
  1462. * @param image
  1463. * @param planDeatilId
  1464. * @return
  1465. */
  1466. public Map<String,Object> updateNodeAndRelationRecordImg(String node,String image,String status,String planDeatilId,String relationCode)throws Exception{
  1467. Map<String,Object> resultMap = new HashedMap();
  1468. try{
  1469. RehabilitationDetailDO detailDO = rehabilitationDetailDao.findById(planDeatilId);
  1470. detailDO.setStatus(1);
  1471. if (StringUtils.isNoneBlank(status)){
  1472. detailDO.setStatus(Integer.parseInt(status));
  1473. }
  1474. detailDO.setUpdateTime(new Date());
  1475. if (StringUtils.isNoneBlank(relationCode)){
  1476. detailDO.setRelationCode(relationCode);
  1477. }
  1478. rehabilitationDetailDao.save(detailDO);
  1479. if (StringUtils.isNoneBlank(image)&&StringUtils.isNoneBlank(node)){
  1480. int j = rehabilitationOperateRecordsDao.updateNodeAndRelationRecordImg(node,image,planDeatilId);
  1481. }
  1482. else if (StringUtils.isNoneBlank(node)){
  1483. int j = rehabilitationOperateRecordsDao.updateNodeByPlanDetailId(node,planDeatilId);
  1484. }
  1485. else if (StringUtils.isNoneBlank(image)){//
  1486. int j = rehabilitationOperateRecordsDao.updateImagByPlanDetailId(image,planDeatilId);
  1487. }
  1488. else{//跟新为已完成
  1489. int j = rehabilitationOperateRecordsDao.updateStatus(1,planDeatilId);
  1490. }
  1491. //如果整个计划的服务项都完成了,整个计划也完成了
  1492. String allSql ="SELECT * FROM wlyy_rehabilitation_plan_detail where plan_id = (SELECT plan_id FROM `wlyy_rehabilitation_plan_detail` WHERE id='"+planDeatilId+"')";
  1493. allSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(allSql);
  1494. List<RehabilitationDetailDO> rehabilitationDetailDOList = jdbcTemplate.query(allSql,new BeanPropertyRowMapper<>(RehabilitationDetailDO.class));
  1495. int allCount=0;
  1496. String planId="";
  1497. for (RehabilitationDetailDO rehabilitationDetailDO : rehabilitationDetailDOList){
  1498. if (rehabilitationDetailDO.getStatus()==1){
  1499. allCount++;
  1500. }
  1501. }
  1502. if (rehabilitationDetailDOList.size()>0 && rehabilitationDetailDOList.size()==allCount){
  1503. planId = rehabilitationDetailDOList.get(0).getPlanId();
  1504. patientRehabilitationPlanDao.updateStatusAndTimeById(2,planId, new Date());
  1505. }
  1506. }catch (Exception e){
  1507. throw new Exception("更新服务状态失败!");
  1508. }
  1509. //更新返回数据提供发送消息使用
  1510. String sql ="SELECT" +
  1511. " i.id as \"id\"," +
  1512. " r.doctor_code," +
  1513. " r.patient_code," +
  1514. " pd.hospital" +
  1515. " FROM" +
  1516. " wlyy_rehabilitation_plan_detail pd" +
  1517. " LEFT JOIN wlyy_rehabilitation_service_item i ON pd.hospital_service_item_id = i.id" +
  1518. " LEFT JOIN wlyy_rehabilitation_operate_records r ON pd.id = r.rehabilitation_detail_id" +
  1519. " WHERE" +
  1520. " pd.id = '"+planDeatilId+"'";
  1521. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1522. if (list!=null && list.size()>0){
  1523. resultMap = list.get(0);
  1524. }
  1525. String itemSql ="SELECT evaluation,title FROM `wlyy_service_item` WHERE id='"+String.valueOf(resultMap.get("id"))+"'";
  1526. List<Map<String,Object>> itemList = jdbcTemplate.queryForList(itemSql);
  1527. if (itemList!=null && itemList.size()>0){
  1528. resultMap.put("evaluation",itemList.get(0).get("evaluation"));
  1529. resultMap.put("title",itemList.get(0).get("title"));
  1530. }
  1531. //保存wlyy_message
  1532. List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(resultMap.get("doctor_code").toString());
  1533. String hospotal = "";
  1534. String patient = resultMap.get("patient_code").toString();
  1535. String doctor = resultMap.get("doctor_code").toString();
  1536. if (depts!=null&&depts.size()>0){
  1537. hospotal=depts.get(0).getOrgCode();
  1538. }
  1539. SystemMessageDO message = new SystemMessageDO();
  1540. message.setType("21");
  1541. message.setSender(patient);
  1542. message.setReceiver(doctor);
  1543. message.setRelationCode(planDeatilId);
  1544. specialistEvaluateSevice.sendMessage(message,hospotal,patient,null,null);
  1545. //发送微信模板消息
  1546. int evaluation = resultMap.get("evaluation")==null?0:Integer.parseInt(resultMap.get("evaluation").toString());
  1547. if (evaluation == 1){
  1548. String serviceItemId = resultMap.get("service_item_id").toString();
  1549. String title = resultMap.get("title").toString();
  1550. BasePatientDO p = basePatientDao.findById(patient);
  1551. BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
  1552. String patientName = p.getName();
  1553. String openId = p.getOpenid();
  1554. /*WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_service","fwxmpj");
  1555. String first = templateConfig.getFirst();
  1556. first = first.replace("key1",(patientName==null?"":patientName));
  1557. String keyword1 = templateConfig.getKeyword1();
  1558. org.json.JSONObject json = new org.json.JSONObject();
  1559. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1560. json.put("keyword1", title);
  1561. json.put("keyword2",doctor1.getName());
  1562. json.put("keyword3", sdf.format(new Date()));
  1563. json.put("toUser", p.getCode());
  1564. json.put("represented",p.getCode());//被代理人
  1565. json.put("remark", "");
  1566. json.put("doctor",doctor);
  1567. json.put("planIds", planDetailId);
  1568. first = first.replace("key2",title);
  1569. json.put("first", first);
  1570. if(StringUtils.isNotBlank(p.getOpenid())){
  1571. pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 25, openId, p.getName(), json);
  1572. }else {
  1573. //发送代理人
  1574. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
  1575. if (jsonArray != null && jsonArray.length() > 0) {
  1576. for (int i = 0; i < jsonArray.length(); i++) {
  1577. org.json.JSONObject j = jsonArray.getJSONObject(i);
  1578. Patient member = (Patient) j.get("member");
  1579. org.json.JSONObject data = json;
  1580. data.remove("toUser");
  1581. data.put("toUser", member.getCode());
  1582. data.remove("first");
  1583. data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
  1584. pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 25, member.getOpenid(), p.getName(), data);
  1585. }
  1586. }
  1587. }*/
  1588. }
  1589. return resultMap;
  1590. }
  1591. /**
  1592. * 电话关怀拨打电话后生成对应记录
  1593. * @param jsonStr
  1594. */
  1595. public RehabilitationOperateRecordsDO planDetailAfterCall(String jsonStr){
  1596. JSONObject jsonObject = JSON.parseObject(jsonStr);
  1597. /*{
  1598. "rehabilitationDetailId":"808080eb764ba46b017669712c640012",
  1599. "doctorCode":"7e06886207e843948ae65d8f91d6ca97",
  1600. "doctorName":"兰冠勇"
  1601. }*/
  1602. RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(jsonObject.getString("rehabilitationDetailId"));
  1603. PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(rehabilitationDetailDO.getPlanId());
  1604. RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO = new RehabilitationOperateRecordsDO();
  1605. rehabilitationOperateRecordsDO.setId(getCode());
  1606. if (rehabilitationDetailDO.getExecuteTime()!=null){
  1607. rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
  1608. }
  1609. rehabilitationOperateRecordsDO.setStatus(3);
  1610. rehabilitationOperateRecordsDO.setRelationRecordImg("[]");
  1611. rehabilitationOperateRecordsDO.setRehabilitationDetailId(rehabilitationDetailDO.getId());
  1612. rehabilitationOperateRecordsDO.setPatientCode(patientRehabilitationPlanDO.getPatient());
  1613. rehabilitationOperateRecordsDO.setPatientName(patientRehabilitationPlanDO.getName());
  1614. rehabilitationOperateRecordsDO.setDoctorCode(jsonObject.getString("doctorCode"));
  1615. rehabilitationOperateRecordsDO.setDoctorName(rehabilitationDetailDO.getDoctorName());
  1616. rehabilitationOperateRecordsDO.setRelationRecordType(5);
  1617. rehabilitationOperateRecordsDO.setCompleteTime(new Date());
  1618. rehabilitationOperateRecordsDO.setCreateTime(new Date());
  1619. rehabilitationOperateRecordsDO.setUpdateTime(new Date());
  1620. if (StringUtils.isNoneBlank(rehabilitationDetailDO.getFrequencyCode())){//限定频次的
  1621. rehabilitationDetailDO.setStatus(3);
  1622. rehabilitationDetailDao.save(rehabilitationDetailDO);
  1623. // rehabilitationOperateRecordsDO.setRelationRecordType(8);
  1624. }
  1625. return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
  1626. }
  1627. /**
  1628. * 更新康复计划项目状态
  1629. * @param status
  1630. * @param planDetailId
  1631. * @return
  1632. */
  1633. public Envelop updatePlanDetailStatusById(Integer status,String planDetailId) throws Exception{
  1634. if(rehabilitationDetailDao.updateStatusById(status,planDetailId)>0){
  1635. return Envelop.getSuccess(SpecialistMapping.api_success);
  1636. }
  1637. return Envelop.getError("更新失败!");
  1638. }
  1639. public Envelop updatePlanDetailExecuteTimeById(Date executeTime,String planDetailId) throws Exception{
  1640. if(rehabilitationDetailDao.updateExecuteTime(executeTime,planDetailId)>0){
  1641. return Envelop.getSuccess(SpecialistMapping.api_success);
  1642. }
  1643. return Envelop.getError("更新失败!");
  1644. }
  1645. /**
  1646. * 计划总进度
  1647. * @return
  1648. */
  1649. public ObjEnvelop planSchedule(String planId,String patientCode){
  1650. Map<String,Object> resultMap = new HashMap<>();
  1651. Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
  1652. Integer finishedCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId);
  1653. PatientRehabilitationPlanDO p =patientRehabilitationPlanDao.findById(planId);
  1654. List<DoctorPatientRelationDO> doctorPatientRelationDO= doctorPatientRelationDao.findByDoctorAndPatient(p.getCreateUser(),p.getPatient());
  1655. List<RehabilitationDetailDO> details=rehabilitationDetailDao.findByPlanId(planId);
  1656. String doctor="";
  1657. String doctorName="";
  1658. if (details!=null&&details.size()>0){
  1659. doctor=details.get(0).getDoctor();
  1660. doctorName=details.get(0).getDoctorName();
  1661. }
  1662. resultMap.put("allCount",allCount);
  1663. resultMap.put("finishedCount",finishedCount);
  1664. resultMap.put("specialistPatientRelationDO",doctorPatientRelationDO);
  1665. if (p!=null){
  1666. resultMap.put("disease",p.getDisease());
  1667. resultMap.put("diseaseName",p.getDiseaseName());
  1668. resultMap.put("createUser",p.getCreateUser());
  1669. resultMap.put("planTitle",p.getTitle());
  1670. resultMap.put("status", p.getStatus());
  1671. resultMap.put("isVerify", p.getIsVerify());
  1672. resultMap.put("patientImg", p.getPatientImg());
  1673. resultMap.put("adviceContent",p.getAdviceContent());
  1674. resultMap.put("createTimeDate",DateUtil.dateToStr(p.getCreateTime(),"yyyy-MM-dd"));
  1675. resultMap.put("createTime", DateUtil.dateToStr(p.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
  1676. resultMap.put("medicalRecordsCode",p.getMedicalRecordsCode());
  1677. List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(p.getCreateUser());
  1678. if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
  1679. resultMap.put("createUserName",p.getCreateUserName());
  1680. resultMap.put("createUserDept",baseDoctorHospitalDO.get(0).getDeptCode());
  1681. resultMap.put("createUserDeptName",baseDoctorHospitalDO.get(0).getDeptName());
  1682. }
  1683. List<BaseDoctorHospitalDO> baseDoctorHospitalDOTo = baseDoctorHospitalDao.findByDoctorCode(doctor);
  1684. if (baseDoctorHospitalDOTo!=null&&baseDoctorHospitalDOTo.size()>0){
  1685. resultMap.put("doctorName",doctorName);
  1686. resultMap.put("doctor",doctor);
  1687. resultMap.put("doctorDept",baseDoctorHospitalDOTo.get(0).getDeptCode());
  1688. resultMap.put("doctorDeptName",baseDoctorHospitalDOTo.get(0).getDeptName());
  1689. }
  1690. PatientMedicalRecordsDO patientMedicalRecordsDO = patientMedicalRecordsDao.findByCode(p.getMedicalRecordsCode());
  1691. resultMap.put("patientMedicalRecordsDO",patientMedicalRecordsDO);
  1692. }
  1693. BasePatientDO basePatientDO = basePatientDao.findById(patientCode);
  1694. Integer age = IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard());
  1695. String sex = IdCardUtil.getSexForIdcard_new(basePatientDO.getIdcard());
  1696. resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
  1697. resultMap.put("age",age);
  1698. resultMap.put("patientPhoto",basePatientDO.getPhoto());
  1699. resultMap.put("patientName",basePatientDO.getName());
  1700. resultMap.put("patientCode",basePatientDO.getId());
  1701. resultMap.put("idcard",basePatientDO.getIdcard());
  1702. // resultMap.put("healthyCondition",healthyCondition);
  1703. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
  1704. }
  1705. /**
  1706. * 根据居民获取康复计划
  1707. * @param patient
  1708. * @return
  1709. */
  1710. public ObjEnvelop planListByPatient(String patient){
  1711. List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patient);
  1712. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,list);
  1713. }
  1714. /**
  1715. * 医生已计划数,已完成计划数(居民数)
  1716. * @param doctorCode
  1717. * @return
  1718. */
  1719. public ObjEnvelop patientCount(String doctorCode){
  1720. Integer count =patientRehabilitationPlanDao.patientCount(doctorCode);
  1721. Integer finishCount = patientRehabilitationPlanDao.getFinishPatientCount(doctorCode);
  1722. Map<String,Object> map = new HashMap<>();
  1723. map.put("planCount",count);
  1724. map.put("finishedPlanCount",finishCount);
  1725. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
  1726. }
  1727. public JSONArray dailyJobReserve1(String startTime, String endTime){
  1728. String sql = "select DISTINCT d.doctor,p.patient,d.hospital from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
  1729. " left join wlyy_hospital_service_item h on d.hospital_service_item_id=h.id " +
  1730. " left join wlyy_service_item i on i.id =h.service_item_id "+
  1731. " where d.status!=1 and d.execute_time>='"+startTime+"' and d.execute_time<='"+endTime+"' and i.reserve=1 and p.status!=0 and d.status=0 ";
  1732. // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
  1733. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1734. String doctorCode = "";
  1735. String patientCode = "";
  1736. // List<String> listMap = null;
  1737. for(Map<String,Object> one:list){
  1738. doctorCode = one.get("doctor")+"";
  1739. patientCode = one.get("patient")+"";
  1740. String sql2 ="select d.id from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
  1741. " left join wlyy_hospital_service_item h on d.hospital_service_item_id=h.id " +
  1742. " left join wlyy_service_item i on i.id =h.service_item_id "+
  1743. " where d.status!=1 and d.execute_time>='"+startTime+"' and d.execute_time<='"+endTime+"' and i.reserve=1 and d.doctor='"+doctorCode+"' and p.patient='"+patientCode+"'";
  1744. List<Map<String,Object>> list2 = jdbcTemplate.queryForList(sql2);
  1745. // listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
  1746. String ids = "";
  1747. for(Map<String,Object> one2 : list2){
  1748. ids += ","+one2.get("id");
  1749. }
  1750. one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
  1751. }
  1752. return new JSONArray(JSON.toJSONString(list));
  1753. }
  1754. /**
  1755. * 根据ids获取数据
  1756. *
  1757. * @param ids
  1758. * @return
  1759. */
  1760. public ObjEnvelop selectByIds(String ids){
  1761. ObjEnvelop envelop = new ObjEnvelop();
  1762. List idList = Arrays.asList(ids.split(","));
  1763. StringBuffer buffer = new StringBuffer();
  1764. for (int i =0;i<idList.size();i++){
  1765. buffer.append("'"+idList.get(i)+"'").append(",");
  1766. }
  1767. buffer.deleteCharAt(buffer.length()-1);
  1768. String sql = "select * from wlyy_rehabilitation_plan_detail where id in("+buffer+")";
  1769. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(sql);
  1770. List<RehabilitationDetailDO> rehabilitationDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(RehabilitationDetailDO.class));
  1771. envelop.setObj(rehabilitationDetailDOS);
  1772. return envelop;
  1773. }
  1774. /**
  1775. * 查询频次列表
  1776. *
  1777. * @return
  1778. */
  1779. public List<Frequency> selectFrequences(){
  1780. List<Frequency> frequencieList = frequencyDao.findByDel();
  1781. return frequencieList;
  1782. }
  1783. public ObjEnvelop getServiceItemsAfterStop(String planId)throws Exception{
  1784. Map<String,Object> reslutMap = new HashMap<>();
  1785. String sql ="SELECT" +
  1786. " p.patient," +
  1787. " p.name," +
  1788. " p.title," +
  1789. " p.disease_name,p.abort_reason,p.abort_time,p.create_time,p.patient_img," +
  1790. " a.*" +
  1791. " FROM" +
  1792. " wlyy_patient_rehabilitation_plan p" +
  1793. " LEFT JOIN (" +
  1794. " SELECT" +
  1795. " d.id," +
  1796. " d.plan_id," +
  1797. " d.hospital," +
  1798. " d.hospital_name," +
  1799. " i.code as service_item_id," +
  1800. " i.name as service_item_name," +
  1801. " d.expense," +
  1802. " r.doctor_code," +
  1803. " r.doctor_name," +
  1804. " r.complete_time, " +
  1805. " i.code as item_type " +
  1806. " FROM" +
  1807. " wlyy_rehabilitation_plan_detail d" +
  1808. " LEFT JOIN wlyy_rehabilitation_service_item i ON d.hospital_service_item_id = i.code "+
  1809. " LEFT JOIN wlyy_rehabilitation_operate_records r ON d.id = r.rehabilitation_detail_id" +
  1810. " WHERE" +
  1811. " r.`status` = 1" +
  1812. " ) a ON p.id = a.plan_id" +
  1813. " WHERE" +
  1814. " p.id = '"+planId+"'";
  1815. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  1816. sql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(sql);
  1817. List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
  1818. Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
  1819. Integer finishCount = list.size();//完成服务项目数
  1820. double totalExpense = 0;
  1821. Set<String> hospitalSet = new HashSet();
  1822. Set<String> serviceDoctor = new HashSet();
  1823. DecimalFormat df = new DecimalFormat("0.00");
  1824. for (Map<String,Object> map : list){
  1825. double expense = 0;
  1826. if (StringUtils.isNotEmpty(String .valueOf(map.get("expense"))) && !"null".equals(String .valueOf(map.get("expense")))){
  1827. expense =Integer.valueOf(String .valueOf(map.get("expense")));
  1828. }
  1829. totalExpense += expense;
  1830. map.put("expense",df.format(expense/100));
  1831. //组装机构和服务医生
  1832. if(map.get("hospital") != null){
  1833. if(map.get("hospital_name") != null && !hospitalSet.contains(("hospital_name") + "")) {
  1834. hospitalSet.add(map.get("hospital_name") + "");
  1835. }
  1836. }
  1837. if(map.get("doctor_code") != null){
  1838. if(map.get("doctor_name") != null && !hospitalSet.contains(("doctor_name") + "")) {
  1839. serviceDoctor.add(map.get("doctor_name") + "");
  1840. }
  1841. }
  1842. }
  1843. reslutMap.put("totalExpense",df.format(totalExpense/100));
  1844. reslutMap.put("allCount",allCount);
  1845. reslutMap.put("finishCount",finishCount);
  1846. reslutMap.put("serviceList",list);
  1847. reslutMap.put("hospitalAll", hospitalSet.toString().replace("[","").replace("]","").replace(",", "、"));
  1848. reslutMap.put("serviceDoctor", serviceDoctor.toString().replace("[","").replace("]","").replace(",", "、"));
  1849. if (list!=null&&list.size()>0){
  1850. reslutMap.put("patientName",list.get(0).get("name"));
  1851. reslutMap.put("abortTime",list.get(0).get("abort_time"));
  1852. reslutMap.put("hospitalName",list.get(0).get("hospital_name"));
  1853. reslutMap.put("abortReason",list.get(0).get("abort_reason"));
  1854. String patientCode = String.valueOf(list.get(0).get("patient"));
  1855. reslutMap.put("patientCode", patientCode);
  1856. reslutMap.put("disease_name", list.get(0).get("disease_name"));
  1857. reslutMap.put("create_time", list.get(0).get("create_time"));
  1858. reslutMap.put("patient_img", list.get(0).get("patient_img"));
  1859. BasePatientDO patient = basePatientDao.findById(patientCode);
  1860. if (patient!=null){
  1861. reslutMap.put("openid", patient.getOpenid());
  1862. reslutMap.put("ssc",patient.getSsc());
  1863. reslutMap.put("mobile",patient.getMobile());
  1864. }
  1865. }
  1866. return ObjEnvelop.getSuccess(SpecialistMapping.api_success,reslutMap);
  1867. }
  1868. public String getCode() {
  1869. return UUID.randomUUID().toString().replaceAll("-", "");
  1870. }
  1871. public List<Map<String,Object>> getPatientAllRehabilitationPlan(String patient){
  1872. String sql = "select p.team_code as teamCode,d.id as doctor,p.create_time as createTime,p.id,d.photo,p.title,d.idcard,YEAR (now()) - YEAR (substring(d.idcard, 7, 8)) AS age, d.sex,p.name,p.patient,p.disease_name,d.name as doctorName,p.advice_content as adviceContent,p.medical_records_code as medicalRecordsCode,p.create_time as create_time " +
  1873. " FROM wlyy_patient_rehabilitation_plan p " +
  1874. " LEFT JOIN base_doctor d ON d.id = p.create_user " +
  1875. "WHERE p.patient='"+patient+"'";
  1876. sql = sql +" union "+
  1877. "SELECT p.team_code as teamCode,d.id AS doctor," +
  1878. "p.create_time AS createTime," +
  1879. "p.id," +
  1880. "d.photo," +
  1881. "p.title," +
  1882. "d.idcard,YEAR (now())-YEAR (substring(d.idcard,7,8)) AS age," +
  1883. "d.sex,p.name," +
  1884. "p.patient," +
  1885. "p.disease_name,"+
  1886. "d.NAME AS doctorName," +
  1887. "p.advice_content AS adviceContent," +
  1888. "p.medical_records_code AS medicalRecordsCode," +
  1889. "p.create_time AS create_time " +
  1890. "FROM " +
  1891. "wlyy_patient_rehabilitation_plan p " +
  1892. "LEFT JOIN base_doctor d ON d.id=p.create_user" +
  1893. " LEFT JOIN (" +
  1894. "SELECT sr.patient AS patient,sr.team_code AS team_code " +
  1895. "FROM wlyy_doctor_patient_relation sr " +
  1896. "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id " +
  1897. "WHERE sr.patient='"+patient+"') d " +
  1898. "ON d.patient=p.patient WHERE " +
  1899. "p.patient='"+patient+"' " +
  1900. " "+
  1901. "ORDER BY create_time DESC";
  1902. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  1903. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  1904. List<Map<String,Object>> result = new ArrayList<>();
  1905. List<Map<String,Object>> hadManage = new ArrayList<>();
  1906. for (Map<String,Object> mp:mapList){//获下转状态
  1907. Date createTimeDate = DateUtil.strToDateLong(mp.get("createTime").toString());
  1908. mp.put("createTimeDate",DateUtil.dateToStrShort(createTimeDate));
  1909. String mpDoctor = mp.get("doctor").toString();
  1910. String manageStatus;
  1911. //获取最近完成服务
  1912. sql = "select si.`code`,si.name,opr.complete_time update_time \n" +
  1913. "from wlyy_rehabilitation_plan_detail pd \n" +
  1914. "INNER JOIN wlyy_rehabilitation_service_item si on si.`code` = pd.hospital_service_item_id \n" +
  1915. "INNER JOIN wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pd.id\n" +
  1916. "where plan_id='"+mp.get("id").toString()+"' and opr.`status` =1 ORDER BY opr.complete_time DESC ";
  1917. List<Map<String,Object>> serverItems = jdbcTemplate.queryForList(sql);
  1918. if(serverItems!=null&&serverItems.size()!=0){
  1919. mp.put("completeServer",serverItems.get(0));
  1920. }
  1921. else{
  1922. mp.put("completeServer","");
  1923. }
  1924. try {
  1925. manageStatus = jdbcTemplate.queryForObject(sql,String.class);
  1926. }catch (Exception e){
  1927. manageStatus="0";
  1928. }
  1929. if (StringUtils.isBlank(manageStatus)||manageStatus.equals("0")){//已下转,即未接收
  1930. mp.put("turnDownState",1);
  1931. result.add(mp);
  1932. }
  1933. else{//已接受
  1934. mp.put("turnDownState",2);
  1935. hadManage.add(mp);
  1936. }
  1937. }
  1938. result.addAll(hadManage);
  1939. return result;
  1940. }
  1941. public List<Map<String,Object>> selectByGuidance(String planId,String itemCode){
  1942. String sql ="SELECT gm.* FROM wlyy_guidance_message_log gm LEFT JOIN wlyy_rehabilitation_plan_detail pd ON pd.id = gm.plan_detail_id " +
  1943. "WHERE pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id = '"+itemCode+"' ORDER BY gm.create_time DESC ";
  1944. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  1945. return mapList;
  1946. }
  1947. @Transactional
  1948. public String manageAllPlanByPatient(String patient,String doctor){
  1949. String sql = "SELECT re.id,re.doctor,re.doctor_name as doctor_name,pl.id planId,pl.name as patientName,pl.create_user,pl.create_user_name specialDoctorName \n" +
  1950. "from wlyy_patient_rehabilitation_plan pl \n" +
  1951. "INNER JOIN wlyy_doctor_patient_relation re\n" +
  1952. "on pl.patient = re.patient \n" +
  1953. "where re.`status`>=0 \n" +
  1954. "and pl.patient ='"+patient+"' and (re.is_manage<>1 or re.is_manage is NULL) ";
  1955. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
  1956. List<Map<String,Object>> planIds = jdbcTemplate.queryForList(sql);
  1957. List<Map<String,Object>> planByCreate = jdbcTemplate.queryForList(sql+" GROUP BY pl.create_user");
  1958. for (Map<String,Object> tmp:planIds){
  1959. sql ="update wlyy_doctor_patient_relation set is_manage=1,manage_user ='"+doctor+"', manage_time ='"+DateUtil.getStringDate()+"' where id='"+tmp.get("id").toString()+"' ";
  1960. jdbcTemplate.execute(sql);
  1961. }
  1962. BaseDoctorDO doctorObject = baseDoctorDao.findById(doctor);//家庭医生
  1963. //接收患者时,给服务医生群组发送消息
  1964. List<String> patientRelationDoctor = new ArrayList<>();
  1965. for (Map<String,Object> tmp:planByCreate){
  1966. try {
  1967. if(!patientRelationDoctor.contains(tmp.get("doctor").toString())){
  1968. //guidanceService.sendSpecialistWeixinMessage(patient,tmp.get("doctor").toString(),2,null,null,null);
  1969. patientRelationDoctor.add(tmp.get("doctor").toString());
  1970. }
  1971. //患者服务医生群组发送Im消息
  1972. com.alibaba.fastjson.JSONArray serverDoctorList =selectPlanServerDoctor(tmp.get("planId").toString(),doctor);
  1973. int length = serverDoctorList.size();
  1974. for (int i=0;i<length;i++){
  1975. JSONObject serverJson = serverDoctorList.getJSONObject(i);
  1976. if (serverJson.getString("type").equals("4")){
  1977. String sessionId = serverJson.getString("sessionId");
  1978. String message= tmp.get("specialDoctorName").toString()+"医生您好,我已确认接收管理患者"+tmp.get("patientName").toString()+",谢谢。";
  1979. imUtil.sendImMsg(doctor,doctorObject.getName(),sessionId,"1",message,"1","");
  1980. }
  1981. }
  1982. //发送模板消息
  1983. /*if(messageService.getMessageNoticeSettingByMessageType(tmp.get("create_user").toString(),"1", MessageNoticeSetting.MessageTypeEnum.systemSwitch.getValue())) {
  1984. Doctor specialistDoctor = doctorDao.findByCode(tmp.get("create_user").toString());
  1985. if(StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
  1986. Doctor SignDoctor = doctorDao.findByCode(doctor);
  1987. Patient p = patientDao.findByCode(patient);
  1988. //[医生姓名]医生您好,[医生姓名]医生已确认接收您的康复下转患者[患者姓名],请访问厦门i健康APP康复管理查看。
  1989. String first = specialistDoctor.getName() + "医生您好,"+SignDoctor.getName()+"医生已确认接收您的康复下转患者"
  1990. + p.getName() +",请访问厦门i健康APP康复管理查看。";
  1991. if (StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
  1992. doctorAssistantUtil.sendWXTemplate(2,specialistDoctor.getOpenid(),first,"请及时处理","康复管理","已接收");
  1993. }
  1994. }
  1995. }*/
  1996. }catch(Exception e){
  1997. e.printStackTrace();
  1998. }
  1999. }
  2000. return null;
  2001. }
  2002. @Transactional(propagation= Propagation.NOT_SUPPORTED)
  2003. public com.alibaba.fastjson.JSONArray selectPlanServerDoctor(String planId,String doctorCode) throws Exception{
  2004. String sql ="SELECT t.patient,t.create_user FROM wlyy_patient_rehabilitation_plan t where t.id='"+planId+"'";//专科
  2005. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  2006. com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
  2007. String patient = "";
  2008. for (Map<String,Object> map:mapList){
  2009. String doctor =map.get("create_user").toString();
  2010. patient = map.get("patient").toString();
  2011. JSONObject object = new JSONObject();
  2012. BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
  2013. object.put("code",doctor1.getId());
  2014. object.put("name",doctor1.getName());
  2015. object.put("level",doctor1.getLevel());
  2016. /*object.put("hospital",doctor1.getHospital());
  2017. object.put("hospitalName",doctor1.getHospitalName());*/
  2018. if (doctor1.getLevel()==1){
  2019. object.put("levelName","专科医生");
  2020. }else if (doctor1.getLevel()==2){
  2021. object.put("levelName","全科医生");
  2022. }
  2023. object.put("photo",doctor1.getPhoto());
  2024. object.put("idcard",doctor1.getIdcard());
  2025. jsonArray.add(object);
  2026. }
  2027. /*SignFamily signFamily = signFamilyDao.findByPatient(patient);
  2028. if (signFamily!=null){
  2029. org.json.JSONObject object = new org.json.JSONObject();
  2030. BaseDoctorDO doctor1 = baseDoctorDao.findById(signFamily.getDoctor());
  2031. object.put("code",doctor1.getId());
  2032. object.put("name",doctor1.getName());
  2033. if (doctor.getLevel()==1){
  2034. object.put("levelName","专科医生");
  2035. }else if (doctor.getLevel()==2){
  2036. object.put("levelName","全科医生");
  2037. }
  2038. object.put("photo",doctor.getPhoto());
  2039. object.put("idcard",doctor.getIdcard());
  2040. object.put("hospital",doctor.getHospital());
  2041. object.put("hospitalName",doctor.getHospitalName());
  2042. array.put(object);
  2043. org.json.JSONObject object1 = new org.json.JSONObject();
  2044. if (StringUtils.isNoneBlank(signFamily.getDoctorHealth())){
  2045. BaseDoctorDO doctor1 = baseDoctorDao.findById(signFamily.getDoctorHealth());
  2046. object1.put("code",doctor1.getId());
  2047. object1.put("name",doctor1.getName());
  2048. object1.put("level",3);
  2049. object1.put("levelName","健管师");
  2050. object1.put("photo",doctor1.getPhoto());
  2051. object1.put("idcard",doctor1.getIdcard());
  2052. object.put("hospital",doctor1.getHospital());
  2053. object.put("hospitalName",doctor1.getHospitalName());
  2054. array.put(object1);
  2055. }
  2056. }*/
  2057. StringBuilder serverGroupSessionId =new StringBuilder();//群聊session_id
  2058. StringBuilder serverGroupSessionName =new StringBuilder();//群聊名称
  2059. JSONObject participants = new JSONObject();//群聊成员
  2060. if (jsonArray!=null){
  2061. for(int i=0;i<jsonArray.size();i++){//获取服务医生P2P 未读消息以及session_id。
  2062. JSONObject jsonObject = jsonArray.getJSONObject(i);
  2063. serverGroupSessionId.append(jsonObject.getString("code")+"_");
  2064. serverGroupSessionName.append(jsonObject.getString("name")+"、");
  2065. participants.put(jsonObject.getString("code"),0);
  2066. if(jsonObject.getString("code").equals(doctorCode)){//
  2067. jsonObject.put("unRead",0);
  2068. jsonObject.put("sessionId","");
  2069. jsonObject.put("type","");
  2070. jsonObject.put("business_type","");
  2071. continue;
  2072. }
  2073. //服务医生间的消息获取
  2074. JSONObject participantsP2P = new JSONObject();
  2075. participantsP2P.put(doctorCode,0);
  2076. participantsP2P.put(jsonObject.getString("code"),0);
  2077. //获取登录医生与其他服务医生的session_id
  2078. //{"data":{"business_type":1,"name":"余研","id":"3438fdc6c1082c7b3c3e93dc27da244b59b694dc","type":"2","create_date":1603436112458},"status":200}
  2079. JSONObject result = imUtil.createSession(participantsP2P,"2",jsonObject.getString("name"),null);
  2080. jsonObject.put("sessionId",result.getJSONObject("data").getString("id"));
  2081. jsonObject.put("type",result.getJSONObject("data").getString("type"));
  2082. jsonObject.put("business_type",result.getJSONObject("data").getInteger("business_type"));
  2083. //获取未读消息
  2084. result = imUtil.getSessionUnreadMessageCount(jsonObject.getString("sessionId"),doctorCode);
  2085. jsonObject.put("unRead",result.getInteger("count"));
  2086. }
  2087. }
  2088. //服务医生群聊数据获取
  2089. JSONObject groupObject = new JSONObject();
  2090. if(StringUtils.isNoneBlank(serverGroupSessionId)&&StringUtils.isNoneBlank(serverGroupSessionName)){
  2091. serverGroupSessionId.append("server_group");
  2092. serverGroupSessionName=serverGroupSessionName.deleteCharAt(serverGroupSessionName.length()-1);
  2093. if(imUtil.sessionIsExist(serverGroupSessionId+"")){//会话存在
  2094. JSONObject result = imUtil.getSessionUnreadMessageCount(serverGroupSessionId+"",doctorCode);
  2095. groupObject.put("unRead",result.getInteger("count"));
  2096. }
  2097. else{
  2098. JSONObject result = imUtil.createSession(participants,"4",serverGroupSessionName+"",serverGroupSessionId+"");
  2099. groupObject.put("unRead",0);
  2100. }
  2101. groupObject.put("name",serverGroupSessionName);
  2102. groupObject.put("sessionId",serverGroupSessionId.toString());
  2103. groupObject.put("business_type",1);
  2104. groupObject.put("type","4");
  2105. }
  2106. jsonArray.add(groupObject);
  2107. return jsonArray;
  2108. }
  2109. /**
  2110. * 每天8点,16点的job
  2111. * @param startTime
  2112. * @param endTime
  2113. * @throws Exception
  2114. */
  2115. public void dailyJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
  2116. JSONArray jsonArray = dailyJob(startTime,endTime);
  2117. org.json.JSONObject jsonObject = null;
  2118. String doctor = "";
  2119. String patient ="";
  2120. Integer num = null;
  2121. String planDetailIds = null;
  2122. for(int i=0;i<jsonArray.length();i++){
  2123. jsonObject = jsonArray.getJSONObject(i);
  2124. doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
  2125. patient = jsonObject.get("patient")+"";//执行的居民
  2126. num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数
  2127. planDetailIds = jsonObject.get("planDetailIds")+"";
  2128. SystemMessageDO message1 = new SystemMessageDO();
  2129. // message1.setSender(patient);
  2130. message1.setType(type.toString());
  2131. message1.setReceiver(doctor);
  2132. message1.setRelationCode(planDetailIds);
  2133. // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
  2134. }
  2135. }
  2136. /**
  2137. * 每天15点的job
  2138. * @param startTime
  2139. * @param endTime
  2140. * @throws Exception
  2141. */
  2142. public void tomorrowJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
  2143. JSONArray jsonArray =tomorrowJob(startTime,endTime);
  2144. org.json.JSONObject jsonObject = null;
  2145. String doctor = "";
  2146. String patient ="";
  2147. Integer num = null;
  2148. String planDetailIds = null;
  2149. for(int i=0;i<jsonArray.length();i++){
  2150. jsonObject = jsonArray.getJSONObject(i);
  2151. doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
  2152. patient = jsonObject.get("patient")+"";//执行的居民
  2153. num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数
  2154. planDetailIds = jsonObject.get("planDetailIds")+"";
  2155. String planId = jsonObject.get("id")+"";
  2156. SystemMessageDO message1 = new SystemMessageDO();
  2157. // message1.setSender(patient);
  2158. message1.setType(type.toString());
  2159. message1.setReceiver(doctor);
  2160. message1.setRelationCode(planDetailIds);
  2161. message1.setReason(planId);
  2162. // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
  2163. }
  2164. }
  2165. /**
  2166. * 每15分钟的job
  2167. *
  2168. * @param startTime
  2169. * @param endTime
  2170. * @param type
  2171. * @throws Exception
  2172. */
  2173. public void dailyByJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
  2174. JSONArray jsonArray = dailyByJob(startTime,endTime);
  2175. org.json.JSONObject jsonObject = null;
  2176. String doctor = "";
  2177. String patient ="";
  2178. Integer num = null;
  2179. String serviceItemName = null;
  2180. String planDetailIds = null;
  2181. Long timeType = null;
  2182. String nowDate = DateUtil.getStringDate();
  2183. String date9 = DateUtil.getStringDateShort()+" 09:00:00";//白天
  2184. String date21 = DateUtil.getStringDateShort()+" 21:00:00";//白天
  2185. String date9s = DateUtil.getNextDay(DateUtil.getNowDate(),1)+" 09:00:00";//晚上
  2186. for(int i=0;i<jsonArray.length();i++){
  2187. jsonObject = jsonArray.getJSONObject(i);
  2188. doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
  2189. patient = jsonObject.get("patient")+"";//执行的居民
  2190. /*num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数*/
  2191. planDetailIds = jsonObject.get("planDetailIds")+"";
  2192. serviceItemName = jsonObject.getString("serviceItemName");
  2193. timeType = jsonObject.getLong("timeType");
  2194. if (timeType!=null){
  2195. if (timeType==1 && nowDate.compareTo(date9)==1&&nowDate.compareTo(date21)==-1){
  2196. SystemMessageDO message1 = new SystemMessageDO();
  2197. // message1.setSender(patient);
  2198. message1.setType(type.toString());
  2199. message1.setReceiver(doctor);
  2200. message1.setRelationCode(planDetailIds);
  2201. message1.setData(serviceItemName);
  2202. // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
  2203. }else if (timeType==2 && nowDate.compareTo(date21)==1&&nowDate.compareTo(date9s)==-1){
  2204. SystemMessageDO message1 = new SystemMessageDO();
  2205. // message1.setSender(patient);
  2206. message1.setType(type.toString());
  2207. message1.setReceiver(doctor);
  2208. message1.setRelationCode(planDetailIds);
  2209. message1.setData(serviceItemName);
  2210. // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
  2211. }else if (timeType==0){
  2212. SystemMessageDO message1 = new SystemMessageDO();
  2213. // message1.setSender(patient);
  2214. message1.setType(type.toString());
  2215. message1.setReceiver(doctor);
  2216. message1.setRelationCode(planDetailIds);
  2217. message1.setData(serviceItemName);
  2218. // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
  2219. }
  2220. }
  2221. }
  2222. }
  2223. public void dailyJobReserve(Integer num,Integer type) throws Exception{
  2224. Long time = num*24*60*60*1000L;
  2225. String startTime = DateUtil.dateToStrShort(new Date(new Date().getTime()+time))+" "+"00:00:00";
  2226. String endTime = DateUtil.dateToStrShort(new Date(new Date().getTime()+time))+" "+"23:59:59";
  2227. JSONArray jsonArray=dailyJobReserve1(startTime,endTime);
  2228. org.json.JSONObject jsonObject = null;
  2229. String doctor = "";
  2230. String patient ="";
  2231. String hospital ="";
  2232. String planDetailIds = null;
  2233. for(int i=0;i<jsonArray.length();i++){
  2234. jsonObject = jsonArray.getJSONObject(i);
  2235. doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
  2236. patient = jsonObject.get("patient")+"";//执行的居民
  2237. hospital = jsonObject.get("hospital")+"";//医院
  2238. planDetailIds = jsonObject.get("planDetailIds")+"";
  2239. SystemMessageDO message1 = new SystemMessageDO();
  2240. // message1.setSender(patient);
  2241. message1.setType(type.toString());
  2242. message1.setReceiver(doctor);
  2243. message1.setRelationCode(planDetailIds);
  2244. // specialistEvaluateSevice.sendMessage(message1,hospital,patient,num,null);
  2245. }
  2246. }
  2247. public List<PatientMedicalRecordsDO> selectByMedicalCode(String code){
  2248. String str[] = code.split(",");
  2249. List<PatientMedicalRecordsDO> medicalRecordsDOS= new ArrayList<>();
  2250. for (int i=0;i<str.length;i++){
  2251. PatientMedicalRecordsDO medicalRecordsDO = medicalRecordsRehabilitationDao.findByCode(str[i]);
  2252. medicalRecordsDOS.add(medicalRecordsDO);
  2253. }
  2254. return medicalRecordsDOS;
  2255. }
  2256. public List<Map<String,Object>> selectAllCompleteServiceItemsByPatient(String patient){
  2257. List<Map<String,Object>> resutList = new ArrayList<>();
  2258. String sql ="select A.id 'planId',pdl.id,pdl.frequency_code,A.patient,A.`name`,si.id 'code',si.`name` 'serviceName',opr.complete_time 'czrq' from \n" +
  2259. "(select p.team_code as teamCode,d.code as doctor,p.create_time as createTime,p.id,p.patient,p.name " +
  2260. "from wlyy_patient_rehabilitation_plan p\n" +
  2261. "LEFT JOIN base_doctor d ON d.id = p.create_user\n" +
  2262. "WHERE p.patient='"+patient+"'\n" +
  2263. "union\n" +
  2264. "SELECT p.team_code as teamCode,d.CODE AS doctor,p.create_time AS createTime,p.id,p.patient,p.name " +
  2265. "from \n" +
  2266. " wlyy_patient_rehabilitation_plan p\n" +
  2267. "LEFT JOIN base_doctor d ON d.id=p.create_user\n" +
  2268. "LEFT JOIN (\n" +
  2269. "SELECT sr.patient AS patient,sr.team_code AS team_code \n" +
  2270. "FROM wlyy_doctor_patient_relation sr \n" +
  2271. "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id \n" +
  2272. "WHERE sr.patient='"+patient+"') d \n" +
  2273. "ON d.patient=p.patient WHERE \n" +
  2274. "p.patient='"+patient+"' \n" +
  2275. "\n" +
  2276. "ORDER BY createTime DESC)A \n" +
  2277. "INNER JOIN wlyy_rehabilitation_plan_detail pdl ON A.id = pdl.plan_id\n" +
  2278. "INNER JOIN wlyy_rehabilitation_service_item si on pdl.hospital_service_item_id = si.id\n" +
  2279. "INNER JOIN wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pdl.id\n" +
  2280. "where pdl.hospital_service_item_id <>2 and opr.`status`=1 order by opr.complete_time desc ";
  2281. sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  2282. List<Map<String,Object>> planDetailList = jdbcTemplate.queryForList(sql);
  2283. resutList.addAll(planDetailList);
  2284. //康复咨询
  2285. sql= "select ct.consult,ct.type,ct.patient,ct.name,ct.czrq,ct.symptoms,top.`status`,top.end_time,top.evaluate,top.evaluate_time,top.reply,top.reply_time, '2' as 'serviceId','康复咨询' as 'serviceName'\n" +
  2286. "from wlyy_consult_team ct\n" +
  2287. "INNER JOIN im_internet_hospital.topics top on top.id = ct.consult \n" +
  2288. "where ct.patient='"+patient+"' and ct.type=18 and ct.del=1";
  2289. List<Map<String,Object>> kangFuList = jdbcTemplate.queryForList(sql);
  2290. for (Map<String,Object> map:kangFuList){
  2291. if (map.get("status").toString().equals("0")&&map.get("reply").toString().equals("0")){
  2292. map.put("serviceStatus","未回复");
  2293. }
  2294. if (map.get("status").toString().equals("0")&&map.get("reply").toString().equals("1")){
  2295. map.put("serviceStatus","未结束");
  2296. }
  2297. if (map.get("status").toString().equals("10")){//&&map.get("evaluate").toString().equals("0")
  2298. map.put("serviceStatus","已结束");
  2299. }
  2300. // if (map.get("status").toString().equals("10")&&map.get("evaluate").toString().equals("1")){
  2301. // map.put("serviceStatus","已结束");
  2302. // }
  2303. }
  2304. resutList.addAll(kangFuList);
  2305. Collections.sort(resutList, new Comparator<Map<String, Object>>() {
  2306. public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  2307. Timestamp map1value = (Timestamp) o1.get("czrq");
  2308. Timestamp map2value = (Timestamp) o2.get("czrq");
  2309. int sort = 1;
  2310. if (map1value.getTime() - map2value.getTime() > 0) {
  2311. return sort == 1 ? -1 : 1;
  2312. } else if (map1value.getTime() - map2value.getTime() < 0) {
  2313. return sort == 1 ? 1 : -1;
  2314. } else {
  2315. return 0;
  2316. }
  2317. }
  2318. });
  2319. return resutList;
  2320. }
  2321. public JSONArray getPlanDetailForModifing(String planId,String templateId){
  2322. String sql;
  2323. JSONArray result = new JSONArray();
  2324. if(StringUtils.isBlank(templateId)){
  2325. sql ="select id from wlyy_rehabilitation_plan_template where title='系统模板'";
  2326. templateId = jdbcTemplate.queryForObject(sql,String.class);
  2327. }
  2328. sql = "select d.hospital_service_item_id as code,i.`name`\n" +
  2329. "from wlyy_rehabilitation_template_detail d LEFT JOIN wlyy_rehabilitation_service_item i\n" +
  2330. "ON i.`code` = d.hospital_service_item_id\n" +
  2331. "where d.template_id = '"+templateId+"'";
  2332. List<Map<String,Object>> templateDetailList = jdbcTemplate.queryForList(sql);
  2333. for (Map<String,Object> map:templateDetailList){
  2334. sql ="select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,i.name \n" +
  2335. "from wlyy_rehabilitation_plan_detail d \n" +
  2336. "LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id \n" +
  2337. "where d.plan_id ='"+planId+"' AND d.execute_time IS NOT NULL and d.execute_time <>''\n" +
  2338. "AND d.`status`<> 1\n" +
  2339. "and d.hospital_service_item_id ='"+map.get("code").toString()+"'\n" +
  2340. "ORDER BY hospital_service_item_id ASC,execute_time ASC;";
  2341. sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
  2342. List<Map<String,Object>> planDetailList = jdbcTemplate.queryForList(sql);
  2343. org.json.JSONObject temp = new org.json.JSONObject();
  2344. temp.put("counts",planDetailList.size());
  2345. temp.put("code",map.get("code").toString());
  2346. temp.put("name",map.get("name").toString());
  2347. temp.put("list",planDetailList);
  2348. result.put(temp);
  2349. }
  2350. return result;
  2351. }
  2352. public org.json.JSONObject selectBySpecialistDoctor(String level, String area, String doctor, String disease, Integer page, Integer pageSize, String doctorType, String patientInfo, String filterPlan, String turnDownState){
  2353. Integer turnDownStateTotal_0=0;//全部
  2354. Integer turnDownStateTotal_1=0;//已下转
  2355. Integer turnDownStateTotal_2=0;//已接受
  2356. Integer turnDownStateTotal_3=0;//未下转
  2357. org.json.JSONObject resultObj = new org.json.JSONObject();
  2358. BaseDoctorDO doctorObj = baseDoctorDao.findById(doctor);
  2359. List<Map<String, Object>> result = new ArrayList<>();
  2360. String sql = "SELECT DISTINCT pr.id,p.`name`,plan.id as planId, p.`id` as code, p.idcard,p.photo, plan.disease,plan.disease_name,YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) as age," +
  2361. "p.sex,pr.doctor AS specialist,pr.doctor_name AS specialistName,pr.disease_code,pr.doctor_name ," +
  2362. "pr.doctor, pr.health_doctor, pr.health_doctor_name, pr.is_manage,pr.manage_user,pr.manage_time FROM" +
  2363. " base_doctor doc,`wlyy_doctor_patient_relation` pr" +
  2364. " LEFT JOIN base_patient p ON p.`id` = pr.patient ";
  2365. //关联居民计划表
  2366. if("1".equals(filterPlan)){
  2367. sql = sql + " INNER JOIN `wlyy_patient_rehabilitation_plan` plan on plan.patient = pr.patient ";
  2368. }
  2369. sql =sql+ " WHERE doc.`id` = pr.doctor ";
  2370. String sqlCondition = "";
  2371. if (doctorType.equalsIgnoreCase("1")){
  2372. sqlCondition +=" AND pr.doctor = '"+doctor+"'";
  2373. }else {
  2374. sqlCondition +=" AND (pr.doctor = '"+doctor+"' or pr.health_doctor = '"+doctor+"') ";
  2375. }
  2376. if(StringUtils.isNoneBlank(patientInfo)){
  2377. sqlCondition +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%') ";
  2378. }
  2379. /* if (level.equalsIgnoreCase("1")){
  2380. sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
  2381. }else if (level.equalsIgnoreCase("2")){
  2382. sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
  2383. }else if (level.equalsIgnoreCase("3")){
  2384. sqlCondition +=" and sf.hospital = '"+area+"' ";
  2385. }*/
  2386. /*if (StringUtils.isNoneBlank(disease)){
  2387. sqlCondition +=" and pr.id IN (SELECT pds.specialist_relation_code FROM wlyy_patient_disease_server pds WHERE pds.del=1 and pds.disease ='"+disease+"')";
  2388. }*/
  2389. //LIMIT+(page-1)*pageSize+","+pageSize
  2390. sqlCondition += " ORDER BY pr.create_time DESC ";
  2391. sql += sqlCondition;
  2392. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  2393. System.out.println("mapList"+sql);
  2394. for (Map<String,Object> map:mapList){
  2395. BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
  2396. List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
  2397. if (depts!=null&&depts.size()>0){
  2398. map.put("dept_code",depts.get(0).getDeptCode());
  2399. map.put("dept_name",depts.get(0).getDeptName());
  2400. }
  2401. Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
  2402. map.put("age",age);
  2403. String specialistRelationCode = map.get("id").toString();
  2404. String relationManageState = map.get("is_manage")==null?"0":map.get("is_manage").toString();//管理状态
  2405. /*List<PatientDiseaseServer> diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1");
  2406. StringBuffer diseaseName = new StringBuffer();
  2407. for (int i=0;i<diseaseServers.size();i++){
  2408. diseaseName.append(diseaseServers.get(i).getDiseaseName()+",");
  2409. }
  2410. if(StringUtils.isNoneBlank(diseaseName)){
  2411. diseaseName.deleteCharAt(diseaseName.length()-1);
  2412. }
  2413. map.put("disease_name",diseaseName);*/
  2414. if(StringUtils.isBlank(relationManageState)||!relationManageState.equals("1")){//未进行管理
  2415. map.put("turnDownState", 1);//已下转
  2416. turnDownStateTotal_1+=1;
  2417. turnDownStateTotal_0+=1;
  2418. if(turnDownState.equals("1")||turnDownState.equals("0")){
  2419. result.add(map);
  2420. }
  2421. }
  2422. else{
  2423. map.put("turnDownState", 2);//已管理
  2424. turnDownStateTotal_2+=1;
  2425. turnDownStateTotal_0+=1;
  2426. if(turnDownState.equals("2")||turnDownState.equals("0")){
  2427. result.add(map);
  2428. }
  2429. }
  2430. }
  2431. //家医端未下转(签约居民,但是还未下转的居民) 专科医生端未下转(与未下转列表同-去除未家签)
  2432. if (doctorType.equalsIgnoreCase("1")){//专科
  2433. sql = "select null as id,p.`name`,p.`id` as code,p.idcard,p.photo,YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) AS age, p.sex,d.create_user AS specialist,d.create_user_name AS specialistName,\n" +
  2434. " d.doctor_name,d.doctor,d.health_doctor,d.health_doctor_name,null as is_manage,null as manage_user,null as manage_time \n" +
  2435. "from wlyy_doctor_patient_relation d,base_patient p ,base_doctor doc where doc.`id` = d.create_user AND d.create_user='"+doctor+"' ";
  2436. }
  2437. sqlCondition="";
  2438. if(StringUtils.isNoneBlank(patientInfo)){
  2439. sqlCondition +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%') ";
  2440. }
  2441. /* if (level.equalsIgnoreCase("1")){
  2442. sqlCondition +=" and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
  2443. }else if (level.equalsIgnoreCase("2")){
  2444. sqlCondition +=" and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
  2445. }else if (level.equalsIgnoreCase("3")){
  2446. sqlCondition +=" and s.hospital = '"+area+"' ";
  2447. }*/
  2448. if (StringUtils.isNoneBlank(disease)){
  2449. sqlCondition +=" AND d.patient in (select patient from wlyy_patient_disease_server pds where pds.del=1 and pds.disease ='"+disease+"') ";
  2450. }
  2451. sql = sql + sqlCondition ;
  2452. if (doctorType.equalsIgnoreCase("1")){//专科
  2453. sql = sql+ " \n" +
  2454. " AND d.patient = p.id \n" +
  2455. "AND d.patient NOT IN ( SELECT i.patient FROM wlyy_patient_rehabilitation_plan i, base_patient p \n" +
  2456. "WHERE i.create_user='"+doctor+"' AND i. STATUS != 0 AND p. id = i.patient \n" +
  2457. "GROUP BY i.patient ORDER BY i.create_time DESC) GROUP BY d.patient ORDER BY d.create_time DESC ";
  2458. }
  2459. List<Map<String, Object>> mapList12 = jdbcTemplate.queryForList(sql);
  2460. System.out.println("mapList2"+sql);
  2461. for (Map<String, Object> map : mapList12) {
  2462. List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
  2463. if (depts!=null&&depts.size()>0){
  2464. map.put("dept_code",depts.get(0).getDeptCode());
  2465. map.put("dept_name",depts.get(0).getDeptName());
  2466. }
  2467. BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
  2468. Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
  2469. map.put("age",age);
  2470. map.put("disease_name", "暂无");
  2471. map.put("turnDownState",3);//未下
  2472. turnDownStateTotal_3+=1;
  2473. turnDownStateTotal_0+=1;
  2474. if(turnDownState.equals("3")||turnDownState.equals("0")){
  2475. result.add(map);
  2476. }
  2477. }
  2478. org.json.JSONObject turnDownStateObj = new org.json.JSONObject();
  2479. turnDownStateObj.put("stateAll",turnDownStateTotal_0);//全部
  2480. turnDownStateObj.put("stateDown",turnDownStateTotal_1);//已下转
  2481. turnDownStateObj.put("stateReceive",turnDownStateTotal_2);//已接受
  2482. turnDownStateObj.put("stateNotDown",turnDownStateTotal_3);//未下转
  2483. resultObj.put("showList",result);
  2484. resultObj.put("turnDownState",turnDownStateObj);
  2485. return resultObj;
  2486. }
  2487. /**
  2488. * 康复管理-生成康复下转专科医生二维码
  2489. * @param doctorCode
  2490. * @param teamCode
  2491. * @param teamName
  2492. * @return
  2493. * @throws Exception
  2494. */
  2495. public String createSpecialDoctorQrCode(String doctorCode,String teamCode,String teamName) throws Exception{
  2496. Map<String, Object> param = new HashedMap();
  2497. String fileUrl = "";
  2498. String appId="";
  2499. //生成二维码图片
  2500. String contentJsonStr="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+""+"%2fwx%2fhtml%2fkfgl%2fhtml%2frecover_manage.html%3FdoctorCode%3D"+doctorCode+"%26teamCode%3D"+teamCode+"%26teamName%3D"+teamName+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  2501. InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
  2502. if (isneiwang) {
  2503. // 圖片列表
  2504. List<String> tempPaths = new ArrayList<String>();
  2505. try {
  2506. ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
  2507. com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
  2508. tempPaths.add(json.getString("fid"));
  2509. String urls = "";
  2510. for (String image : tempPaths) {
  2511. if (urls.length() == 0) {
  2512. urls = image;
  2513. } else {
  2514. urls += "," + image;
  2515. }
  2516. }
  2517. fileUrl = "" + urls;
  2518. } catch (Exception e) {
  2519. e.printStackTrace();
  2520. }
  2521. } else {
  2522. try {
  2523. //fileUrl = "" + CommonUtil.PrescriptionQRCodetoNeiWang(ipt);
  2524. }catch (Exception e){
  2525. e.printStackTrace();
  2526. }
  2527. }
  2528. System.out.println("服务码-----------1"+fileUrl);
  2529. param.put("doctorCode", doctorCode);
  2530. param.put("imageUrl",fileUrl);
  2531. return fileUrl;
  2532. }
  2533. public org.json.JSONObject selectBySpecialistDoctor1(String level, String area, String doctor, String disease, Integer page, Integer pageSize, String doctorType, String patientInfo, String filterPlan, String turnDownState){
  2534. Integer turnDownStateTotal_0=0;//全部
  2535. Integer turnDownStateTotal_1=0;//已下转
  2536. Integer turnDownStateTotal_2=0;//已接受
  2537. Integer turnDownStateTotal_3=0;//未下转
  2538. org.json.JSONObject resultObj = new org.json.JSONObject();
  2539. List<Map<String, Object>> result = new ArrayList<>();
  2540. String sql = "select DISTINCT t.id as \"id\"," +
  2541. " p.name as \"name\"," +
  2542. " p.id as \"code\"," +
  2543. " p.idcard as \"idcard\"," +
  2544. " p.photo as \"photo\"," +
  2545. " p.sex as \"sex\"," +
  2546. " t.disease as \"disease\"," +
  2547. " t.disease_name as \"disease_name\"," +
  2548. " YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) as age," +
  2549. " d.doctor as \"doctor\"," +
  2550. " d.doctor_name as \"doctor_name\"," +
  2551. " t.create_user as \"create_user\"," +
  2552. " t.create_user_name as \"create_user_name\"," +
  2553. " t.create_time as \"create_time\"," +
  2554. " t.is_verify as \"is_verify\"" +
  2555. " from wlyy_patient_rehabilitation_plan t left join wlyy_rehabilitation_plan_detail d on t.id =d.plan_id" +
  2556. " left join base_doctor doc on d.doctor=doc.id LEFT JOIN base_patient p ON p.`id` = t.patient" +
  2557. " where 1=1 " ;
  2558. if(StringUtils.isNoneBlank(patientInfo)){
  2559. sql +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%') ";
  2560. }
  2561. if (doctorType.equalsIgnoreCase("1")){
  2562. sql +=" AND d.doctor = '"+doctor+"'";
  2563. }else {
  2564. sql +=" AND (d.doctor = '"+doctor+"' or t.create_user = '"+doctor+"') ";
  2565. }
  2566. /* if (level.equalsIgnoreCase("1")){
  2567. sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
  2568. }else if (level.equalsIgnoreCase("2")){
  2569. sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
  2570. }else if (level.equalsIgnoreCase("3")){
  2571. sqlCondition +=" and sf.hospital = '"+area+"' ";
  2572. }*/
  2573. /*if (StringUtils.isNoneBlank(disease)){
  2574. sqlCondition +=" and pr.id IN (SELECT pds.specialist_relation_code FROM wlyy_patient_disease_server pds WHERE pds.del=1 and pds.disease ='"+disease+"')";
  2575. }*/
  2576. //LIMIT+(page-1)*pageSize+","+pageSize
  2577. sql += " ORDER BY p.create_time DESC ";
  2578. List<Map<String,Object>> mapList = hibenateUtils.createSQLQuery(sql,page,pageSize);
  2579. System.out.println("mapList"+sql);
  2580. for (Map<String,Object> map:mapList){
  2581. BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
  2582. List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
  2583. if (depts!=null&&depts.size()>0){
  2584. map.put("dept_code",depts.get(0).getDeptCode());
  2585. map.put("dept_name",depts.get(0).getDeptName());
  2586. }
  2587. Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
  2588. map.put("age",age);
  2589. String specialistRelationCode = map.get("id").toString();
  2590. String relationManageState = map.get("is_verify")==null?"0":map.get("is_verify").toString();//管理状态
  2591. /*List<PatientDiseaseServer> diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1");
  2592. StringBuffer diseaseName = new StringBuffer();
  2593. for (int i=0;i<diseaseServers.size();i++){
  2594. diseaseName.append(diseaseServers.get(i).getDiseaseName()+",");
  2595. }
  2596. if(StringUtils.isNoneBlank(diseaseName)){
  2597. diseaseName.deleteCharAt(diseaseName.length()-1);
  2598. }
  2599. map.put("disease_name",diseaseName);*/
  2600. if(StringUtils.isBlank(relationManageState)||!relationManageState.equals("1")){
  2601. map.put("turnDownState", 1);//已确认
  2602. turnDownStateTotal_1+=1;
  2603. turnDownStateTotal_0+=1;
  2604. if(turnDownState.equals("1")||turnDownState.equals("0")){
  2605. result.add(map);
  2606. }
  2607. }
  2608. else{
  2609. map.put("turnDownState", 2);//未确认
  2610. turnDownStateTotal_2+=1;
  2611. turnDownStateTotal_0+=1;
  2612. result.add(map);
  2613. }
  2614. }
  2615. org.json.JSONObject turnDownStateObj = new org.json.JSONObject();
  2616. turnDownStateObj.put("stateAll",turnDownStateTotal_0);//全部
  2617. turnDownStateObj.put("stateDown",turnDownStateTotal_1);//已下转
  2618. turnDownStateObj.put("stateReceive",turnDownStateTotal_2);//已接受
  2619. turnDownStateObj.put("stateNotDown",turnDownStateTotal_3);//未下转
  2620. resultObj.put("showList",result);
  2621. resultObj.put("turnDownState",turnDownStateObj);
  2622. return resultObj;
  2623. }
  2624. public List<Map<String,Object>> calendarPlanDetailItems(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode) throws Exception{
  2625. String sqlCondition = "";
  2626. if (searchTask!=null){
  2627. if(searchTask==8){
  2628. sqlCondition+="and d.doctor='"+doctorCode+"' ";
  2629. }else {
  2630. sqlCondition+=" and i.code="+searchTask+" " ;
  2631. }
  2632. }
  2633. if(status!=null){
  2634. sqlCondition += "and d.status="+status;
  2635. }//服务项目
  2636. String sql = " select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code,DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s') as createTime from wlyy_rehabilitation_plan_detail d " +
  2637. " LEFT JOIN wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id " +
  2638. " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
  2639. " where d.plan_id='"+planId+"' "+sqlCondition+" group by i.code";
  2640. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  2641. for (Map<String,Object> map:mapList){
  2642. String sql1 = "SELECT d.frequency_code,d.plan_id as planId ,d.id,DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s') AS createTime " +
  2643. "FROM wlyy_rehabilitation_plan_detail d " +
  2644. "WHERE d.plan_id = '"+planId+"' and d.hospital_service_item_id='"+map.get("code")+"'ORDER BY d.create_time DESC";
  2645. List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sql1);
  2646. if (mapList1!=null&&mapList1.size()!=0){
  2647. Map<String,Object> map1 = mapList1.get(0);
  2648. map.put("frequency_code",map1.get("frequency_code"));
  2649. map.put("planId",map1.get("planId"));
  2650. map.put("id",map1.get("id"));
  2651. map.put("createTime",map1.get("createTime"));
  2652. }
  2653. }
  2654. for (Map<String,Object> map:mapList){
  2655. if (!StringUtils.isNoneBlank(map.get("frequency_code").toString())){//
  2656. String sqlCount = "SELECT ror.id,MAX(ror.complete_time) as date,count(*) as total FROM `wlyy_rehabilitation_operate_records` ror, " +
  2657. "wlyy_rehabilitation_plan_detail pd WHERE pd.id = ror.rehabilitation_detail_id " +
  2658. "AND pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id='"+map.get("code")+"' AND ror.`status`=1 ";
  2659. List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
  2660. int count = 0;
  2661. /* if (map.get("code").toString().equalsIgnoreCase("6")){
  2662. String allPlanSql = "select wf.id as id,wf.followup_no as followupNo,wf.followup_date as followupDate,wf.followup_plan_date as followupPlanDate,wf.followup_next_date as followupNextDate,\n" +
  2663. "wf.followup_type as followupType,wf.followup_class as followupClass,wf.followup_manager_status as followupManagerStatus,wf.doctor_code as doctorCode,wf.doctor_name as doctorName,\n" +
  2664. "wf.jwdoctor_code as jwdoctorCode,wf.org_code as orgCode,wf.org_name as orgName,wf.jworg_code as jworgCode,wf.patient_code as patientCode,wf.patient_name as patientName,wf.idcard,\n" +
  2665. "wf.data_from as dataFrom,wf.status,wf.followup_content_phone as followupContentPhone,wf.creater,wf.sign_type as signType,wf.admin_team_code as adminTeamCode,wf.sign_code as signCode,\n" +
  2666. "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
  2667. "and wf.patient_code = '"+map.get("patient")+"' order by wf.followup_plan_date desc";
  2668. List<Map<String , Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
  2669. count = allPlanList.size();
  2670. }*/
  2671. /*if (map.get("code").toString().equalsIgnoreCase("7")){
  2672. String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, pr.`code`, \n" +
  2673. "LEFT(pr.create_time,19) AS createTime, pr.doctor, pr.min_drug_day AS minDrugDay, LEFT(pr.pres_create_time,19) AS presCreateTime \n" +
  2674. "FROM wlyy_prescription pr LEFT JOIN wlyy_patient p ON pr.patient = p.`code` WHERE 1=1 AND pr.patient = '"+map.get("patient")+"' AND pr.status = 100 GROUP BY pr.`code`;";
  2675. List<Map<String , Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
  2676. count = allPrescrList.size();
  2677. }
  2678. if (mapList1!=null && mapList1.size()!=0){
  2679. Map<String,Object> map1 = mapList1.get(0);
  2680. map.put("compeletTotal",new Integer(map1.get("total").toString()) + count );
  2681. map.put("firstDate",map1.get("date"));
  2682. }*/
  2683. }else {
  2684. int codeCount = 0 ;
  2685. /* if (map.get("code").toString().equalsIgnoreCase("6")){ //康复随访
  2686. //该居民的所有随访计划,需要同步展示到康复计划-康复随访内
  2687. String allPlanSql = "select wf.id as id,wf.followup_no as followupNo,wf.followup_date as followupDate,wf.followup_plan_date as followupPlanDate,wf.followup_next_date as followupNextDate,\n" +
  2688. "wf.followup_type as followupType,wf.followup_class as followupClass,wf.followup_manager_status as followupManagerStatus,wf.doctor_code as doctorCode,wf.doctor_name as doctorName,\n" +
  2689. "wf.jwdoctor_code as jwdoctorCode,wf.org_code as orgCode,wf.org_name as orgName,wf.jworg_code as jworgCode,wf.patient_code as patientCode,wf.patient_name as patientName,wf.idcard,\n" +
  2690. "wf.data_from as dataFrom,wf.status,wf.followup_content_phone as followupContentPhone,wf.creater,wf.sign_type as signType,wf.admin_team_code as adminTeamCode,wf.sign_code as signCode,\n" +
  2691. "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
  2692. "and wf.patient_code = '"+map.get("patient")+"' order by wf.followup_plan_date desc";
  2693. List<Map<String , Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
  2694. codeCount = allPlanList.size();
  2695. map.put("allPlanList",allPlanList);
  2696. }
  2697. if (map.get("code").toString().equalsIgnoreCase("7")){ //康复复诊
  2698. //居民的处方续方,需要同步展示到康复计划-康复复诊内
  2699. String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, pr.`code`, \n" +
  2700. "LEFT(pr.create_time,19) AS createTime, pr.doctor, pr.min_drug_day AS minDrugDay, LEFT(pr.pres_create_time,19) AS presCreateTime \n" +
  2701. "FROM wlyy_prescription pr LEFT JOIN wlyy_patient p ON pr.patient = p.`code` WHERE 1=1 AND pr.patient = '"+map.get("patient")+"' AND pr.status = 100 GROUP BY pr.`code`;";
  2702. List<Map<String , Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
  2703. codeCount = allPrescrList.size();
  2704. map.put("allPrescrList",allPrescrList);
  2705. }*/
  2706. String sqlCount="SELECT\n" +
  2707. "\tCOUNT(pd.id) AS total ,\n" +
  2708. "\tCOUNT(CASE WHEN pd.`status`=1 THEN 1 ELSE NULL END) AS compeletTotal\n" +
  2709. "FROM\n" +
  2710. "\t wlyy_rehabilitation_plan_detail pd\n" +
  2711. "WHERE\n" +
  2712. "\t pd.plan_id = '"+planId+"' " +
  2713. "AND pd.hospital_service_item_id='"+map.get("code")+"' and (pd.frequency_code IS NOT NULL AND pd.frequency_code<>'')\n";
  2714. List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
  2715. if (mapList1!=null && mapList1.size()!=0){
  2716. Map<String,Object> map1 = mapList1.get(0);
  2717. map.put("total",new Integer(map1.get("total").toString()) + codeCount);
  2718. map.put("compeletTotal",new Integer(map1.get("compeletTotal").toString()) + codeCount);
  2719. }
  2720. String dateSql = "SELECT MAX(CASE WHEN pd.`status`=1 THEN pd.execute_time ELSE NULL END) AS firstDate FROM wlyy_rehabilitation_plan_detail pd " +
  2721. "WHERE pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id='"+map.get("code")+"'";
  2722. List<Map<String,Object>> mapList2 = jdbcTemplate.queryForList(dateSql);
  2723. if (mapList2!=null && mapList2.size()!=0){
  2724. Map<String,Object> map1 = mapList2.get(0);
  2725. map.put("firstDate",map1.get("firstDate"));
  2726. String condition = "";
  2727. if (map1.get("firstDate")!=null&&StringUtils.isNoneBlank(map1.get("firstDate").toString())){
  2728. condition = "and pd.execute_time >='"+map1.get("firstDate").toString()+"'";
  2729. }
  2730. String dateSql1 = "SELECT pd.execute_time as lastDate FROM wlyy_rehabilitation_plan_detail pd " +
  2731. "WHERE pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id='"+map.get("code")+"' and pd.status=0 "+condition+" order by pd.execute_time ASC ";
  2732. List<Map<String,Object>> mapList3 = jdbcTemplate.queryForList(dateSql1);
  2733. if (mapList3!=null&&mapList3.size()!=0){
  2734. Map<String,Object> map2 = mapList3.get(0);
  2735. map.put("lastDate",map2.get("lastDate"));
  2736. }else {
  2737. map.put("lastDate",null);
  2738. }
  2739. }
  2740. }
  2741. if (map.get("code").toString().equalsIgnoreCase("2"))
  2742. {//康复咨询
  2743. //总康复咨询数量
  2744. String sqlTotal = "select count(*)\n" +
  2745. "from wlyy_consult a,wlyy_consult_team b where a.id = b.consult and a.patient = '"+map.get("patient")+"' and a.del = '1' and a.type=18";
  2746. Integer consultTotal = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
  2747. /* String healthCount = "SELECT * FROM wlyy_patient_reservation WHERE incidental_msg_type = 0 AND source = 4 AND patient = '"+map.get("patient")+"' ORDER BY start_time DESC";
  2748. List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthCount);
  2749. map.put("healthList",healthList);
  2750. map.put("total",consultTotal + healthList.size());*/
  2751. //完成康复咨询数量
  2752. /* sqlTotal = "select count(*)\n" +
  2753. "from wlyy_consult a,wlyy_consult_team b where a.code = b.consult and a.patient = '"+map.get("patient")+"' and a.del = '1' and a.type=18 and b.`status`=1";
  2754. consultTotal = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
  2755. map.put("compeletTotal",consultTotal + healthList.size());*/
  2756. //上次发起时间
  2757. String sqlTemp ="select a.czrq\n" +
  2758. "from wlyy_consult a,wlyy_consult_team b where a.id = b.consult and a.patient = '"+map.get("patient")+"' and a.del = '1' and a.type=18 order by a.czrq desc limit 1";
  2759. List<Map<String,Object>> czrqMap = jdbcTemplate.queryForList(sqlTemp);
  2760. if(czrqMap.size()!=0){
  2761. if(czrqMap.get(0).get("czrq")!=null){
  2762. map.put("lastDate",czrqMap.get(0).get("czrq").toString());
  2763. }
  2764. }
  2765. else{
  2766. map.put("lastDate",null);
  2767. }
  2768. /* //未回复康复咨询数量
  2769. sqlTotal="SELECT count(*) FROM wlyy.wlyy_consult_team a WHERE a.type = 18\n" +
  2770. "AND EXISTS ( SELECT DISTINCT t.id consultId FROM "+imDBName+".topics t, "+imDBName+".participants p, "+imDBName+".doctors d, "+imDBName+".sessions s \n" +
  2771. "WHERE p.participant_id = d.id AND t.session_id = p.session_id AND t.session_id = s.id\n" +
  2772. "AND s.type =18 AND t.`reply` = 0 AND a.consult = t.id\n" +
  2773. "and a.id in( select b.id from wlyy_consult a,wlyy_consult_team b \n" +
  2774. "where a.code = b.consult and a.patient = '"+map.get("patient")+"' and a.del = '1' and a.type=18 )\n" +
  2775. ")";
  2776. Integer noReplay = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
  2777. map.put("noReplay",noReplay);*/
  2778. }
  2779. }
  2780. return mapList;
  2781. }
  2782. public PatientRehabilitationPlanDO confirmManage(String patient,String signDoctor,String specialist,String relationId,String planId) throws Exception {
  2783. String sqlCondition;
  2784. if (StringUtils.isNoneBlank(relationId)){
  2785. sqlCondition=" and pr.id='"+relationId+"' ";
  2786. }
  2787. else{
  2788. sqlCondition=" and pr.doctor = '"+specialist+ "'";
  2789. }
  2790. PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(planId);
  2791. if (patientRehabilitationPlanDO!=null){
  2792. patientRehabilitationPlanDO.setIsVerify("1");
  2793. patientRehabilitationPlanDao.save(patientRehabilitationPlanDO);
  2794. String specialistSql = "select pr.doctor,pr.patient from wlyy_doctor_patient_relation pr where pr.patient='"+patient+"' "+sqlCondition;
  2795. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(specialistSql);
  2796. if (mapList!=null&&mapList.size()!=0){
  2797. Map<String,Object> map = mapList.get(0);
  2798. String doctor = (String)map.get("doctor");
  2799. String patient1 = (String)map.get("patient");
  2800. //guidanceService.sendSpecialistWeixinMessage(patient1,doctor,2,null,null,null);
  2801. }
  2802. //下转患者被家庭医生确认管理时,专科医生收到推送
  2803. /*if(messageService.getMessageNoticeSettingByMessageType(specialist,"1", MessageNoticeSetting.MessageTypeEnum.systemSwitch.getValue())) {
  2804. Doctor specialistDoctor = doctorDao.findByCode(specialist);
  2805. if(StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
  2806. Doctor doctor = doctorDao.findByCode(signDoctor);
  2807. Patient p = patientDao.findByCode(patient);
  2808. //[医生姓名]医生您好,[医生姓名]医生已确认接收您的康复下转患者[患者姓名],请访问厦门i健康APP康复管理查看。
  2809. String first = specialistDoctor.getName() + "医生您好,"+doctor.getName()+"医生已确认接收您的康复下转患者"
  2810. + p.getName() +",请访问厦门i健康APP康复管理查看。";
  2811. doctorAssistantUtil.sendWXTemplate(2,specialistDoctor.getOpenid(),first,"请及时处理","康复管理","已接收");
  2812. }
  2813. }*/
  2814. //确认管理给管理医生群组发送消息
  2815. /* if (StringUtils.isNoneBlank(planId)){
  2816. try {
  2817. JSONArray serverDoctorList =selectPlanServerDoctor(planId,signDoctor);
  2818. int length = serverDoctorList.length();
  2819. BaseDoctorDO doctor = baseDoctorDao.findById(signDoctor);
  2820. Patient p = patientDao.findByCode(patient);
  2821. Doctor specialistDoctor = doctorDao.findByCode(specialist);
  2822. for (int i=0;i<length;i++){
  2823. org.json.JSONObject serverJson = serverDoctorList.getJSONObject(i);
  2824. if (serverJson.getString("type").equals("4")){
  2825. String sessionId = serverJson.getString("sessionId");
  2826. String message= specialistDoctor.getName()+"医生您好,我已确认接收管理患者"+p.getName()+",谢谢。";
  2827. ImUtill.sendImMsg(signDoctor,doctor.getName(),sessionId,"1",message,"1");
  2828. }
  2829. }
  2830. }catch(Exception e){
  2831. e.printStackTrace();
  2832. }
  2833. }*/
  2834. }
  2835. return patientRehabilitationPlanDO;
  2836. }
  2837. public org.json.JSONObject selectByPlanDetaiId(String patient, String planId, String code, Integer page, Integer pagesize){
  2838. org.json.JSONObject object = new org.json.JSONObject();
  2839. String sql ="SELECT\n" +
  2840. " DATE_FORMAT(r.complete_time,'%Y-%m-%d %H:%i:%s') AS completeTime," +
  2841. " r.doctor_code AS doctorCode," +
  2842. " r.doctor_name AS doctorName," +
  2843. " r.`status`," +
  2844. " r.id as recordId," +
  2845. " si.`name`," +
  2846. " si.`code`," +
  2847. " pd.plan_id," +
  2848. " pd.id," +
  2849. " r.relation_code as relationCode," +
  2850. " r.flag " +
  2851. "FROM " +
  2852. " wlyy_rehabilitation_operate_records r " +
  2853. "LEFT JOIN wlyy_rehabilitation_plan_detail pd ON r.rehabilitation_detail_id = pd.id " +
  2854. "LEFT JOIN wlyy_rehabilitation_service_item si ON si.code= pd.hospital_service_item_id " +
  2855. "LEFT JOIN base_doctor d ON d.id = r.doctor_code " +
  2856. "WHERE " +
  2857. " pd.plan_id = '"+planId+"' " +
  2858. " AND pd.hospital_service_item_id = '"+code+"' " +
  2859. "ORDER BY " +
  2860. " r.complete_time DESC " ;
  2861. sql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(sql);
  2862. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  2863. String sqlCount ="SELECT\n" +
  2864. "\tCOUNT(*) as total\n" +
  2865. "FROM\n" +
  2866. "\t wlyy_rehabilitation_operate_records r\n" +
  2867. "LEFT JOIN wlyy_rehabilitation_plan_detail pd ON r.rehabilitation_detail_id = pd.id\n" +
  2868. "LEFT JOIN wlyy_rehabilitation_service_item si ON si.code= pd.hospital_service_item_id\n" +
  2869. "LEFT JOIN base_doctor d ON d.id = r.doctor_code\n" +
  2870. "WHERE\n" +
  2871. "\t pd.plan_id = '"+planId+"'\n" +
  2872. "\t\tAND pd.hospital_service_item_id = '"+code+"'\n";
  2873. List<Map<String,Object>> maps = jdbcTemplate.queryForList(sqlCount);
  2874. /*String followupSql = "select wf.id as id,wf.followup_no as followupNo,wf.followup_date as completeTime,wf.followup_plan_date as followupPlanDate,wf.followup_next_date as followupNextDate,\n" +
  2875. "wf.followup_type as followupType,wf.followup_class as followupClass,wf.followup_manager_status as followupManagerStatus,wf.doctor_code as doctorCode,wf.doctor_name as doctorName,\n" +
  2876. "wf.jwdoctor_code as jwdoctorCode,wf.org_code as orgCode,wf.org_name as orgName,wf.jworg_code as jworgCode,wf.patient_code as patientCode,wf.patient_name as patientName,wf.idcard,\n" +
  2877. "wf.data_from as dataFrom,wf.status,wf.followup_content_phone as followupContentPhone,wf.creater,wf.sign_type as signType,wf.admin_team_code as adminTeamCode,wf.sign_code as signCode,\n" +
  2878. "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
  2879. "and wf.patient_code = '"+patient+"' ";
  2880. List<Map<String,Object>> followupList = jdbcTemplate.queryForList(followupSql);
  2881. mapList.addAll(followupList);*/
  2882. Collections.sort(mapList, new Comparator<Map<String, Object>>() {
  2883. public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  2884. Timestamp map1value = (Timestamp) o1.get("completeTime");
  2885. Timestamp map2value = (Timestamp) o2.get("completeTime");
  2886. int sort = 1;
  2887. if (map1value.getTime() - map2value.getTime() > 0) {
  2888. return sort == 1 ? -1 : 1;
  2889. } else if (map1value.getTime() - map2value.getTime() < 0) {
  2890. return sort == 1 ? 1 : -1;
  2891. } else {
  2892. return 0;
  2893. }
  2894. }
  2895. });
  2896. object.put("list",startPage(mapList,page,pagesize));
  2897. object.put("total",new Integer(maps.get(0).get("total").toString()) );
  2898. object.put("page",page);
  2899. object.put("pagesize",pagesize);
  2900. return object;
  2901. }
  2902. /**
  2903. * 开始分页
  2904. * @param list
  2905. * @param pageNum 页码
  2906. * @param pageSize 每页多少条数据
  2907. * @return
  2908. */
  2909. public static List startPage(List list, Integer pageNum,
  2910. Integer pageSize) {
  2911. if (pageNum == null){
  2912. pageNum = 1;
  2913. }
  2914. if (pageSize == null){
  2915. pageSize = 10;
  2916. }
  2917. if (list == null) {
  2918. return null;
  2919. }
  2920. if (list.size() == 0) {
  2921. return null;
  2922. }
  2923. Integer count = list.size(); // 记录总数
  2924. Integer pageCount = 0; // 页数
  2925. if (count % pageSize == 0) {
  2926. pageCount = count / pageSize;
  2927. } else {
  2928. pageCount = count / pageSize + 1;
  2929. }
  2930. int fromIndex = 0; // 开始索引
  2931. int toIndex = 0; // 结束索引
  2932. if (pageNum != pageCount) {
  2933. fromIndex = (pageNum - 1) * pageSize;
  2934. toIndex = fromIndex + pageSize;
  2935. } else {
  2936. fromIndex = (pageNum - 1) * pageSize;
  2937. toIndex = count;
  2938. }
  2939. List pageList = list.subList(fromIndex, toIndex);
  2940. return pageList;
  2941. }
  2942. /**
  2943. * 获取康复服务项目列表
  2944. * @return
  2945. * @param name
  2946. */
  2947. public List<Map<String, Object>> getServiceItemList(String name) {
  2948. String sql = "SELECT code,`name` FROM `wlyy_rehabilitation_service_item` ";
  2949. if(StringUtils.isNotBlank(name)){
  2950. sql += "where name like '%" + name + "%' ";
  2951. }
  2952. List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
  2953. return list;
  2954. }
  2955. @Transactional(propagation= Propagation.NOT_SUPPORTED)
  2956. public List<PatientMedicalRecordsDO> getNewRehabilitation(String patient,String doctorCode) throws Exception {
  2957. //智业中山同步病历
  2958. String result = "";
  2959. List<PatientMedicalRecordsDO> query = new ArrayList<>();
  2960. BasePatientDO patient1 = basePatientDao.findById(patient);
  2961. BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
  2962. String orgCode="";
  2963. List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorCode);
  2964. if(baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
  2965. orgCode=baseDoctorHospitalDO.get(0).getOrgCode();
  2966. }
  2967. if (demoFlag) {//demoFlag
  2968. result = patientRecordService.getJosnFileResullt("event" + "2");
  2969. } else {
  2970. org.json.JSONObject jsonEvent = new org.json.JSONObject();
  2971. List<Map<String, String>> resultMap = patientRecordService.getAllEvent_new(patient, "2", "1", "1", "2010-10-10 00:00:00",orgCode);
  2972. jsonEvent.put("data", JSON.parseArray(JSON.toJSONString(resultMap)));
  2973. result = jsonEvent.toString();
  2974. }
  2975. com.alibaba.fastjson.JSONObject rejson = com.alibaba.fastjson.JSONObject.parseObject(result);
  2976. com.alibaba.fastjson.JSONArray temlist = rejson.getJSONArray("data");
  2977. if (temlist.size() != 0) {//存在病历信息
  2978. com.alibaba.fastjson.JSONObject tem = temlist.getJSONObject(0);
  2979. /**
  2980. * {
  2981. "orgName": "厦门大学附属心血管病医院",
  2982. "createTime": "2013-09-26 10:13:38",
  2983. "patient": "386a35b8d17a47cbab6174ae7952b9b6",
  2984. "orgCode": "182",
  2985. "dataFrom": "1",
  2986. "id": "9f35ff1f-f683-4f3c-a0a5-7ff8ef3df89e",
  2987. "eventType": "2",
  2988. "dianosis": "高血压2级",
  2989. "eventDate": "2013-09-26 10:13:38"
  2990. }
  2991. */
  2992. PatientMedicalRecordsDO pmr = new PatientMedicalRecordsDO();
  2993. pmr.setHospitalName(tem.getString("orgName"));
  2994. pmr.setHospital(tem.getString("orgCode"));
  2995. if (demoFlag) {//测试获取为病历模板 hospitalcode获取为自己的code
  2996. pmr.setHospital("ac02a9b87a3611e69f7c005056850d66");//
  2997. }
  2998. // pmr.setDischargeDiagnosis(re.getDiagnosis());
  2999. pmr.setDischargeDiagnosisName(tem.getString("dianosis"));
  3000. // pmr.setAdmittingDiagnosis(re.getDiagnosis());
  3001. pmr.setJwpatient(tem.getString("patient"));
  3002. pmr.setAdmittingDiagnosisName(tem.getString("dianosis"));
  3003. pmr.setEvent(tem.getString("id"));
  3004. pmr.setDataFrom(tem.getString("dataFrom"));
  3005. pmr.setAdvice("出院继续观察");
  3006. if (tem.getString("dataFrom").equals("4"))//3中山 4智业
  3007. {
  3008. try {
  3009. String html = rehabilitationInfoService.getEmrContentByRID(tem.getString("patient"),tem.getString("id"),tem.getString("orgCode"));
  3010. if (StringUtils.isNoneBlank(html)){
  3011. List<String> tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.in\" diagpop=\"1\">" + "(.*?)</TD>");
  3012. String diagnosisIn =tmp.size()>0?tmp.get(0):"";
  3013. tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.out\" diagpop=\"1\">" + "(.*?)</TD>");
  3014. String diagnosisOut =tmp.size()>0?tmp.get(0):"";
  3015. if (StringUtils.isNoneBlank(diagnosisIn)){//入院诊断
  3016. pmr.setAdmittingDiagnosisName(diagnosisIn);
  3017. }
  3018. if (StringUtils.isNoneBlank(diagnosisOut)){//出院诊断
  3019. pmr.setDischargeDiagnosisName(diagnosisOut);
  3020. }
  3021. }
  3022. }catch (Exception e){
  3023. e.printStackTrace();
  3024. }
  3025. }
  3026. if (tem.getString("dataFrom").equals("3"))//3中山 4智业
  3027. {
  3028. try {
  3029. com.alibaba.fastjson.JSONObject zsResult = zsRehabilitationInfoService.zsHospitalRecordDetail(tem.getString("patient"),tem.getString("id"));
  3030. com.alibaba.fastjson.JSONObject zsResultData = zsResult.getJSONObject("data");
  3031. if (zsResult.getInteger("status")==200&&zsResultData!=null){
  3032. if(zsResultData.containsKey("入院诊断")&&StringUtils.isNoneBlank(zsResultData.getString("入院诊断"))){
  3033. pmr.setDischargeDiagnosisName(zsResultData.getString("入院诊断"));
  3034. }
  3035. if (zsResultData.containsKey("出院诊断")&&StringUtils.isNoneBlank(zsResultData.getString("出院诊断"))){
  3036. pmr.setAdmittingDiagnosisName(zsResultData.getString("出院诊断"));
  3037. }
  3038. }
  3039. }catch (Exception e){
  3040. e.printStackTrace();
  3041. }
  3042. }
  3043. // pmr.setDiseaseCode(diseaseObj.getString("disease"));//疾病code
  3044. // pmr.setDiseaseName(diseaseObj.getString("diseaseName"));//疾病名称
  3045. String jsonData = JSON.toJSONString(pmr);
  3046. //创建居民住院病历
  3047. objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
  3048. PatientMedicalRecordsDO patientMedicalRecordsDO = objectMapper.readValue(jsonData, PatientMedicalRecordsDO.class);
  3049. PatientMedicalRecordsDO patientMedicalRecordsDO1 = rehabilitationInfoService.createMedicalRecords(doctorCode, patient, patient1.getName(), patientMedicalRecordsDO, null);
  3050. if (patientMedicalRecordsDO1 != null) { //创建病历成功
  3051. query.add(patientMedicalRecordsDO1);
  3052. return query;
  3053. }
  3054. }
  3055. String sql = "SELECT pmrr.* FROM wlyy_patient_medical_records_rehabilitation pmrr WHERE pmrr.patient = '"+patient+"' and (data_from=3 or data_from=4) GROUP BY id DESC LIMIT 0,1";//find_in_set('"+diseaseCode+"',disease)
  3056. query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(PatientMedicalRecordsDO.class));
  3057. return query;
  3058. }
  3059. public List<Map<String,Object>> selectPlanByPatient(String patient, Integer status, String planId,String doctor){
  3060. if (StringUtils.isNoneBlank(planId)){
  3061. String planSql = "select p.patient " +
  3062. " FROM wlyy_patient_rehabilitation_plan p where p.id='"+planId+"' ";
  3063. List<Map<String,Object>> maps = jdbcTemplate.queryForList(planSql);
  3064. if (maps!=null&&maps.size()!=0){
  3065. Map<String,Object> map = maps.get(0);
  3066. patient = map.get("patient").toString();
  3067. }
  3068. }
  3069. String sql = "select d.id as doctor,p.create_time as createTime,p.id,d.photo,p.title,d.idcard,YEAR (now()) - YEAR (substring(d.idcard, 7, 8)) AS age, d.sex,p.name,p.patient,d.name as doctorName,p.advice_content as adviceContent,p.medical_records_code as medicalRecordsCode,p.create_time as create_time " +
  3070. " FROM wlyy_patient_rehabilitation_plan p " +
  3071. " LEFT JOIN base_doctor d ON d.id = p.create_user " +
  3072. "WHERE p.patient='"+patient+"'";
  3073. if (status!=null){
  3074. sql +=" and p.status ="+status;
  3075. }
  3076. if (StringUtils.isNoneBlank(doctor)){
  3077. BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
  3078. if (doctor1!=null&&doctor1.getLevel()==1){
  3079. sql +=" and p.create_user ='"+doctor+"'";
  3080. }
  3081. }
  3082. /*sql+=" union ";
  3083. sql+=" SELECT d.CODE AS doctor," +
  3084. "p.create_time AS createTime," +
  3085. "p.id," +
  3086. "d.photo," +
  3087. "p.title," +
  3088. "d.idcard,YEAR (now())-YEAR (substring(d.idcard,7,8)) AS age," +
  3089. "d.sex,p.name," +
  3090. "p.patient," +
  3091. "d.NAME AS doctorName," +
  3092. "d.dept_name AS deptName," +
  3093. "hospital_name AS hospitalName," +
  3094. "p.advice_content AS adviceContent," +
  3095. "p.medical_records_code AS medicalRecordsCode," +
  3096. "p.create_time AS create_time " +
  3097. "FROM " +
  3098. "wlyy_patient_rehabilitation_plan p " +
  3099. "LEFT JOIN base_doctor d ON d.id=p.create_user" +
  3100. " LEFT JOIN (" +
  3101. "SELECT sr.patient AS patient,sr.team_code AS team_code " +
  3102. "FROM wlyy_doctor_patient_relation sr " +
  3103. "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id " +
  3104. "WHERE se.doctor='"+doctor+"' " +
  3105. "AND sr.patient='"+patient+"') d " +
  3106. "ON d.patient=p.patient WHERE " +
  3107. "p.patient='"+patient+"' " +
  3108. "AND d.team_code=p.team_code ";
  3109. */
  3110. sql+=" ORDER BY create_time DESC ";
  3111. //sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
  3112. List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
  3113. for (Map<String,Object> map:mapList){
  3114. List<BaseDoctorHospitalDO> depts=baseDoctorHospitalDao.findByDoctorCode(map.get("doctor").toString());
  3115. if(depts!=null&&depts.size()>0){
  3116. map.put("deptCode",depts.get(0).getDeptCode());
  3117. map.put("deptName",depts.get(0).getDeptName());
  3118. map.put("orgCode",depts.get(0).getOrgCode());
  3119. map.put("orgName",depts.get(0).getOrgName());
  3120. }
  3121. String sqlSpecilist = "select * from wlyy_doctor_patient_relation where doctor = '"+map.get("doctor")+"' and patient ='"+patient+"' and status=1";
  3122. List<Map<String,Object>> maps = jdbcTemplate.queryForList(sqlSpecilist);
  3123. map.put("specialist",maps);
  3124. }
  3125. return mapList;
  3126. }
  3127. }