|  | @ -74,7 +74,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |      * @param jsonData
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject newOrder(String patient,String jsonData) throws Exception{
 | 
	
		
			
				|  |  |     public JSONObject newOrder(String patient,String jsonData,String proxyPatient) throws Exception{
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         EmergencyAssistanceDO assistanceDO = JSON.parseObject(jsonData,EmergencyAssistanceDO.class);
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(patient);
 | 
	
	
		
			
				|  | @ -89,6 +89,18 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         assistanceDO.setPatientIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |         assistanceDO.setPatientName(patientDO.getName());
 | 
	
		
			
				|  |  |         assistanceDO.setPatientPhone(patientDO.getMobile());
 | 
	
		
			
				|  |  |         if(patient.equals(proxyPatient)) {//本人发起
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatient(patient);
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatientName(patientDO.getName());
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatientPhone(patientDO.getMobile());
 | 
	
		
			
				|  |  |             assistanceDO.setType(1);
 | 
	
		
			
				|  |  |         }else {//家人
 | 
	
		
			
				|  |  |             BasePatientDO proxyPatientDO = patientDao.findById(proxyPatient);
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatient(proxyPatient);
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatientName(proxyPatientDO.getName());
 | 
	
		
			
				|  |  |             assistanceDO.setProxyPatientPhone(proxyPatientDO.getMobile());
 | 
	
		
			
				|  |  |             assistanceDO.setType(2);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (emergencyAssistanceDao.findByPatientAndStatus(patient,1)!=null){
 | 
	
		
			
				|  |  |             String failMsg = "当前居民存在申请中的救助,请完成后再申请";
 | 
	
	
		
			
				|  | @ -140,7 +152,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         assistanceDO = emergencyAssistanceDao.save(assistanceDO);
 | 
	
		
			
				|  |  |         //创建im会话  紧急救助咨询的sessionid  为居民code+(wlyy_consult_team表consult)+20
 | 
	
		
			
				|  |  |         JSONObject IMObj = consultTeamService.addServiceConsult(assistanceDO.getId(),patient,null);
 | 
	
		
			
				|  |  |         JSONObject IMObj = consultTeamService.addServiceConsult(assistanceDO.getId(),patient,proxyPatient,null);
 | 
	
		
			
				|  |  |         String sessionId=patient+"_"+ IMObj.getJSONObject("resultMsg").getString("consult") + "_20";
 | 
	
		
			
				|  |  |         assistanceDO.setSessionId(sessionId);
 | 
	
		
			
				|  |  |         //向会话中发送一条 陈XX发起紧急救助
 | 
	
	
		
			
				|  | @ -308,7 +320,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         tmpObj.put("status_1",0);//申请中
 | 
	
		
			
				|  |  |         StringBuilder sql = new StringBuilder(" select ord.status,count(ord.id) count from base_emergency_assistance_order ord where 1=1") ;
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql.append( " and ord.patient='"+patient+"' group by ord.status  ");
 | 
	
		
			
				|  |  |             sql.append( " and (ord.patient='"+patient+"' or ord.proxy_patient='"+patient+"' ) group by ord.status  ");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         else if (StringUtils.isNotBlank(doctor))    {
 | 
	
		
			
				|  |  |             sql.append(" AND EXISTS (" +
 | 
	
	
		
			
				|  | @ -359,6 +371,31 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<EmergencyAssistanceDO> getOrderList(String patient,String doctor,String status,Integer page,Integer pageSize,String sort){
 | 
	
		
			
				|  |  |         StringBuilder sql = new StringBuilder(" select ord.* from base_emergency_assistance_order ord where 1=1 ");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(doctor)){
 | 
	
		
			
				|  |  |             sql.append(" 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 = i.team_code " +
 | 
	
		
			
				|  |  |                     " and i.del = 1 and sr.`status`=1  and i.code='emergencyAssistance' and m.doctor_code = '"+doctor+"' and m.del = '1') ");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql.append(" and ( ord.patient  = '"+patient+"' or ord.proxy_patient='"+patient+"' )");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql.append(" and ord.status in ( '").append(status.replace(",","','")).append("') ");
 | 
	
		
			
				|  |  |         sql.append(" order by ord.create_time "+sort+" limit "+page*pageSize+","+pageSize);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<EmergencyAssistanceDO> resultList = jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper(EmergencyAssistanceDO.class));
 | 
	
		
			
				|  |  |         for (EmergencyAssistanceDO obj:resultList){
 | 
	
		
			
				|  |  |             BasePatientDO patientDO = patientDao.findById(obj.getPatient());
 | 
	
		
			
				|  |  |             obj.setPatientPhoto(patientDO.getPhoto());
 | 
	
		
			
				|  |  |             obj.setPatientSex(patientDO.getSex());
 | 
	
		
			
				|  |  |             obj.setPatientAge(IdCardUtil.getAgeForIdcard(patientDO.getIdcard()));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return resultList;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<EmergencyAssistanceDO> doctorGetOrderList(String patient,String doctor,String status,Integer page,Integer pageSize,String sort){
 | 
	
		
			
				|  |  |         StringBuilder sql = new StringBuilder(" select ord.* from base_emergency_assistance_order ord where 1=1 ");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(doctor)){
 | 
	
		
			
				|  |  |             sql.append(" AND EXISTS (" +
 | 
	
	
		
			
				|  | @ -385,6 +422,13 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject cancelOrder(String patient,String orderId){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         if (patientDO==null){
 | 
	
		
			
				|  |  |             String failMsg = "当前居民信息获取失败";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if (assistanceDO==null){
 | 
	
		
			
				|  |  |             String failMsg = "当前救助工单不存在";
 | 
	
	
		
			
				|  | @ -406,9 +450,15 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         assistanceDO.setStatus(-1);
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateUser(patient);
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateUserName(assistanceDO.getPatientName());
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateUserName(patientDO.getName());
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         //im是否结束会话?
 | 
	
		
			
				|  |  |         //结束救助咨询
 | 
	
		
			
				|  |  |         if (!consultTeamService.finishEmergencyConsult(assistanceDO,patient,2)){
 | 
	
		
			
				|  |  |             String failMsg = "咨询结束失败 无法完成工单";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         emergencyAssistanceDao.save(assistanceDO);
 | 
	
		
			
				|  |  |         String failMsg = "当前救助工单已取消";
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
	
		
			
				|  | @ -446,7 +496,13 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateUser(doctor);
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateUserName(assistanceDO.getDoctorName());
 | 
	
		
			
				|  |  |         assistanceDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         //im会话是否结束?
 | 
	
		
			
				|  |  |         //结束会话
 | 
	
		
			
				|  |  |         if (!consultTeamService.finishEmergencyConsult(assistanceDO,doctor,2)){
 | 
	
		
			
				|  |  |             String failMsg = "咨询结束失败 无法完成工单";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return getOrderDetail(orderId);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -531,4 +587,23 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String test(String doctor,String orderID){
 | 
	
		
			
				|  |  | //        JSONObject message = new JSONObject();
 | 
	
		
			
				|  |  | //        message.put("session_id","808080eb78b5d8e90178b5fcfa330001_4028030c78f1df510178f217a6c50001_20");
 | 
	
		
			
				|  |  | //        message.put("sender_name","一一");
 | 
	
		
			
				|  |  | //        message.put("sender_code","808080eb78b5d8e90178b5fcfa330001");
 | 
	
		
			
				|  |  | //        message.put("order_id","4028030c78f1df510178f217a6a70000");
 | 
	
		
			
				|  |  | //        message.put("content_type",40);
 | 
	
		
			
				|  |  | //        imUtill.sendMDTSocketMessageToDoctor(doctor,message.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //结束救助咨询
 | 
	
		
			
				|  |  |         EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderID);
 | 
	
		
			
				|  |  |         if (!consultTeamService.finishEmergencyConsult(assistanceDO,doctor,2)){
 | 
	
		
			
				|  |  |             String failMsg = "咨询结束失败 无法完成工单";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return failMsg;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |