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> 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 = baseDoctorRoleDao.findByDoctorCode(doctor.getId()); for(BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){ if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){ doctorType = 1; break; }else { doctorType = 2; } } String orgName=""; String deptName=""; List 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> 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> patientRehabilitationPlanDOList = jdbcTemplate.queryForList(sql); List> resultList = new ArrayList<>(); BasePatientDO patient =null; if(patientRehabilitationPlanDOList.size()>0&&patientRehabilitationPlanDOList.get(0).get("id")!=null){ for(Map one:patientRehabilitationPlanDOList){ Map 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> 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> list = hibenateUtils.createSQLQuery(sql,page,pageSize); List> 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> specialistPatientRelationList = jdbcTemplate.queryForList(sql); List> resultList = new ArrayList<>(); for(Map temp: specialistPatientRelationList){ String doctorCode = temp.get("doctor")+""; Map 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> 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> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql); Map 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> signFamilyList = jdbcTemplate.queryForList(signFamilySql); if(signFamilyList != null && signFamilyList.size() >0 ) { Map 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> diseaseList = jdbcTemplate.queryForList(diseaseSql); List disease = new ArrayList<>(); for(Map one2:diseaseList){ disease.add(one2.get("disease_name")+""); } resultMap.put("diseaseList",disease);*/ //计划列表 List list = patientRehabilitationPlanDao.findByPatientAndCreateUser(patientCode,doctorCode); List> rehabilitationPlanList = new ArrayList<>(); for(PatientRehabilitationPlanDO one:list){ Map 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> planList = getPatientAllRehabilitationPlan(patient); StringBuilder planCondition = new StringBuilder(); planCondition .append("'"+planList.get(0).get("id").toString()+"'"); for (int i=1;i> rehabilitationDetailList = jdbcTemplate.queryForList(sql); // List rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId); Map> map = new LinkedHashMap<>(); for(Map one:rehabilitationDetailList){ String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD); Map m = null; if(map.containsKey(executeTime)){ m = map.get(executeTime); Map family = null; Map specialist = null; if(one.get("type")!=null){ if((Integer)one.get("type")==1){//家庭医生 if(m.containsKey("family")){ family = (Map)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)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()); if(one.get("type")!=null){ if((Integer)one.get("type")==1){//家庭医生 Map 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 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 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> rehabilitationDetailList = jdbcTemplate.queryForList(sql); // List rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId); Map> map = new LinkedHashMap<>(); for(Map one:rehabilitationDetailList){ String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.YYYY_MM_DD); Map m = null; if(map.containsKey(executeTime)){ m = map.get(executeTime); Map family = null; Map specialist = null; if(one.get("type")!=null){ if((Integer)one.get("type")==1){//家庭医生 if(m.containsKey("family")){ family = (Map)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)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()); if(one.get("type")!=null){ if((Integer)one.get("type")==1){//家庭医生 Map 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 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 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'' " ; 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> 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> planList = getPatientAllRehabilitationPlan(patient); StringBuilder planCondition = new StringBuilder(); planCondition .append("'"+planList.get(0).get("id").toString()+"'"); for (int i=1;i'' " ; 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> 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> serviceItemList = jdbcTemplate.queryForList(sql); // if(serviceItemList.size()>0){ // Map serviceItem = serviceItemList.get(0); List> resultList = new ArrayList<>(); for(Map one:serviceItemList){ Map 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 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 messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString()); List> messageMapList = new ArrayList<>(); for(GuidanceMessageLogDO one2:messageList){ Map 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 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 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> serviceItemList = jdbcTemplate.queryForList(sql); if (serviceItemList.size()==0){ return ObjEnvelop.getSuccess(SpecialistMapping.api_success,new HashMap<>()); } Map one = serviceItemList.get(0); Map resultMap = new HashMap<>(); List 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 = 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 messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString()); List> messageMapList = new ArrayList<>(); for(GuidanceMessageLogDO one2:messageList){ Map 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 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 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 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> 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> patientInfoList = jdbcTemplate.queryForList(patientInfoSql); Map patientInfo = new HashMap<>(); String rehabilitationOrg = ""; for(Map one:patientInfoList){ rehabilitationOrg+=","+one.get("hospital_name"); } patientInfo.put("rehabilitationOrg",StringUtils.isNotEmpty(rehabilitationOrg)?rehabilitationOrg.substring(1):""); resultMap.put("patientInfo",patientInfo); //服务医生 //完成项目=全部的服务项目-未完成的服务项目 List> serviceDoctorList = new ArrayList<>(); //全科医生和健管师要是同一个人,就显示全科医生 /* if(!generalDoctor.equals(healthDoctor)){ */ if(StringUtils.isNotEmpty(healthDoctor)){ Map 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 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> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql); BaseDoctorDO baseDoctorDO = null; for(Map 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 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 d:serviceDoctorList){ BaseDoctorDO baseDoctorDO1 = baseDoctorDao.findById(d.get("doctorCode").toString()); d.put("doctorPhoto",baseDoctorDO1!=null?baseDoctorDO1.getPhoto():""); } resultMap.put("serviceDoctorList",serviceDoctorList); //康复计划 List> planList = new ArrayList<>(); List 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 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 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 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> planDetails = jdbcTemplate.queryForList(planDetailSql); List> planDetailList = new ArrayList<>(); for(Map 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 map = new HashMap<>(); map.put("id",id);//id // List 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> planDetailList2 = jdbcTemplate.queryForList(planDetailCountSql); Integer planDetailFinish = 0; Integer planDetailUnfinish = 0; for(Map 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 = baseDoctorRoleDao.findByDoctorCode(doctor); if (baseDoctorRoleDO!=null){ for (BaseDoctorRoleDO baseDoctorRoleDO1:baseDoctorRoleDO){ if ("specialist".equalsIgnoreCase(baseDoctorRoleDO1.getRoleCode())){ doctorType=1; break; }else { doctorType=2; } } } } List 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 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> 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> 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 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> serviceDoctorList = new ArrayList<>(); if(StringUtils.isNotEmpty(generalDoctor)){ Map 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 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> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql); for(Map 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 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 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 list = rehabilitationDetailDao.dailyJob(startTime,endTime); List> list = jdbcTemplate.queryForList(sql); String doctorCode = ""; String patientCode = ""; List listMap = null; for(Map 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 list = rehabilitationDetailDao.dailyJob(startTime,endTime); List> list = jdbcTemplate.queryForList(sql); String doctorCode = ""; String patientCode = ""; List listMap = null; for(Map 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 list = rehabilitationDetailDao.dailyJob(startTime,endTime); List> list = jdbcTemplate.queryForList(sql); String doctorCode = ""; String patientCode = ""; List listMap = null; for(Map 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 updateNodeAndRelationRecordImg(String node,String image,String status,String planDeatilId,String relationCode,String recordId)throws Exception{ Map 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 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> 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> 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 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 resultMap = new HashMap<>(); Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数 Integer finishedCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId); PatientRehabilitationPlanDO p =patientRehabilitationPlanDao.findById(planId); List doctorPatientRelationDO= doctorPatientRelationDao.findByDoctorAndPatient(p.getCreateUser(),p.getPatient()); List details=rehabilitationDetailDao.findByPlanId(planId); List dicts=wlyyHospitalSysDictDao.findByDictName("healthCondition"); String doctor=""; String doctorName=""; List> doctorMaps=new ArrayList<>(); if (details!=null&&details.size()>0){ for (RehabilitationDetailDO rehabilitationDetailDO:details){ Map doctorMap = new HashMap<>(); doctor=rehabilitationDetailDO.getDoctor(); doctorName=rehabilitationDetailDO.getDoctorName(); List 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 = 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 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 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 list = rehabilitationDetailDao.dailyJob(startTime,endTime); List> list = jdbcTemplate.queryForList(sql); String doctorCode = ""; String patientCode = ""; // List listMap = null; for(Map 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> list2 = jdbcTemplate.queryForList(sql2); // listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode); String ids = ""; for(Map 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 rehabilitationDetailDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(RehabilitationDetailDO.class)); envelop.setObj(rehabilitationDetailDOS); return envelop; } /** * 查询频次列表 * * @return */ public List selectFrequences(){ List frequencieList = frequencyDao.findByDel(); return frequencieList; } public Map getServiceItemsAfterStop(String planId)throws Exception{ Map 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> list = jdbcTemplate.queryForList(sql); Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数 Integer finishCount = list.size();//完成服务项目数 double totalExpense = 0; Set hospitalSet = new HashSet(); Set serviceDoctor = new HashSet(); DecimalFormat df = new DecimalFormat("0.00"); for (Map 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> 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> mapList = jdbcTemplate.queryForList(sql); List> result = new ArrayList<>(); List> hadManage = new ArrayList<>(); for (Map 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> 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> 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> 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> planIds = jdbcTemplate.queryForList(sql); List> planByCreate = jdbcTemplate.queryForList(sql+" GROUP BY pl.create_user"); for (Map 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 patientRelationDoctor = new ArrayList<>(); for (Map 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> mapList = jdbcTemplate.queryForList(sql); com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray(); String patient = ""; for (Map 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 selectByMedicalCode(String code){ String str[] = code.split(","); List medicalRecordsDOS= new ArrayList<>(); for (int i=0;i> selectAllCompleteServiceItemsByPatient(String patient){ List> 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> 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> kangFuList = jdbcTemplate.queryForList(sql); for (Map 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>() { public int compare(Map o1, Map 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> templateDetailList = jdbcTemplate.queryForList(sql); for (Map 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> 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> 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> mapList = jdbcTemplate.queryForList(sql); System.out.println("mapList"+sql); for (Map map:mapList){ BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString()); List 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 diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1"); StringBuffer diseaseName = new StringBuffer(); for (int i=0;i> mapList12 = jdbcTemplate.queryForList(sql); System.out.println("mapList2"+sql); for (Map map : mapList12) { List 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 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 tempPaths = new ArrayList(); 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> 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> mapList = hibenateUtils.createSQLQuery(sql,page,pageSize); System.out.println("mapList"+sql); for (Map map:mapList){ BasePatientDO patientDo = basePatientDao.findById(map.get("code").toString()); List 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 diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode,"1"); StringBuffer diseaseName = new StringBuffer(); for (int i=0;i> 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> mapList = jdbcTemplate.queryForList(sql); for (Map 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> mapList1 = jdbcTemplate.queryForList(sql1); if (mapList1!=null&&mapList1.size()!=0){ Map 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 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> 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> 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> allPrescrList = jdbcTemplate.queryForList(allPrescrSql); count = allPrescrList.size(); } if (mapList1!=null && mapList1.size()!=0){ Map 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> 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> 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> mapList1 = jdbcTemplate.queryForList(sqlCount); if (mapList1!=null && mapList1.size()!=0){ Map 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> mapList2 = jdbcTemplate.queryForList(dateSql); if (mapList2!=null && mapList2.size()!=0){ Map 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> mapList3 = jdbcTemplate.queryForList(dateSql1); if (mapList3!=null&&mapList3.size()!=0){ Map 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> 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> 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> mapList = jdbcTemplate.queryForList(specialistSql); if (mapList!=null&&mapList.size()!=0){ Map 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> 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> 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> followupList = jdbcTemplate.queryForList(followupSql); mapList.addAll(followupList);*/ Collections.sort(mapList, new Comparator>() { public int compare(Map o1, Map 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> getServiceItemList(String name) { String sql = "SELECT code,`name` FROM `wlyy_rehabilitation_service_item` "; if(StringUtils.isNotBlank(name)){ sql += "where name like '%" + name + "%' "; } List> list = jdbcTemplate.queryForList(sql); return list; } @Transactional(propagation= Propagation.NOT_SUPPORTED) public List getNewRehabilitation(String patient,String doctorCode) throws Exception { //智业中山同步病历 String result = ""; List query = new ArrayList<>(); BasePatientDO patient1 = basePatientDao.findById(patient); BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode); String orgCode=""; List 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> 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 tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.in\" diagpop=\"1\">" + "(.*?)"); String diagnosisIn =tmp.size()>0?tmp.get(0):""; tmp = HtmlUtil.getTagContent(html,"xid=\"diagnosis.out\" diagpop=\"1\">" + "(.*?)"); 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> 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> maps = jdbcTemplate.queryForList(planSql); if (maps!=null&&maps.size()!=0){ Map 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> mapList = jdbcTemplate.queryForList(sql); for (Map map:mapList){ List 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> maps = jdbcTemplate.queryForList(sqlSpecilist); map.put("specialist",maps); } return mapList; } /** * * @param planId 计划id * @param planDetailId 计划详情id * @param itemId 服务项目code * @return */ public List> 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> mapList = jdbcTemplate.queryForList(sql); for (Map map:mapList){ String doctorCode = map.get("doctor")+""; BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode); List 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); } }