|  | @ -1,6 +1,7 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.assistance;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.serializer.SerializerFeature;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.assistance.EmergencyAssistanceDao;
 | 
	
	
		
			
				|  | @ -95,6 +96,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         Map<String,Object> mapTmp = items.get(0);
 | 
	
		
			
				|  |  |         List<BaseDoctorDO> doctorDOS = baseTeamMemberDao.findAllMembers(mapTmp.get("team_code").toString());
 | 
	
		
			
				|  |  |         assistanceDO.setTeamCode(mapTmp.get("team_code").toString());
 | 
	
		
			
				|  |  |         if (doctorDOS.size()==0){
 | 
	
		
			
				|  |  |             String failMsg = "紧急救助服务项服务医生为空,不可发起救助";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
	
		
			
				|  | @ -112,7 +114,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |                 distance = distanceTmp;
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctor(doctorDO.getId());
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctorName(doctorDO.getName());
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctorAddress("");
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctorAddress(doctorDO.getDoctorLocateAddress());
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctorLon(doctorDO.getDoctorLon());
 | 
	
		
			
				|  |  |                 assistanceDO.setDoctorLat(doctorDO.getDoctorLat());
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -133,11 +135,6 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |         return getOrderDetail(assistanceDO.getId());
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 救助工单详情
 | 
	
		
			
				|  |  |      * @param orderID
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject getOrderDetail(String orderID){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderID);
 | 
	
	
		
			
				|  | @ -147,17 +144,98 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<BaseDoctorDO> doctorDOS = baseTeamMemberDao.findAllMembers(assistanceDO.getTeamCode());
 | 
	
		
			
				|  |  |         double distance = 0.0;
 | 
	
		
			
				|  |  |         JSONArray otherDoctorDistance = new JSONArray();
 | 
	
		
			
				|  |  |         JSONObject otherDoctorDistanceObj = new JSONObject();
 | 
	
		
			
				|  |  |         for (BaseDoctorDO doctorDO:doctorDOS){
 | 
	
		
			
				|  |  |             if (StringUtils.isBlank(doctorDO.getDoctorLat())||StringUtils.isBlank(doctorDO.getDoctorLon())){
 | 
	
		
			
				|  |  |                 continue;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
 | 
	
		
			
				|  |  |             if (doctorDO.getId().equals(assistanceDO.getDoctor())){//服务医生
 | 
	
		
			
				|  |  |                 assistanceDO.setDistance(distance);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else {
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("doctor",doctorDO.getId());
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("doctorName",doctorDO.getName());
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("doctorAddress",doctorDO.getDoctorLocateAddress());
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("doctorLon",doctorDO.getDoctorLon());
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("doctorLat",doctorDO.getDoctorLat());
 | 
	
		
			
				|  |  |                 otherDoctorDistanceObj.put("distance",distanceTmp);
 | 
	
		
			
				|  |  |                 otherDoctorDistance.add(otherDoctorDistanceObj);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         assistanceDO.setOtherDoctorDistance(otherDoctorDistance.toJSONString());
 | 
	
		
			
				|  |  |         BasePatientDO patientDO = patientDao.findById(assistanceDO.getPatient());
 | 
	
		
			
				|  |  |         assistanceDO.setPatientPhoto(patientDO.getPhoto());
 | 
	
		
			
				|  |  |         assistanceDO.setPatientSex(patientDO.getSex());
 | 
	
		
			
				|  |  |         assistanceDO.setPatientAge(IdCardUtil.getAgeForIdcard(patientDO.getIdcard()));
 | 
	
		
			
				|  |  |         double distance=countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(assistanceDO.getDoctorLat()),Double.parseDouble(assistanceDO.getDoctorLon()));
 | 
	
		
			
				|  |  |         assistanceDO.setDistance(distance);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg,JSONObject.parseObject(JSON.toJSONStringWithDateFormat(assistanceDO,"yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue)));
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 救助工单详情
 | 
	
		
			
				|  |  |      * @param orderID
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */ //医生无法查看已取消
 | 
	
		
			
				|  |  |     public JSONObject doctorGetOrderDetail(String orderID,String doctor){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BaseDoctorDO doctorDO = doctorDao.findById(doctor);
 | 
	
		
			
				|  |  |         if (doctorDO==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 = "当前救助工单不存在";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (assistanceDO.getStatus()==-1){
 | 
	
		
			
				|  |  |             String failMsg = "当前工单已取消 无法查看";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return getOrderDetail(orderID);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 救助工单详情
 | 
	
		
			
				|  |  |      * @param orderID
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      *///患者只能查看已完成
 | 
	
		
			
				|  |  |     public JSONObject patientGetOrderDetail(String orderID,String patient){
 | 
	
		
			
				|  |  |         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 = "当前救助工单不存在";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (assistanceDO.getStatus()!=0){
 | 
	
		
			
				|  |  |             String failMsg = "当前工单未完成 无法查看";
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return getOrderDetail(orderID);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 居民救助历史tab数量
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
	
		
			
				|  | @ -323,6 +401,7 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         else {
 | 
	
		
			
				|  |  |             doctorDO.setDoctorLocateAddress(doctorAddress);
 | 
	
		
			
				|  |  |             doctorDO.setDoctorLat(doctorLat);
 | 
	
		
			
				|  |  |             doctorDO.setDoctorLon(doctorLon);
 | 
	
		
			
				|  |  |             doctorDao.save(doctorDO);
 |