123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- package com.diagbot.facade.data;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.dto.data.ABehospitalInfoDTO;
- import com.diagbot.entity.BehospitalInfo;
- import com.diagbot.entity.MedicalRecord;
- import com.diagbot.entity.QcType;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.facade.QcAbnormalFacade;
- import com.diagbot.facade.QcTypeFacade;
- import com.diagbot.service.impl.BehospitalInfoServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.StringUtil;
- import com.diagbot.util.TZDBConn;
- import com.diagbot.vo.data.ABehospitalInfoVO;
- import com.diagbot.vo.data.ADeleteFlagVO;
- import com.diagbot.vo.data.APlaceFileVO;
- import com.google.common.collect.Lists;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- import java.util.List;
- @Component
- public class ABehospitalInfoFacade extends BehospitalInfoServiceImpl {
- @Autowired
- @Qualifier("behospitalInfoServiceImpl")
- private BehospitalInfoServiceImpl behospitalInfoService;
- @Autowired
- private QcTypeFacade qcTypeFacade;
- @Autowired
- private AMedAbnormalInfoFacade aMedAbnormalInfoFacade;
- @Value("${log_switch.enable}")
- private boolean logSwitch;
- private TZDBConn tzDBConn = new TZDBConn();
- /**
- * 终末质控-同步前一天的入院记录
- */
- public void executeBehospital() {
- //String sql="select * from br_inpatientinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
- String sql="select * from br_inpatientinfo where cjcxrq>=(select CONVERT(varchar,GETDATE()-2,23)) and cjcxrq<(select CONVERT(varchar,GETDATE(),23)) ORDER BY cjcxrq DESC";
- List<BehospitalInfo> behospitalInfoList = tzDBConn.getBehospitalInfo(sql);
- execute(behospitalInfoList);
- }
- /**
- * 同步前一天的入院记录
- */
- public void executeBehospitalPast() {
- String sql="select * from br_inpatientinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
- List<BehospitalInfo> behospitalInfoList = tzDBConn.getBehospitalInfo(sql);
- execute(behospitalInfoList);
- }
- /**
- * 通过接口更新病人住院记录信息
- * @param list
- * @return
- */
- public RespDTO<List<ABehospitalInfoDTO>> executeBehospital(List<ABehospitalInfoVO> list) {
- try {
- if(list!=null && list.size()>0) {
- List<BehospitalInfo> behospitalInfoList = Lists.newArrayList();
- list.stream().forEach(s->{
- BehospitalInfo behospitalInfo=new BehospitalInfo();
- BeanUtil.copyProperties(s,behospitalInfo);
- if(StringUtil.isNotBlank(s.getBirthday())) {
- behospitalInfo.setBirthday(DateUtil.parseDate(s.getBirthday()));
- }
- if(StringUtil.isNotBlank(s.getLeaveHospitalDate())) {
- behospitalInfo.setLeaveHospitalDate(DateUtil.parseDateTime(s.getLeaveHospitalDate()));
- }
- if(StringUtil.isNotBlank(s.getBehospitalDate())){
- behospitalInfo.setBehospitalDate(DateUtil.parseDateTime(s.getBehospitalDate()));
- }
- if(StringUtil.isNotBlank(s.getPlacefileDate())){
- behospitalInfo.setPlacefileDate(DateUtil.parseDateTime(s.getPlacefileDate()));
- }
- behospitalInfoList.add(behospitalInfo);
- });
- //循环验证数据有效性
- for (BehospitalInfo behospitalInfo:behospitalInfoList) {
- if("".equals(behospitalInfo.getBehospitalCode())) {
- return RespDTO.onError("请输入病人住院编码!");
- }else if(behospitalInfo.getHospitalId()==null){
- return RespDTO.onError("请输入医院编码!");
- }else if("".equals(behospitalInfo.getBehDeptId())){
- return RespDTO.onError("请输入住院科室编码!");
- }else if("".equals(behospitalInfo.getBehDeptName())){
- return RespDTO.onError("请输入住院科室名称!");
- }
- }
- execute(behospitalInfoList);
- if(logSwitch){
- behospitalInfoList.forEach(s->{
- aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-正常","", JSON.toJSONString(list),"","");
- });
- }
- return RespDTO.onSuc("操作正常!");
- }else{
- return RespDTO.onError("未接收到数据!");
- }
- }catch (Exception e){
- log.error(e.getMessage(),e);
- aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-异常","", JSON.toJSONString(list),"",e.getMessage());
- return RespDTO.onError("数据处理异常,详情查看日志表");
- }
- }
- public void execute(List<BehospitalInfo> behospitalInfoList){
- List<BehospitalInfo> addE = Lists.newLinkedList();
- List<BehospitalInfo> updateE = Lists.newLinkedList();
- behospitalInfoList.stream().forEach(s -> {
- BehospitalInfo behospitalInfo = this.getOne(new QueryWrapper<BehospitalInfo>()
- .eq("behospital_code", s.getBehospitalCode())
- .eq("hospital_id", s.getHospitalId())
- .eq("is_deleted",IsDeleteEnum.N), false);
- if (behospitalInfo != null) {
- s.setGmtModified(new Date());
- s.setQcTypeId(initQcTypeId(s));
- updateE.add(s);
- } else {
- s.setGmtCreate(new Date());
- s.setQcTypeId(initQcTypeId(s));
- addE.add(s);
- }
- });
- if(addE.size()>0){
- behospitalInfoService.saveBatch(addE);
- }
- if(updateE.size()>0){
- behospitalInfoService.updateBatchByKey(updateE);
- }
- }
- /**
- * 初始化QcTypeId
- * @param s
- * @return
- */
- private Long initQcTypeId(BehospitalInfo s) {
- Long qcTypeId = Long.valueOf("0");
- //根据科室查找对应质控类型
- List<QcType> qcTypeList = qcTypeFacade.list(new QueryWrapper<QcType>()
- .eq("beh_dept_id", s.getBehDeptId())
- .eq("hospital_id", s.getHospitalId())
- .eq("is_deleted", IsDeleteEnum.N));
- if(qcTypeList == null || qcTypeList.size() == 0){
- //无质控类型时,新增后初始化
- QcType qcType = qcTypeFacade.getOne(new QueryWrapper<QcType>()
- .eq("default_module", 1)
- .eq("hospital_id", s.getHospitalId())
- .eq("is_deleted", IsDeleteEnum.N));
- qcTypeId = qcType.getId();
- } else if (qcTypeList.size() == 1) {
- qcTypeId = qcTypeList.get(0).getId();
- }else {
- //查找是否有性别区分质控类型
- for (QcType qcType:qcTypeList) {
- if (qcType.getSex().equals(s.getSex())) {
- qcTypeId = qcType.getId();
- }
- }
- }
- return qcTypeId;
- }
- public RespDTO deleteFlag(ADeleteFlagVO aDeleteFlagVO){
- try {
- //验证数据是否存在
- if(StringUtil.isEmpty(aDeleteFlagVO.getBehospitalCode())){
- return RespDTO.onError("请输入病人住院编码!");
- }else if(aDeleteFlagVO.getHospitalId()==null){
- return RespDTO.onError("请输入医院编码!");
- }else {
- UpdateWrapper<BehospitalInfo> updateWrapper=new UpdateWrapper<>();
- updateWrapper.eq("behospital_code", aDeleteFlagVO.getBehospitalCode())
- .eq("hospital_id", aDeleteFlagVO.getHospitalId())
- .eq("is_deleted",IsDeleteEnum.N)
- .set("is_deleted",IsDeleteEnum.Y)
- .set("gmt_modified", DateUtil.now());
- Boolean flag=update(new BehospitalInfo(),updateWrapper);
- //aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-删除",JSON.toJSONString(aDeleteFlagVO),"","删除成功!");
- return RespDTO.onSuc(flag);
- }
- }catch (Exception e){
- aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-删除","",JSON.toJSONString(aDeleteFlagVO),"",e.getMessage());
- return RespDTO.onError(e.getMessage());
- }
- }
- public RespDTO placeFileFlag(APlaceFileVO aPlaceFileVO){
- try {
- //验证数据是否存在
- if(StringUtil.isBlank(aPlaceFileVO.getBehospitalCode())){
- return RespDTO.onError("请输入病人住院编码!");
- }else if(aPlaceFileVO.getHospitalId()==null){
- return RespDTO.onError("请输入医院编码!");
- }else{
- UpdateWrapper<BehospitalInfo> updateWrapper=new UpdateWrapper<>();
- updateWrapper.eq("behospital_code", aPlaceFileVO.getBehospitalCode())
- .eq("hospital_id", aPlaceFileVO.getHospitalId())
- .eq("is_deleted",IsDeleteEnum.N)
- .set("is_placefile","1")
- .set("placefile_date",aPlaceFileVO.getPlaceFileDate().isEmpty()?DateUtil.formatDateTime(DateUtil.now()):DateUtil.parseDateTime(aPlaceFileVO.getPlaceFileDate()))
- .set("gmt_modified", DateUtil.now());
- Boolean flag=update(new BehospitalInfo(),updateWrapper);
- return RespDTO.onSuc(flag);
- }
- }catch (Exception e){
- aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-归档","",JSON.toJSONString(aPlaceFileVO),"",e.getMessage());
- return RespDTO.onError(e.getMessage());
- }
- }
- }
|