123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450 |
- package com.yihu.rehabilitation.service;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.yihu.fastdfs.FastDFSUtil;
- import com.yihu.jw.doctor.dao.BaseDoctorDao;
- import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
- import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
- import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
- import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
- import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
- import com.yihu.jw.entity.base.patient.BasePatientDO;
- import com.yihu.jw.entity.door.SignFamily;
- import com.yihu.jw.entity.hospital.DmHospitalDO;
- import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
- import com.yihu.jw.entity.hospital.doctor.Frequency;
- import com.yihu.jw.entity.hospital.message.SystemMessageDO;
- import com.yihu.jw.entity.hospital.team.WlyyAdminTeamDO;
- import com.yihu.jw.entity.patient.Patient;
- import com.yihu.jw.entity.specialist.DoctorPatientRelationDO;
- import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
- import com.yihu.jw.entity.specialist.rehabilitation.*;
- import com.yihu.jw.entity.util.TransforSqlUtl;
- import com.yihu.jw.hospital.HospitalDao;
- import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
- import com.yihu.jw.hospital.team.dao.WlyyAdminTeamDao;
- import com.yihu.jw.im.util.ImUtil;
- import com.yihu.jw.patient.dao.BasePatientDao;
- import com.yihu.jw.rehabilitation.*;
- import com.yihu.jw.restmodel.web.Envelop;
- import com.yihu.jw.restmodel.web.MixEnvelop;
- import com.yihu.jw.restmodel.web.ObjEnvelop;
- import com.yihu.jw.rm.base.BaseRequestMapping;
- import com.yihu.jw.rm.specialist.SpecialistMapping;
- import com.yihu.jw.util.common.IdCardUtil;
- import com.yihu.jw.util.common.QrcodeUtil;
- import com.yihu.jw.util.date.DateUtil;
- import com.yihu.jw.utils.hibernate.HibenateUtils;
- import com.yihu.rehabilitation.dao.*;
- import com.yihu.rehabilitation.util.HtmlUtil;
- import io.swagger.models.auth.In;
- import org.apache.commons.collections.map.HashedMap;
- import org.apache.commons.lang3.StringUtils;
- import org.json.JSONArray;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import javax.management.MXBean;
- import java.io.InputStream;
- import java.sql.SQLClientInfoException;
- import java.sql.Timestamp;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * Created by 刘文彬 on 2018/8/16.
- */
- @Service
- @Transactional
- public class RehabilitationManageService {
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private RehabilitationDetailDao rehabilitationDetailDao;
- @Autowired
- private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
- @Autowired
- private GuidanceMessageLogDao guidanceMessageLogDao;
- @Autowired
- private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
- @Autowired
- private RehabilitationDetailAppointmentDao rehabilitationDetailAppointmentDao;
- @Autowired
- private BaseDoctorDao baseDoctorDao;
- @Autowired
- private BaseDoctorRoleDao baseDoctorRoleDao;
- @Autowired
- private BasePatientDao basePatientDao;
- @Autowired
- private SignFamilyDao signFamilyDao;
- @Autowired
- private SpecialistEvaluateSevice specialistEvaluateSevice;
- @Autowired
- private FrequencyDao frequencyDao;
- @Autowired
- private ImUtil imUtil;
- @Autowired
- private PatientMedicalRecordsRehabilitationDao medicalRecordsRehabilitationDao;
- @Autowired
- private BaseDoctorHospitalDao baseDoctorHospitalDao;
- @Autowired
- private HibenateUtils hibenateUtils;
- @Autowired
- private DoctorPatientRelationDao doctorPatientRelationDao;
- @Autowired
- private FastDFSUtil fastDFSUtil;
- @Autowired
- private PatientMedicalRecordsRehabilitationDao patientMedicalRecordsDao;
- @Value("${im.data_base_name}")
- private String imDBName;
- @Value("${neiwang.enable}")
- private Boolean isneiwang; //如果不是内网项目要转到到内网wlyy在上传
- @Autowired
- private ZsRehabilitationInfoService zsRehabilitationInfoService;
- @Autowired
- private PatientRecordService patientRecordService;
- @Autowired
- private RehabilitationInfoService rehabilitationInfoService;
- @Autowired
- private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
- @Autowired
- private ObjectMapper objectMapper;
- @Value("${demo.flag}")
- private Boolean demoFlag;
- @Autowired
- private WlyyAdminTeamDao wlyyAdminTeamDao;
- @Autowired
- private HospitalDao hospitalDao;
- /**
- * 预约协诊
- * @param doctor
- * @param doctorName
- * @param sendTime
- * @param planDetailId
- */
- public ObjEnvelop appointmentConsultation(String patient,String doctor, String doctorName,
- String appointmentDoctor,String appointmentDoctorName,String sendTime, String planDetailId,String opDoctor){
- RehabilitationDetailAppointmentDO appointment = new RehabilitationDetailAppointmentDO();
- appointment.setAppointmentTime(sendTime+":00");
- appointment.setCreateTime(new Date());
- appointment.setDoctor(doctor);
- appointment.setDoctorName(doctorName);
- appointment.setAppointmentDoctor(appointmentDoctor);
- appointment.setAppointmentDoctorName(appointmentDoctorName);
- appointment.setIsSend(0);
- appointment.setRehabilitationPlanDetailId(planDetailId);
- appointment.setPatient(patient);
- rehabilitationDetailAppointmentDao.save(appointment);
- return ObjEnvelop.getSuccess("获取成功",appointment);
- }
- /**
- * 康复管理(专科)-- 计划列表
- * @param doctorCode
- * @param diseaseCode
- * @param planType
- * @param todaybacklog
- * @param page
- * @param pageSize
- * @return
- * @throws Exception
- */
- 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{
- Integer doctorType =null;
- BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
- List<BaseDoctorRoleDO> baseDoctorRoleDO = baseDoctorRoleDao.findByDoctorCode(doctor.getId());
- for(BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){
- if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){
- doctorType = 1;
- break;
- }else {
- doctorType = 2;
- }
- }
- String orgName="";
- String deptName="";
- List<BaseDoctorHospitalDO> orgs = baseDoctorHospitalDao.findByDoctorCode(doctorCode);
- if(orgs!=null&&orgs.size()>0){
- orgName=orgs.get(0).getOrgName();
- deptName=orgs.get(0).getDeptName();
- }
- String sql = " select DISTINCT p.* " +
- " from wlyy_rehabilitation_plan_detail a INNER JOIN wlyy_patient_rehabilitation_plan p " +
- " on a.plan_id = p.id " ;
- if(doctorType==2){//家医是根据签约关系过滤
- sql+=" INNER JOIN wlyy_sign_family f ON f.patient = p.patient \n" +
- "\tand f.expenses_status=1\n" +
- "\tAND f.STATUS >= 1 \n" +
- "\tAND ( f.doctor = '"+doctorCode+"' OR f.doctor_health = '"+doctorCode+"' ) ";
- }
- sql += " where 1=1 ";
- if(todaybacklog!=null&&todaybacklog==1){
- String todayStart = DateUtil.getStringDateShort()+" "+"00:00:00";
- String todayEnd = DateUtil.getStringDateShort()+" "+"23:59:59";
- sql += " and a.execute_time>='"+todayStart+"' and a.execute_time<='"+todayEnd+"'";
- }
- if(planType!=null){
- sql += " and p.plan_type="+planType;
- }
- if(StringUtils.isNotEmpty(diseaseCode)){
- sql+=" and p.disease='"+diseaseCode+"'";
- }
- if(StringUtils.isNotEmpty(patientCondition)){//姓名idcard模糊查询
- sql +=" AND EXISTS (select id from base_patient where `id` = p.patient and ( `name` LIKE '%"+patientCondition+"%' or idcard like '%"+patientCondition+"%') )";
- }
- if (doctorType==1){
- sql +=" AND (p.create_user = '"+doctorCode+"' \n" +
- "\tOR a.doctor = '"+doctorCode+"' ) ";
- }
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planAll2(sql);
- List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
- int count = 0;
- if(rstotal!=null&&rstotal.size()>0&&rstotal.get(0).get("id")!=null){
- count = rstotal.size();
- }
- sql += " ORDER BY p.create_time DESC LIMIT "+(page-1)*pageSize+","+pageSize;
- System.out.println("sql==="+sql);
- List<Map<String,Object>> patientRehabilitationPlanDOList = jdbcTemplate.queryForList(sql);
- List<Map<String,Object>> resultList = new ArrayList<>();
- BasePatientDO patient =null;
- if(patientRehabilitationPlanDOList.size()>0&&patientRehabilitationPlanDOList.get(0).get("id")!=null){
- for(Map<String,Object> one:patientRehabilitationPlanDOList){
- Map<String,Object> resultMap = new HashMap<>();
- String onePlanType=one.get("plan_type")==null?"":one.get("plan_type").toString();
- if ("2".equalsIgnoreCase(onePlanType)){
- String adminTeam=one.get("admin_team_code")==null?"":one.get("admin_team_code").toString();
- if (StringUtils.isNoneBlank(adminTeam)){
- WlyyAdminTeamDO wlyyAdminTeamDO =wlyyAdminTeamDao.findOne(Integer.valueOf(adminTeam));
- if (wlyyAdminTeamDO!=null){
- DmHospitalDO dmHospitalDO = hospitalDao.findByCode(wlyyAdminTeamDO.getOrgCode());
- if (dmHospitalDO!=null){
- resultMap.put("location",dmHospitalDO.getName());
- }
- }
- }
- }else {
- resultMap.put("location",orgName);
- }
- resultMap.put("diseaseName",one.get("disease_name"));
- resultMap.put("deptName",deptName);
- // Integer age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
- // String sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
- // resultMap.put("age",age);
- resultMap.put("hospitalName",one.get("hospital_name"));
- // resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
- resultMap.put("patientName",one.get("name"));
- resultMap.put("patientCode",one.get("patient"));
- patient = basePatientDao.findById(one.get("patient").toString());
- if (patient!=null){
- resultMap.put("photo",patient!=null?patient.getPhoto():"");
- Integer age = IdCardUtil.getAgeForIdcard(patient.getIdcard());
- String sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
- resultMap.put("age",age);
- resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
- resultMap.put("age",age);
- SignFamily signFamily = signFamilyDao.findByPatient(one.get("patient").toString());
- if (signFamily != null){
- resultMap.put("hospitalName",signFamily.getHospitalName());
- }else {
- resultMap.put("hospitalName","");
- }
- }
- resultMap.put("id",one.get("id"));
- resultMap.put("status",one.get("status"));//康复计划状态
- //健康情况
- String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+one.get("patient")+"' and label_type=8";
- List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
- String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
- String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
- resultMap.put("healthyCondition",healthyCondition);
- resultMap.put("healthyConditionType",healthyConditionType);
- //安排类型
- String planTypeName = null;
- Integer planTypeTemp = (Integer)one.get("plan_type");
- switch (planTypeTemp){
- case 1:planTypeName="康复计划" ;break;
- case 2:planTypeName="(转)社区医院" ;break;
- case 3:planTypeName="(转)转家庭病床" ;break;
- }
- resultMap.put("planTypeName",planTypeName);
- resultMap.put("planCreateUser",one.get("create_user"));
- //今日待办(即今日全部的项目)
- Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"00:00:00");
- Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"23:59:59");
- Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.get("id").toString(),beginTime,endTime);
- resultMap.put("todayBacklogCount",todayBacklogCount);//今日待办总数
- //已完成
- Integer finishedCount = rehabilitationDetailDao.completenessCount(1,one.get("id").toString(),beginTime,endTime);
- resultMap.put("finishedCount",finishedCount);//已完成
- //未完成
- Integer notstartedCount = rehabilitationDetailDao.completenessCount(0,one.get("id").toString(),beginTime,endTime);//未开始
- Integer underwayCount = rehabilitationDetailDao.completenessCount(2,one.get("id").toString(),beginTime,endTime);//已预约
- Integer unfinishedCount = notstartedCount+underwayCount;
- resultMap.put("unfinishedCount",unfinishedCount);//未完成
- //完成度(已完成/(已完成+未完成))
- Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.get("id").toString());
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.get("id").toString());
- resultMap.put("allCount",allCount);//总数
- resultMap.put("allFinishCount",allFinishCount);//全部已完成数
- resultMap.put("createTime",one.get("create_time"));
- resultList.add(resultMap);
- }
- }
- return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,Long.valueOf(count));
- }
- //查询康复计划
- public MixEnvelop findPatientRehabilitation(String doctor,String diseaseCode,String patientCondition,Integer page,Integer pageSize){
- String sql ="select DISTINCT t.* from wlyy_patient_rehabilitation_plan t left join base_patient b on t.patient=b.id" +
- " left join wlyy_rehabilitation_plan_detail p on t.id=p.plan_id where 1=1";
- String countSql="select count(1) as \"count\" from wlyy_patient_rehabilitation_plan t left join base_patient b on t.patient=b.id " +
- " left join wlyy_rehabilitation_plan_detail p on t.id=p.plan_id where 1=1";
- if (StringUtils.isNotBlank(doctor)){
- sql+=" and (t.create_user='"+doctor+"' or p.doctor='"+doctor+"')";
- countSql+=" and (t.create_user='"+doctor+"' or p.doctor='"+doctor+"')";
- }
- if (StringUtils.isNotBlank(diseaseCode)){
- sql+=" and t.disease='"+diseaseCode+"'";
- countSql+=" and t.disease='"+diseaseCode+"'";
- }
- if (StringUtils.isNotBlank(patientCondition)){
- sql+=" and (b.name like '%"+patientCondition+"%' or b.idcard like '%"+patientCondition+"%')";
- countSql+=" and (b.name like '%"+patientCondition+"%' or b.idcard like '%"+patientCondition+"%')";
- }
- countSql+=" group by t.id";
- sql+=" order by t.create_time desc";
- List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,pageSize);
- List<Map<String,Object>> countList = hibenateUtils.createSQLQuery(countSql);
- Integer count=0;
- if (countList!=null&&countList.size()>0){
- count=Integer.parseInt(countList.get(0).get("count").toString());
- }
- MixEnvelop mixEnvelop= new MixEnvelop();
- mixEnvelop.setTotalCount(count);
- mixEnvelop.setDetailModelList(list);
- mixEnvelop.setPageSize(pageSize);
- mixEnvelop.setCurrPage(page);
- return mixEnvelop;
- }
- //删除康复计划
- public void delteRehabilitaionPlan(String planId,String doctorCode) throws Exception{
- PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(planId);
- if (patientRehabilitationPlanDO!=null){
- if (!doctorCode.equalsIgnoreCase(patientRehabilitationPlanDO.getCreateUser())){
- throw new Exception("当前医生非创建者不能删除");
- }if (patientRehabilitationPlanDO.getStatus()>=1){
- throw new Exception("开始的计划不能删除");
- }
- patientRehabilitationPlanDao.delete(patientRehabilitationPlanDO);
- rehabilitationDetailDao.deleteDetailOnlyByPlanId(planId);
- }
- }
- /**
- * 康复管理更多计划
- * @param currentDoctorCode
- * @param patientCode
- * @return
- * @throws Exception
- */
- public ObjEnvelop findRehabilitationPlanDetailList(String currentDoctorCode,String patientCode) throws Exception{
- 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+"' ";
- //sql = TransforSqlUtl.specialistPatientRelationAll2(sql);
- List<Map<String,Object>> specialistPatientRelationList = jdbcTemplate.queryForList(sql);
- List<Map<String,Object>> resultList = new ArrayList<>();
- for(Map<String,Object> temp: specialistPatientRelationList){
- String doctorCode = temp.get("doctor")+"";
- Map<String,Object> resultMap = new HashMap<>();
- Integer isOperator = 0;
- resultMap.put("patientCode",patientCode);//居民code
- String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+patientCode+"' and label_type=8";
- List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
- String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
- String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
- resultMap.put("healthyCondition",healthyCondition);
- resultMap.put("healthyConditionType",healthyConditionType);
- //专科医生
- 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+"'";
- specialistRelationSql = TransforSqlUtl.specialistPatientRelationAll2(specialistRelationSql);
- List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
- Map<String,Object> specialistMap = specialistRelationList.get(0);
- resultMap.put("specialistAdminTeamName",specialistMap.get("teamName"));
- resultMap.put("specialistHospitalName",specialistMap.get("specialistHospitalName"));//专科医生所在医院
- Integer specialistUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(doctorCode,patientCode,1);
- Integer specialistFinishCount1 = rehabilitationDetailDao.findItemByDoctor(doctorCode,patientCode);
- Integer specialistServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(doctorCode,patientCode,1);
- /*Integer specialistUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(specialistMap.get("health_assistant")+"",patientCode,1);
- Integer specialistFinishCount2 = rehabilitationDetailDao.findItemByDoctor(specialistMap.get("health_assistant")+"",patientCode);
- Integer specialistServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(specialistMap.get("health_assistant")+"",patientCode,1);*/
- resultMap.put("specialistFinishItemCount",specialistFinishCount1-specialistUnfinishCount1);//完成项目
- resultMap.put("specialistServiceRecordCount",specialistServiceCount1);//服务次数
- //家庭医生(包括全科医生、健管师)
- 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+"'";
- List<Map<String,Object>> signFamilyList = jdbcTemplate.queryForList(signFamilySql);
- if(signFamilyList != null && signFamilyList.size() >0 ) {
- Map<String, Object> signFamilyMap = signFamilyList.get(0);
- resultMap.put("signFamilyAdminTeamName", signFamilyMap.get("teamName"));
- resultMap.put("familyHospitalName", signFamilyMap.get("hospital_name"));//家庭医生所在医院
- Integer familyUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
- Integer familyFinishCount1 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor") + "", patientCode);
- Integer familyServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
- if ((signFamilyMap.get("doctor") + "").equals(signFamilyMap.get("doctor_health") + "")) {
- resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1);//完成项目
- resultMap.put("signFamilyServiceRecordCount", familyServiceCount1);//服务次数
- } else {
- Integer familyUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
- Integer familyFinishCount2 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode);
- Integer familyServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
- resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1 + familyFinishCount2 - familyUnfinishCount2);//完成项目
- resultMap.put("signFamilyServiceRecordCount", familyServiceCount1 + familyServiceCount2);//服务次数
- }
- //基础信息
- resultMap.put("hospitalName", signFamilyMap.get("hospital_name"));
- Integer age = IdCardUtil.getAgeForIdcard(signFamilyMap.get("idcard") + "");
- String sex = IdCardUtil.getSexForIdcard_new(signFamilyMap.get("idcard") + "");
- resultMap.put("age", age);
- resultMap.put("sex", "1".equals(sex) ? "男" : ("2".equals(sex) ? "女" : "未知"));
- resultMap.put("patientName", signFamilyMap.get("patientName"));
- }
- /* //疾病类型
- 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")+"' ";
- List<Map<String,Object>> diseaseList = jdbcTemplate.queryForList(diseaseSql);
- List<String> disease = new ArrayList<>();
- for(Map<String,Object> one2:diseaseList){
- disease.add(one2.get("disease_name")+"");
- }
- resultMap.put("diseaseList",disease);*/
- //计划列表
- List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatientAndCreateUser(patientCode,doctorCode);
- List<Map<String,Object>> rehabilitationPlanList = new ArrayList<>();
- for(PatientRehabilitationPlanDO one:list){
- Map<String,Object> planMap = new HashMap<>();
- planMap.put("planId",one.getId());
- //安排类型
- String planTypeName = null;
- Integer planTypeTemp = one.getPlanType();
- switch (planTypeTemp){
- case 1:planTypeName="康复计划" ;break;
- case 2:planTypeName="(转)社区医院" ;break;
- case 3:planTypeName="(转)转家庭病床" ;break;
- }
- planMap.put("planTypeName",planTypeName);
- planMap.put("status",one.getStatus());//0已中止,1进行中,2已完成
- if(currentDoctorCode.equals(doctorCode)){
- isOperator = 1;
- }
- planMap.put("isOperator",isOperator);
- //状态(0未完成,1已完成,2已预约)
- //今日待办
- Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"00:00:00");
- Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"23:59:59");
- Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.getId(),beginTime,endTime);
- planMap.put("todayBacklogCount",todayBacklogCount);
- //已完成
- Integer finishedCount = rehabilitationDetailDao.completenessCount(1,one.getId(),beginTime,endTime);
- planMap.put("finishedCount",finishedCount);//已完成
- //未完成
- Integer notstartedCount = rehabilitationDetailDao.completenessCount(0,one.getId(),beginTime,endTime);//未完成
- Integer underwayCount = rehabilitationDetailDao.completenessCount(2,one.getId(),beginTime,endTime);//已预约
- Integer unfinishedCount = notstartedCount+underwayCount;
- planMap.put("unfinishedCount",unfinishedCount);//未完成
- //完成度(已完成/(已完成+未完成))
- Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.getId());
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
- planMap.put("allCount",allCount);//总数
- planMap.put("allFinishCount",allFinishCount);//全部已完成数
- rehabilitationPlanList.add(planMap);
- }
- resultMap.put("rehabilitationPlanList",rehabilitationPlanList);
- BasePatientDO p = basePatientDao.findById(patientCode);
- resultMap.put("patientPhoto",p.getPhoto());
- resultList.add(resultMap);
- }
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultList);
- }
- /**
- * 日历
- * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
- * @param status 任务状态(0未完成,1已完成,2已预约)
- * @param doctorCode 登陆医生
- * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
- */
- public ObjEnvelop calendarPlanDetailByPatient(String executeStartTime,String executeEndTime,String patient,Integer searchTask,Integer status,String doctorCode,String taskExecutor) throws Exception{
- List<Map<String,Object>> planList = getPatientAllRehabilitationPlan(patient);
- StringBuilder planCondition = new StringBuilder();
- planCondition .append("'"+planList.get(0).get("id").toString()+"'");
- for (int i=1;i<planList.size();i++){
- planCondition .append(",'"+planList.get(0).get("id").toString()+"'");
- }
- String sql = " select d.* from wlyy_rehabilitation_plan_detail d " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " where d.plan_id in ("+planCondition+") " +
- "" ;
- if(StringUtils.isNotBlank(executeStartTime)){
- sql += " and d.execute_time>='"+executeStartTime+"' ";
- }
- if(StringUtils.isNotBlank(executeEndTime)){
- sql += " and d.execute_time<='"+executeEndTime+"' ";
- }
- if(searchTask!=null){
- if(searchTask==8){
- sql+=" and d.doctor='"+doctorCode+"' " ;
- }else {
- sql+=" and i.code="+searchTask+" " ;
- }
- }
- if(taskExecutor.equals("1")){ //我的任务
- sql+="and d.doctor='"+doctorCode+"' ";
- }
- if(taskExecutor.equals("2")){//他人任务
- sql+="and d.doctor <>'"+doctorCode+"' ";
- }
- if(status!=null){
- sql+= " and d.status="+status;
- }
- sql += " ORDER BY d.execute_time ";
- List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
- // List<RehabilitationDetailDO> rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId);
- Map<String,Map<String,Object>> map = new LinkedHashMap<>();
- for(Map<String,Object> one:rehabilitationDetailList){
- String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD);
- Map<String,Object> m = null;
- if(map.containsKey(executeTime)){
- m = map.get(executeTime);
- Map<String,Integer> family = null;
- Map<String,Integer> specialist = null;
- if(one.get("type")!=null){
- if((Integer)one.get("type")==1){//家庭医生
- if(m.containsKey("family")){
- family = (Map<String,Integer>)m.get("family");
- }else{
- family = new HashMap<>();
- family.put("all",0);
- family.put("finish",0);
- }
- if((Integer)one.get("status")==1){
- family.put("finish",family.get("finish")+1);
- }
- family.put("all",family.get("all")+1);
- m.put("family",family);
- }else if((Integer)one.get("type")==2){//专科医生
- if(m.containsKey("specialist")){
- specialist = (Map<String,Integer>)m.get("specialist");
- }else{
- specialist = new HashMap<>();
- specialist.put("all",0);
- specialist.put("finish",0);
- }
- if((Integer)one.get("status")==1){
- specialist.put("finish",(specialist.get("finish"))+1);
- }
- specialist.put("all",(specialist.get("all"))+1);
- m.put("specialist",specialist);
- }
- }
- }else{
- m = new HashMap<>();
- // m.put("specialist",new HashMap<String,Object>());
- if(one.get("type")!=null){
- if((Integer)one.get("type")==1){//家庭医生
- Map<String,Integer> family = new HashMap<>();
- family.put("all",0);
- family.put("finish",0);
- if((Integer)one.get("status")==1){
- family.put("finish",family.get("finish")+1);
- }
- family.put("all",family.get("all")+1);
- m.put("family",family);
- }else if((Integer)one.get("type")==2){//专科医生
- Map<String,Integer> specialist = new HashMap<>();
- specialist.put("all",0);
- specialist.put("finish",0);
- if((Integer)one.get("status")==1){
- specialist.put("finish",specialist.get("finish")+1);
- }
- specialist.put("all",specialist.get("all")+1);
- m.put("specialist",specialist);
- }
- }
- }
- //myTaskFlag,1:有自己任务,0:没有自己任务
- if(StringUtils.isNotEmpty(doctorCode)){
- if(m.containsKey("myTaskFlag")){
- if((Integer)m.get("myTaskFlag")==0){
- if(doctorCode.equals(one.get("doctor").toString())){
- m.put("myTaskFlag",1);
- }else{
- m.put("myTaskFlag",0);
- }
- }
- }else{
- if(doctorCode.equals(one.get("doctor").toString())){
- m.put("myTaskFlag",1);
- }else{
- m.put("myTaskFlag",0);
- }
- }
- }
- if(m.containsKey("planDetailIds")){
- m.put("planDetailIds",m.get("planDetailIds")+","+one.get("id"));
- }else{
- m.put("planDetailIds",one.get("id")+"");
- }
- map.put(executeTime,m);
- }
- /*List list = new ArrayList();
- for(String key : map.keySet()){
- Map<String,Object> result = map.get(key);
- result.put("executeTime", key);
- list.add(result);
- }*/
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
- }
- /**
- * 日历
- * @param planId 计划id
- * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
- * @param status 任务状态(0未完成,1已完成,2已预约)
- * @param doctorCode 登陆医生
- * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
- */
- public ObjEnvelop calendarPlanDetail(String executeStartTime,String executeEndTime,String planId,Integer searchTask,Integer status,String doctorCode,String taskExecutor) throws Exception{
- String[] planIdlist = planId.split(",");
- StringBuilder planCondition = new StringBuilder();
- planCondition .append("'"+planIdlist[0]+"'");
- for (int i=1;i<planIdlist.length;i++){
- planCondition .append(",'"+planIdlist[i]+"'");
- }
- String sql = " select d.* from wlyy_rehabilitation_plan_detail d " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " where d.plan_id in ("+planCondition+") " +
- " " ;
- if(StringUtils.isNotBlank(executeStartTime)){
- sql += " and d.execute_time>='"+executeStartTime+"' ";
- }
- if(StringUtils.isNotBlank(executeEndTime)){
- sql += " and d.execute_time<='"+executeEndTime+"' ";
- }
- if(searchTask!=null){
- if(searchTask==8){
- sql+=" and d.doctor='"+doctorCode+"' " ;
- }else {
- sql+=" and i.code="+searchTask+" " ;
- }
- }
- if (StringUtils.isNoneBlank(taskExecutor)){
- if(taskExecutor.equals("1")){ //我的任务
- sql+="and d.doctor='"+doctorCode+"' ";
- }
- if(taskExecutor.equals("2")){//他人任务
- sql+="and d.doctor <>'"+doctorCode+"' ";
- }
- }else {
- sql+="and d.doctor='"+doctorCode+"' ";
- }
- if(status!=null){
- sql+= " and d.status="+status;
- }
- sql += " ORDER BY d.execute_time ";
- List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
- // List<RehabilitationDetailDO> rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId);
- Map<String,Map<String,Object>> map = new LinkedHashMap<>();
- for(Map<String,Object> one:rehabilitationDetailList){
- String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD);
- Map<String,Object> m = null;
- if(map.containsKey(executeTime)){
- m = map.get(executeTime);
- Map<String,Integer> family = null;
- Map<String,Integer> specialist = null;
- if(one.get("type")!=null){
- if((Integer)one.get("type")==1){//家庭医生
- if(m.containsKey("family")){
- family = (Map<String,Integer>)m.get("family");
- }else{
- family = new HashMap<>();
- family.put("all",0);
- family.put("finish",0);
- }
- if((Integer)one.get("status")==1){
- family.put("finish",family.get("finish")+1);
- }
- family.put("all",family.get("all")+1);
- m.put("family",family);
- }else if((Integer)one.get("type")==2){//专科医生
- if(m.containsKey("specialist")){
- specialist = (Map<String,Integer>)m.get("specialist");
- }else{
- specialist = new HashMap<>();
- specialist.put("all",0);
- specialist.put("finish",0);
- }
- if((Integer)one.get("status")==1){
- specialist.put("finish",(specialist.get("finish"))+1);
- }
- specialist.put("all",(specialist.get("all"))+1);
- m.put("specialist",specialist);
- }
- }
- }else{
- m = new HashMap<>();
- // m.put("specialist",new HashMap<String,Object>());
- if(one.get("type")!=null){
- if((Integer)one.get("type")==1){//家庭医生
- Map<String,Integer> family = new HashMap<>();
- family.put("all",0);
- family.put("finish",0);
- if((Integer)one.get("status")==1){
- family.put("finish",family.get("finish")+1);
- }
- family.put("all",family.get("all")+1);
- m.put("family",family);
- }else if((Integer)one.get("type")==2){//专科医生
- Map<String,Integer> specialist = new HashMap<>();
- specialist.put("all",0);
- specialist.put("finish",0);
- if((Integer)one.get("status")==1){
- specialist.put("finish",specialist.get("finish")+1);
- }
- specialist.put("all",specialist.get("all")+1);
- m.put("specialist",specialist);
- }
- }
- }
- //myTaskFlag,1:有自己任务,0:没有自己任务
- if(StringUtils.isNotEmpty(doctorCode)){
- if(m.containsKey("myTaskFlag")){
- if((Integer)m.get("myTaskFlag")==0){
- if(doctorCode.equals(one.get("doctor").toString())){
- m.put("myTaskFlag",1);
- }else{
- m.put("myTaskFlag",0);
- }
- }
- }else{
- if(doctorCode.equals(one.get("doctor").toString())){
- m.put("myTaskFlag",1);
- }else{
- m.put("myTaskFlag",0);
- }
- }
- }
- if(m.containsKey("planDetailIds")){
- m.put("planDetailIds",m.get("planDetailIds")+","+one.get("id"));
- }else{
- m.put("planDetailIds",one.get("id")+"");
- }
- map.put(executeTime,m);
- }
- /*List list = new ArrayList();
- for(String key : map.keySet()){
- Map<String,Object> result = map.get(key);
- result.put("executeTime", key);
- list.add(result);
- }*/
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
- }
- /**
- * 日历列表
- * @param planId 计划id
- * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
- * @param status 任务状态(0未完成,1已完成,2已预约)
- * @param doctorCode 登陆医生
- * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
- */
- public ObjEnvelop calendarPlanDetailList(String planId,Integer searchTask,Integer status,String doctorCode,String executeStartTime,String executeEndTime,String taskExecutor){
- String[] planIdlist = planId.split(",");
- StringBuilder planCondition = new StringBuilder();
- planCondition .append("'"+planIdlist[0]+"'");
- for (int i=1;i<planIdlist.length;i++){
- planCondition .append(",'"+planIdlist[i]+"'");
- }
- 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 " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " where d.plan_id in ("+planCondition+" )AND d.execute_time IS NOT NULL " +
- " and d.execute_time <>'' " ;
- if(searchTask!=null){
- if(searchTask==8){//
- sql+="and d.doctor='"+doctorCode+"' ";
- }else {
- sql+=" and i.code="+searchTask+" " ;
- }/*else if(searchTask==5){
- sql+=" and i.reserve=1 " ;
- }*/
- }
- if("1".equals(taskExecutor)){ //我的任务
- sql+="and d.doctor='"+doctorCode+"' ";
- }
- if("2".equals(taskExecutor)){//他人任务
- sql+="and d.doctor <>'"+doctorCode+"' ";
- }
- if (StringUtils.isNoneBlank(executeEndTime)&&StringUtils.isNoneBlank(executeStartTime)){
- sql+="and d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' ";
- }
- if(status!=null){
- sql+= "and d.status="+status;
- }
- sql +=" order by d.execute_time desc ";
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
- List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,rehabilitationDetailList);
- }
- /**
- * 日历列表
- * @param searchTask 快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
- * @param status 任务状态(0未完成,1已完成,2已预约)
- * @param doctorCode 登陆医生
- * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
- */
- public ObjEnvelop calendarPlanDetailListByPatient(String executeStartTime,String executeEndTime,String patient,Integer searchTask,Integer status,String doctorCode,String taskExecutor){
- List<Map<String,Object>> planList = getPatientAllRehabilitationPlan(patient);
- StringBuilder planCondition = new StringBuilder();
- planCondition .append("'"+planList.get(0).get("id").toString()+"'");
- for (int i=1;i<planList.size();i++){
- planCondition .append(",'"+planList.get(0).get("id").toString()+"'");
- }
- 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 " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " where d.plan_id in ("+planCondition+" )AND d.execute_time IS NOT NULL and d.execute_time <>'' " ;
- if(searchTask!=null){
- if(searchTask==8){//
- sql+="and d.doctor='"+doctorCode+"' ";
- }else {
- sql+=" and i.code="+searchTask+" " ;
- }/*else if(searchTask==5){
- sql+=" and i.reserve=1 " ;
- }*/
- }
- if("1".equals(taskExecutor)){ //我的任务
- sql+="and d.doctor='"+doctorCode+"' ";
- }
- if("2".equals(taskExecutor)){//他人任务
- sql+="and d.doctor <>'"+doctorCode+"' ";
- }
- if (StringUtils.isNoneBlank(executeEndTime)&&StringUtils.isNoneBlank(executeStartTime)){
- sql+="and d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' ";
- }
- if(status!=null){
- sql+= "and d.status="+status;
- }
- sql +=" order by d.execute_time desc ";
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
- List<Map<String,Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,rehabilitationDetailList);
- }
- /**
- * 多个康复计划服务项目内容列表
- * @param planDetailIds
- * @return
- * @throws Exception
- */
- public ObjEnvelop serviceItemList(String planDetailIds,String doctorCode) throws Exception{
- String[] s = planDetailIds.split(",");
- String planDetailList = "";
- for(String one:s){
- planDetailList +=",'"+one+"'";
- }
- String planDetailResult = StringUtils.isNotEmpty(planDetailList)?planDetailList.substring(1):"";
- 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," +
- " 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 " +
- " from wlyy_rehabilitation_plan_detail d " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
- " where d.id in ("+planDetailResult+") order BY d.execute_time ASC";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
- List<Map<String,Object>> serviceItemList = jdbcTemplate.queryForList(sql);
- // if(serviceItemList.size()>0){
- // Map<String,Object> serviceItem = serviceItemList.get(0);
- List<Map<String,Object>> resultList = new ArrayList<>();
- for(Map<String,Object> one:serviceItemList){
- Map<String,Object> resultMap = new HashMap<>();
- Integer isMyTask = 0;
- if(StringUtils.isNotEmpty(doctorCode)&&doctorCode.equals(one.get("executeDoctor")+"")){
- isMyTask=1;
- }
- resultMap.put("isMyTask",isMyTask);//0不是自己的任务,1是自己的任务
- // if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
- // executeDoctorList.add(one.get("create_user_name")+"");
- // }
- List<String> executeDoctorList = new ArrayList<>();
- executeDoctorList.add(one.get("executeDoctorName")+"");
- resultMap.put("executeDoctorList",executeDoctorList);//执行医生名称列表
- resultMap.put("executeDoctorCode",one.get("executeDoctor")+"");//执行医生code
- resultMap.put("executeDoctorName",one.get("executeDoctorName")+"");//执行医生code
- resultMap.put("specialistDoctorCode",one.get("createDoctor")+"");//创建人(专科)医生code
- resultMap.put("specialistDoctorName",one.get("createDoctorName")+"");//创建人(专科)医生名字
- resultMap.put("title",one.get("name"));//项目标题
- resultMap.put("planDetaiId",one.get("id"));//计划服务项目id
- resultMap.put("planId",one.get("planId"));//计划id
- resultMap.put("shortExecuteTime",DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.HH_MM));//项目标题
- resultMap.put("content",one.get("content"));//项目内容
- resultMap.put("hospitalName",one.get("hospital_name"));//地点
- resultMap.put("executeTime",one.get("execute_time"));//执行时间
- DecimalFormat df = new DecimalFormat("0.00");
- resultMap.put("expense", one.get("expense")!=null?df.format(((Integer)one.get("expense")*1.00)):0);//收费
- resultMap.put("reserve",null);//是否需要预约(1预约、0不预约)
- resultMap.put("planStatus",one.get("planStatus"));//计划的状态
- Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
- String statusName = "";
- switch (status){
- case 0:{statusName="未完成";break;}
- case 1:{statusName="已完成";break;}
- case 2:{statusName="已预约";break;}
- }
- resultMap.put("statusName",statusName);//状态
- //指导与汇报
- List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
- List<Map<String,Object>> messageMapList = new ArrayList<>();
- for(GuidanceMessageLogDO one2:messageList){
- Map<String,Object> map = new HashMap<>();
- map.put("doctorName",one2.getDoctorName());
- map.put("adminTeamName",one2.getAdminTeamName());
- map.put("content",one2.getContent());
- map.put("contentType",one2.getContentType());
- map.put("createTime",DateUtil.dateToStr(one2.getCreateTime(),"MM-dd HH:mm"));
- messageMapList.add(map);
- }
- /* Integer itemType = (Integer) one.get("itemType");*/
- resultMap.put("messageList",messageMapList);//指导与汇报记录
- resultMap.put("patient",one.get("patient"));
- resultMap.put("itemType",one.get("code"));
- resultMap.put("detaiType",one.get("detaiType"));
- resultMap.put("status",status);//状态
- //是否完成任务
- List<RehabilitationOperateRecordsDO> operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
- Integer operate = 0;
- if(operateList.size()>0){
- operate =1;
- RehabilitationOperateRecordsDO temp = operateList.get(0);
- operate =1;
- Date completeTime = temp.getCompleteTime();
- String completeTimeStr = DateUtil.dateToStr(completeTime,DateUtil.YYYY_MM_DD_HH_MM);
- resultMap.put("completeTime",completeTimeStr);//完成时间
- resultMap.put("operatorDoctorName",temp.getDoctorName());//执行医生名称
- resultMap.put("node",temp.getNode());
- resultMap.put("relationRecordImg",(temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg()))?(new JSONArray(temp.getRelationRecordImg())):null);//json格式
- resultMap.put("relationRecordCode",temp.getRelationRecordCode());
- resultMap.put("completeTimeShort",DateUtil.dateToStr(completeTime,"yyyy/MM/dd"));
- }
- resultMap.put("operate",operate);//是否完成任务(默认0:未完成,1:已完成)
- List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(one.get("patient").toString(),"1",1);
- if(list.size()>0){
- resultMap.put("familyDoctorCode",list.get(0).getDoctor());
- resultMap.put("familyDoctorName",list.get(0).getDoctorName());
- }else{
- resultMap.put("familyDoctorCode","");
- resultMap.put("familyDoctorName","");
- }
- resultList.add(resultMap);
- }
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultList);
- // }
- // return MixEnvelop.getError("没有该服务项详情信息!");
- }
- /**
- * 康复计划服务项目确认页
- * @param planDetailId
- * @return
- * @throws Exception
- *
- */
- public ObjEnvelop serviceItem(String planDetailId,String doctorCode,String recordId) throws Exception{
- 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, " +
- " 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," +
- " 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 "+
- " ,a.appointment_time appointmentTime,a.appointment_doctor appointmentDoctor,a.appointment_doctor_name appointmentDoctorName,d.reservation_type reservationType" +
- " from wlyy_rehabilitation_plan_detail d " +
- " LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id = h.code "+
- " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
- " LEFT JOIN wlyy_plan_detail_appointment a on d.id=.a.rehabilitation_plan_detail_id " +
- " where d.id = '"+planDetailId+"'";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName2(sql);
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
- sql = TransforSqlUtl.wlyy_plan_detail_appointmentAppDoctorName(sql);
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
- System.out.println("sql===="+sql);
- List<Map<String,Object>> serviceItemList = jdbcTemplate.queryForList(sql);
- if (serviceItemList.size()==0){
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,new HashMap<>());
- }
- Map<String,Object> one = serviceItemList.get(0);
- Map<String,Object> resultMap = new HashMap<>();
- List<String> executeDoctorList = new ArrayList<>();
- Integer isMyTask = 0;
- //判断登陆者和执行医生是不是同一个人
- if(StringUtils.isNotEmpty(doctorCode)&&doctorCode.equals(one.get("executeDoctor")+"")){
- isMyTask=1;
- }
- // 协诊预约信息
- resultMap.put("appointmentTime",one.get("appointmentTime"));
- resultMap.put("appointmentDoctor",one.get("appointmentDoctor"));
- resultMap.put("appointmentDoctorName",one.get("appointmentDoctorName"));
- resultMap.put("reservationType",one.get("reservationType"));//复诊类型:1线上,2线下,3远程
- resultMap.put("executeTime",one.get("execute_time"));
- resultMap.put("frequencyCode",one.get("frequencyCode")+"");
- resultMap.put("isMyTask",isMyTask);//0不是自己的任务,1是自己的任务
- // if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
- // executeDoctorList.add(one.get("create_user_name")+"");
- // }
- List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(one.get("executeDoctor").toString());
- if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
- resultMap.put("executeDoctorDept",baseDoctorHospitalDO.get(0).getDeptCode());
- resultMap.put("executeDoctorDeptName",baseDoctorHospitalDO.get(0).getDeptName());
- }
- executeDoctorList.add(one.get("executeDoctorName")+"");//
- resultMap.put("remark",one.get("remark"));//备注
- resultMap.put("executeDoctorList",executeDoctorList);//执行医生名称列表
- resultMap.put("executeDoctorCode",one.get("executeDoctor")+"");//执行医生code
- resultMap.put("executeDoctorName",one.get("executeDoctorName")+"");//执行医生名称
- resultMap.put("specialistDoctorCode",one.get("createDoctor")+"");//创建人(专科)医生code
- resultMap.put("specialistDoctorName",one.get("createDoctorName")+"");//创建人(专科)医生名字
- resultMap.put("title",one.get("title"));//项目标题
- resultMap.put("shortExecuteTime",DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.HH_MM));//项目标题
- resultMap.put("content",one.get("content"));//项目内容
- resultMap.put("hospitalName",one.get("hospital_name"));//地点
- resultMap.put("executeTime",one.get("execute_time"));//执行时间
- DecimalFormat df = new DecimalFormat("0.00");
- resultMap.put("expense",one.get("expense")!=null?df.format(((Integer)one.get("expense")*1.00)):0);//收费
- resultMap.put("reserve",one.get("reserve"));//是否需要预约(1预约、0不预约)
- resultMap.put("planStatus",one.get("planStatus"));//计划的状态
- resultMap.put("relationCode",one.get("relationCode"));//业务关联code
- Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
- String statusName = "";
- switch (status){
- case 0:{statusName="未完成";break;}
- case 1:{statusName="已完成";break;}
- case 2:{statusName="已预约";break;}
- case 3:{statusName="待录入";break;}
- }
- resultMap.put("statusName",statusName);//状态名称
- resultMap.put("status",status);//状态
- resultMap.put("disease",one.get("disease"));
- resultMap.put("diseaseName",one.get("diseaseName"));
- resultMap.put("planTitle",one.get("planTitle"));
- resultMap.put("planId",one.get("planId"));
- //指导与汇报
- List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
- List<Map<String,Object>> messageMapList = new ArrayList<>();
- for(GuidanceMessageLogDO one2:messageList){
- Map<String,Object> map = new HashMap<>();
- map.put("doctorName",one2.getDoctorName());
- map.put("adminTeamName",one2.getAdminTeamName());
- map.put("content",one2.getContent());
- map.put("contentType",one2.getContentType());
- map.put("doctorType",one2.getDoctorType());//医生类型
- map.put("createTime",DateUtil.dateToStr(one2.getCreateTime(),"MM-dd HH:mm"));
- messageMapList.add(map);
- }
- resultMap.put("messageList",messageMapList);//指导与汇报记录
- resultMap.put("patient",one.get("patient"));
- resultMap.put("patientName",one.get("patientName"));
- resultMap.put("type",one.get("itemType"));//1扫码、0上传附件、2、健康教育,3、健康指导,4、随访
- //是否完成任务
- List<RehabilitationOperateRecordsDO> operateList = new ArrayList<>();
- if(StringUtils.isNoneBlank(recordId)){
- operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailIdAndId(one.get("id").toString(),recordId);
- }else {
- operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
- }
- Integer operate = 0;
- if(operateList.size()>0){
- RehabilitationOperateRecordsDO temp = operateList.get(0);
- operate =1;
- Date completeTime = temp.getCompleteTime();
- String completeTimeStr = DateUtil.dateToStr(completeTime,DateUtil.YYYY_MM_DD_HH_MM);
- resultMap.put("completeTime",completeTimeStr);//完成时间
- resultMap.put("operatorDoctorName",temp.getDoctorName());//执行医生名称
- resultMap.put("node",temp.getNode());
- resultMap.put("recordStatus",temp.getStatus());//操作记录
- resultMap.put("recordRelationCode",temp.getRelationCode());
- resultMap.put("recordFlag",temp.getFlag());
- resultMap.put("recordId",temp.getId());
- JSONArray imgs = new JSONArray();
- if (temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg())){
- resultMap.put("relationRecordImg",(temp.getRelationRecordImg()!=null&&StringUtils.isNotEmpty(temp.getRelationRecordImg()))?(new JSONArray(temp.getRelationRecordImg())):null);//json格式
- }
- else{
- resultMap.put("relationRecordImg",imgs);
- }
- /* if(itemType!=1&&itemType!=0){*/
- resultMap.put("relationRecordCode",temp.getRelationRecordCode());
- resultMap.put("completeTimeShort",DateUtil.dateToStr(completeTime,"yyyy/MM/dd"));
- /* }*/
- }
- List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(one.get("patient").toString(),"1",1);
- if(list.size()>0){
- resultMap.put("familyDoctorCode",list.get(0).getDoctor());
- resultMap.put("familyDoctorName",list.get(0).getDoctorName());
- }else{
- resultMap.put("familyDoctorCode","");
- resultMap.put("familyDoctorName","");
- }
- resultMap.put("operate",operate);//是否完成任务(默认0:未完成,1:已完成)
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
- }
- /**
- * 康复管理居民详情页
- * @param patientCode
- * @return
- */
- public ObjEnvelop patientRehabilitationDetail(String patientCode){
- Map<String,Object> resultMap = new HashMap<>();
- String healthDoctor = null;
- String healthDoctorName =null;
- String generalDoctor = null;
- String generalDoctorName = null;
- Integer age = null;
- String sex = null;
- String signHospitalName = null;
- org.json.JSONObject json = new org.json.JSONObject();
- String healthyConditionSql =" select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='"+patientCode+"' and label_type=8";
- List<Map<String,Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
- String healthyCondition = healthyConditionList.size()>0?healthyConditionList.get(0).get("label_name")+"":"";
- String healthyConditionType = healthyConditionList.size()>0?healthyConditionList.get(0).get("label")+"":"";
- BasePatientDO patient = basePatientDao.findById(patientCode);
- //个人基础信息(康复机构)
- 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 " +
- " where p.patient='"+patientCode+"' and p.status=1 ";
- List<Map<String,Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
- Map<String,Object> patientInfo = new HashMap<>();
- String rehabilitationOrg = "";
- for(Map<String,Object> one:patientInfoList){
- rehabilitationOrg+=","+one.get("hospital_name");
- }
- patientInfo.put("rehabilitationOrg",StringUtils.isNotEmpty(rehabilitationOrg)?rehabilitationOrg.substring(1):"");
- resultMap.put("patientInfo",patientInfo);
- //服务医生
- //完成项目=全部的服务项目-未完成的服务项目
- List<Map<String,Object>> serviceDoctorList = new ArrayList<>();
- //全科医生和健管师要是同一个人,就显示全科医生
- /* if(!generalDoctor.equals(healthDoctor)){
- */
- if(StringUtils.isNotEmpty(healthDoctor)){
- Map<String,Object> healthDoctorMap = new HashMap<>();
- healthDoctorMap.put("type","健管师");
- healthDoctorMap.put("doctorName",healthDoctorName);
- healthDoctorMap.put("doctorCode",healthDoctor);
- Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor,patientCode,1);
- Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor,patientCode);
- Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor,patientCode,1);
- healthDoctorMap.put("finishedItem",healthFinishCount-healthUnfinishCount);
- healthDoctorMap.put("serviceCount",healthServiceCount);
- serviceDoctorList.add(healthDoctorMap);
- }
- /* }*/
- if(StringUtils.isNotEmpty(generalDoctor)){
- Map<String,Object> generalDoctorMap = new HashMap<>();
- generalDoctorMap.put("type","全科医生");
- generalDoctorMap.put("doctorName",generalDoctorName);
- generalDoctorMap.put("doctorCode",generalDoctor);
- Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor,patientCode,1);
- Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor,patientCode);
- Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor,patientCode,1);
- generalDoctorMap.put("finishedItem",generalFinishCount-generalUnfinishCount);
- generalDoctorMap.put("serviceCount",generalServiceCount);
- serviceDoctorList.add(generalDoctorMap);
- }
- 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+"'";
- specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
- List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
- BaseDoctorDO baseDoctorDO = null;
- for(Map<String,Object> one:specialistRelationList){
- String doctor = one.get("doctor")+"";
- String doctorName = one.get("doctor_name")+"";
- Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor,patientCode,1);
- Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor,patientCode);
- Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor,patientCode,1);
- Map<String,Object> map = new HashMap<>();
- map.put("finishedItem",finishCount-unfinishCount);
- map.put("serviceCount",serviceCount);
- map.put("doctorName",doctorName);
- map.put("doctorCode",doctor);
- map.put("type","专科医生");
- serviceDoctorList.add(map);
- }
- for (Map<String,Object> d:serviceDoctorList){
- BaseDoctorDO baseDoctorDO1 = baseDoctorDao.findById(d.get("doctorCode").toString());
- d.put("doctorPhoto",baseDoctorDO1!=null?baseDoctorDO1.getPhoto():"");
- }
- resultMap.put("serviceDoctorList",serviceDoctorList);
- //康复计划
- List<Map<String,Object>> planList = new ArrayList<>();
- List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patientCode);
- Integer planUnderway = 0;//进行中
- Integer planFinish = 0;//已完成
- for(PatientRehabilitationPlanDO one:list){
- if(one.getStatus()==1){
- planUnderway+=1;
- }else if(one.getStatus()==2){
- planFinish+=1;
- }
- Map<String,Object> map = new HashMap<>();
- //安排类型
- String planTypeName = null;
- Integer planTypeTemp = one.getPlanType();
- switch (planTypeTemp){
- case 1:planTypeName="康复计划" ;break;
- case 2:planTypeName="(转)社区医院" ;break;
- case 3:planTypeName="(转)转家庭病床" ;break;
- }
- map.put("createUser",one.getCreateUser());
- map.put("createUserName",one.getCreateUserName());
- map.put("planId",one.getId());
- map.put("planTypeName",planTypeName);
- String statusName = "";
- Integer status = one.getStatus();
- switch (status){
- case 0:{statusName="已中止";break;}
- case 1:{statusName="进行中";break;}
- case 2:{statusName="已完成";break;}
- }
- map.put("planTypeName",planTypeName);//安排类型名称
- map.put("statusName",statusName);//状态名称
- map.put("medicalRecordsCode",one.getMedicalRecordsCode());//住院code
- map.put("adviceContent",one.getAdviceContent());//康复建议
- //已完成
- Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,one.getId());
- map.put("allFinishCount",allFinishCount);//已完成
- //完成度(已完成/(已完成+未完成))
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
- map.put("allCount",allCount);//总数
- List<RehabilitationDetailDO> detailList = rehabilitationDetailDao.getAllRehabilitationDetail(one.getId());
- if(detailList.size()>0){
- Date executeTimeStart = detailList.get(0).getExecuteTime();
- Date executeTimeEnd = detailList.get(detailList.size()-1).getExecuteTime();
- String executeStart = DateUtil.dateToStr(executeTimeStart,"yyyy/MM/dd");
- String executeEnd = DateUtil.dateToStr(executeTimeEnd,"yyyy/MM/dd");
- map.put("time",executeStart+"-"+executeEnd);
- }else{
- map.put("time","");
- }
- planList.add(map);
- }
- resultMap.put("planList",planList);
- //康复计划-已完成、进行中
- resultMap.put("planUnderway",planUnderway);//进行中
- resultMap.put("planFinish",planFinish);//已完成
- resultMap.put("healthyCondition",healthyCondition);
- resultMap.put("healthyConditionType",healthyConditionType);
- resultMap.put("signHospitalName",signHospitalName);
- age = IdCardUtil.getAgeForIdcard(patient.getIdcard());
- sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
- resultMap.put("patientCode", patientCode);
- resultMap.put("patientName", patient.getName());
- resultMap.put("age",age);
- resultMap.put("sex",sex);
- resultMap.put("photo",patient.getPhoto());
- resultMap.put("mobile",patient.getMobile());
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
- }
- /**
- * 居民康复计划详情页-近期康复相关记录
- * @param patientCode
- * @param startTime
- * @param endTime
- */
- public ObjEnvelop recentPlanDetailRecord(String patientCode,String startTime,String endTime,Integer page, Integer pageSize) throws Exception{
- Map<String,Object> resultMap = new HashMap<>();
- //近期康复相关记录
- // String currentTime = DateUtil.getStringDate();
- 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 " +
- " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id" +
- " left join wlyy_rehabilitation_operate_records s on s.rehabilitation_detail_id=d.id " +
- " where d.status=1 and p.patient='"+patientCode+"' and d.frequency_code IS NOT NULL AND d.frequency_code <>'' ";
- if(StringUtils.isNotEmpty(startTime)){
- planDetailSql += " and d.execute_Time>='"+startTime+"' ";
- }
- if(StringUtils.isNotEmpty(endTime)){
- planDetailSql += " and d.execute_time<='"+endTime+"' ";
- }
- planDetailSql += " ORDER BY s.complete_time DESC LIMIT "+(page-1)*pageSize+","+pageSize;
- planDetailSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(planDetailSql);
- List<Map<String,Object>> planDetails = jdbcTemplate.queryForList(planDetailSql);
- List<Map<String,Object>> planDetailList = new ArrayList<>();
- for(Map<String,Object> one:planDetails){
- Date executeTimeDate = (Date)one.get("complete_time");
- String executeTime = DateUtil.dateToStr(executeTimeDate,"yyyy/MM/dd HH:mm");
- String content = one.get("code")+"";
- String title = one.get("name")+"";
- Integer status = (Integer)one.get("status");
- String statusName = "";
- switch (status){
- case 0:{statusName="未完成";break;}
- case 1:{statusName="已完成";break;}
- case 2:{statusName="已预约";break;}
- }
- String id = one.get("id").toString();
- Map<String,Object> map = new HashMap<>();
- map.put("id",id);//id
- // List<RehabilitationOperateRecordsDO> rehabilitationOperateRecords = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(id);
- // Date completeTime = rehabilitationOperateRecords!=null&&rehabilitationOperateRecords.size()>0?rehabilitationOperateRecords.get(0).getCompleteTime():null;
- // String completeTimeStr = completeTime!=null?DateUtil.dateToStr(completeTime,"yyyy/MM/dd HH:mm"):"";
- map.put("executeTime",executeTime);//执行时间
- map.put("title",title);//项目标题
- map.put("content",content);//项目内容
- map.put("statusName",statusName);//状态名称
- planDetailList.add(map);
- }
- resultMap.put("planDetailList",planDetailList);//康复相关记录列表
- 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" +
- " LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where p.patient='"+patientCode+"' ";
- List<Map<String,Object>> planDetailList2 = jdbcTemplate.queryForList(planDetailCountSql);
- Integer planDetailFinish = 0;
- Integer planDetailUnfinish = 0;
- for(Map<String,Object> one:planDetailList2){
- Integer status = (Integer)one.get("num");
- if(status==1){
- planDetailFinish+=1;
- }else{
- planDetailUnfinish+=1;
- }
- }
- resultMap.put("planDetailFinish",planDetailFinish);//已完成
- resultMap.put("planDetailUnfinish",planDetailUnfinish);//未完成
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
- }
- /**
- * 保存康复管理指导留言信息
- * @param messageId
- * @param doctor
- */
- @Transactional
- public Envelop saveGuidanceMessage(String messageId,String doctor,String content,String planDetailId,Integer contentType) throws Exception{
- BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
- Integer doctorType =null;
- if (doctorDO!=null){
- List<BaseDoctorRoleDO> baseDoctorRoleDO = baseDoctorRoleDao.findByDoctorCode(doctor);
- if (baseDoctorRoleDO!=null){
- for (BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){
- if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){
- doctorType=1;
- break;
- }else {
- doctorType=2;
- }
- }
- }
- }
- List<String> patientList = rehabilitationDetailDao.findPatientById(planDetailId);
- String patient = patientList.size()>0?patientList.get(0):"";
- GuidanceMessageLogDO guidanceMessageLogDO = new GuidanceMessageLogDO();
- guidanceMessageLogDO.setMessageId(messageId);
- guidanceMessageLogDO.setPlanDetailId(planDetailId);
- guidanceMessageLogDO.setContent(content);
- guidanceMessageLogDO.setDoctor(doctor);
- guidanceMessageLogDO.setContentType(contentType);
- guidanceMessageLogDO.setDoctorType(doctorType);
- Integer adminTeamCode = null;
- String doctorName = null;
- if(doctorType==1){
- List<DoctorPatientRelationDO> specialistPatientRelationDO = doctorPatientRelationDao.findByDoctorAndPatient(doctor,patient);
- if (specialistPatientRelationDO!=null&&specialistPatientRelationDO.size()>0){
- //adminTeamCode = specialistPatientRelationDO.get(0).getTeamCode();
- doctorName = specialistPatientRelationDO.get(0).getDoctorName();
- }
- }else if(doctorType==2){
- String signFamilySql = " select f.* from wlyy_sign_family f where f.status=1 and f.expenses_status='1' and f.patient='"+patient+"'";
- List<Map<String,Object>> signFamily = jdbcTemplate.queryForList(signFamilySql);
- adminTeamCode = (Integer)signFamily.get(0).get("admin_team_code");
- doctorName = signFamily.get(0).get("doctor_name").toString();
- }
- /* String adminTeamSql = " select t.* from base_team t where t.del='1' and t.id="+adminTeamCode;
- List<Map<String,Object>> adminTeam = jdbcTemplate.queryForList(adminTeamSql);*/
- String adminTeamName = "";
- guidanceMessageLogDO.setAdminTeamCode(adminTeamCode);
- guidanceMessageLogDO.setAdminTeamName(adminTeamName);
- guidanceMessageLogDO.setDoctorName(doctorName);
- guidanceMessageLogDO.setCreateTime(new Date());
- guidanceMessageLogDO.setUpdateTime(new Date());
- guidanceMessageLogDao.save(guidanceMessageLogDO);
- return Envelop.getSuccess(SpecialistMapping.api_success);
- }
- /**
- * 康复管理-更新康复计划操作完成日志状态
- * @param planDetailId
- * @param status
- * @throws Exception
- */
- @Transactional
- public Envelop updateStatusRehabilitationOperate(Integer status,String planDetailId){
- if(rehabilitationOperateRecordsDao.updateStatus(status,planDetailId)>0){
- return Envelop.getSuccess(SpecialistMapping.api_success);
- }
- return Envelop.getError("更新失败!");
- }
- /**
- * app端居民详情服务医生列表
- * @param patientCode
- * @return
- */
- public ObjEnvelop serviceDoctorList(String patientCode){
- List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(patientCode,"1",1);
- String healthDoctor = null;
- String healthDoctorName =null;
- String generalDoctor = null;
- String generalDoctorName = null;
- if(list!=null&&list.size()>0){
- SignFamily signFamily = list.get(0);
- healthDoctor = signFamily.getDoctorHealth();
- healthDoctorName = signFamily.getDoctorHealthName();
- generalDoctor = signFamily.getDoctor();
- generalDoctorName = signFamily.getDoctorName();
- }
- //服务医生
- //完成项目=全部的服务项目-未完成的服务项目
- List<Map<String,Object>> serviceDoctorList = new ArrayList<>();
- if(StringUtils.isNotEmpty(generalDoctor)){
- Map<String,Object> generalDoctorMap = new HashMap<>();
- generalDoctorMap.put("type","全科医生");
- generalDoctorMap.put("doctorName",generalDoctorName);
- generalDoctorMap.put("doctorCode",generalDoctor);
- Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor,patientCode,1);
- Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor,patientCode);
- Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor,patientCode,1);
- generalDoctorMap.put("finishedItem",generalFinishCount-generalUnfinishCount);
- generalDoctorMap.put("serviceCount",generalServiceCount);
- serviceDoctorList.add(generalDoctorMap);
- }
- if(StringUtils.isNotEmpty(healthDoctor)){
- Map<String,Object> healthDoctorMap = new HashMap<>();
- healthDoctorMap.put("type","健管师");
- healthDoctorMap.put("doctorName",healthDoctorName);
- healthDoctorMap.put("doctorCode",healthDoctor);
- Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor,patientCode,1);
- Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor,patientCode);
- Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor,patientCode,1);
- healthDoctorMap.put("finishedItem",healthFinishCount-healthUnfinishCount);
- healthDoctorMap.put("serviceCount",healthServiceCount);
- serviceDoctorList.add(healthDoctorMap);
- }
- 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+"'";
- specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
- List<Map<String,Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
- for(Map<String,Object> one:specialistRelationList){
- String doctor = one.get("doctor")+"";
- String doctorName = one.get("doctor_name")+"";
- Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor,patientCode,1);
- Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor,patientCode);
- Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor,patientCode,1);
- Map<String,Object> map = new HashMap<>();
- map.put("finishedItem",finishCount-unfinishCount);
- map.put("serviceCount",serviceCount);
- map.put("doctorName",doctorName);
- map.put("doctorCode",doctor);
- map.put("type","专科医生");
- serviceDoctorList.add(map);
- }
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,serviceDoctorList);
- }
- /**
- * app端、微信端计划的服务项目列表
- * @param planId
- * @param searchTask
- * @param status
- * @param executeStartTime
- * @param executeEndTime
- * @return
- */
- public ObjEnvelop appCalendarPlanDetailList(String planId,Integer searchTask,Integer status,String executeStartTime,String executeEndTime){
- Map<String,Object> resultMap = new HashMap<>();
- ObjEnvelop objEnvelop = calendarPlanDetailList(planId,searchTask,status,null,executeStartTime,executeEndTime,"0");
- Integer finishCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId);
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);
- resultMap.put("planDetailList",objEnvelop.getObj());
- resultMap.put("finishCount",finishCount);
- resultMap.put("allCount",allCount);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
- }
- /**
- * 每日康复服务通知
- * @param startTime
- * @param endTime
- * @return
- */
- public JSONArray dailyJob(String startTime,String endTime){
- 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";
- // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- String doctorCode = "";
- String patientCode = "";
- List<String> listMap = null;
- for(Map<String,Object> one:list){
- doctorCode = one.get("doctor")+"";
- patientCode = one.get("patient")+"";
- listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
- String ids = "";
- for(String one2 : listMap){
- ids += ","+one2;
- }
- one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
- }
- return new JSONArray(list);
- }
- /**
- * 明日康复计划提醒
- *
- * @param startTime
- * @param endTime
- * @return
- */
- public JSONArray tomorrowJob(String startTime,String endTime){
- 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";
- // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- String doctorCode = "";
- String patientCode = "";
- List<String> listMap = null;
- for(Map<String,Object> one:list){
- doctorCode = one.get("doctor")+"";
- patientCode = one.get("patient")+"";
- listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
- String ids = "";
- for(String one2 : listMap){
- ids += ","+one2;
- }
- one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
- }
- return new JSONArray(list);
- }
- /**
- * 每日康复计划提醒
- *
- * @param startTime
- * @param endTime
- * @return
- */
- public JSONArray dailyByJob(String startTime,String endTime){
- 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";
- // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- String doctorCode = "";
- String patientCode = "";
- List<String> listMap = null;
- for(Map<String,Object> one:list){
- doctorCode = one.get("doctor")+"";
- patientCode = one.get("patient")+"";
- listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
- String ids = "";
- for(String one2 : listMap){
- ids += ","+one2;
- }
- one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
- }
- return new JSONArray(list);
- }
- /**
- * 更新康复计划项目操作日志并且确认完成更新status.
- * @param node
- * @param image
- * @param planDeatilId
- * @return
- */
- public Map<String,Object> updateNodeAndRelationRecordImg(String node,String image,String status,String planDeatilId,String relationCode,String recordId)throws Exception{
- Map<String,Object> resultMap = new HashedMap();
- try{
- if (!StringUtils.isNoneBlank(recordId)){
- RehabilitationDetailDO detailDO = rehabilitationDetailDao.findById(planDeatilId);
- detailDO.setStatus(1);
- if (StringUtils.isNoneBlank(status)){
- detailDO.setStatus(Integer.parseInt(status));
- }
- detailDO.setUpdateTime(new Date());
- if (StringUtils.isNoneBlank(relationCode)){
- detailDO.setRelationCode(relationCode);
- }
- rehabilitationDetailDao.save(detailDO);
- if (StringUtils.isNoneBlank(image)&&StringUtils.isNoneBlank(node)){
- int j = rehabilitationOperateRecordsDao.updateNodeAndRelationRecordImg(node,image,planDeatilId);
- }
- else if (StringUtils.isNoneBlank(node)){
- int j = rehabilitationOperateRecordsDao.updateNodeByPlanDetailId(node,planDeatilId);
- }
- else if (StringUtils.isNoneBlank(image)){//
- int j = rehabilitationOperateRecordsDao.updateImagByPlanDetailId(image,planDeatilId);
- }
- else{//跟新为已完成
- int j = rehabilitationOperateRecordsDao.updateStatus(1,planDeatilId);
- }
- //如果整个计划的服务项都完成了,整个计划也完成了
- String allSql ="SELECT * FROM wlyy_rehabilitation_plan_detail where plan_id = (SELECT plan_id FROM `wlyy_rehabilitation_plan_detail` WHERE id='"+planDeatilId+"')";
- allSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(allSql);
- List<RehabilitationDetailDO> rehabilitationDetailDOList = jdbcTemplate.query(allSql,new BeanPropertyRowMapper<>(RehabilitationDetailDO.class));
- int allCount=0;
- String planId="";
- for (RehabilitationDetailDO rehabilitationDetailDO : rehabilitationDetailDOList){
- if (rehabilitationDetailDO.getStatus()==1){
- allCount++;
- }
- }
- if (rehabilitationDetailDOList.size()>0 && rehabilitationDetailDOList.size()==allCount){
- planId = rehabilitationDetailDOList.get(0).getPlanId();
- patientRehabilitationPlanDao.updateStatusAndTimeById(2,planId, new Date());
- }
- }else {
- if (StringUtils.isNoneBlank(image)&&StringUtils.isNoneBlank(node)){
- int j = rehabilitationOperateRecordsDao.updateNodeAndRelationRecordImgById(node,image,recordId);
- }
- else if (StringUtils.isNoneBlank(node)){
- int j = rehabilitationOperateRecordsDao.updateNodeByPlanDetailIdById(node,recordId);
- }
- else if (StringUtils.isNoneBlank(image)){//
- int j = rehabilitationOperateRecordsDao.updateImagByPlanDetailIdById(image,recordId);
- }
- else{//跟新为已完成
- int j = rehabilitationOperateRecordsDao.updateStatusById(1,recordId);
- }
- }
- }catch (Exception e){
- throw new Exception("更新服务状态失败!");
- }
- //更新返回数据提供发送消息使用
- String sql ="SELECT" +
- " i.id as \"id\"," +
- " r.doctor_code," +
- " r.patient_code," +
- " pd.hospital" +
- " FROM" +
- " wlyy_rehabilitation_plan_detail pd" +
- " LEFT JOIN wlyy_rehabilitation_service_item i ON pd.hospital_service_item_id = i.id" +
- " LEFT JOIN wlyy_rehabilitation_operate_records r ON pd.id = r.rehabilitation_detail_id" +
- " WHERE" +
- " pd.id = '"+planDeatilId+"'";
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- if (list!=null && list.size()>0){
- resultMap = list.get(0);
- }
- String itemSql ="SELECT evaluation,title FROM `wlyy_service_item` WHERE id='"+String.valueOf(resultMap.get("id"))+"'";
- List<Map<String,Object>> itemList = jdbcTemplate.queryForList(itemSql);
- if (itemList!=null && itemList.size()>0){
- resultMap.put("evaluation",itemList.get(0).get("evaluation"));
- resultMap.put("title",itemList.get(0).get("title"));
- }
- //保存wlyy_message
- List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(resultMap.get("doctor_code").toString());
- String hospotal = "";
- String patient = resultMap.get("patient_code").toString();
- String doctor = resultMap.get("doctor_code").toString();
- if (depts!=null&&depts.size()>0){
- hospotal=depts.get(0).getOrgCode();
- }
- SystemMessageDO message = new SystemMessageDO();
- message.setType("21");
- message.setSender(patient);
- message.setReceiver(doctor);
- message.setRelationCode(planDeatilId);
- specialistEvaluateSevice.sendMessage(message,hospotal,patient,null,null);
- //发送微信模板消息
- int evaluation = resultMap.get("evaluation")==null?0:Integer.parseInt(resultMap.get("evaluation").toString());
- if (evaluation == 1){
- String serviceItemId = resultMap.get("service_item_id").toString();
- String title = resultMap.get("title").toString();
- BasePatientDO p = basePatientDao.findById(patient);
- BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
- String patientName = p.getName();
- String openId = p.getOpenid();
- /*WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_service","fwxmpj");
- String first = templateConfig.getFirst();
- first = first.replace("key1",(patientName==null?"":patientName));
- String keyword1 = templateConfig.getKeyword1();
- org.json.JSONObject json = new org.json.JSONObject();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- json.put("keyword1", title);
- json.put("keyword2",doctor1.getName());
- json.put("keyword3", sdf.format(new Date()));
- json.put("toUser", p.getCode());
- json.put("represented",p.getCode());//被代理人
- json.put("remark", "");
- json.put("doctor",doctor);
- json.put("planIds", planDetailId);
- first = first.replace("key2",title);
- json.put("first", first);
- if(StringUtils.isNotBlank(p.getOpenid())){
- pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 25, openId, p.getName(), json);
- }else {
- //发送代理人
- JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
- if (jsonArray != null && jsonArray.length() > 0) {
- for (int i = 0; i < jsonArray.length(); i++) {
- org.json.JSONObject j = jsonArray.getJSONObject(i);
- Patient member = (Patient) j.get("member");
- org.json.JSONObject data = json;
- data.remove("toUser");
- data.put("toUser", member.getCode());
- data.remove("first");
- data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
- pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 25, member.getOpenid(), p.getName(), data);
- }
- }
- }*/
- }
- return resultMap;
- }
- /**
- * 电话关怀拨打电话后生成对应记录
- * @param jsonStr
- */
- public RehabilitationOperateRecordsDO planDetailAfterCall(String jsonStr){
- JSONObject jsonObject = JSON.parseObject(jsonStr);
- /*{
- "rehabilitationDetailId":"808080eb764ba46b017669712c640012",
- "doctorCode":"7e06886207e843948ae65d8f91d6ca97",
- "doctorName":"兰冠勇"
- }*/
- RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(jsonObject.getString("rehabilitationDetailId"));
- PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(rehabilitationDetailDO.getPlanId());
- RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO = new RehabilitationOperateRecordsDO();
- rehabilitationOperateRecordsDO.setId(getCode());
- if (rehabilitationDetailDO.getExecuteTime()!=null){
- rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
- }
- rehabilitationOperateRecordsDO.setStatus(3);
- rehabilitationOperateRecordsDO.setRelationRecordImg("[]");
- rehabilitationOperateRecordsDO.setRehabilitationDetailId(rehabilitationDetailDO.getId());
- rehabilitationOperateRecordsDO.setPatientCode(patientRehabilitationPlanDO.getPatient());
- rehabilitationOperateRecordsDO.setPatientName(patientRehabilitationPlanDO.getName());
- rehabilitationOperateRecordsDO.setDoctorCode(jsonObject.getString("doctorCode"));
- rehabilitationOperateRecordsDO.setDoctorName(rehabilitationDetailDO.getDoctorName());
- rehabilitationOperateRecordsDO.setRelationRecordType(5);
- rehabilitationOperateRecordsDO.setCompleteTime(new Date());
- rehabilitationOperateRecordsDO.setCreateTime(new Date());
- rehabilitationOperateRecordsDO.setUpdateTime(new Date());
- if (StringUtils.isNoneBlank(rehabilitationDetailDO.getFrequencyCode())){//限定频次的
- rehabilitationDetailDO.setStatus(3);
- rehabilitationDetailDao.save(rehabilitationDetailDO);
- // rehabilitationOperateRecordsDO.setRelationRecordType(8);
- }
- return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
- }
- /**
- * 更新康复计划项目状态
- * @param status
- * @param planDetailId
- * @return
- */
- public Envelop updatePlanDetailStatusById(Integer status,String planDetailId) throws Exception{
- if(rehabilitationDetailDao.updateStatusById(status,planDetailId)>0){
- return Envelop.getSuccess(SpecialistMapping.api_success);
- }
- return Envelop.getError("更新失败!");
- }
- public Envelop updatePlanDetailExecuteTimeById(Date executeTime,String planDetailId) throws Exception{
- if(rehabilitationDetailDao.updateExecuteTime(executeTime,planDetailId)>0){
- return Envelop.getSuccess(SpecialistMapping.api_success);
- }
- return Envelop.getError("更新失败!");
- }
- /**
- * 计划总进度
- * @return
- */
- public ObjEnvelop planSchedule(String planId,String patientCode){
- Map<String,Object> resultMap = new HashMap<>();
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
- Integer finishedCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId);
- PatientRehabilitationPlanDO p =patientRehabilitationPlanDao.findById(planId);
- List<DoctorPatientRelationDO> doctorPatientRelationDO= doctorPatientRelationDao.findByDoctorAndPatient(p.getCreateUser(),p.getPatient());
- List<RehabilitationDetailDO> details=rehabilitationDetailDao.findByPlanId(planId);
- List<WlyyHospitalSysDictDO> dicts=wlyyHospitalSysDictDao.findByDictName("healthCondition");
- String doctor="";
- String doctorName="";
- List<Map<String,Object>> doctorMaps=new ArrayList<>();
- if (details!=null&&details.size()>0){
- for (RehabilitationDetailDO rehabilitationDetailDO:details){
- Map<String,Object> doctorMap = new HashMap<>();
- doctor=rehabilitationDetailDO.getDoctor();
- doctorName=rehabilitationDetailDO.getDoctorName();
- List<BaseDoctorHospitalDO> baseDoctorHospitalDOTo = baseDoctorHospitalDao.findByDoctorCode(doctor);
- BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor);
- if (baseDoctorDO!=null){
- doctorMap.put("photo",baseDoctorDO.getPhoto());
- doctorMap.put("jobTitle",baseDoctorDO.getJobTitleName());
- }
- if (baseDoctorHospitalDOTo!=null&&baseDoctorHospitalDOTo.size()>0){
- doctorMap.put("doctorName",doctorName);
- doctorMap.put("doctor",doctor);
- doctorMap.put("doctorDept",baseDoctorHospitalDOTo.get(0).getDeptCode());
- doctorMap.put("doctorDeptName",baseDoctorHospitalDOTo.get(0).getDeptName());
- }
- doctorMaps.add(doctorMap);
- }
- }
- resultMap.put("doctorMaps",doctorMaps);
- resultMap.put("allCount",allCount);
- resultMap.put("finishedCount",finishedCount);
- resultMap.put("specialistPatientRelationDO",doctorPatientRelationDO);
- if (p!=null){
- resultMap.put("disease",p.getDisease());
- resultMap.put("planType",p.getPlanType());
- resultMap.put("healthStatusCode",p.getHealthStatusCode());
- for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:dicts){
- if (p.getHealthStatusCode().equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
- resultMap.put("healthStatusName",wlyyHospitalSysDictDO.getDictValue());
- break;
- }
- }
- resultMap.put("diseaseName",p.getDiseaseName());
- resultMap.put("createUser",p.getCreateUser());
- resultMap.put("planTitle",p.getTitle());
- resultMap.put("status", p.getStatus());
- resultMap.put("isVerify", p.getIsVerify());
- resultMap.put("patientImg", p.getPatientImg());
- resultMap.put("adviceContent",p.getAdviceContent());
- resultMap.put("createTimeDate",DateUtil.dateToStr(p.getCreateTime(),"yyyy-MM-dd"));
- resultMap.put("createTime", DateUtil.dateToStr(p.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
- resultMap.put("medicalRecordsCode",p.getMedicalRecordsCode());
- List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(p.getCreateUser());
- if (baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
- resultMap.put("createUserName",p.getCreateUserName());
- resultMap.put("createUserDept",baseDoctorHospitalDO.get(0).getDeptCode());
- resultMap.put("createUserDeptName",baseDoctorHospitalDO.get(0).getDeptName());
- }
- PatientMedicalRecordsDO patientMedicalRecordsDO = patientMedicalRecordsDao.findByCode(p.getMedicalRecordsCode());
- resultMap.put("patientMedicalRecordsDO",patientMedicalRecordsDO);
- }
- Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"00:00:00");
- Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort()+ " "+"23:59:59");
- Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(planId,beginTime,endTime);
- resultMap.put("todayBacklogCount",todayBacklogCount);//今日待办总数
- BasePatientDO basePatientDO = basePatientDao.findById(patientCode);
- Integer age = IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard());
- String sex = IdCardUtil.getSexForIdcard_new(basePatientDO.getIdcard());
- resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
- resultMap.put("age",age);
- resultMap.put("patientPhoto",basePatientDO.getPhoto());
- resultMap.put("patientName",basePatientDO.getName());
- resultMap.put("patientCode",basePatientDO.getId());
- resultMap.put("idcard",basePatientDO.getIdcard());
- // resultMap.put("healthyCondition",healthyCondition);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,resultMap);
- }
- /**
- * 根据居民获取康复计划
- * @param patient
- * @return
- */
- public ObjEnvelop planListByPatient(String patient){
- List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patient);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,list);
- }
- /**
- * 医生已计划数,已完成计划数(居民数)
- * @param doctorCode
- * @return
- */
- public ObjEnvelop patientCount(String doctorCode){
- Integer count =patientRehabilitationPlanDao.patientCount(doctorCode);
- Integer finishCount = patientRehabilitationPlanDao.getFinishPatientCount(doctorCode);
- Map<String,Object> map = new HashMap<>();
- map.put("planCount",count);
- map.put("finishedPlanCount",finishCount);
- return ObjEnvelop.getSuccess(SpecialistMapping.api_success,map);
- }
- public JSONArray dailyJobReserve1(String startTime, String endTime){
- 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 " +
- " left join wlyy_hospital_service_item h on d.hospital_service_item_id=h.id " +
- " left join wlyy_service_item i on i.id =h.service_item_id "+
- " 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 ";
- // List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- String doctorCode = "";
- String patientCode = "";
- // List<String> listMap = null;
- for(Map<String,Object> one:list){
- doctorCode = one.get("doctor")+"";
- patientCode = one.get("patient")+"";
- String sql2 ="select d.id 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 d.hospital_service_item_id=h.id " +
- " left join wlyy_service_item i on i.id =h.service_item_id "+
- " 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+"'";
- List<Map<String,Object>> list2 = jdbcTemplate.queryForList(sql2);
- // listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
- String ids = "";
- for(Map<String,Object> one2 : list2){
- ids += ","+one2.get("id");
- }
- one.put("planDetailIds",StringUtils.isNotEmpty(ids)?ids.substring(1):"");
- }
- return new JSONArray(JSON.toJSONString(list));
- }
- /**
- * 根据ids获取数据
- *
- * @param ids
- * @return
- */
- public ObjEnvelop selectByIds(String ids){
- ObjEnvelop envelop = new ObjEnvelop();
- List idList = Arrays.asList(ids.split(","));
- StringBuffer buffer = new StringBuffer();
- for (int i =0;i<idList.size();i++){
- buffer.append("'"+idList.get(i)+"'").append(",");
- }
- buffer.deleteCharAt(buffer.length()-1);
- String sql = "select * from wlyy_rehabilitation_plan_detail where id in("+buffer+")";
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(sql);
- List<RehabilitationDetailDO> rehabilitationDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(RehabilitationDetailDO.class));
- envelop.setObj(rehabilitationDetailDOS);
- return envelop;
- }
- /**
- * 查询频次列表
- *
- * @return
- */
- public List<Frequency> selectFrequences(){
- List<Frequency> frequencieList = frequencyDao.findByDel();
- return frequencieList;
- }
- public Map<String,Object> getServiceItemsAfterStop(String planId)throws Exception{
- Map<String,Object> reslutMap = new HashMap<>();
- String sql ="SELECT" +
- " p.patient," +
- " p.name," +
- " p.title," +
- " p.disease_name,p.abort_reason,p.abort_time,p.create_time,p.patient_img," +
- " a.*" +
- " FROM" +
- " wlyy_patient_rehabilitation_plan p" +
- " LEFT JOIN (" +
- " SELECT" +
- " d.id," +
- " d.plan_id," +
- " d.hospital," +
- " d.hospital_name," +
- " i.code as service_item_id," +
- " i.name as service_item_name," +
- " d.expense," +
- " r.doctor_code," +
- " r.doctor_name," +
- " r.complete_time, " +
- " i.code as item_type " +
- " FROM" +
- " wlyy_rehabilitation_plan_detail d" +
- " LEFT JOIN wlyy_rehabilitation_service_item i ON d.hospital_service_item_id = i.code "+
- " LEFT JOIN wlyy_rehabilitation_operate_records r ON d.id = r.rehabilitation_detail_id" +
- " WHERE" +
- " r.`status` = 1" +
- " ) a ON p.id = a.plan_id" +
- " WHERE" +
- " p.id = '"+planId+"'";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
- sql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(sql);
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
- Integer finishCount = list.size();//完成服务项目数
- double totalExpense = 0;
- Set<String> hospitalSet = new HashSet();
- Set<String> serviceDoctor = new HashSet();
- DecimalFormat df = new DecimalFormat("0.00");
- for (Map<String,Object> map : list){
- double expense = 0;
- if (StringUtils.isNotEmpty(String .valueOf(map.get("expense"))) && !"null".equals(String .valueOf(map.get("expense")))){
- expense =Integer.valueOf(String .valueOf(map.get("expense")));
- }
- totalExpense += expense;
- map.put("expense",df.format(expense/100));
- //组装机构和服务医生
- if(map.get("hospital") != null){
- if(map.get("hospital_name") != null && !hospitalSet.contains(("hospital_name") + "")) {
- hospitalSet.add(map.get("hospital_name") + "");
- }
- }
- if(map.get("doctor_code") != null){
- if(map.get("doctor_name") != null && !hospitalSet.contains(("doctor_name") + "")) {
- serviceDoctor.add(map.get("doctor_name") + "");
- }
- }
- }
- reslutMap.put("totalExpense",df.format(totalExpense/100));
- reslutMap.put("allCount",allCount);
- reslutMap.put("finishCount",finishCount);
- reslutMap.put("serviceList",list);
- reslutMap.put("hospitalAll", hospitalSet.toString().replace("[","").replace("]","").replace(",", "、"));
- reslutMap.put("serviceDoctor", serviceDoctor.toString().replace("[","").replace("]","").replace(",", "、"));
- if (list!=null&&list.size()>0){
- reslutMap.put("patientName",list.get(0).get("name"));
- reslutMap.put("abortTime",list.get(0).get("abort_time"));
- reslutMap.put("hospitalName",list.get(0).get("hospital_name"));
- reslutMap.put("abortReason",list.get(0).get("abort_reason"));
- String patientCode = String.valueOf(list.get(0).get("patient"));
- reslutMap.put("patientCode", patientCode);
- reslutMap.put("disease_name", list.get(0).get("disease_name"));
- reslutMap.put("create_time", list.get(0).get("create_time"));
- reslutMap.put("patient_img", list.get(0).get("patient_img"));
- BasePatientDO patient = basePatientDao.findById(patientCode);
- if (patient!=null){
- reslutMap.put("openid", patient.getOpenid());
- reslutMap.put("ssc",patient.getSsc());
- reslutMap.put("mobile",patient.getMobile());
- }
- }
- return reslutMap;
- }
- public String getCode() {
- return UUID.randomUUID().toString().replaceAll("-", "");
- }
- public List<Map<String,Object>> getPatientAllRehabilitationPlan(String patient){
- 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 " +
- " FROM wlyy_patient_rehabilitation_plan p " +
- " LEFT JOIN base_doctor d ON d.id = p.create_user " +
- "WHERE p.patient='"+patient+"'";
- sql = sql +" union "+
- "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 " +
- "FROM " +
- "wlyy_patient_rehabilitation_plan p " +
- "LEFT JOIN base_doctor d ON d.id=p.create_user" +
- " LEFT JOIN (" +
- "SELECT sr.patient AS patient,sr.team_code AS team_code " +
- "FROM wlyy_doctor_patient_relation sr " +
- "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id " +
- "WHERE sr.patient='"+patient+"') d " +
- "ON d.patient=p.patient WHERE " +
- "p.patient='"+patient+"' " +
- " "+
- "ORDER BY create_time DESC";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- List<Map<String,Object>> result = new ArrayList<>();
- List<Map<String,Object>> hadManage = new ArrayList<>();
- for (Map<String,Object> mp:mapList){//获下转状态
- Date createTimeDate = DateUtil.strToDateLong(mp.get("createTime").toString());
- mp.put("createTimeDate",DateUtil.dateToStrShort(createTimeDate));
- String mpDoctor = mp.get("doctor").toString();
- String manageStatus;
- //获取最近完成服务
- sql = "select si.`code`,si.name,opr.complete_time update_time \n" +
- "from wlyy_rehabilitation_plan_detail pd \n" +
- "INNER JOIN wlyy_rehabilitation_service_item si on si.`code` = pd.hospital_service_item_id \n" +
- "INNER JOIN wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pd.id\n" +
- "where plan_id='"+mp.get("id").toString()+"' and opr.`status` =1 ORDER BY opr.complete_time DESC ";
- List<Map<String,Object>> serverItems = jdbcTemplate.queryForList(sql);
- if(serverItems!=null&&serverItems.size()!=0){
- mp.put("completeServer",serverItems.get(0));
- }
- else{
- mp.put("completeServer","");
- }
- try {
- manageStatus = jdbcTemplate.queryForObject(sql,String.class);
- }catch (Exception e){
- manageStatus="0";
- }
- if (StringUtils.isBlank(manageStatus)||manageStatus.equals("0")){//已下转,即未接收
- mp.put("turnDownState",1);
- result.add(mp);
- }
- else{//已接受
- mp.put("turnDownState",2);
- hadManage.add(mp);
- }
- }
- result.addAll(hadManage);
- return result;
- }
- public List<Map<String,Object>> selectByGuidance(String planId,String itemCode){
- String sql ="SELECT gm.* FROM wlyy_guidance_message_log gm LEFT JOIN wlyy_rehabilitation_plan_detail pd ON pd.id = gm.plan_detail_id " +
- "WHERE pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id = '"+itemCode+"' ORDER BY gm.create_time DESC ";
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- return mapList;
- }
- @Transactional
- public String manageAllPlanByPatient(String patient,String doctor){
- 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" +
- "from wlyy_patient_rehabilitation_plan pl \n" +
- "INNER JOIN wlyy_doctor_patient_relation re\n" +
- "on pl.patient = re.patient \n" +
- "where re.`status`>=0 \n" +
- "and pl.patient ='"+patient+"' and (re.is_manage<>1 or re.is_manage is NULL) ";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
- List<Map<String,Object>> planIds = jdbcTemplate.queryForList(sql);
- List<Map<String,Object>> planByCreate = jdbcTemplate.queryForList(sql+" GROUP BY pl.create_user");
- for (Map<String,Object> tmp:planIds){
- sql ="update wlyy_doctor_patient_relation set is_manage=1,manage_user ='"+doctor+"', manage_time ='"+DateUtil.getStringDate()+"' where id='"+tmp.get("id").toString()+"' ";
- jdbcTemplate.execute(sql);
- }
- BaseDoctorDO doctorObject = baseDoctorDao.findById(doctor);//家庭医生
- //接收患者时,给服务医生群组发送消息
- List<String> patientRelationDoctor = new ArrayList<>();
- for (Map<String,Object> tmp:planByCreate){
- try {
- if(!patientRelationDoctor.contains(tmp.get("doctor").toString())){
- //guidanceService.sendSpecialistWeixinMessage(patient,tmp.get("doctor").toString(),2,null,null,null);
- patientRelationDoctor.add(tmp.get("doctor").toString());
- }
- //患者服务医生群组发送Im消息
- com.alibaba.fastjson.JSONArray serverDoctorList =selectPlanServerDoctor(tmp.get("planId").toString(),doctor);
- int length = serverDoctorList.size();
- for (int i=0;i<length;i++){
- JSONObject serverJson = serverDoctorList.getJSONObject(i);
- if (serverJson.getString("type").equals("4")){
- String sessionId = serverJson.getString("sessionId");
- String message= tmp.get("specialDoctorName").toString()+"医生您好,我已确认接收管理患者"+tmp.get("patientName").toString()+",谢谢。";
- imUtil.sendImMsg(doctor,doctorObject.getName(),sessionId,"1",message,"1","");
- }
- }
- //发送模板消息
- /*if(messageService.getMessageNoticeSettingByMessageType(tmp.get("create_user").toString(),"1", MessageNoticeSetting.MessageTypeEnum.systemSwitch.getValue())) {
- Doctor specialistDoctor = doctorDao.findByCode(tmp.get("create_user").toString());
- if(StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
- Doctor SignDoctor = doctorDao.findByCode(doctor);
- Patient p = patientDao.findByCode(patient);
- //[医生姓名]医生您好,[医生姓名]医生已确认接收您的康复下转患者[患者姓名],请访问厦门i健康APP康复管理查看。
- String first = specialistDoctor.getName() + "医生您好,"+SignDoctor.getName()+"医生已确认接收您的康复下转患者"
- + p.getName() +",请访问厦门i健康APP康复管理查看。";
- if (StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
- doctorAssistantUtil.sendWXTemplate(2,specialistDoctor.getOpenid(),first,"请及时处理","康复管理","已接收");
- }
- }
- }*/
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- return null;
- }
- @Transactional(propagation= Propagation.NOT_SUPPORTED)
- public com.alibaba.fastjson.JSONArray selectPlanServerDoctor(String planId,String doctorCode) throws Exception{
- 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+"'";//专科
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
- String patient = "";
- for (Map<String,Object> map:mapList){
- String doctor =map.get("create_user").toString();
- patient = map.get("patient").toString();
- JSONObject object = new JSONObject();
- BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
- object.put("code",doctor1.getId());
- object.put("name",doctor1.getName());
- object.put("level",doctor1.getLevel());
- /*object.put("hospital",doctor1.getHospital());
- object.put("hospitalName",doctor1.getHospitalName());*/
- if (doctor1.getLevel()==1){
- object.put("levelName","专科医生");
- }else if (doctor1.getLevel()==2){
- object.put("levelName","全科医生");
- }
- object.put("photo",doctor1.getPhoto());
- object.put("idcard",doctor1.getIdcard());
- jsonArray.add(object);
- }
- /*SignFamily signFamily = signFamilyDao.findByPatient(patient);
- if (signFamily!=null){
- org.json.JSONObject object = new org.json.JSONObject();
- BaseDoctorDO doctor1 = baseDoctorDao.findById(signFamily.getDoctor());
- object.put("code",doctor1.getId());
- object.put("name",doctor1.getName());
- if (doctor.getLevel()==1){
- object.put("levelName","专科医生");
- }else if (doctor.getLevel()==2){
- object.put("levelName","全科医生");
- }
- object.put("photo",doctor.getPhoto());
- object.put("idcard",doctor.getIdcard());
- object.put("hospital",doctor.getHospital());
- object.put("hospitalName",doctor.getHospitalName());
- array.put(object);
- org.json.JSONObject object1 = new org.json.JSONObject();
- if (StringUtils.isNoneBlank(signFamily.getDoctorHealth())){
- BaseDoctorDO doctor1 = baseDoctorDao.findById(signFamily.getDoctorHealth());
- object1.put("code",doctor1.getId());
- object1.put("name",doctor1.getName());
- object1.put("level",3);
- object1.put("levelName","健管师");
- object1.put("photo",doctor1.getPhoto());
- object1.put("idcard",doctor1.getIdcard());
- object.put("hospital",doctor1.getHospital());
- object.put("hospitalName",doctor1.getHospitalName());
- array.put(object1);
- }
- }*/
- StringBuilder serverGroupSessionId =new StringBuilder();//群聊session_id
- StringBuilder serverGroupSessionName =new StringBuilder();//群聊名称
- JSONObject participants = new JSONObject();//群聊成员
- if (jsonArray!=null){
- for(int i=0;i<jsonArray.size();i++){//获取服务医生P2P 未读消息以及session_id。
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- serverGroupSessionId.append(jsonObject.getString("code")+"_");
- serverGroupSessionName.append(jsonObject.getString("name")+"、");
- participants.put(jsonObject.getString("code"),0);
- if(jsonObject.getString("code").equals(doctorCode)){//
- jsonObject.put("unRead",0);
- jsonObject.put("sessionId","");
- jsonObject.put("type","");
- jsonObject.put("business_type","");
- continue;
- }
- //服务医生间的消息获取
- JSONObject participantsP2P = new JSONObject();
- participantsP2P.put(doctorCode,0);
- participantsP2P.put(jsonObject.getString("code"),0);
- //获取登录医生与其他服务医生的session_id
- //{"data":{"business_type":1,"name":"余研","id":"3438fdc6c1082c7b3c3e93dc27da244b59b694dc","type":"2","create_date":1603436112458},"status":200}
- JSONObject result = imUtil.createSession(participantsP2P,"2",jsonObject.getString("name"),null);
- jsonObject.put("sessionId",result.getJSONObject("data").getString("id"));
- jsonObject.put("type",result.getJSONObject("data").getString("type"));
- jsonObject.put("business_type",result.getJSONObject("data").getInteger("business_type"));
- //获取未读消息
- result = imUtil.getSessionUnreadMessageCount(jsonObject.getString("sessionId"),doctorCode);
- jsonObject.put("unRead",result.getInteger("count"));
- }
- }
- //服务医生群聊数据获取
- JSONObject groupObject = new JSONObject();
- if(StringUtils.isNoneBlank(serverGroupSessionId)&&StringUtils.isNoneBlank(serverGroupSessionName)){
- serverGroupSessionId.append("server_group");
- serverGroupSessionName=serverGroupSessionName.deleteCharAt(serverGroupSessionName.length()-1);
- if(imUtil.sessionIsExist(serverGroupSessionId+"")){//会话存在
- JSONObject result = imUtil.getSessionUnreadMessageCount(serverGroupSessionId+"",doctorCode);
- groupObject.put("unRead",result.getInteger("count"));
- }
- else{
- JSONObject result = imUtil.createSession(participants,"4",serverGroupSessionName+"",serverGroupSessionId+"");
- groupObject.put("unRead",0);
- }
- groupObject.put("name",serverGroupSessionName);
- groupObject.put("sessionId",serverGroupSessionId.toString());
- groupObject.put("business_type",1);
- groupObject.put("type","4");
- }
- jsonArray.add(groupObject);
- return jsonArray;
- }
- /**
- * 每天8点,16点的job
- * @param startTime
- * @param endTime
- * @throws Exception
- */
- public void dailyJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
- JSONArray jsonArray = dailyJob(startTime,endTime);
- org.json.JSONObject jsonObject = null;
- String doctor = "";
- String patient ="";
- Integer num = null;
- String planDetailIds = null;
- for(int i=0;i<jsonArray.length();i++){
- jsonObject = jsonArray.getJSONObject(i);
- doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
- patient = jsonObject.get("patient")+"";//执行的居民
- num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数
- planDetailIds = jsonObject.get("planDetailIds")+"";
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
- }
- }
- /**
- * 每天15点的job
- * @param startTime
- * @param endTime
- * @throws Exception
- */
- public void tomorrowJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
- JSONArray jsonArray =tomorrowJob(startTime,endTime);
- org.json.JSONObject jsonObject = null;
- String doctor = "";
- String patient ="";
- Integer num = null;
- String planDetailIds = null;
- for(int i=0;i<jsonArray.length();i++){
- jsonObject = jsonArray.getJSONObject(i);
- doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
- patient = jsonObject.get("patient")+"";//执行的居民
- num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数
- planDetailIds = jsonObject.get("planDetailIds")+"";
- String planId = jsonObject.get("id")+"";
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- message1.setReason(planId);
- // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
- }
- }
- /**
- * 每15分钟的job
- *
- * @param startTime
- * @param endTime
- * @param type
- * @throws Exception
- */
- public void dailyByJobSendMessage(String startTime,String endTime,Integer type) throws Exception{
- JSONArray jsonArray = dailyByJob(startTime,endTime);
- org.json.JSONObject jsonObject = null;
- String doctor = "";
- String patient ="";
- Integer num = null;
- String serviceItemName = null;
- String planDetailIds = null;
- Long timeType = null;
- String nowDate = DateUtil.getStringDate();
- String date9 = DateUtil.getStringDateShort()+" 09:00:00";//白天
- String date21 = DateUtil.getStringDateShort()+" 21:00:00";//白天
- String date9s = DateUtil.getNextDay(DateUtil.getNowDate(),1)+" 09:00:00";//晚上
- for(int i=0;i<jsonArray.length();i++){
- jsonObject = jsonArray.getJSONObject(i);
- doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
- patient = jsonObject.get("patient")+"";//执行的居民
- /*num = (Integer)jsonObject.get("num");//需要今日需要执行的项目数*/
- planDetailIds = jsonObject.get("planDetailIds")+"";
- serviceItemName = jsonObject.getString("serviceItemName");
- timeType = jsonObject.getLong("timeType");
- if (timeType!=null){
- if (timeType==1 && nowDate.compareTo(date9)==1&&nowDate.compareTo(date21)==-1){
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- message1.setData(serviceItemName);
- // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
- }else if (timeType==2 && nowDate.compareTo(date21)==1&&nowDate.compareTo(date9s)==-1){
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- message1.setData(serviceItemName);
- // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
- }else if (timeType==0){
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- message1.setData(serviceItemName);
- // specialistEvaluateSevice.sendMessage(message1,null,patient,num,null);
- }
- }
- }
- }
- public void dailyJobReserve(Integer num,Integer type) throws Exception{
- Long time = num*24*60*60*1000L;
- String startTime = DateUtil.dateToStrShort(new Date(new Date().getTime()+time))+" "+"00:00:00";
- String endTime = DateUtil.dateToStrShort(new Date(new Date().getTime()+time))+" "+"23:59:59";
- JSONArray jsonArray=dailyJobReserve1(startTime,endTime);
- org.json.JSONObject jsonObject = null;
- String doctor = "";
- String patient ="";
- String hospital ="";
- String planDetailIds = null;
- for(int i=0;i<jsonArray.length();i++){
- jsonObject = jsonArray.getJSONObject(i);
- doctor = jsonObject.get("doctor")+"";//执行的医生(接收的医生)
- patient = jsonObject.get("patient")+"";//执行的居民
- hospital = jsonObject.get("hospital")+"";//医院
- planDetailIds = jsonObject.get("planDetailIds")+"";
- SystemMessageDO message1 = new SystemMessageDO();
- // message1.setSender(patient);
- message1.setType(type.toString());
- message1.setReceiver(doctor);
- message1.setRelationCode(planDetailIds);
- // specialistEvaluateSevice.sendMessage(message1,hospital,patient,num,null);
- }
- }
- public List<PatientMedicalRecordsDO> selectByMedicalCode(String code){
- String str[] = code.split(",");
- List<PatientMedicalRecordsDO> medicalRecordsDOS= new ArrayList<>();
- for (int i=0;i<str.length;i++){
- PatientMedicalRecordsDO medicalRecordsDO = medicalRecordsRehabilitationDao.findByCode(str[i]);
- medicalRecordsDOS.add(medicalRecordsDO);
- }
- return medicalRecordsDOS;
- }
- public List<Map<String,Object>> selectAllCompleteServiceItemsByPatient(String patient){
- List<Map<String,Object>> resutList = new ArrayList<>();
- 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" +
- "(select p.team_code as teamCode,d.code as doctor,p.create_time as createTime,p.id,p.patient,p.name " +
- "from wlyy_patient_rehabilitation_plan p\n" +
- "LEFT JOIN base_doctor d ON d.id = p.create_user\n" +
- "WHERE p.patient='"+patient+"'\n" +
- "union\n" +
- "SELECT p.team_code as teamCode,d.CODE AS doctor,p.create_time AS createTime,p.id,p.patient,p.name " +
- "from \n" +
- " wlyy_patient_rehabilitation_plan p\n" +
- "LEFT JOIN base_doctor d ON d.id=p.create_user\n" +
- "LEFT JOIN (\n" +
- "SELECT sr.patient AS patient,sr.team_code AS team_code \n" +
- "FROM wlyy_doctor_patient_relation sr \n" +
- "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id \n" +
- "WHERE sr.patient='"+patient+"') d \n" +
- "ON d.patient=p.patient WHERE \n" +
- "p.patient='"+patient+"' \n" +
- "\n" +
- "ORDER BY createTime DESC)A \n" +
- "INNER JOIN wlyy_rehabilitation_plan_detail pdl ON A.id = pdl.plan_id\n" +
- "INNER JOIN wlyy_rehabilitation_service_item si on pdl.hospital_service_item_id = si.id\n" +
- "INNER JOIN wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pdl.id\n" +
- "where pdl.hospital_service_item_id <>2 and opr.`status`=1 order by opr.complete_time desc ";
- sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
- List<Map<String,Object>> planDetailList = jdbcTemplate.queryForList(sql);
- resutList.addAll(planDetailList);
- //康复咨询
- 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" +
- "from wlyy_consult_team ct\n" +
- "INNER JOIN im_internet_hospital.topics top on top.id = ct.consult \n" +
- "where ct.patient='"+patient+"' and ct.type=18 and ct.del=1";
- List<Map<String,Object>> kangFuList = jdbcTemplate.queryForList(sql);
- for (Map<String,Object> map:kangFuList){
- if (map.get("status").toString().equals("0")&&map.get("reply").toString().equals("0")){
- map.put("serviceStatus","未回复");
- }
- if (map.get("status").toString().equals("0")&&map.get("reply").toString().equals("1")){
- map.put("serviceStatus","未结束");
- }
- if (map.get("status").toString().equals("10")){//&&map.get("evaluate").toString().equals("0")
- map.put("serviceStatus","已结束");
- }
- // if (map.get("status").toString().equals("10")&&map.get("evaluate").toString().equals("1")){
- // map.put("serviceStatus","已结束");
- // }
- }
- resutList.addAll(kangFuList);
- Collections.sort(resutList, new Comparator<Map<String, Object>>() {
- public int compare(Map<String, Object> o1, Map<String, Object> o2) {
- Timestamp map1value = (Timestamp) o1.get("czrq");
- Timestamp map2value = (Timestamp) o2.get("czrq");
- int sort = 1;
- if (map1value.getTime() - map2value.getTime() > 0) {
- return sort == 1 ? -1 : 1;
- } else if (map1value.getTime() - map2value.getTime() < 0) {
- return sort == 1 ? 1 : -1;
- } else {
- return 0;
- }
- }
- });
- return resutList;
- }
- public JSONArray getPlanDetailForModifing(String planId,String templateId){
- String sql;
- JSONArray result = new JSONArray();
- if(StringUtils.isBlank(templateId)){
- sql ="select id from wlyy_rehabilitation_plan_template where title='系统模板'";
- templateId = jdbcTemplate.queryForObject(sql,String.class);
- }
- sql = "select d.hospital_service_item_id as code,i.`name`\n" +
- "from wlyy_rehabilitation_template_detail d LEFT JOIN wlyy_rehabilitation_service_item i\n" +
- "ON i.`code` = d.hospital_service_item_id\n" +
- "where d.template_id = '"+templateId+"'";
- List<Map<String,Object>> templateDetailList = jdbcTemplate.queryForList(sql);
- for (Map<String,Object> map:templateDetailList){
- sql ="select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,i.name \n" +
- "from wlyy_rehabilitation_plan_detail d \n" +
- "LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id \n" +
- "where d.plan_id ='"+planId+"' AND d.execute_time IS NOT NULL and d.execute_time <>''\n" +
- "AND d.`status`<> 1\n" +
- "and d.hospital_service_item_id ='"+map.get("code").toString()+"'\n" +
- "ORDER BY hospital_service_item_id ASC,execute_time ASC;";
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
- List<Map<String,Object>> planDetailList = jdbcTemplate.queryForList(sql);
- org.json.JSONObject temp = new org.json.JSONObject();
- temp.put("counts",planDetailList.size());
- temp.put("code",map.get("code").toString());
- temp.put("name",map.get("name").toString());
- temp.put("list",planDetailList);
- result.put(temp);
- }
- return result;
- }
- 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){
- Integer turnDownStateTotal_0=0;//全部
- Integer turnDownStateTotal_1=0;//已下转
- Integer turnDownStateTotal_2=0;//已接受
- Integer turnDownStateTotal_3=0;//未下转
- org.json.JSONObject resultObj = new org.json.JSONObject();
- BaseDoctorDO doctorObj = baseDoctorDao.findById(doctor);
- List<Map<String, Object>> result = new ArrayList<>();
- 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," +
- "p.sex,pr.doctor AS specialist,pr.doctor_name AS specialistName,pr.disease_code,pr.doctor_name ," +
- "pr.doctor, pr.health_doctor, pr.health_doctor_name, pr.is_manage,pr.manage_user,pr.manage_time FROM" +
- " base_doctor doc,`wlyy_doctor_patient_relation` pr" +
- " LEFT JOIN base_patient p ON p.`id` = pr.patient ";
- //关联居民计划表
- if("1".equals(filterPlan)){
- sql = sql + " INNER JOIN `wlyy_patient_rehabilitation_plan` plan on plan.patient = pr.patient ";
- }
- sql =sql+ " WHERE doc.`id` = pr.doctor ";
- String sqlCondition = "";
- if (doctorType.equalsIgnoreCase("1")){
- sqlCondition +=" AND pr.doctor = '"+doctor+"'";
- }else {
- sqlCondition +=" AND (pr.doctor = '"+doctor+"' or pr.health_doctor = '"+doctor+"') ";
- }
- if(StringUtils.isNoneBlank(patientInfo)){
- sqlCondition +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%') ";
- }
- /* if (level.equalsIgnoreCase("1")){
- sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("2")){
- sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("3")){
- sqlCondition +=" and sf.hospital = '"+area+"' ";
- }*/
- /*if (StringUtils.isNoneBlank(disease)){
- sqlCondition +=" and pr.id IN (SELECT pds.specialist_relation_code FROM wlyy_patient_disease_server pds WHERE pds.del=1 and pds.disease ='"+disease+"')";
- }*/
- //LIMIT+(page-1)*pageSize+","+pageSize
- sqlCondition += " ORDER BY pr.create_time DESC ";
- sql += sqlCondition;
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- System.out.println("mapList"+sql);
- for (Map<String,Object> map:mapList){
- BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
- List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
- if (depts!=null&&depts.size()>0){
- map.put("dept_code",depts.get(0).getDeptCode());
- map.put("dept_name",depts.get(0).getDeptName());
- }
- Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
- map.put("age",age);
- String specialistRelationCode = map.get("id").toString();
- String relationManageState = map.get("is_manage")==null?"0":map.get("is_manage").toString();//管理状态
- /*List<PatientDiseaseServer> diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1");
- StringBuffer diseaseName = new StringBuffer();
- for (int i=0;i<diseaseServers.size();i++){
- diseaseName.append(diseaseServers.get(i).getDiseaseName()+",");
- }
- if(StringUtils.isNoneBlank(diseaseName)){
- diseaseName.deleteCharAt(diseaseName.length()-1);
- }
- map.put("disease_name",diseaseName);*/
- if(StringUtils.isBlank(relationManageState)||!relationManageState.equals("1")){//未进行管理
- map.put("turnDownState", 1);//已下转
- turnDownStateTotal_1+=1;
- turnDownStateTotal_0+=1;
- if(turnDownState.equals("1")||turnDownState.equals("0")){
- result.add(map);
- }
- }
- else{
- map.put("turnDownState", 2);//已管理
- turnDownStateTotal_2+=1;
- turnDownStateTotal_0+=1;
- if(turnDownState.equals("2")||turnDownState.equals("0")){
- result.add(map);
- }
- }
- }
- //家医端未下转(签约居民,但是还未下转的居民) 专科医生端未下转(与未下转列表同-去除未家签)
- if (doctorType.equalsIgnoreCase("1")){//专科
- 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" +
- " 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" +
- "from wlyy_doctor_patient_relation d,base_patient p ,base_doctor doc where doc.`id` = d.create_user AND d.create_user='"+doctor+"' ";
- }
- sqlCondition="";
- if(StringUtils.isNoneBlank(patientInfo)){
- sqlCondition +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%') ";
- }
- /* if (level.equalsIgnoreCase("1")){
- sqlCondition +=" and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("2")){
- sqlCondition +=" and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("3")){
- sqlCondition +=" and s.hospital = '"+area+"' ";
- }*/
- if (StringUtils.isNoneBlank(disease)){
- sqlCondition +=" AND d.patient in (select patient from wlyy_patient_disease_server pds where pds.del=1 and pds.disease ='"+disease+"') ";
- }
- sql = sql + sqlCondition ;
- if (doctorType.equalsIgnoreCase("1")){//专科
- sql = sql+ " \n" +
- " AND d.patient = p.id \n" +
- "AND d.patient NOT IN ( SELECT i.patient FROM wlyy_patient_rehabilitation_plan i, base_patient p \n" +
- "WHERE i.create_user='"+doctor+"' AND i. STATUS != 0 AND p. id = i.patient \n" +
- "GROUP BY i.patient ORDER BY i.create_time DESC) GROUP BY d.patient ORDER BY d.create_time DESC ";
- }
- List<Map<String, Object>> mapList12 = jdbcTemplate.queryForList(sql);
- System.out.println("mapList2"+sql);
- for (Map<String, Object> map : mapList12) {
- List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
- if (depts!=null&&depts.size()>0){
- map.put("dept_code",depts.get(0).getDeptCode());
- map.put("dept_name",depts.get(0).getDeptName());
- }
- BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
- Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
- map.put("age",age);
- map.put("disease_name", "暂无");
- map.put("turnDownState",3);//未下
- turnDownStateTotal_3+=1;
- turnDownStateTotal_0+=1;
- if(turnDownState.equals("3")||turnDownState.equals("0")){
- result.add(map);
- }
- }
- org.json.JSONObject turnDownStateObj = new org.json.JSONObject();
- turnDownStateObj.put("stateAll",turnDownStateTotal_0);//全部
- turnDownStateObj.put("stateDown",turnDownStateTotal_1);//已下转
- turnDownStateObj.put("stateReceive",turnDownStateTotal_2);//已接受
- turnDownStateObj.put("stateNotDown",turnDownStateTotal_3);//未下转
- resultObj.put("showList",result);
- resultObj.put("turnDownState",turnDownStateObj);
- return resultObj;
- }
- /**
- * 康复管理-生成康复下转专科医生二维码
- * @param doctorCode
- * @param teamCode
- * @param teamName
- * @return
- * @throws Exception
- */
- public String createSpecialDoctorQrCode(String doctorCode,String teamCode,String teamName) throws Exception{
- Map<String, Object> param = new HashedMap();
- String fileUrl = "";
- String appId="";
- //生成二维码图片
- 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";
- InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
- if (isneiwang) {
- // 圖片列表
- List<String> tempPaths = new ArrayList<String>();
- try {
- ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
- com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
- tempPaths.add(json.getString("fid"));
- String urls = "";
- for (String image : tempPaths) {
- if (urls.length() == 0) {
- urls = image;
- } else {
- urls += "," + image;
- }
- }
- fileUrl = "" + urls;
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- try {
- //fileUrl = "" + CommonUtil.PrescriptionQRCodetoNeiWang(ipt);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- System.out.println("服务码-----------1"+fileUrl);
- param.put("doctorCode", doctorCode);
- param.put("imageUrl",fileUrl);
- return fileUrl;
- }
- 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){
- Integer turnDownStateTotal_0=0;//全部
- Integer turnDownStateTotal_1=0;//已下转
- Integer turnDownStateTotal_2=0;//已接受
- Integer turnDownStateTotal_3=0;//未下转
- org.json.JSONObject resultObj = new org.json.JSONObject();
- List<Map<String, Object>> result = new ArrayList<>();
- String sql = "select DISTINCT t.id as \"id\"," +
- " p.name as \"name\"," +
- " p.id as \"code\"," +
- " p.idcard as \"idcard\"," +
- " p.photo as \"photo\"," +
- " p.sex as \"sex\"," +
- " t.disease as \"disease\"," +
- " t.disease_name as \"disease_name\"," +
- " YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) as age," +
- " d.doctor as \"doctor\"," +
- " d.doctor_name as \"doctor_name\"," +
- " t.create_user as \"create_user\"," +
- " t.create_user_name as \"create_user_name\"," +
- " t.create_time as \"create_time\"," +
- " t.is_verify as \"is_verify\"" +
- " from wlyy_patient_rehabilitation_plan t left join wlyy_rehabilitation_plan_detail d on t.id =d.plan_id" +
- " left join base_doctor doc on d.doctor=doc.id LEFT JOIN base_patient p ON p.`id` = t.patient" +
- " where 1=1 " ;
- if(StringUtils.isNoneBlank(patientInfo)){
- sql +=" AND (p.idcard like '%"+patientInfo+"%' OR p.`name`like '%"+patientInfo+"%' or d.doctor_name like '%"+patientInfo+"%') ";
- }
- if (doctorType.equalsIgnoreCase("1")){
- sql +=" AND d.doctor = '"+doctor+"'";
- }else {
- sql +=" AND (d.doctor = '"+doctor+"' or t.create_user = '"+doctor+"') ";
- }
- /* if (level.equalsIgnoreCase("1")){
- sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("2")){
- sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='"+area+"' and dh.del=1 )";
- }else if (level.equalsIgnoreCase("3")){
- sqlCondition +=" and sf.hospital = '"+area+"' ";
- }*/
- /*if (StringUtils.isNoneBlank(disease)){
- sqlCondition +=" and pr.id IN (SELECT pds.specialist_relation_code FROM wlyy_patient_disease_server pds WHERE pds.del=1 and pds.disease ='"+disease+"')";
- }*/
- //LIMIT+(page-1)*pageSize+","+pageSize
- sql += " ORDER BY t.create_time DESC ";
- List<Map<String,Object>> mapList = hibenateUtils.createSQLQuery(sql,page,pageSize);
- System.out.println("mapList"+sql);
- for (Map<String,Object> map:mapList){
- BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString());
- List<BaseDoctorHospitalDO> depts= baseDoctorHospitalDao.findByDoctorCode(doctor);
- if (depts!=null&&depts.size()>0){
- map.put("dept_code",depts.get(0).getDeptCode());
- map.put("dept_name",depts.get(0).getDeptName());
- }
- Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(),patientDo.getBirthday());
- map.put("age",age);
- String specialistRelationCode = map.get("id").toString();
- String relationManageState = map.get("is_verify")==null?"0":map.get("is_verify").toString();//管理状态
- /*List<PatientDiseaseServer> diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1");
- StringBuffer diseaseName = new StringBuffer();
- for (int i=0;i<diseaseServers.size();i++){
- diseaseName.append(diseaseServers.get(i).getDiseaseName()+",");
- }
- if(StringUtils.isNoneBlank(diseaseName)){
- diseaseName.deleteCharAt(diseaseName.length()-1);
- }
- map.put("disease_name",diseaseName);*/
- if(StringUtils.isBlank(relationManageState)||!relationManageState.equals("1")){
- map.put("turnDownState", 1);//已确认
- turnDownStateTotal_1+=1;
- turnDownStateTotal_0+=1;
- if(turnDownState.equals("1")||turnDownState.equals("0")){
- result.add(map);
- }
- }
- else{
- map.put("turnDownState", 2);//未确认
- turnDownStateTotal_2+=1;
- turnDownStateTotal_0+=1;
- result.add(map);
- }
- }
- org.json.JSONObject turnDownStateObj = new org.json.JSONObject();
- turnDownStateObj.put("stateAll",turnDownStateTotal_0);//全部
- turnDownStateObj.put("stateDown",turnDownStateTotal_1);//已下转
- turnDownStateObj.put("stateReceive",turnDownStateTotal_2);//已接受
- turnDownStateObj.put("stateNotDown",turnDownStateTotal_3);//未下转
- resultObj.put("showList",result);
- resultObj.put("turnDownState",turnDownStateObj);
- return resultObj;
- }
- public List<Map<String,Object>> calendarPlanDetailItems(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode) throws Exception{
- String sqlCondition = "";
- if (searchTask!=null){
- if(searchTask==8){
- sqlCondition+="and d.doctor='"+doctorCode+"' ";
- }else {
- sqlCondition+=" and i.code="+searchTask+" " ;
- }
- }
- if(status!=null){
- sqlCondition += "and d.status="+status;
- }//服务项目
- 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 " +
- " LEFT JOIN wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id " +
- " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
- " where d.plan_id='"+planId+"' "+sqlCondition+" group by i.code";
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- for (Map<String,Object> map:mapList){
- 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 " +
- "FROM wlyy_rehabilitation_plan_detail d " +
- "WHERE d.plan_id = '"+planId+"' and d.hospital_service_item_id='"+map.get("code")+"'ORDER BY d.create_time DESC";
- List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sql1);
- if (mapList1!=null&&mapList1.size()!=0){
- Map<String,Object> map1 = mapList1.get(0);
- map.put("frequency_code",map1.get("frequency_code"));
- map.put("planId",map1.get("planId"));
- map.put("id",map1.get("id"));
- map.put("createTime",map1.get("createTime"));
- }
- }
- for (Map<String,Object> map:mapList){
- if (!StringUtils.isNoneBlank(map.get("frequency_code").toString())){//
- String sqlCount = "SELECT ror.id,MAX(ror.complete_time) as date,count(*) as total FROM `wlyy_rehabilitation_operate_records` ror, " +
- "wlyy_rehabilitation_plan_detail pd WHERE pd.id = ror.rehabilitation_detail_id " +
- "AND pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id='"+map.get("code")+"' AND ror.`status`=1 ";
- List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
- int count = 0;
- if (map.get("code").toString().equalsIgnoreCase("6")){
- 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" +
- "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" +
- "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" +
- "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" +
- "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
- "and wf.patient_code = '"+map.get("patient")+"' order by wf.followup_plan_date desc";
- List<Map<String , Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
- count = allPlanList.size();
- }
- if (map.get("code").toString().equalsIgnoreCase("7")){
- String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, \n" +
- "LEFT(pr.create_time,19) AS createTime, pr.doctor \n" +
- "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 ;";
- List<Map<String , Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
- count = allPrescrList.size();
- }
- if (mapList1!=null && mapList1.size()!=0){
- Map<String,Object> map1 = mapList1.get(0);
- map.put("compeletTotal",new Integer(map1.get("total").toString()) + count );
- map.put("firstDate",map1.get("date"));
- }
- }else {
- int codeCount = 0 ;
- /* if (map.get("code").toString().equalsIgnoreCase("6")){ //康复随访
- //该居民的所有随访计划,需要同步展示到康复计划-康复随访内
- 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" +
- "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" +
- "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" +
- "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" +
- "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
- "and wf.patient_code = '"+map.get("patient")+"' order by wf.followup_plan_date desc";
- List<Map<String , Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
- codeCount = allPlanList.size();
- map.put("allPlanList",allPlanList);
- }
- if (map.get("code").toString().equalsIgnoreCase("7")){ //康复复诊
- //居民的处方续方,需要同步展示到康复计划-康复复诊内
- String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, pr.`code`, \n" +
- "LEFT(pr.create_time,19) AS createTime, pr.doctor, pr.min_drug_day AS minDrugDay, LEFT(pr.pres_create_time,19) AS presCreateTime \n" +
- "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`;";
- List<Map<String , Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
- codeCount = allPrescrList.size();
- map.put("allPrescrList",allPrescrList);
- }*/
- String sqlCount="SELECT\n" +
- "\tCOUNT(pd.id) AS total ,\n" +
- "\tCOUNT(CASE WHEN pd.`status`=1 THEN 1 ELSE NULL END) AS compeletTotal\n" +
- "FROM\n" +
- "\t wlyy_rehabilitation_plan_detail pd\n" +
- "WHERE\n" +
- "\t pd.plan_id = '"+planId+"' " +
- "AND pd.hospital_service_item_id='"+map.get("code")+"' and (pd.frequency_code IS NOT NULL AND pd.frequency_code<>'')\n";
- List<Map<String,Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
- if (mapList1!=null && mapList1.size()!=0){
- Map<String,Object> map1 = mapList1.get(0);
- map.put("total",new Integer(map1.get("total").toString()) + codeCount);
- map.put("compeletTotal",new Integer(map1.get("compeletTotal").toString()) + codeCount);
- }
- String dateSql = "SELECT MAX(CASE WHEN pd.`status`=1 THEN pd.execute_time ELSE NULL END) AS firstDate FROM wlyy_rehabilitation_plan_detail pd " +
- "WHERE pd.plan_id = '"+planId+"' AND pd.hospital_service_item_id='"+map.get("code")+"'";
- List<Map<String,Object>> mapList2 = jdbcTemplate.queryForList(dateSql);
- if (mapList2!=null && mapList2.size()!=0){
- Map<String,Object> map1 = mapList2.get(0);
- map.put("firstDate",map1.get("firstDate"));
- String condition = "";
- if (map1.get("firstDate")!=null&&StringUtils.isNoneBlank(map1.get("firstDate").toString())){
- condition = "and pd.execute_time >='"+map1.get("firstDate").toString()+"'";
- }
- String dateSql1 = "SELECT pd.execute_time as lastDate FROM wlyy_rehabilitation_plan_detail pd " +
- "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 ";
- List<Map<String,Object>> mapList3 = jdbcTemplate.queryForList(dateSql1);
- if (mapList3!=null&&mapList3.size()!=0){
- Map<String,Object> map2 = mapList3.get(0);
- map.put("lastDate",map2.get("lastDate"));
- }else {
- map.put("lastDate",null);
- }
- }
- }
- if (map.get("code").toString().equalsIgnoreCase("2"))
- {//康复咨询
- //总康复咨询数量
- String sqlTotal = "select count(*)\n" +
- "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+"'";
- Integer consultTotal = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
- /*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";
- List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthCount);
- map.put("healthList",healthList);*/
- map.put("total",consultTotal );
- //完成康复咨询数量
- sqlTotal = "select count(*)\n" +
- "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+"'";
- consultTotal = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
- map.put("compeletTotal",consultTotal );
- //上次发起时间
- String sqlTemp ="select a.czrq\n" +
- "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";
- List<Map<String,Object>> czrqMap = jdbcTemplate.queryForList(sqlTemp);
- if(czrqMap.size()!=0){
- if(czrqMap.get(0).get("czrq")!=null){
- map.put("lastDate",czrqMap.get(0).get("czrq").toString());
- }
- }
- else{
- map.put("lastDate",null);
- }
- //未回复康复咨询数量
- sqlTotal="SELECT count(*) FROM wlyy.wlyy_consult_team a WHERE a.type = 18\n" +
- "AND EXISTS ( SELECT DISTINCT t.id consultId FROM "+imDBName+".topics t, "+imDBName+".participants p, "+imDBName+".doctors d, "+imDBName+".sessions s \n" +
- "WHERE p.participant_id = d.id AND t.session_id = p.session_id AND t.session_id = s.id\n" +
- "AND s.type =18 AND t.`reply` = 0 AND a.consult = t.id\n" +
- "and a.id in( select b.id from wlyy_consult a,wlyy_consult_team b \n" +
- "where a.id = b.consult and a.patient = '"+map.get("patient")+"' and a.del = '1' and a.type=18 and b.doctor='"+doctorCode+"' )\n" +
- ")";
- Integer noReplay = jdbcTemplate.queryForObject(sqlTotal,Integer.class);
- map.put("noReplay",noReplay);
- }
- }
- return mapList;
- }
- public PatientRehabilitationPlanDO confirmManage(String patient,String signDoctor,String specialist,String relationId,String planId) throws Exception {
- String sqlCondition;
- if (StringUtils.isNoneBlank(relationId)){
- sqlCondition=" and pr.id='"+relationId+"' ";
- }
- else{
- sqlCondition=" and pr.doctor = '"+specialist+ "'";
- }
- PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(planId);
- if (patientRehabilitationPlanDO!=null){
- patientRehabilitationPlanDO.setIsVerify("1");
- patientRehabilitationPlanDao.save(patientRehabilitationPlanDO);
- String specialistSql = "select pr.doctor,pr.patient from wlyy_doctor_patient_relation pr where pr.patient='"+patient+"' "+sqlCondition;
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(specialistSql);
- if (mapList!=null&&mapList.size()!=0){
- Map<String,Object> map = mapList.get(0);
- String doctor = (String)map.get("doctor");
- String patient1 = (String)map.get("patient");
- //guidanceService.sendSpecialistWeixinMessage(patient1,doctor,2,null,null,null);
- }
- //下转患者被家庭医生确认管理时,专科医生收到推送
- /*if(messageService.getMessageNoticeSettingByMessageType(specialist,"1", MessageNoticeSetting.MessageTypeEnum.systemSwitch.getValue())) {
- Doctor specialistDoctor = doctorDao.findByCode(specialist);
- if(StringUtils.isNoneBlank(specialistDoctor.getOpenid())){
- Doctor doctor = doctorDao.findByCode(signDoctor);
- Patient p = patientDao.findByCode(patient);
- //[医生姓名]医生您好,[医生姓名]医生已确认接收您的康复下转患者[患者姓名],请访问厦门i健康APP康复管理查看。
- String first = specialistDoctor.getName() + "医生您好,"+doctor.getName()+"医生已确认接收您的康复下转患者"
- + p.getName() +",请访问厦门i健康APP康复管理查看。";
- doctorAssistantUtil.sendWXTemplate(2,specialistDoctor.getOpenid(),first,"请及时处理","康复管理","已接收");
- }
- }*/
- //确认管理给管理医生群组发送消息
- /* if (StringUtils.isNoneBlank(planId)){
- try {
- JSONArray serverDoctorList =selectPlanServerDoctor(planId,signDoctor);
- int length = serverDoctorList.length();
- BaseDoctorDO doctor = baseDoctorDao.findById(signDoctor);
- Patient p = patientDao.findByCode(patient);
- Doctor specialistDoctor = doctorDao.findByCode(specialist);
- for (int i=0;i<length;i++){
- org.json.JSONObject serverJson = serverDoctorList.getJSONObject(i);
- if (serverJson.getString("type").equals("4")){
- String sessionId = serverJson.getString("sessionId");
- String message= specialistDoctor.getName()+"医生您好,我已确认接收管理患者"+p.getName()+",谢谢。";
- ImUtill.sendImMsg(signDoctor,doctor.getName(),sessionId,"1",message,"1");
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }*/
- }
- return patientRehabilitationPlanDO;
- }
- public org.json.JSONObject selectByPlanDetaiId(String patient, String planId, String code, Integer page, Integer pagesize){
- org.json.JSONObject object = new org.json.JSONObject();
- String sql ="SELECT\n" +
- " DATE_FORMAT(r.complete_time,'%Y-%m-%d %H:%i:%s') AS completeTime," +
- " r.doctor_code AS doctorCode," +
- " r.doctor_name AS doctorName," +
- " r.`status`," +
- " r.id as recordId," +
- " si.`name`," +
- " si.`code`," +
- " pd.plan_id," +
- " pd.id," +
- " r.relation_code as relationCode," +
- " r.flag " +
- "FROM " +
- " wlyy_rehabilitation_operate_records r " +
- "LEFT JOIN wlyy_rehabilitation_plan_detail pd ON r.rehabilitation_detail_id = pd.id " +
- "LEFT JOIN wlyy_rehabilitation_service_item si ON si.code= pd.hospital_service_item_id " +
- "LEFT JOIN base_doctor d ON d.id = r.doctor_code " +
- "WHERE " +
- " pd.plan_id = '"+planId+"' " +
- " AND pd.hospital_service_item_id = '"+code+"' " +
- "ORDER BY " +
- " r.complete_time DESC " ;
- sql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(sql);
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- String sqlCount ="SELECT\n" +
- "\tCOUNT(*) as total\n" +
- "FROM\n" +
- "\t wlyy_rehabilitation_operate_records r\n" +
- "LEFT JOIN wlyy_rehabilitation_plan_detail pd ON r.rehabilitation_detail_id = pd.id\n" +
- "LEFT JOIN wlyy_rehabilitation_service_item si ON si.code= pd.hospital_service_item_id\n" +
- "LEFT JOIN base_doctor d ON d.id = r.doctor_code\n" +
- "WHERE\n" +
- "\t pd.plan_id = '"+planId+"'\n" +
- "\t\tAND pd.hospital_service_item_id = '"+code+"'\n";
- List<Map<String,Object>> maps = jdbcTemplate.queryForList(sqlCount);
- /*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" +
- "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" +
- "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" +
- "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" +
- "wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
- "and wf.patient_code = '"+patient+"' ";
- List<Map<String,Object>> followupList = jdbcTemplate.queryForList(followupSql);
- mapList.addAll(followupList);*/
- Collections.sort(mapList, new Comparator<Map<String, Object>>() {
- public int compare(Map<String, Object> o1, Map<String, Object> o2) {
- Timestamp map1value =Timestamp.valueOf (o1.get("completeTime").toString()) ;
- Timestamp map2value = Timestamp.valueOf (o2.get("completeTime").toString());
- int sort = 1;
- if (map1value.getTime() - map2value.getTime() > 0) {
- return sort == 1 ? -1 : 1;
- } else if (map1value.getTime() - map2value.getTime() < 0) {
- return sort == 1 ? 1 : -1;
- } else {
- return 0;
- }
- }
- });
- object.put("list",startPage(mapList,page,pagesize));
- object.put("total",new Integer(maps.get(0).get("total").toString()) );
- object.put("page",page);
- object.put("pagesize",pagesize);
- return object;
- }
- /**
- * 开始分页
- * @param list
- * @param pageNum 页码
- * @param pageSize 每页多少条数据
- * @return
- */
- public static List startPage(List list, Integer pageNum,
- Integer pageSize) {
- if (pageNum == null){
- pageNum = 1;
- }
- if (pageSize == null){
- pageSize = 10;
- }
- if (list == null) {
- return null;
- }
- if (list.size() == 0) {
- return null;
- }
- Integer count = list.size(); // 记录总数
- Integer pageCount = 0; // 页数
- if (count % pageSize == 0) {
- pageCount = count / pageSize;
- } else {
- pageCount = count / pageSize + 1;
- }
- int fromIndex = 0; // 开始索引
- int toIndex = 0; // 结束索引
- if (pageNum != pageCount) {
- fromIndex = (pageNum - 1) * pageSize;
- toIndex = fromIndex + pageSize;
- } else {
- fromIndex = (pageNum - 1) * pageSize;
- toIndex = count;
- }
- List pageList = list.subList(fromIndex, toIndex);
- return pageList;
- }
- /**
- * 获取康复服务项目列表
- * @return
- * @param name
- */
- public List<Map<String, Object>> getServiceItemList(String name) {
- String sql = "SELECT code,`name` FROM `wlyy_rehabilitation_service_item` ";
- if(StringUtils.isNotBlank(name)){
- sql += "where name like '%" + name + "%' ";
- }
- List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
- return list;
- }
- @Transactional(propagation= Propagation.NOT_SUPPORTED)
- public List<PatientMedicalRecordsDO> getNewRehabilitation(String patient,String doctorCode) throws Exception {
- //智业中山同步病历
- String result = "";
- List<PatientMedicalRecordsDO> query = new ArrayList<>();
- BasePatientDO patient1 = basePatientDao.findById(patient);
- BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
- String orgCode="";
- List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorCode);
- if(baseDoctorHospitalDO!=null&&baseDoctorHospitalDO.size()>0){
- orgCode=baseDoctorHospitalDO.get(0).getOrgCode();
- }
- if (demoFlag) {//demoFlag
- result = patientRecordService.getJosnFileResullt("event" + "2");
- } else {
- org.json.JSONObject jsonEvent = new org.json.JSONObject();
- List<Map<String, String>> resultMap = patientRecordService.getAllEvent_new(patient, "2", "1", "1", "2010-10-10 00:00:00",orgCode);
- jsonEvent.put("data", JSON.parseArray(JSON.toJSONString(resultMap)));
- result = jsonEvent.toString();
- }
- com.alibaba.fastjson.JSONObject rejson = com.alibaba.fastjson.JSONObject.parseObject(result);
- com.alibaba.fastjson.JSONArray temlist = rejson.getJSONArray("data");
- if (temlist.size() != 0) {//存在病历信息
- com.alibaba.fastjson.JSONObject tem = temlist.getJSONObject(0);
- /**
- * {
- "orgName": "厦门大学附属心血管病医院",
- "createTime": "2013-09-26 10:13:38",
- "patient": "386a35b8d17a47cbab6174ae7952b9b6",
- "orgCode": "182",
- "dataFrom": "1",
- "id": "9f35ff1f-f683-4f3c-a0a5-7ff8ef3df89e",
- "eventType": "2",
- "dianosis": "高血压2级",
- "eventDate": "2013-09-26 10:13:38"
- }
- */
- PatientMedicalRecordsDO pmr = new PatientMedicalRecordsDO();
- pmr.setHospitalName(tem.getString("orgName"));
- pmr.setHospital(tem.getString("orgCode"));
- if (demoFlag) {//测试获取为病历模板 hospitalcode获取为自己的code
- pmr.setHospital("ac02a9b87a3611e69f7c005056850d66");//
- }
- // pmr.setDischargeDiagnosis(re.getDiagnosis());
- pmr.setDischargeDiagnosisName(tem.getString("dianosis"));
- // pmr.setAdmittingDiagnosis(re.getDiagnosis());
- pmr.setJwpatient(tem.getString("patient"));
- pmr.setAdmittingDiagnosisName(tem.getString("dianosis"));
- pmr.setEvent(tem.getString("id"));
- pmr.setDataFrom(tem.getString("dataFrom"));
- pmr.setAdvice("出院继续观察");
- if (tem.getString("dataFrom").equals("4"))//3中山 4智业
- {
- try {
- String html = rehabilitationInfoService.getEmrContentByRID(tem.getString("patient"),tem.getString("id"),tem.getString("orgCode"));
- if (StringUtils.isNoneBlank(html)){
- List<String> tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.in\" diagpop=\"1\">" + "(.*?)</TD>");
- String diagnosisIn =tmp.size()>0?tmp.get(0):"";
- tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.out\" diagpop=\"1\">" + "(.*?)</TD>");
- String diagnosisOut =tmp.size()>0?tmp.get(0):"";
- if (StringUtils.isNoneBlank(diagnosisIn)){//入院诊断
- pmr.setAdmittingDiagnosisName(diagnosisIn);
- }
- if (StringUtils.isNoneBlank(diagnosisOut)){//出院诊断
- pmr.setDischargeDiagnosisName(diagnosisOut);
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- if (tem.getString("dataFrom").equals("3"))//3中山 4智业
- {
- try {
- com.alibaba.fastjson.JSONObject zsResult = zsRehabilitationInfoService.zsHospitalRecordDetail(tem.getString("patient"),tem.getString("id"));
- com.alibaba.fastjson.JSONObject zsResultData = zsResult.getJSONObject("data");
- if (zsResult.getInteger("status")==200&&zsResultData!=null){
- if(zsResultData.containsKey("入院诊断")&&StringUtils.isNoneBlank(zsResultData.getString("入院诊断"))){
- pmr.setDischargeDiagnosisName(zsResultData.getString("入院诊断"));
- }
- if (zsResultData.containsKey("出院诊断")&&StringUtils.isNoneBlank(zsResultData.getString("出院诊断"))){
- pmr.setAdmittingDiagnosisName(zsResultData.getString("出院诊断"));
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- // pmr.setDiseaseCode(diseaseObj.getString("disease"));//疾病code
- // pmr.setDiseaseName(diseaseObj.getString("diseaseName"));//疾病名称
- String jsonData = JSON.toJSONString(pmr);
- //创建居民住院病历
- objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
- PatientMedicalRecordsDO patientMedicalRecordsDO = objectMapper.readValue(jsonData, PatientMedicalRecordsDO.class);
- PatientMedicalRecordsDO patientMedicalRecordsDO1 = rehabilitationInfoService.createMedicalRecords(doctorCode, patient, patient1.getName(), patientMedicalRecordsDO, null);
- if (patientMedicalRecordsDO1 != null) { //创建病历成功
- query.add(patientMedicalRecordsDO1);
- return query;
- }
- }
- 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)
- query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(PatientMedicalRecordsDO.class));
- return query;
- }
- public List<Map<String,Object>> selectPlanByPatient(String patient, Integer status, String planId,String doctor){
- if (StringUtils.isNoneBlank(planId)){
- String planSql = "select p.patient " +
- " FROM wlyy_patient_rehabilitation_plan p where p.id='"+planId+"' ";
- List<Map<String,Object>> maps = jdbcTemplate.queryForList(planSql);
- if (maps!=null&&maps.size()!=0){
- Map<String,Object> map = maps.get(0);
- patient = map.get("patient").toString();
- }
- }
- 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 " +
- " FROM wlyy_patient_rehabilitation_plan p " +
- " LEFT JOIN base_doctor d ON d.id = p.create_user " +
- "WHERE p.patient='"+patient+"'";
- if (status!=null){
- sql +=" and p.status ="+status;
- }
- if (StringUtils.isNoneBlank(doctor)){
- BaseDoctorDO doctor1 = baseDoctorDao.findById(doctor);
- if (doctor1!=null&&doctor1.getLevel()==1){
- sql +=" and p.create_user ='"+doctor+"'";
- }
- }
- /*sql+=" union ";
- sql+=" SELECT d.CODE AS doctor," +
- "p.create_time AS createTime," +
- "p.id," +
- "d.photo," +
- "p.title," +
- "d.idcard,YEAR (now())-YEAR (substring(d.idcard,7,8)) AS age," +
- "d.sex,p.name," +
- "p.patient," +
- "d.NAME AS doctorName," +
- "d.dept_name AS deptName," +
- "hospital_name AS hospitalName," +
- "p.advice_content AS adviceContent," +
- "p.medical_records_code AS medicalRecordsCode," +
- "p.create_time AS create_time " +
- "FROM " +
- "wlyy_patient_rehabilitation_plan p " +
- "LEFT JOIN base_doctor d ON d.id=p.create_user" +
- " LEFT JOIN (" +
- "SELECT sr.patient AS patient,sr.team_code AS team_code " +
- "FROM wlyy_doctor_patient_relation sr " +
- "JOIN wlyy_doctor_special_share se ON se.special_code=sr.id " +
- "WHERE se.doctor='"+doctor+"' " +
- "AND sr.patient='"+patient+"') d " +
- "ON d.patient=p.patient WHERE " +
- "p.patient='"+patient+"' " +
- "AND d.team_code=p.team_code ";
- */
- sql+=" ORDER BY create_time DESC ";
- //sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- for (Map<String,Object> map:mapList){
- List<BaseDoctorHospitalDO> depts=baseDoctorHospitalDao.findByDoctorCode(map.get("doctor").toString());
- if(depts!=null&&depts.size()>0){
- map.put("deptCode",depts.get(0).getDeptCode());
- map.put("deptName",depts.get(0).getDeptName());
- map.put("orgCode",depts.get(0).getOrgCode());
- map.put("orgName",depts.get(0).getOrgName());
- }
- String sqlSpecilist = "select * from wlyy_doctor_patient_relation where doctor = '"+map.get("doctor")+"' and patient ='"+patient+"' and status=1";
- List<Map<String,Object>> maps = jdbcTemplate.queryForList(sqlSpecilist);
- map.put("specialist",maps);
- }
- return mapList;
- }
- /**
- *
- * @param planId 计划id
- * @param planDetailId 计划详情id
- * @param itemId 服务项目code
- * @return
- */
- public List<Map<String,Object>> selectPlanDetailByPlan(String planId,String planDetailId,String itemId){
- String sql ="SELECT * FROM wlyy_rehabilitation_plan_detail pd WHERE " +
- "pd.plan_id = '"+planId+"' " +
- "AND pd.id <>'"+planDetailId+"' " +
- "and pd.hospital_service_item_id='"+itemId+"' and status=0 order by pd.execute_time asc";
- sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(sql);
- List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
- for (Map<String,Object> map:mapList){
- String doctorCode = map.get("doctor")+"";
- BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode);
- List<BaseDoctorHospitalDO> depts=baseDoctorHospitalDao.findByDoctorCode(doctorCode);
- if (depts!=null&&depts.size()>0){
- map.put("hospital",depts.get(0).getOrgCode());
- map.put("hospitalName",depts.get(0).getOrgName());
- map.put("dept",depts.get(0).getDeptCode());
- map.put("deptName",depts.get(0).getDeptName());
- }
- }
- return mapList;
- }
- public Integer updateRelationCodeByDetailId(String planDetailId,String relationCode) throws Exception{
- String sql ="update wlyy_rehabilitation_plan_detail t set t.relation_code="+relationCode+" where t.id='"+planDetailId+"'";
- return jdbcTemplate.update(sql);
- }
- }
|