|
@ -1,18 +1,39 @@
|
|
|
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.hospital.prescription.dao.*;
|
|
|
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionDiagnosisVO;
|
|
|
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
|
|
|
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 io.swagger.annotations.ApiParam;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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 org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 处方状态变更
|
|
|
* 处方状态更新job
|
|
|
* Created by zdm on 2019/7/20.
|
|
|
* 互联网医院线上下处方之后保存到中山医院的临时表-(中山医院正式下处方,审核成功之后保存,审核失败不保存)-审核成功之后药房发药,回调互联网医院。
|
|
|
* 在正式下处方的时候,互联网医院每两分钟到中山医院获取处方详情:
|
|
|
* 1、若是可以正常查询且状态为审方成功,则只需要变更状态,调用im消息通知居民
|
|
|
* 2、若可以正常查询处方,状态为失败,则需要将状态改为失败,并根据处方号重新获取新的处方直到成功为止。
|
|
|
* 3、若根据处方号查询不到处方,则需要根据门诊就诊记录(有就诊次数的数据)获取处方号,再获取处方状态重复1、2
|
|
|
*/
|
|
|
@Component
|
|
|
@Transactional
|
|
@ -20,50 +41,176 @@ public class PrescriptionStatusUpdateService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(PrescriptionStatusUpdateService.class);
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Value("${hlwyyEntrance.url}")
|
|
|
private String hlwyyEntranceUrl;
|
|
|
@Autowired
|
|
|
private PrescriptionDao prescriptionDao;
|
|
|
@Autowired
|
|
|
private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
|
|
|
@Autowired
|
|
|
private PrescriptionInfoDao prescriptionInfoDao;
|
|
|
@Autowired
|
|
|
private OutpatientDao outpatientDao;
|
|
|
|
|
|
public void autoPush() throws Exception{
|
|
|
logger.info("job执行中++++++++++++++++++++++++");
|
|
|
//获取所有未结束处方
|
|
|
String sql = "SELECT a.id ,a.start_time,a.end_time FROM wlyy.wlyy_channel_recommend_article a WHERE a.del_flag>0 AND a.type=2";
|
|
|
//获取所有就诊中已挂号、已下临时处方、并且未结束的处方
|
|
|
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 " +
|
|
|
"LEFT JOIN base.wlyy_prescription pre on o.id=pre.outpatient_id WHERE o.status=1 AND o.con_no IS NOT NULL AND pre.real_order IS NOT NULL ";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
//处方号
|
|
|
String realOrder=String.valueOf(map.get("real_order"));
|
|
|
//门诊就诊唯一号
|
|
|
String admNo=String.valueOf(map.get("adm_no"));
|
|
|
//第三方居民唯一号
|
|
|
String patientMappingCode=String.valueOf(map.get("mapping_code"));
|
|
|
//中山医院居民就诊次数
|
|
|
String conNo=String.valueOf(map.get("con_no"));
|
|
|
//处方原状态
|
|
|
String status=String.valueOf(map.get("status"));
|
|
|
//处方Id
|
|
|
String preId=String.valueOf(map.get("preId"));
|
|
|
//门诊记录Id
|
|
|
String outPatientId=String.valueOf(map.get("id"));
|
|
|
|
|
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
// //获取当前时间
|
|
|
// String dateString = format.format(new Date());
|
|
|
// Date now = DateUtil.strToDate(dateString,"yyyy-MM-dd HH:mm:ss");
|
|
|
// //获取自动推送的时间列表
|
|
|
// String sql = "SELECT a.id ,a.start_time,a.end_time FROM wlyy.wlyy_channel_recommend_article a WHERE a.del_flag>0 AND a.type=2";
|
|
|
// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
// for (Map<String, Object> map : list) {
|
|
|
// String id=String.valueOf(map.get("id"));
|
|
|
// if(map.get("start_time") !=null && map.get("end_time")!=null) {
|
|
|
// //开始时间
|
|
|
// Date startTime = DateUtil.strToDate(map.get("start_time") + "", "yyyy-MM-dd HH:mm:ss");
|
|
|
// //结束时间
|
|
|
// Date endTime = DateUtil.strToDate(map.get("end_time") + "", "yyyy-MM-dd HH:mm:ss");
|
|
|
//
|
|
|
// int startEqual = now.compareTo(startTime);
|
|
|
// int endEqual = now.compareTo(endTime);
|
|
|
//
|
|
|
// if (endEqual >= 0) {
|
|
|
// //当前时间>=结束时间 状态变更为失效
|
|
|
// updateChannelStatusById(id, 0);
|
|
|
// }else if (startEqual == 2 ) {
|
|
|
// //-1删除,0失效,1生效,2未生效
|
|
|
// //当前时间>=起始时间 状态变更为生效
|
|
|
// updateChannelStatusById(id, 1);
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
/* public void updateChannelStatusById(String id,Integer status){
|
|
|
String countSql = "update wlyy.wlyy_channel_recommend_article wp SET wp.del_flag="+status+" ,wp.last_update_time=NOW() WHERE wp.id='"+id+"'";
|
|
|
jdbcTemplate.update(countSql);
|
|
|
}*/
|
|
|
//根据处方号获取处方状态
|
|
|
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);
|
|
|
//若用处方号获取处方为空,则需要使用居民编号及门诊就诊唯一号查询
|
|
|
if(null==wlyyPrescriptionVOS){
|
|
|
preExistFlag=false;
|
|
|
params.remove("realOrder");
|
|
|
wlyyPrescriptionVOS= getWlyyPrescriptionVO(params);
|
|
|
}
|
|
|
//根据处方id获取处方详情
|
|
|
WlyyPrescriptionDO wlyyPrescriptionDO=prescriptionDao.findOne(preId);
|
|
|
//根据门诊id获取门诊记录:如果处方状态为已完成,需要将门诊状态改为已诊
|
|
|
WlyyOutpatientDO wlyyOutpatientDO=outpatientDao.findById(outPatientId);
|
|
|
if(null!=wlyyPrescriptionVOS){
|
|
|
//如果状态为100,门诊记录需要变更为结束
|
|
|
WlyyPrescriptionVO wlyyPrescriptionVO=wlyyPrescriptionVOS.get(0);
|
|
|
wlyyPrescriptionDO.setStatus(wlyyPrescriptionVO.getStatus());
|
|
|
//用处方号获取不到处方时,重新更新处方到本地
|
|
|
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);
|
|
|
}
|
|
|
if(100==wlyyPrescriptionVO.getStatus()){
|
|
|
wlyyOutpatientDO.setStatus("2");
|
|
|
}
|
|
|
outpatientDao.save(wlyyOutpatientDO);
|
|
|
prescriptionDao.save(wlyyPrescriptionDO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取处方详情
|
|
|
* @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){
|
|
|
logger.info("result:"+listEnvelop.getDetailModelList());
|
|
|
List<WlyyPrescriptionVO> wlyyPrescriptionVOS=listEnvelop.getDetailModelList();
|
|
|
return wlyyPrescriptionVOS;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|