|
@ -2,11 +2,9 @@ package com.yihu.jw.service.channel;
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.*;
|
|
|
import com.yihu.jw.hospital.prescription.dao.*;
|
|
|
import com.yihu.jw.hospital.prescription.service.PrescriptionLogService;
|
|
|
import com.yihu.jw.im.service.ImService;
|
|
|
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionDiagnosisVO;
|
|
|
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
|
|
@ -14,6 +12,7 @@ import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
|
|
|
import com.yihu.jw.restmodel.web.ListEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.status.EnvelopStatus;
|
|
|
import com.yihu.jw.util.http.HttpUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -21,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -50,8 +50,12 @@ public class PrescriptionStatusUpdateService {
|
|
|
private OutpatientDao outpatientDao;
|
|
|
@Autowired
|
|
|
private ImService imService;
|
|
|
@Autowired
|
|
|
private PrescriptionLogService prescriptionLogService;
|
|
|
|
|
|
public void autoPush() throws Exception{
|
|
|
public void autoPush() throws Exception {
|
|
|
|
|
|
logger.info("autoPush start");
|
|
|
//获取所有就诊中已挂号、已下临时处方、并且未结束的处方
|
|
|
String sql = "SELECT o.id,o.con_no,o.register_no,p.mapping_code,pre.adm_no,pre.real_order,pre.id preId,pre.dispensary_type,pre.status " +
|
|
|
"FROM base.wlyy_outpatient o LEFT JOIN base.wlyy_patient_mapping p ON o.patient=p.patient " +
|
|
@ -60,45 +64,53 @@ public class PrescriptionStatusUpdateService {
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
//处方号
|
|
|
String realOrder=String.valueOf(map.get("real_order"));
|
|
|
String realOrder = String.valueOf(map.get("real_order"));
|
|
|
//门诊就诊唯一号
|
|
|
String admNo=String.valueOf(map.get("adm_no"));
|
|
|
String admNo = String.valueOf(map.get("adm_no"));
|
|
|
//第三方居民唯一号
|
|
|
String patientMappingCode=String.valueOf(map.get("mapping_code"));
|
|
|
String patientMappingCode = String.valueOf(map.get("mapping_code"));
|
|
|
//中山医院居民就诊次数
|
|
|
String conNo=String.valueOf(map.get("con_no"));
|
|
|
String conNo = String.valueOf(map.get("con_no"));
|
|
|
//处方原状态
|
|
|
String status=String.valueOf(map.get("status"));
|
|
|
String status = String.valueOf(map.get("status"));
|
|
|
//处方Id
|
|
|
String preId=String.valueOf(map.get("preId"));
|
|
|
String preId = String.valueOf(map.get("preId"));
|
|
|
//门诊记录Id
|
|
|
String outPatientId=String.valueOf(map.get("id"));
|
|
|
String outPatientId = String.valueOf(map.get("id"));
|
|
|
|
|
|
//根据处方号获取处方状态
|
|
|
Map<String, Object> params =new HashMap<>();
|
|
|
params.put("registerSn",null);
|
|
|
params.put("patNo",patientMappingCode);
|
|
|
params.put("admNo",admNo);
|
|
|
params.put("realOrder",realOrder);
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("registerSn", null);
|
|
|
params.put("patNo", patientMappingCode);
|
|
|
params.put("admNo", admNo);
|
|
|
params.put("realOrder", realOrder);
|
|
|
//判断处方是否存在
|
|
|
boolean preExistFlag=true;
|
|
|
List<WlyyPrescriptionVO> wlyyPrescriptionVOS= getWlyyPrescriptionVO(params);
|
|
|
boolean preExistFlag = true;
|
|
|
List<WlyyPrescriptionVO> wlyyPrescriptionVOS = getWlyyPrescriptionVO(params);
|
|
|
//若用处方号获取处方为空,则需要使用居民编号及门诊就诊唯一号查询
|
|
|
if(null==wlyyPrescriptionVOS){
|
|
|
preExistFlag=false;
|
|
|
if (null == wlyyPrescriptionVOS) {
|
|
|
preExistFlag = false;
|
|
|
params.remove("realOrder");
|
|
|
wlyyPrescriptionVOS= getWlyyPrescriptionVO(params);
|
|
|
wlyyPrescriptionVOS = getWlyyPrescriptionVO(params);
|
|
|
}
|
|
|
|
|
|
//根据处方id获取处方详情
|
|
|
WlyyPrescriptionDO wlyyPrescriptionDO=prescriptionDao.findOne(preId);
|
|
|
WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(preId);
|
|
|
//根据门诊id获取门诊记录:如果处方状态为已完成,需要将门诊状态改为已诊
|
|
|
WlyyOutpatientDO wlyyOutpatientDO=outpatientDao.findById(outPatientId);
|
|
|
if(null!=wlyyPrescriptionVOS){
|
|
|
ObjectMapper objectMapper=new ObjectMapper();
|
|
|
WlyyPrescriptionVO wlyyPrescriptionVO=objectMapper.convertValue(wlyyPrescriptionVOS.get(0),WlyyPrescriptionVO.class);
|
|
|
//如果状态为100,门诊记录需要变更为结束
|
|
|
// wlyyPrescriptionVOS.get(0);
|
|
|
wlyyPrescriptionDO.setStatus(wlyyPrescriptionVO.getStatus());
|
|
|
WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outPatientId);
|
|
|
|
|
|
if (null != wlyyPrescriptionVOS) {
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
WlyyPrescriptionVO wlyyPrescriptionVO = objectMapper.convertValue(wlyyPrescriptionVOS.get(0), WlyyPrescriptionVO.class);
|
|
|
|
|
|
//如果处方状态一致,则不做操作
|
|
|
if (wlyyPrescriptionDO.getStatus() != wlyyPrescriptionVO.getStatus()) {
|
|
|
return;
|
|
|
}
|
|
|
//存储处方操作日志
|
|
|
prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(),wlyyPrescriptionDO.getStatus(),2, wlyyPrescriptionDO.getDoctor(), wlyyPrescriptionDO.getDoctorName(),"", new Date());
|
|
|
|
|
|
//调用im发送模板消息
|
|
|
/**
|
|
|
* 续方取消:-3 支付过期取消,-2 患者自己取消 ,-1 医生取消
|
|
@ -109,128 +121,143 @@ public class PrescriptionStatusUpdateService {
|
|
|
* 已完成:100 已完成/未评价 ,101 已完成已经评价
|
|
|
*/
|
|
|
try {
|
|
|
if(13<wlyyPrescriptionVO.getStatus()){
|
|
|
if (13 < wlyyPrescriptionVO.getStatus() && wlyyPrescriptionDO.getStatus() < 20) {
|
|
|
logger.info("autoPush imService send");
|
|
|
imService.pushPrescriptionImMessage(wlyyPrescriptionVO);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("im异常:"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
logger.error("im异常:" + e.getMessage());
|
|
|
}
|
|
|
//用处方号获取不到处方时,重新更新处方到本地
|
|
|
if(!preExistFlag){
|
|
|
//删除原有药品信息
|
|
|
List<WlyyPrescriptionInfoDO> oldInfos = prescriptionInfoDao.findByPrescriptionId(preId);
|
|
|
if(oldInfos!=null&&oldInfos.size()>0){
|
|
|
prescriptionInfoDao.delete(oldInfos);
|
|
|
}
|
|
|
//删除之前诊断
|
|
|
List<WlyyPrescriptionDiagnosisDO> ds = prescriptionDiagnosisDao.findByPrescriptionId(preId);
|
|
|
if(ds!=null&&ds.size()>0){
|
|
|
prescriptionDiagnosisDao.delete(ds);
|
|
|
}
|
|
|
String Icd10 = "";
|
|
|
String Icd10Name = "";
|
|
|
List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS=new ArrayList<>();
|
|
|
for(WlyyPrescriptionDiagnosisVO diagnosisVO:wlyyPrescriptionVO.getDiagnosisVOs()){
|
|
|
WlyyPrescriptionDiagnosisDO diagnosisDO=new WlyyPrescriptionDiagnosisDO();
|
|
|
//将诊断拼接放到门诊记录中
|
|
|
if("1".equals(diagnosisVO.getType())){
|
|
|
Icd10 = diagnosisVO.getCode()+","+Icd10;
|
|
|
Icd10Name+=diagnosisVO.getName()+","+Icd10Name;
|
|
|
}else {
|
|
|
Icd10+=diagnosisVO.getCode()+",";
|
|
|
Icd10Name+=diagnosisVO.getName()+",";
|
|
|
}
|
|
|
diagnosisDO.setCode(diagnosisVO.getCode());
|
|
|
diagnosisDO.setName(diagnosisVO.getName());
|
|
|
diagnosisDO.setType(diagnosisVO.getType());
|
|
|
diagnosisDO.setPrescriptionId(preId);
|
|
|
diagnosisDO.setCreateTime(new Date());
|
|
|
wlyyPrescriptionDiagnosisDOS.add(diagnosisDO);
|
|
|
}
|
|
|
//重新保存诊断
|
|
|
prescriptionDiagnosisDao.save(wlyyPrescriptionDiagnosisDOS);
|
|
|
//药品更新
|
|
|
List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS=new ArrayList<>();
|
|
|
for(WlyyPrescriptionInfoVO infoVO:wlyyPrescriptionVO.getInfoVOs()){
|
|
|
WlyyPrescriptionInfoDO infoDO=new WlyyPrescriptionInfoDO();
|
|
|
//处方code 关联表wlyy_prescription code
|
|
|
infoDO.setPrescriptionId(preId);
|
|
|
//药品编号
|
|
|
infoDO.setDrugNo(infoVO.getDrugNo());
|
|
|
//药品名称
|
|
|
infoDO.setDrugName(infoVO.getDrugName());
|
|
|
//库房号
|
|
|
infoDO.setDispDeposite(infoVO.getDispDeposite());
|
|
|
// 药量
|
|
|
infoDO.setDosage(infoVO.getDosage());
|
|
|
//数量
|
|
|
infoDO.setQuantity(infoVO.getQuantity());
|
|
|
//单位
|
|
|
infoDO.setUnit(infoVO.getUnit());
|
|
|
//單位名稱
|
|
|
infoDO.setUnitName(infoVO.getUnitName());
|
|
|
//包装单位
|
|
|
infoDO.setPackUnit(infoVO.getPackUnit());
|
|
|
//包装单位名称
|
|
|
infoDO.setPackUnitName(infoVO.getPackUnitName());
|
|
|
// 用法
|
|
|
infoDO.setSupplyCode(infoVO.getSupplyCode());
|
|
|
//用法名稱
|
|
|
infoDO.setSupplyName(infoVO.getSupplyName());
|
|
|
//天数
|
|
|
infoDO.setDays(infoVO.getDays());
|
|
|
//组号
|
|
|
infoDO.setFrequency(infoVO.getFrequency());
|
|
|
//药品收费码
|
|
|
infoDO.setSerial(infoVO.getSerial());
|
|
|
//库房号
|
|
|
infoDO.setGroupNo(infoVO.getGroupNo());
|
|
|
//规格
|
|
|
infoDO.setSpecification(infoVO.getSpecification());
|
|
|
// 1可用 0删除
|
|
|
infoDO.setDel(1);
|
|
|
//频率
|
|
|
infoDO.setUsageCode(infoVO.getUsageCode());
|
|
|
//頻率名稱
|
|
|
infoDO.setUsageName(infoVO.getUsageName());
|
|
|
//包装价格
|
|
|
infoDO.setPackRetprice(infoVO.getPackRetprice());
|
|
|
wlyyPrescriptionInfoDOS.add(infoDO);
|
|
|
}
|
|
|
prescriptionInfoDao.save(wlyyPrescriptionInfoDOS);
|
|
|
|
|
|
Icd10 = Icd10.substring(0,Icd10.length()-1);
|
|
|
Icd10Name = Icd10Name.substring(0,Icd10Name.length()-1);
|
|
|
wlyyOutpatientDO.setIcd10(Icd10);
|
|
|
wlyyOutpatientDO.setIcd10Name(Icd10Name);
|
|
|
|
|
|
//his处方变更时,会删除原本处方,重新更新处方到本地
|
|
|
if (!preExistFlag) {
|
|
|
updatePrescriptionInfo(preId,wlyyPrescriptionVO,wlyyOutpatientDO);
|
|
|
}
|
|
|
if(100==wlyyPrescriptionVO.getStatus()){
|
|
|
//更改门诊状态为已经检查
|
|
|
if (100 == wlyyPrescriptionVO.getStatus()) {
|
|
|
wlyyOutpatientDO.setStatus("2");
|
|
|
}
|
|
|
outpatientDao.save(wlyyOutpatientDO);
|
|
|
|
|
|
//更新处方状态记录
|
|
|
wlyyPrescriptionDO.setStatus(wlyyPrescriptionVO.getStatus());
|
|
|
prescriptionDao.save(wlyyPrescriptionDO);
|
|
|
}
|
|
|
}
|
|
|
logger.info("autoPush end");
|
|
|
}
|
|
|
|
|
|
public void updatePrescriptionInfo(String preId, WlyyPrescriptionVO wlyyPrescriptionVO, WlyyOutpatientDO wlyyOutpatientDO) {
|
|
|
|
|
|
logger.info("autoPush updatePrescriptionInfo ");
|
|
|
//删除原有药品信息
|
|
|
List<WlyyPrescriptionInfoDO> oldInfos = prescriptionInfoDao.findByPrescriptionId(preId);
|
|
|
if (oldInfos != null && oldInfos.size() > 0) {
|
|
|
prescriptionInfoDao.delete(oldInfos);
|
|
|
}
|
|
|
//删除之前诊断
|
|
|
List<WlyyPrescriptionDiagnosisDO> ds = prescriptionDiagnosisDao.findByPrescriptionId(preId);
|
|
|
if (ds != null && ds.size() > 0) {
|
|
|
prescriptionDiagnosisDao.delete(ds);
|
|
|
}
|
|
|
String Icd10 = "";
|
|
|
String Icd10Name = "";
|
|
|
List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS = new ArrayList<>();
|
|
|
for (WlyyPrescriptionDiagnosisVO diagnosisVO : wlyyPrescriptionVO.getDiagnosisVOs()) {
|
|
|
WlyyPrescriptionDiagnosisDO diagnosisDO = new WlyyPrescriptionDiagnosisDO();
|
|
|
//将诊断拼接放到门诊记录中
|
|
|
if ("1".equals(diagnosisVO.getType())) {
|
|
|
Icd10 = diagnosisVO.getCode() + "," + Icd10;
|
|
|
Icd10Name += diagnosisVO.getName() + "," + Icd10Name;
|
|
|
} else {
|
|
|
Icd10 += diagnosisVO.getCode() + ",";
|
|
|
Icd10Name += diagnosisVO.getName() + ",";
|
|
|
}
|
|
|
diagnosisDO.setCode(diagnosisVO.getCode());
|
|
|
diagnosisDO.setName(diagnosisVO.getName());
|
|
|
diagnosisDO.setType(diagnosisVO.getType());
|
|
|
diagnosisDO.setPrescriptionId(preId);
|
|
|
diagnosisDO.setCreateTime(new Date());
|
|
|
wlyyPrescriptionDiagnosisDOS.add(diagnosisDO);
|
|
|
}
|
|
|
//重新保存诊断
|
|
|
prescriptionDiagnosisDao.save(wlyyPrescriptionDiagnosisDOS);
|
|
|
//药品更新
|
|
|
List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = new ArrayList<>();
|
|
|
for (WlyyPrescriptionInfoVO infoVO : wlyyPrescriptionVO.getInfoVOs()) {
|
|
|
WlyyPrescriptionInfoDO infoDO = new WlyyPrescriptionInfoDO();
|
|
|
//处方code 关联表wlyy_prescription code
|
|
|
infoDO.setPrescriptionId(preId);
|
|
|
//药品编号
|
|
|
infoDO.setDrugNo(infoVO.getDrugNo());
|
|
|
//药品名称
|
|
|
infoDO.setDrugName(infoVO.getDrugName());
|
|
|
//库房号
|
|
|
infoDO.setDispDeposite(infoVO.getDispDeposite());
|
|
|
// 药量
|
|
|
infoDO.setDosage(infoVO.getDosage());
|
|
|
//数量
|
|
|
infoDO.setQuantity(infoVO.getQuantity());
|
|
|
//单位
|
|
|
infoDO.setUnit(infoVO.getUnit());
|
|
|
//單位名稱
|
|
|
infoDO.setUnitName(infoVO.getUnitName());
|
|
|
//包装单位
|
|
|
infoDO.setPackUnit(infoVO.getPackUnit());
|
|
|
//包装单位名称
|
|
|
infoDO.setPackUnitName(infoVO.getPackUnitName());
|
|
|
// 用法
|
|
|
infoDO.setSupplyCode(infoVO.getSupplyCode());
|
|
|
//用法名稱
|
|
|
infoDO.setSupplyName(infoVO.getSupplyName());
|
|
|
//天数
|
|
|
infoDO.setDays(infoVO.getDays());
|
|
|
//组号
|
|
|
infoDO.setFrequency(infoVO.getFrequency());
|
|
|
//药品收费码
|
|
|
infoDO.setSerial(infoVO.getSerial());
|
|
|
//库房号
|
|
|
infoDO.setGroupNo(infoVO.getGroupNo());
|
|
|
//规格
|
|
|
infoDO.setSpecification(infoVO.getSpecification());
|
|
|
// 1可用 0删除
|
|
|
infoDO.setDel(1);
|
|
|
//频率
|
|
|
infoDO.setUsageCode(infoVO.getUsageCode());
|
|
|
//頻率名稱
|
|
|
infoDO.setUsageName(infoVO.getUsageName());
|
|
|
//包装价格
|
|
|
infoDO.setPackRetprice(infoVO.getPackRetprice());
|
|
|
wlyyPrescriptionInfoDOS.add(infoDO);
|
|
|
}
|
|
|
prescriptionInfoDao.save(wlyyPrescriptionInfoDOS);
|
|
|
|
|
|
Icd10 = Icd10.substring(0, Icd10.length() - 1);
|
|
|
Icd10Name = Icd10Name.substring(0, Icd10Name.length() - 1);
|
|
|
wlyyOutpatientDO.setIcd10(Icd10);
|
|
|
wlyyOutpatientDO.setIcd10Name(Icd10Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取处方详情
|
|
|
*
|
|
|
* @param params
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public List<WlyyPrescriptionVO> getWlyyPrescriptionVO(Map<String, Object> params)throws Exception{
|
|
|
//根据处方号获取处方状态
|
|
|
String result= HttpUtils.doGet(hlwyyEntranceUrl+"/mqsdk/BS16017",params).getContent();
|
|
|
ObjectMapper objectMapper=new ObjectMapper();
|
|
|
ListEnvelop listEnvelop=objectMapper.readValue(result,ListEnvelop.class);
|
|
|
if(null!=listEnvelop&& EnvelopStatus.success.code.equals(listEnvelop.getStatus())&&null!=listEnvelop.getDetailModelList()&&listEnvelop.getDetailModelList().size()>0){
|
|
|
public List<WlyyPrescriptionVO> getWlyyPrescriptionVO(Map<String, Object> params) throws Exception {
|
|
|
//根据处方号获取处方状态
|
|
|
String result = HttpUtils.doGet(hlwyyEntranceUrl + "/mqsdk/BS16017", params).getContent();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
ListEnvelop listEnvelop = objectMapper.readValue(result, ListEnvelop.class);
|
|
|
if (null != listEnvelop && EnvelopStatus.success.code.equals(listEnvelop.getStatus()) && null != listEnvelop.getDetailModelList() && listEnvelop.getDetailModelList().size() > 0) {
|
|
|
// logger.info("result:"+listEnvelop.getDetailModelList());
|
|
|
List<WlyyPrescriptionVO> wlyyPrescriptionVOS=listEnvelop.getDetailModelList();
|
|
|
return wlyyPrescriptionVOS;
|
|
|
}
|
|
|
return null;
|
|
|
List<WlyyPrescriptionVO> wlyyPrescriptionVOS = listEnvelop.getDetailModelList();
|
|
|
return wlyyPrescriptionVOS;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|