RehabilitationManageService.java 187 KB

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