|
@ -0,0 +1,320 @@
|
|
|
|
package com.yihu.jw.care.service.assistance;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.yihu.jw.care.dao.assistance.EmergencyAssistanceDao;
|
|
|
|
import com.yihu.jw.care.dao.sign.ServicePackageSignRecordDao;
|
|
|
|
import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
|
|
|
|
import com.yihu.jw.care.util.CountDistance;
|
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
|
import com.yihu.jw.entity.care.assistance.EmergencyAssistanceDO;
|
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.print.DocFlavor;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Bing on 2021/4/12.
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistanceDO, EmergencyAssistanceDao> {
|
|
|
|
@Autowired
|
|
|
|
private EmergencyAssistanceDao emergencyAssistanceDao;
|
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
@Autowired
|
|
|
|
private BasePatientDao patientDao;
|
|
|
|
@Autowired
|
|
|
|
private ServicePackageSignRecordDao servicePackageSignRecordDao;
|
|
|
|
@Autowired
|
|
|
|
private BaseTeamMemberDao baseTeamMemberDao;
|
|
|
|
@Autowired
|
|
|
|
private CountDistance countDistance;
|
|
|
|
@Autowired
|
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新建居民紧急救助
|
|
|
|
* @param patient
|
|
|
|
* @param jsonData
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject newOrder(String patient,String jsonData){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
EmergencyAssistanceDO assistanceDO = JSON.parseObject(jsonData,EmergencyAssistanceDO.class);
|
|
|
|
BasePatientDO patientDO = patientDao.findById(patient);
|
|
|
|
if (patientDO==null){
|
|
|
|
String failMsg = "当前居民未存在,请先进行建档";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
assistanceDO.setPatient(patient);
|
|
|
|
assistanceDO.setPatientIdcard(patientDO.getIdcard());
|
|
|
|
assistanceDO.setPatientName(patientDO.getName());
|
|
|
|
assistanceDO.setPatientPhone(patientDO.getMobile());
|
|
|
|
|
|
|
|
if (emergencyAssistanceDao.findByPatientAndStatus(patient,1)!=null){
|
|
|
|
String failMsg = "当前居民存在申请中的救助,请完成后再申请";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
//签约防走失服务包
|
|
|
|
String sql ="SELECT i.code,team_code,org_code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i \n" +
|
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
|
"and sr.patient = '"+assistanceDO.getPatient()+"' and i.code='emergencyAssistance' ";
|
|
|
|
List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
|
|
|
|
if (items.size()==0){
|
|
|
|
String failMsg = "当前居民未签约紧急救助服务项,请先进行签约";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
Map<String,Object> mapTmp = items.get(0);
|
|
|
|
List<BaseDoctorDO> doctorDOS = baseTeamMemberDao.findAllMembers(mapTmp.get("team_code").toString());
|
|
|
|
if (doctorDOS.size()==0){
|
|
|
|
String failMsg = "紧急救助服务项服务医生为空,不可发起救助";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
//获取距离患者最近的一个医生
|
|
|
|
double distance = 0.0;
|
|
|
|
for (BaseDoctorDO doctorDO:doctorDOS){
|
|
|
|
double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
|
|
|
|
if (distanceTmp>distance){
|
|
|
|
distance = distanceTmp;
|
|
|
|
assistanceDO.setDoctor(doctorDO.getId());
|
|
|
|
assistanceDO.setDoctorName(doctorDO.getName());
|
|
|
|
assistanceDO.setDoctorAddress("");
|
|
|
|
assistanceDO.setDoctorLon(118.0388772928781+"");
|
|
|
|
assistanceDO.setDoctorLat(24.472242502394266+"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//创建im会话
|
|
|
|
|
|
|
|
// assistanceDO.setSessionId();
|
|
|
|
//向会话中发送一条 陈XX发起紧急救助
|
|
|
|
if (StringUtils.isNotBlank(assistanceDO.getSendMessage())){
|
|
|
|
//新建工单message不为空时 ,发送对应的消息
|
|
|
|
}
|
|
|
|
emergencyAssistanceDao.save(assistanceDO);
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,assistanceDO);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 救助工单详情
|
|
|
|
* @param orderID
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject getOrderDetail(String orderID){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderID);
|
|
|
|
if (assistanceDO==null){
|
|
|
|
String failMsg = "当前救助工单不存在";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
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,assistanceDO);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 居民救助历史tab数量
|
|
|
|
* @param patient
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject getTabStatusCounts(String patient){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
JSONObject tmpObj = new JSONObject();
|
|
|
|
tmpObj.put("status_-1",0);//已取消
|
|
|
|
tmpObj.put("status_0",0);//已完成
|
|
|
|
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" +
|
|
|
|
" and ord.patient='"+patient+"' group by ord.status ");
|
|
|
|
List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql.toString());
|
|
|
|
for (Map<String,Object> map:sqlResult){
|
|
|
|
tmpObj.put("status_"+map.get("status"),map.get("count"));
|
|
|
|
}
|
|
|
|
Integer All = 0;
|
|
|
|
Set<String> keySet = tmpObj.keySet();
|
|
|
|
for (String key : keySet){
|
|
|
|
All+=tmpObj.getInteger(key);
|
|
|
|
}
|
|
|
|
tmpObj.put("all",All);
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,tmpObj);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JSONObject existApplyStatus(String patient){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
JSONObject tmpObj = new JSONObject();
|
|
|
|
EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findByPatientAndStatus(patient,1);
|
|
|
|
if (assistanceDO==null){
|
|
|
|
tmpObj.put("exist","false");
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,tmpObj);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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);
|
|
|
|
tmpObj.put("exist","true");
|
|
|
|
tmpObj.put("assistanceDO",assistanceDO);
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,tmpObj);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查看居民救助历史记录
|
|
|
|
* @param patient
|
|
|
|
* @param doctor
|
|
|
|
* @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+"' ");
|
|
|
|
}
|
|
|
|
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 JSONObject cancelOrder(String patient,String orderId){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
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.getPatient().equals(patient)){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
assistanceDO.setStatus(-1);
|
|
|
|
assistanceDO.setUpdateUser(patient);
|
|
|
|
assistanceDO.setUpdateUserName(assistanceDO.getPatientName());
|
|
|
|
assistanceDO.setUpdateTime(new Date());
|
|
|
|
//im是否结束会话?
|
|
|
|
emergencyAssistanceDao.save(assistanceDO);
|
|
|
|
String failMsg = "当前救助工单已取消";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,assistanceDO);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param doctor
|
|
|
|
* @param orderId
|
|
|
|
* @param conclusion 必传
|
|
|
|
* @param conclusionImg 非必传
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject updateConclusion(String doctor,String orderId,String conclusion,String conclusionImg){
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderId);
|
|
|
|
if (assistanceDO==null){
|
|
|
|
String failMsg = "当前救助工单不存在,无法取消";
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
|
result.put(ResponseContant.resultMsg,failMsg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
assistanceDO.setConclusion(conclusion);
|
|
|
|
if (StringUtils.isNotBlank(conclusionImg)){
|
|
|
|
assistanceDO.setConclusionImg(conclusionImg);
|
|
|
|
}
|
|
|
|
assistanceDO.setStatus(0);
|
|
|
|
assistanceDO.setUpdateUser(doctor);
|
|
|
|
assistanceDO.setUpdateUserName(assistanceDO.getDoctorName());
|
|
|
|
assistanceDO.setUpdateTime(new Date());
|
|
|
|
//im会话是否结束?
|
|
|
|
return getOrderDetail(orderId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public JSONObject updateDoctorLocation(String doctor,String orderId,String doctorAddress,String doctorLat,String doctorLon){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
doctorDO.setDoctorLat(doctorLat);
|
|
|
|
doctorDO.setDoctorLon(doctorLon);
|
|
|
|
doctorDao.save(doctorDO);
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(orderId)){
|
|
|
|
EmergencyAssistanceDO assistanceDO = emergencyAssistanceDao.findOne(orderId);
|
|
|
|
if (assistanceDO!=null){
|
|
|
|
assistanceDO.setDoctorAddress(doctorAddress);
|
|
|
|
assistanceDO.setDoctorLat(doctorLat);
|
|
|
|
assistanceDO.setDoctorLon(doctorLon);
|
|
|
|
emergencyAssistanceDao.save(assistanceDO);
|
|
|
|
return getOrderDetail(orderId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
|
result.put(ResponseContant.resultMsg,null);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|