ABehospitalInfoFacade.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package com.diagbot.facade.data;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  5. import com.diagbot.dto.RespDTO;
  6. import com.diagbot.dto.data.ABehospitalInfoDTO;
  7. import com.diagbot.entity.BehospitalInfo;
  8. import com.diagbot.entity.MedicalRecord;
  9. import com.diagbot.entity.QcType;
  10. import com.diagbot.enums.IsDeleteEnum;
  11. import com.diagbot.facade.QcAbnormalFacade;
  12. import com.diagbot.facade.QcTypeFacade;
  13. import com.diagbot.service.impl.BehospitalInfoServiceImpl;
  14. import com.diagbot.util.BeanUtil;
  15. import com.diagbot.util.DateUtil;
  16. import com.diagbot.util.StringUtil;
  17. import com.diagbot.util.TZDBConn;
  18. import com.diagbot.vo.data.ABehospitalInfoVO;
  19. import com.diagbot.vo.data.ADeleteFlagVO;
  20. import com.diagbot.vo.data.APlaceFileVO;
  21. import com.google.common.collect.Lists;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Qualifier;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.stereotype.Component;
  26. import java.util.Date;
  27. import java.util.List;
  28. @Component
  29. public class ABehospitalInfoFacade extends BehospitalInfoServiceImpl {
  30. @Autowired
  31. @Qualifier("behospitalInfoServiceImpl")
  32. private BehospitalInfoServiceImpl behospitalInfoService;
  33. @Autowired
  34. private QcTypeFacade qcTypeFacade;
  35. @Autowired
  36. private AMedAbnormalInfoFacade aMedAbnormalInfoFacade;
  37. @Value("${log_switch.enable}")
  38. private boolean logSwitch;
  39. private TZDBConn tzDBConn = new TZDBConn();
  40. /**
  41. * 终末质控-同步前一天的入院记录
  42. */
  43. public void executeBehospital() {
  44. //String sql="select * from br_inpatientinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
  45. 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";
  46. List<BehospitalInfo> behospitalInfoList = tzDBConn.getBehospitalInfo(sql);
  47. execute(behospitalInfoList);
  48. }
  49. /**
  50. * 同步前一天的入院记录
  51. */
  52. public void executeBehospitalPast() {
  53. String sql="select * from br_inpatientinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
  54. List<BehospitalInfo> behospitalInfoList = tzDBConn.getBehospitalInfo(sql);
  55. execute(behospitalInfoList);
  56. }
  57. /**
  58. * 通过接口更新病人住院记录信息
  59. * @param list
  60. * @return
  61. */
  62. public RespDTO<List<ABehospitalInfoDTO>> executeBehospital(List<ABehospitalInfoVO> list) {
  63. try {
  64. if(list!=null && list.size()>0) {
  65. List<BehospitalInfo> behospitalInfoList = Lists.newArrayList();
  66. list.stream().forEach(s->{
  67. BehospitalInfo behospitalInfo=new BehospitalInfo();
  68. BeanUtil.copyProperties(s,behospitalInfo);
  69. if(StringUtil.isNotBlank(s.getBirthday())) {
  70. behospitalInfo.setBirthday(DateUtil.parseDate(s.getBirthday()));
  71. }
  72. if(StringUtil.isNotBlank(s.getLeaveHospitalDate())) {
  73. behospitalInfo.setLeaveHospitalDate(DateUtil.parseDateTime(s.getLeaveHospitalDate()));
  74. }
  75. if(StringUtil.isNotBlank(s.getBehospitalDate())){
  76. behospitalInfo.setBehospitalDate(DateUtil.parseDateTime(s.getBehospitalDate()));
  77. }
  78. if(StringUtil.isNotBlank(s.getPlacefileDate())){
  79. behospitalInfo.setPlacefileDate(DateUtil.parseDateTime(s.getPlacefileDate()));
  80. }
  81. behospitalInfoList.add(behospitalInfo);
  82. });
  83. //循环验证数据有效性
  84. for (BehospitalInfo behospitalInfo:behospitalInfoList) {
  85. if("".equals(behospitalInfo.getBehospitalCode())) {
  86. return RespDTO.onError("请输入病人住院编码!");
  87. }else if(behospitalInfo.getHospitalId()==null){
  88. return RespDTO.onError("请输入医院编码!");
  89. }else if("".equals(behospitalInfo.getBehDeptId())){
  90. return RespDTO.onError("请输入住院科室编码!");
  91. }else if("".equals(behospitalInfo.getBehDeptName())){
  92. return RespDTO.onError("请输入住院科室名称!");
  93. }
  94. }
  95. execute(behospitalInfoList);
  96. if(logSwitch){
  97. behospitalInfoList.forEach(s->{
  98. aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-正常","", JSON.toJSONString(list),"","");
  99. });
  100. }
  101. return RespDTO.onSuc("操作正常!");
  102. }else{
  103. return RespDTO.onError("未接收到数据!");
  104. }
  105. }catch (Exception e){
  106. log.error(e.getMessage(),e);
  107. aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-异常","", JSON.toJSONString(list),"",e.getMessage());
  108. return RespDTO.onError("数据处理异常,详情查看日志表");
  109. }
  110. }
  111. public void execute(List<BehospitalInfo> behospitalInfoList){
  112. List<BehospitalInfo> addE = Lists.newLinkedList();
  113. List<BehospitalInfo> updateE = Lists.newLinkedList();
  114. behospitalInfoList.stream().forEach(s -> {
  115. BehospitalInfo behospitalInfo = this.getOne(new QueryWrapper<BehospitalInfo>()
  116. .eq("behospital_code", s.getBehospitalCode())
  117. .eq("hospital_id", s.getHospitalId())
  118. .eq("is_deleted",IsDeleteEnum.N), false);
  119. if (behospitalInfo != null) {
  120. s.setGmtModified(new Date());
  121. s.setQcTypeId(initQcTypeId(s));
  122. updateE.add(s);
  123. } else {
  124. s.setGmtCreate(new Date());
  125. s.setQcTypeId(initQcTypeId(s));
  126. addE.add(s);
  127. }
  128. });
  129. if(addE.size()>0){
  130. behospitalInfoService.saveBatch(addE);
  131. }
  132. if(updateE.size()>0){
  133. behospitalInfoService.updateBatchByKey(updateE);
  134. }
  135. }
  136. /**
  137. * 初始化QcTypeId
  138. * @param s
  139. * @return
  140. */
  141. private Long initQcTypeId(BehospitalInfo s) {
  142. Long qcTypeId = Long.valueOf("0");
  143. //根据科室查找对应质控类型
  144. List<QcType> qcTypeList = qcTypeFacade.list(new QueryWrapper<QcType>()
  145. .eq("beh_dept_id", s.getBehDeptId())
  146. .eq("hospital_id", s.getHospitalId())
  147. .eq("is_deleted", IsDeleteEnum.N));
  148. if(qcTypeList == null || qcTypeList.size() == 0){
  149. //无质控类型时,新增后初始化
  150. QcType qcType = qcTypeFacade.getOne(new QueryWrapper<QcType>()
  151. .eq("default_module", 1)
  152. .eq("hospital_id", s.getHospitalId())
  153. .eq("is_deleted", IsDeleteEnum.N));
  154. qcTypeId = qcType.getId();
  155. } else if (qcTypeList.size() == 1) {
  156. qcTypeId = qcTypeList.get(0).getId();
  157. }else {
  158. //查找是否有性别区分质控类型
  159. for (QcType qcType:qcTypeList) {
  160. if (qcType.getSex().equals(s.getSex())) {
  161. qcTypeId = qcType.getId();
  162. }
  163. }
  164. }
  165. return qcTypeId;
  166. }
  167. public RespDTO deleteFlag(ADeleteFlagVO aDeleteFlagVO){
  168. try {
  169. //验证数据是否存在
  170. if(StringUtil.isEmpty(aDeleteFlagVO.getBehospitalCode())){
  171. return RespDTO.onError("请输入病人住院编码!");
  172. }else if(aDeleteFlagVO.getHospitalId()==null){
  173. return RespDTO.onError("请输入医院编码!");
  174. }else {
  175. UpdateWrapper<BehospitalInfo> updateWrapper=new UpdateWrapper<>();
  176. updateWrapper.eq("behospital_code", aDeleteFlagVO.getBehospitalCode())
  177. .eq("hospital_id", aDeleteFlagVO.getHospitalId())
  178. .eq("is_deleted",IsDeleteEnum.N)
  179. .set("is_deleted",IsDeleteEnum.Y)
  180. .set("gmt_modified", DateUtil.now());
  181. Boolean flag=update(new BehospitalInfo(),updateWrapper);
  182. //aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-删除",JSON.toJSONString(aDeleteFlagVO),"","删除成功!");
  183. return RespDTO.onSuc(flag);
  184. }
  185. }catch (Exception e){
  186. aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-删除","",JSON.toJSONString(aDeleteFlagVO),"",e.getMessage());
  187. return RespDTO.onError(e.getMessage());
  188. }
  189. }
  190. public RespDTO placeFileFlag(APlaceFileVO aPlaceFileVO){
  191. try {
  192. //验证数据是否存在
  193. if(StringUtil.isBlank(aPlaceFileVO.getBehospitalCode())){
  194. return RespDTO.onError("请输入病人住院编码!");
  195. }else if(aPlaceFileVO.getHospitalId()==null){
  196. return RespDTO.onError("请输入医院编码!");
  197. }else{
  198. UpdateWrapper<BehospitalInfo> updateWrapper=new UpdateWrapper<>();
  199. updateWrapper.eq("behospital_code", aPlaceFileVO.getBehospitalCode())
  200. .eq("hospital_id", aPlaceFileVO.getHospitalId())
  201. .eq("is_deleted",IsDeleteEnum.N)
  202. .set("is_placefile","1")
  203. .set("placefile_date",aPlaceFileVO.getPlaceFileDate().isEmpty()?DateUtil.formatDateTime(DateUtil.now()):DateUtil.parseDateTime(aPlaceFileVO.getPlaceFileDate()))
  204. .set("gmt_modified", DateUtil.now());
  205. Boolean flag=update(new BehospitalInfo(),updateWrapper);
  206. return RespDTO.onSuc(flag);
  207. }
  208. }catch (Exception e){
  209. aMedAbnormalInfoFacade.saveAbnormalInfo("病人住院登记-归档","",JSON.toJSONString(aPlaceFileVO),"",e.getMessage());
  210. return RespDTO.onError(e.getMessage());
  211. }
  212. }
  213. }