|  | @ -7,6 +7,7 @@ import com.yihu.jw.care.dao.apply.PatientBedApplyDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.message.OrgNoticeDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.message.UserNoticeDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.security.SecurityMonitoringOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.doctor.DoctorServicePermissionsService;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
	
		
			
				|  | @ -47,6 +48,10 @@ public class DoctorMessageService {
 | 
	
		
			
				|  |  |     private UserNoticeDao userNoticeDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SystemMessageDao messageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorHospitalDao doctorHospitalDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorServicePermissionsService doctorServicePermissionsService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -317,4 +322,68 @@ public class DoctorMessageService {
 | 
	
		
			
				|  |  |         return systemMessageDOS;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Integer todoworkTotal(String doctor){
 | 
	
		
			
				|  |  |         Integer total=0;
 | 
	
		
			
				|  |  |         BaseDoctorDO  doctorDO = baseDoctorDao.findById(doctor);
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  |         if (null!=doctorDO){
 | 
	
		
			
				|  |  |             if (1==doctorDO.getLevel()){//社区医生
 | 
	
		
			
				|  |  |                 //健康咨询+待处理续方
 | 
	
		
			
				|  |  |                  sql = " SELECT count(a.id)  FROM wlyy_consult a,wlyy_consult_team b,base_patient d WHERE a.id=b.consult " +
 | 
	
		
			
				|  |  |                         " AND b.patient=d.id  AND b.doctor='"+doctor+"'  and b.status = 0 AND a.type in (25) ";
 | 
	
		
			
				|  |  |                 total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 sql = " SELECT count(distinct a.id) from base_care_prescription a LEFT JOIN base_patient p ON a.patient = p.id, " +
 | 
	
		
			
				|  |  |                         " base_service_package_sign_record sr,base_service_package_record r,base_service_package pack, base_team_member m " +
 | 
	
		
			
				|  |  |                         " WHERE  sr.id = r.sign_id and sr.patient = a.patient and r.service_package_id = pack.id and " +
 | 
	
		
			
				|  |  |                         " m.team_code = r.team_code  and m.doctor_code = '"+doctor+"'  and a.status = 1 ";
 | 
	
		
			
				|  |  |                 total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (2==doctorDO.getLevel()){//助老员
 | 
	
		
			
				|  |  |                 //紧急救助、安防、生活
 | 
	
		
			
				|  |  |                 if(doctorServicePermissionsService.isPermission(doctor,8)==1){
 | 
	
		
			
				|  |  |                     sql = " select count(ord.id) from base_emergency_assistance_order ord where 1=1  AND EXISTS (SELECT sr.patient from " +
 | 
	
		
			
				|  |  |                             " base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i ,base_team_member m " +
 | 
	
		
			
				|  |  |                             " where ord.patient = CONVERT(sr.patient USING utf8) and  sr.id = r.sign_id and sr.status=1 and " +
 | 
	
		
			
				|  |  |                             " r.service_package_id = i.service_package_id and  m.team_code = r.team_code  and i.del = 1 and sr.`status`=1 " +
 | 
	
		
			
				|  |  |                             " and i.code='emergencyAssistance' and m.doctor_code = '"+doctor+"' and m.del = '1') " +
 | 
	
		
			
				|  |  |                             " and ord.status in ( '1') ";
 | 
	
		
			
				|  |  |                     total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if(doctorServicePermissionsService.isPermission(doctor,10)==1){
 | 
	
		
			
				|  |  |                     sql = " select count(ord.id) from base_security_monitoring_order ord INNER JOIN base_patient p on p.id = ord.patient " +
 | 
	
		
			
				|  |  |                             " where 1=1    and  EXISTS ( SELECT 1 from base_service_package_sign_record sr,base_service_package_record r, " +
 | 
	
		
			
				|  |  |                             " base_service_package_item i ,base_team_member m where ord.patient = CONVERT(sr.patient USING utf8) and " +
 | 
	
		
			
				|  |  |                             "  sr.id = r.sign_id and sr.status=1 and  r.service_package_id = i.service_package_id and " +
 | 
	
		
			
				|  |  |                             "  m.team_code = r.team_code  and i.del = 1 and sr.`status`=1 and m.doctor_code = '"+doctor+"' and m.del = '1') " +
 | 
	
		
			
				|  |  |                             "  and ord.status='1'  ";
 | 
	
		
			
				|  |  |                     total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if(doctorServicePermissionsService.isPermission(doctor,7)==1){
 | 
	
		
			
				|  |  |                     List<BaseDoctorHospitalDO> doctorHospitalDOs = doctorHospitalDao.findByDoctorCode(doctor);
 | 
	
		
			
				|  |  |                     if (doctorHospitalDOs.size()>0){
 | 
	
		
			
				|  |  |                         String hospital = doctorHospitalDOs.get(0).getOrgCode();
 | 
	
		
			
				|  |  |                         sql =" SELECT count(o.id)   FROM  base_life_care_order o LEFT JOIN base_patient p ON o.patient = p.id  " +
 | 
	
		
			
				|  |  |                                 "WHERE  o.hospital = '"+hospital+"'  AND (o.`status` = 1 or -100 = 1) and o.pay_status>0 and o.status<>0 ";
 | 
	
		
			
				|  |  |                         total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (3==doctorDO.getLevel()){//教师
 | 
	
		
			
				|  |  |                 //上门、在线咨询
 | 
	
		
			
				|  |  |                 sql = " SELECT count(a.id)  FROM wlyy_consult a,wlyy_consult_team b,base_patient d WHERE a.id=b.consult " +
 | 
	
		
			
				|  |  |                         " AND b.patient=d.id  AND b.doctor='"+doctor+"'  and b.status = 0 AND a.type in (23) ";
 | 
	
		
			
				|  |  |                 total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 sql = "  select count(DISTINCT o.id) as total  from base_door_coach_order o LEFT JOIN base_org h on h.code=o.hospital " +
 | 
	
		
			
				|  |  |                         " and h.del=1 where 1=1  and o.status in (3,4,5)and o.doctor= '"+doctor+"' ";
 | 
	
		
			
				|  |  |                 total += jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return total;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |