|
@ -0,0 +1,199 @@
|
|
|
package com.yihu.jw.care.service.consult;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.care.dao.sign.ServicePackageSignRecordDao;
|
|
|
import com.yihu.jw.care.service.sign.ServicePackageService;
|
|
|
import com.yihu.jw.entity.base.im.ConsultDo;
|
|
|
import com.yihu.jw.entity.base.im.ConsultTeamDo;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.dao.ConsultTeamDao;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.yihu.jw.rm.hospital.BaseHospitalRequestMapping.PatientIM.patientInfo;
|
|
|
|
|
|
/**
|
|
|
* Created by yeshijie on 2020/12/23.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ConsultTeamService {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private ConsultDao consultDao;
|
|
|
@Autowired
|
|
|
private ImUtil imUtill;
|
|
|
@Autowired
|
|
|
private ConsultTeamDao consultTeamDao;
|
|
|
@Autowired
|
|
|
private ServicePackageService servicePackageService;
|
|
|
@Autowired
|
|
|
private ServicePackageSignRecordDao servicePackageSignRecordDao;
|
|
|
|
|
|
|
|
|
public JSONObject updateIMMsg(String sessionId,String sessionType,String msgId,String content){
|
|
|
JSONObject result = new JSONObject();
|
|
|
if(StringUtils.isEmpty(sessionId) || StringUtils.isEmpty(sessionType) || StringUtils.isEmpty(msgId) || StringUtils.isEmpty(content)){
|
|
|
result.put("data", "参数【sessionId,sessionType,msgId,content】不可为空!");
|
|
|
result.put("status", -1);
|
|
|
return result ;
|
|
|
}
|
|
|
JSONObject contentJsonObj = null;
|
|
|
try{
|
|
|
contentJsonObj = JSONObject.parseObject(content);
|
|
|
}catch (Exception e){
|
|
|
result.put("status", -1);
|
|
|
result.put("data", "【content】必须是json格式:" + e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
String response = imUtill.updateMessage(sessionId,sessionType,msgId,content);
|
|
|
return JSONObject.parseObject(response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据咨询查关联业务记录
|
|
|
* @param code
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject queryByConsultCode(String code,Integer type){
|
|
|
JSONObject result = new JSONObject();
|
|
|
if(StringUtils.isEmpty(code) || null == type){
|
|
|
return null;
|
|
|
}
|
|
|
ConsultDo consult = consultDao.queryByIdAndType(code,type);
|
|
|
|
|
|
if(null == consult){
|
|
|
result.put("data", "");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
switch (type) {
|
|
|
case 20:
|
|
|
// WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(consult.getRelationCode());
|
|
|
// JSONObject patientInfo = wlyyDoorServiceOrderService.queryOrderCardInfo(orderDO);
|
|
|
result.put("data", patientInfo);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if(null == result.get("data")){
|
|
|
result.put("data", consult);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加一条咨询记录
|
|
|
* @param patient 患者信息
|
|
|
* @param title 咨询标题
|
|
|
* @param type 咨询类型:20 紧急救助咨询
|
|
|
* @return
|
|
|
*/
|
|
|
public ConsultDo addConsult(String patient, String title, String symptoms, String images, int type) {
|
|
|
ConsultDo consult = new ConsultDo();
|
|
|
consult.setCzrq(new Date());
|
|
|
consult.setDel("1");
|
|
|
consult.setPatient(patient);
|
|
|
consult.setTitle(title);
|
|
|
consult.setSymptoms(symptoms);
|
|
|
consult.setImages(images);
|
|
|
consult.setType(type);
|
|
|
return consultDao.save(consult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加紧急救助咨询
|
|
|
* @param orderId
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject addServiceConsult(String orderId,String patient,String symptoms) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
// 判断居民是否已经签约
|
|
|
List<ServicePackageSignRecordDO> signRecordDOs = servicePackageSignRecordDao.findByStatusAndPatient(1,patient);
|
|
|
if(signRecordDOs.size() == 0){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前居民未签约,无法进行紧急救助咨询!";
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 添加咨询记录
|
|
|
BasePatientDO patientDO = patientDao.findById(patient);
|
|
|
if(null == patientDO){
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
String failMsg = "当前咨询的居民不存在!";
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//咨询记录
|
|
|
String title = patientDO.getName() + "-发起了服务咨询";
|
|
|
ConsultDo consult = addConsult(patient,title,symptoms,patientDO.getPhone(),20);
|
|
|
|
|
|
//咨询详细信息
|
|
|
ConsultTeamDo consultTeam = new ConsultTeamDo();
|
|
|
consultTeam.setType(20); //紧急救助咨询
|
|
|
// consultTeam.setAdminTeamId(signFamily.getAdminTeamId());
|
|
|
consultTeam.setRelationCode(orderId); //关联业务code
|
|
|
consultTeam.setSymptoms(symptoms);
|
|
|
consultTeam.setPatient(patient);
|
|
|
consultTeam.setName(patientDO.getName());
|
|
|
consultTeam.setBirthday(patientDO.getBirthday());
|
|
|
consultTeam.setSex(patientDO.getSex());
|
|
|
consultTeam.setPhoto(patientDO.getPhoto());
|
|
|
consultTeam.setCzrq(new Date());
|
|
|
consultTeam.setDel("1");
|
|
|
consultTeam.setStatus(0);
|
|
|
consultTeam.setEvaluate(0);
|
|
|
consultTeam.setDoctorRead(1); // 医生未读数量为1
|
|
|
consult.setRelationCode(orderId);//关联业务code
|
|
|
consultTeam.setConsult(consult.getId()); // 设置咨询标识
|
|
|
|
|
|
//(im创建咨询) 紧急救助咨询的sessionid为居民code+咨询类型
|
|
|
String sessionId = patient + "_" + consult.getId() + "_" + consultTeam.getType();
|
|
|
|
|
|
//4、 紧急救助咨询-参与者
|
|
|
JSONObject participants = new JSONObject();
|
|
|
participants.put(patient, 0);
|
|
|
//加入团队医生
|
|
|
List<Map<String,Object>> doctorList = servicePackageService.fingdDoctorByPaitenId(patient,"emergencyAssistance");
|
|
|
for(Map<String,Object> map:doctorList){
|
|
|
participants.put(String.valueOf(map.get("id")), 0);
|
|
|
}
|
|
|
|
|
|
String content = patientDO.getName() + "-紧急救助咨询";
|
|
|
JSONObject messages = imUtill.getCreateTopicMessage(patient, patientDO.getName(), consult.getTitle(), content, consult.getImages(), "");
|
|
|
|
|
|
JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getId(), content, participants, messages, ImUtil.SESSION_TYPE_EMERGENCY_ASSISTANCE);
|
|
|
if (imResponseJson == null || imResponseJson.getInteger("status") == -1) {
|
|
|
String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, failMsg);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
consultTeam.setStartMsgId(imResponseJson.get("start_msg_id").toString());
|
|
|
consultTeamDao.save(consultTeam);
|
|
|
consultDao.save(consult);
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, consultTeam);
|
|
|
return result;
|
|
|
}
|
|
|
}
|