DataPageDockFacade.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package com.diagbot.facade;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import com.diagbot.biz.push.entity.Item;
  5. import com.diagbot.biz.push.entity.Lis;
  6. import com.diagbot.biz.push.entity.Pacs;
  7. import com.diagbot.dto.IndicationDTO;
  8. import com.diagbot.dto.PushDTO;
  9. import com.diagbot.dto.PushPlanDTO;
  10. import com.diagbot.dto.RespDTO;
  11. import com.diagbot.entity.TranDatadockingLog;
  12. import com.diagbot.util.*;
  13. import com.diagbot.vo.*;
  14. import com.diagbot.xm.vo.StructuralDataVo;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Component;
  20. import java.net.MalformedURLException;
  21. import java.net.URL;
  22. import java.net.URLEncoder;
  23. import java.util.Date;
  24. import java.util.List;
  25. import java.util.Map;
  26. /*
  27. * @Description:对外对接业务处理类
  28. * @Author:liuqq
  29. * @time: 2020/11/04 14:51
  30. **/
  31. @Component
  32. @Slf4j
  33. public class DataPageDockFacade {
  34. @Autowired
  35. private MrFacade mrFacade;
  36. @Autowired
  37. private PushFacade pushFacade;
  38. @Autowired
  39. private DataDockingLogFacade dataDockingLogFacade;
  40. @Value("${data-page.url}")
  41. private String dataPageUrl;
  42. private TZDBConn tzDBConn = new TZDBConn();
  43. private TZDBConn1 tzDBConn1 = new TZDBConn1();
  44. /**
  45. * @Description:静态知识开单合理性
  46. * @Author:liuqq
  47. * @time: ${DATE} ${TIME}
  48. **/
  49. public RespDTO<String> getStaticKnowledge(StaticKnowledgeHISVO staticKnowledgeHISVO) {
  50. // String hisName=StringUtils.isNotEmpty(staticKnowledgeHISVO.getHisName())?JSON.toJSONString(staticKnowledgeHISVO.getHisName(), SerializerFeature.BrowserCompatible):"";
  51. // String hisDetailName=StringUtils.isNotEmpty(staticKnowledgeHISVO.getHisName())?JSON.toJSONString(staticKnowledgeHISVO.getHisName(), SerializerFeature.BrowserCompatible):"";
  52. if (StringUtil.isNotEmpty(staticKnowledgeHISVO.getHisDetailName()) && staticKnowledgeHISVO.getType()==4) {
  53. staticKnowledgeHISVO.setHisName(staticKnowledgeHISVO.getHisDetailName());
  54. }
  55. String url = dataPageUrl + "/informationOut.html?hospitalId=" + staticKnowledgeHISVO.getHospitalId()
  56. + "&type=" + staticKnowledgeHISVO.getType()
  57. + "&hisName=" + URLEncoder.encode(staticKnowledgeHISVO.getHisName());
  58. URL urlString = null;
  59. try {
  60. urlString=new URL( url);
  61. } catch (MalformedURLException e) {
  62. e.printStackTrace();
  63. }
  64. return RespDTO.onSuc(urlString);
  65. }
  66. /**
  67. * @Description:页面推送模式
  68. * @Author:liuqq
  69. * @time: ${DATE} ${TIME}
  70. **/
  71. public RespDTO<String> getDataService(DataPageDockVO dataPageDockVO) {
  72. //参数校验
  73. if (dataPageDockVO.getHospitalId() == null) {
  74. return RespDTO.onError("请输入医院id");
  75. } else if ("".equals(dataPageDockVO.getShowType())) {
  76. return RespDTO.onError("请输入展示类型,横版:ver,或竖版hor");
  77. } else if ("".equals(dataPageDockVO.getPlanCode())) {
  78. return RespDTO.onError("请输入方案编码");
  79. }
  80. String url = "";
  81. String pushMrId = "";
  82. PushJoinVO pushJoinVO = new PushJoinVO();
  83. BeanUtil.copyProperties(dataPageDockVO, pushJoinVO);
  84. // 将基本参数保存到redis
  85. String mrId = mrFacade.createMr(pushJoinVO);
  86. //开单合理性推理时,验证下是否有推送,无推送时,不给url,code为“-1”
  87. if (dataPageDockVO.getPlanCode().equals("order_rational") || dataPageDockVO.getPlanCode().equals("medical_lis") || dataPageDockVO.getPlanCode().equals("medical_pacs")) {
  88. IndicationPushVO indicationPushVO = new IndicationPushVO();
  89. //初始化开单合理性入参
  90. BeanUtil.copyProperties(dataPageDockVO, indicationPushVO);
  91. indicationPushVO.setRuleType("1,2,3,4");
  92. IndicationDTO indicationDTO = pushFacade.indicationPush(indicationPushVO);
  93. if (indicationDTO != null) {
  94. if (ListUtil.isNotEmpty(indicationDTO.getBillMsgList()) || ListUtil.isNotEmpty(indicationDTO.getHighRiskList())
  95. || ListUtil.isNotEmpty(indicationDTO.getCriticalValList()) || ListUtil.isNotEmpty(indicationDTO.getOtherList())) {
  96. pushMrId = mrFacade.createIndicationMr(indicationDTO);
  97. } else {
  98. return RespDTO.onError("无开单合理性提醒!");
  99. }
  100. } else {
  101. return RespDTO.onError("无开单合理性提醒!");
  102. }
  103. }
  104. if ("hor".equals(dataPageDockVO.getShowType())) {
  105. url = dataPageUrl + "/cdssHorizontal.html?pushMrId=" + pushMrId + "&mrId=" + mrId + "&hospitalId=" + dataPageDockVO.getHospitalId() + "&planCode=" + dataPageDockVO.getPlanCode();
  106. } else {
  107. url = dataPageUrl + "/cdss.html?pushMrId=" + pushMrId + "&mrId=" + mrId + "&hospitalId=" + dataPageDockVO.getHospitalId() + "&planCode=" + dataPageDockVO.getPlanCode();
  108. }
  109. return RespDTO.onSuc(url);
  110. }
  111. /**
  112. * @Description:病历推理
  113. * @Author:liuqq
  114. * @time: ${DATE} ${TIME}
  115. **/
  116. public PushDTO getEnginePush(DataEngineVO dataEngineVO) {
  117. PushVO pushVO = new PushVO();
  118. BeanUtil.copyProperties(dataEngineVO, pushVO);
  119. PushDTO pushDTO = pushFacade.push(pushVO);
  120. pushDTO.setDebug(null);
  121. pushDTO.setSymptom(null);
  122. pushDTO.setVital(null);
  123. pushDTO.setOperations(null);
  124. pushDTO.setMedicines(null);
  125. pushDTO.setComplications(null);
  126. pushDTO.setTreat(null);
  127. try {
  128. TranDatadockingLog tranDatadockingLog = new TranDatadockingLog();
  129. tranDatadockingLog.setHospitalId(dataEngineVO.getHospitalId());
  130. tranDatadockingLog.setParamIn(JSON.toJSONString(dataEngineVO));
  131. tranDatadockingLog.setParamOut(JSON.toJSONString(pushDTO));
  132. tranDatadockingLog.setRemark("数据引擎模式," + dataEngineVO.getPlanCode());
  133. tranDatadockingLog.setTransTime(new Date());
  134. dataDockingLogFacade.save(tranDatadockingLog);
  135. } catch (Exception e) {
  136. log.error("数据引擎模式,增加日志异常", e.getMessage());
  137. }
  138. return pushDTO;
  139. }
  140. /**
  141. * @Description: 开单合理性及检查、检查报告检阅
  142. * @Author:liuqq
  143. * @time: ${DATE} ${TIME}
  144. **/
  145. public RespDTO getEngineIndicationPush(DataEngineVO dataEngineVO) {
  146. IndicationPushVO indicationPushVO = new IndicationPushVO();
  147. BeanUtil.copyProperties(dataEngineVO, indicationPushVO);
  148. indicationPushVO.setRuleType("1,2,3,4");
  149. IndicationDTO indicationDTO = pushFacade.indicationPush(indicationPushVO);
  150. indicationDTO.setDebug(null);
  151. if (indicationDTO != null) {
  152. if (ListUtil.isNotEmpty(indicationDTO.getBillMsgList()) || ListUtil.isNotEmpty(indicationDTO.getHighRiskList())
  153. || ListUtil.isNotEmpty(indicationDTO.getCriticalValList()) || ListUtil.isNotEmpty(indicationDTO.getOtherList())) {
  154. return RespDTO.onSuc(indicationDTO);
  155. } else {
  156. return RespDTO.onError("无开单合理性提醒!");
  157. }
  158. } else {
  159. return RespDTO.onError("无开单合理性提醒!");
  160. }
  161. }
  162. public PushPlanDTO getOperationPlanPush(DataEngineVO dataEngineVO) {
  163. PushPlanVO pushPlanVO = new PushPlanVO();
  164. BeanUtil.copyProperties(dataEngineVO, pushPlanVO);
  165. PushPlanDTO pushPlanDTO = pushFacade.pushPlan(pushPlanVO);
  166. pushPlanDTO.setDebug(null);
  167. try {
  168. TranDatadockingLog tranDatadockingLog = new TranDatadockingLog();
  169. tranDatadockingLog.setHospitalId(dataEngineVO.getHospitalId());
  170. tranDatadockingLog.setParamIn(JSON.toJSONString(dataEngineVO));
  171. tranDatadockingLog.setParamOut(JSON.toJSONString(pushPlanDTO));
  172. tranDatadockingLog.setRemark("数据引擎模式," + dataEngineVO.getPlanCode());
  173. tranDatadockingLog.setTransTime(new Date());
  174. dataDockingLogFacade.save(tranDatadockingLog);
  175. } catch (Exception e) {
  176. log.error("数据引擎模式,增加日志异常", e.getMessage());
  177. }
  178. return pushPlanDTO;
  179. }
  180. //湘雅根据视图来取所需数据
  181. public RespDTO<String> getDataServiceXY(StructuralDataVo structuralDataVo) {
  182. if (structuralDataVo.getBehospitalCode().contains("_")){
  183. structuralDataVo.setBehospitalCode(structuralDataVo.getBehospitalCode().substring(0,structuralDataVo.getBehospitalCode().indexOf("_")));
  184. }
  185. DataPageDockVO dataPageDockVO = new DataPageDockVO();
  186. RespDTO<String> respDTO =new RespDTO<>();
  187. try {
  188. String where = " where behospitalCode = '" + structuralDataVo.getBehospitalCode() + "' and behospitalNum = '" + structuralDataVo.getFileCode() + "'";
  189. String DrugSql = " select * from drug " + " where behospitalCode = '" + structuralDataVo.getBehospitalCode() + "' and fileCode = '" + structuralDataVo.getFileCode() + "'";
  190. String DiagSql = " select * from diag "+" where behospitalCode = '" + structuralDataVo.getBehospitalCode() + "' and fileCode = '" + structuralDataVo.getFileCode() + "'";
  191. String InfoSql = " select * from medical_records where PATIENTID ='"+structuralDataVo.getBehospitalCode()+"' and VISITID = '"+structuralDataVo.getFileCode()+"'";
  192. String InfoSqlaa = " select * from medical_record " +where;
  193. String lisSql = " select * from assay_details " + where;
  194. String PacsSql = " select * from check_details " + where;
  195. String OpsSql = " select * from homepage_operation " + where;
  196. // //得到基本信息并赋予
  197. Map<String, String> map = tzDBConn1.getInfo(InfoSql);
  198. dataPageDockVO.setPlanCode(structuralDataVo.getPlanCode());
  199. dataPageDockVO.setHospitalId(structuralDataVo.getHospitalId());//医院id
  200. dataPageDockVO.setShowType(structuralDataVo.getShowType());//展示方式
  201. if (StringUtils.isNotEmpty(map.get("SEX"))){
  202. dataPageDockVO.setSex(Integer.valueOf(map.get("SEX").equals("男")?"1":map.get("SEX").equals("女")?"2":"3"));//性别
  203. }
  204. dataPageDockVO.setAge(StringUtils.isNotEmpty(map.get("AGE"))?map.get("AGE"):"18");//年龄
  205. dataPageDockVO.setMarriage(map.get("MARRIAGE"));//婚姻
  206. dataPageDockVO.setChief(map.get("CHIEF"));//主诉
  207. dataPageDockVO.setSymptom(map.get("SYMPTOM"));//现病史
  208. // dataPageDockVO.setChief("体温39.2,高热,植入钢板");//主诉
  209. // dataPageDockVO.setSymptom("体温39.2,高热,植入钢板");//现病史
  210. dataPageDockVO.setPasts(map.get("PASTS"));//既往史
  211. dataPageDockVO.setPersonal(map.get("PERSONAL"));//个人史
  212. dataPageDockVO.setMarital(map.get("MARITAL"));//婚育史
  213. dataPageDockVO.setFamily(map.get("FAMILY"));//家族史
  214. dataPageDockVO.setMenstrual(map.get("MENSTRUAL"));//月经史
  215. dataPageDockVO.setVital(map.get("VITAL"));//查体
  216. System.out.println(JSON.toJSONString(dataPageDockVO) + "-------------------------------------信息");
  217. //获取Order信息并赋予
  218. List<Lis> lisOrder = structuralDataVo.getLisOrder();
  219. if (lisOrder.size()>0){
  220. lisOrder.forEach(lis -> {
  221. lis.setDetailName("");
  222. lis.setUniqueName("");
  223. });
  224. }
  225. dataPageDockVO.setPacsOrder(structuralDataVo.getPacsOrder());
  226. dataPageDockVO.setLisOrder(lisOrder);
  227. dataPageDockVO.setOperationOrder(structuralDataVo.getOperationOrder());
  228. dataPageDockVO.setDrugOrder(structuralDataVo.getDrugOrder());
  229. dataPageDockVO.setDiseaseName(structuralDataVo.getDiseaseName());
  230. dataPageDockVO.setDiagOrder(structuralDataVo.getDiagOrder());
  231. System.out.println(JSON.toJSONString(dataPageDockVO) + "-------------------------------------Order");
  232. //获取历史信息并赋予
  233. //根据方案编码来判断是否是多参考值 如果是根据repNo来获取他们的值
  234. if (structuralDataVo.getPlanCode().equals("medical_lis")){
  235. if (StringUtils.isNotEmpty(structuralDataVo.getRepNo())){
  236. lisSql= lisSql+" and repNo='"+structuralDataVo.getRepNo()+"'";
  237. }
  238. dataPageDockVO.setLis(tzDBConn.getLis(lisSql));
  239. dataPageDockVO.setDiag(tzDBConn.getDiag(DiagSql));
  240. }else if (structuralDataVo.getPlanCode().equals("medical_pacs")){
  241. if (StringUtils.isNotEmpty(structuralDataVo.getRepNo())){
  242. PacsSql= PacsSql+" and repNo='"+structuralDataVo.getRepNo()+"'";
  243. }
  244. dataPageDockVO.setPacs(tzDBConn.getPacs(PacsSql));
  245. dataPageDockVO.setDiag(tzDBConn.getDiag(DiagSql));
  246. }else {
  247. dataPageDockVO.setPacs(tzDBConn.getPacs(PacsSql));
  248. dataPageDockVO.setLis(tzDBConn.getLis(lisSql));
  249. dataPageDockVO.setDrug(tzDBConn.getDrug(DrugSql));
  250. dataPageDockVO.setDiag(tzDBConn.getDiag(DiagSql));
  251. dataPageDockVO.setOperation(tzDBConn.getOperation(OpsSql));
  252. }
  253. System.out.println(JSON.toJSONString(dataPageDockVO) + "---------------------------------------历史数据");
  254. respDTO= this.getDataService(dataPageDockVO);
  255. //保存入参到库里 方便以后查看
  256. TranDatadockingLog tranDatadockingLog = new TranDatadockingLog();
  257. tranDatadockingLog.setDoctorCode("正常入参");
  258. tranDatadockingLog.setHospitalId(dataPageDockVO.getHospitalId());
  259. tranDatadockingLog.setSexType(JSON.toJSONString(structuralDataVo));
  260. tranDatadockingLog.setParamIn(JSON.toJSONString(dataPageDockVO));
  261. tranDatadockingLog.setParamOut(JSON.toJSONString(respDTO));
  262. tranDatadockingLog.setRemark("方案编码," + dataPageDockVO.getPlanCode());
  263. tranDatadockingLog.setInquiryCode("病人住院号: " + structuralDataVo.getBehospitalCode()+"_"+structuralDataVo.getFileCode());
  264. tranDatadockingLog.setTransTime(new Date());
  265. dataDockingLogFacade.save(tranDatadockingLog);
  266. } catch (Exception e) {
  267. TranDatadockingLog tranDatadockingLog = new TranDatadockingLog();
  268. tranDatadockingLog.setSexType("获取数据失败," + JSON.toJSONString(structuralDataVo));
  269. tranDatadockingLog.setRemark("错误异常," + e.getMessage());
  270. tranDatadockingLog.setParamIn(JSON.toJSONString(dataPageDockVO));
  271. tranDatadockingLog.setParamOut(JSON.toJSONString(respDTO));
  272. tranDatadockingLog.setInquiryCode("病人住院号: " + structuralDataVo.getBehospitalCode()+"_"+structuralDataVo.getFileCode());
  273. tranDatadockingLog.setTransTime(new Date());
  274. dataDockingLogFacade.save(tranDatadockingLog);
  275. } finally {
  276. tzDBConn.close();
  277. }
  278. return respDTO;
  279. }
  280. }