Form1.cs 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  1. using Common;
  2. using iTextSharp.text;
  3. using iTextSharp.text.pdf;
  4. using LisPacsDataUpload.business;
  5. using LisPacsDataUpload.Models;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. using System.Xml;
  16. namespace LisPacsDataUpload
  17. {
  18. public partial class Form1 : Form
  19. {
  20. private static int zlhrConstant_true=1;// 是临生免 常量
  21. //定时器
  22. private System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
  23. //private DateTime Date;
  24. //private int PageSize = 10;
  25. //private int PageIndex = 0;
  26. //PageIndex = PageIndex + 1;
  27. // int PageStart = (PageIndex - 1) * PageSize + 1;
  28. //int PageEnd = PageSize * PageIndex;
  29. private int UploadPacs;//是否上传pacs
  30. private string ShowLog = "";
  31. private int Lis_total = 0;//今日lis上传总数
  32. private int pacs_total = 0;//今日pacs上传总数
  33. private string DicPacs = AppDomain.CurrentDomain.BaseDirectory + "Pacs\\";
  34. private string DicLis = AppDomain.CurrentDomain.BaseDirectory + "Lis\\";
  35. private int zlhr = 0;// 是否为临生免
  36. private int lisSource = 1;// 0中联老版lis 1 中联新版lis 2 专业版临生免 3 三方lis
  37. private int open_multiple_upload_flag = 0;// 开启多个线程上传
  38. private delegate void SetTextCallback(string text);
  39. //在给textBox1.text赋值的地方调用以下方法即可
  40. public Form1()
  41. {
  42. InitializeComponent();
  43. this.MinimumSize = new Size(0, 0);
  44. timer1.Interval = OracleHelper<object>.Time();
  45. timer1.Enabled = true;
  46. timer1.Tick += new EventHandler(DataUpload);//添加事件
  47. timer1.Start();
  48. }
  49. private void Form1_Load(object sender, EventArgs e)
  50. {
  51. ShowLog = "启动正常。";
  52. LogHelper.Info(ShowLog);
  53. this.SetText(ShowLog);
  54. ShowCheckBox1();
  55. ShowCheckBox2();
  56. UploadPacs = OracleHelper<object>.UploadPacs();
  57. GetLisDefault();
  58. if (UploadPacs == 1)
  59. {
  60. GetPacsDefault();
  61. }
  62. //AutoStart();
  63. DataUpload(sender, e);
  64. }
  65. private void ShowCheckBox1()
  66. {
  67. string sql_lis = @"select 互认,zlhr,open_multiple_upload,lis_source from 互认配置表";
  68. DataTable dt_lis = OracleHelper<object>.RunQueryDS(sql_lis);
  69. int total = int.Parse(dt_lis.Rows[0]["互认"].ToString());
  70. if (total == 1)
  71. {
  72. checkBox1.Checked = true;
  73. }
  74. else
  75. {
  76. checkBox1.Checked = false;
  77. }
  78. int zlhrValue = int.Parse(dt_lis.Rows[0]["zlhr"].ToString());
  79. if (zlhrValue == zlhrConstant_true)
  80. {
  81. zlhr= zlhrValue;
  82. }
  83. open_multiple_upload_flag = int.Parse(dt_lis.Rows[0]["open_multiple_upload"].ToString());
  84. lisSource= int.Parse(dt_lis.Rows[0]["lis_source"].ToString());
  85. }
  86. private void ShowCheckBox2()
  87. {
  88. XmlDocument xmldoc = new XmlDocument();
  89. string xmlpath = AppDomain.CurrentDomain.BaseDirectory + "Xml.xml";
  90. xmldoc.Load(xmlpath);
  91. string str = xmldoc.SelectSingleNode("/root/key").InnerXml;
  92. if (str == "0")
  93. {
  94. checkBox2.Checked = false;
  95. }
  96. else
  97. {
  98. checkBox2.Checked = true;
  99. }
  100. }
  101. /// <summary>
  102. /// 开机启动
  103. /// </summary>
  104. private void AutoStart()
  105. {
  106. try
  107. {
  108. XmlDocument xmldoc = new XmlDocument();
  109. string xmlpath = AppDomain.CurrentDomain.BaseDirectory + "Xml.xml";
  110. xmldoc.Load(xmlpath);
  111. string str = xmldoc.SelectSingleNode("/root/key").InnerXml;
  112. if (str == "0")
  113. {
  114. string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
  115. string path = Application.ExecutablePath.ToLower(); //将当前程序起动路径
  116. string name = System.IO.Path.GetFileName(path); //获得应用程序名称
  117. var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true);
  118. if (regKey != null && regKey.GetValue("LisPacsDataUpload") == null)
  119. {
  120. regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);
  121. regKey.SetValue("LisPacsDataUpload", path);
  122. regKey.Close();
  123. }
  124. XmlElement element = (XmlElement)xmldoc.SelectSingleNode("/root/key");
  125. element.InnerText = "1";
  126. xmldoc.Save(xmlpath);
  127. ShowLog = "写入注册表成功。";
  128. this.SetText(ShowLog);
  129. LogHelper.Info("写入注册表成功。");
  130. }
  131. else
  132. {
  133. ShowLog = "不允许此操作!";
  134. this.SetText(ShowLog);
  135. if (checkBox2.Checked)
  136. {
  137. checkBox2.Checked = false;
  138. }
  139. else
  140. {
  141. checkBox2.Checked = true;
  142. }
  143. }
  144. }
  145. catch (Exception ex)
  146. {
  147. //ShowLog = "不允许此操作!";
  148. //this.SetText(ShowLog);
  149. if (checkBox2.Checked)
  150. {
  151. checkBox2.Checked = false;
  152. }
  153. else
  154. {
  155. checkBox2.Checked = true;
  156. }
  157. ShowLog = "写入注册表异常:" + ex.Message;
  158. this.SetText(ShowLog);
  159. LogHelper.Info(ShowLog);
  160. }
  161. }
  162. private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
  163. {
  164. //switch (e.Button)
  165. //{
  166. // case System.Windows.Forms.MouseButtons.Left: //左击
  167. // //判断是否已经最小化于托盘
  168. // if (WindowState == FormWindowState.Minimized)
  169. // {
  170. // //还原窗体显示
  171. // WindowState = FormWindowState.Normal;
  172. // //激活窗体并给予它焦点
  173. // this.Activate();
  174. // //任务栏区显示图标
  175. // this.ShowInTaskbar = true;
  176. // //托盘区图标隐藏
  177. // notifyIcon1.Visible = false;
  178. // }
  179. // break;
  180. // case System.Windows.Forms.MouseButtons.Right:
  181. // //MessageBox.Show("右键");
  182. // break;
  183. //}
  184. }
  185. private void open_click(object sender, EventArgs e)
  186. {
  187. if (WindowState == FormWindowState.Minimized)
  188. {
  189. WindowState = FormWindowState.Normal;
  190. this.Activate();
  191. this.ShowInTaskbar = true;
  192. }
  193. }
  194. private void close_click(object sender, EventArgs e)
  195. {
  196. //this.Close();
  197. LogHelper.Info("程序退出。");
  198. System.Environment.Exit(0);
  199. }
  200. private void Form1_SizeChanged(object sender, EventArgs e)
  201. {
  202. //判断是否选择的是最小化按钮
  203. if (WindowState == FormWindowState.Minimized)
  204. {
  205. //托盘显示图标等于托盘图标对象
  206. //注意notifyIcon1是控件的名字而不是对象的名字
  207. //隐藏任务栏区图标
  208. this.ShowInTaskbar = false;
  209. //图标显示在托盘区
  210. notifyIcon1.Visible = true;
  211. }
  212. }
  213. private void DataUpload(object source, EventArgs e)
  214. {
  215. LogHelper.Info("开始轮询。");
  216. DateTime Date = DateTime.Now;
  217. int time = Date.Hour;
  218. int StartTime = OracleHelper<object>.StartTime();//18
  219. if (time == 0)
  220. {//今日上传数清零
  221. Lis_total = 0;
  222. pacs_total = 0;
  223. }
  224. else if (time < StartTime && time > 7)//
  225. {
  226. ShowLog = "开始轮询时间为[" + StartTime + "]点至明日早上7点,现在是" + time + "点。";
  227. this.SetText(ShowLog);
  228. LogHelper.Info(ShowLog);
  229. if (Directory.Exists(DicLis))
  230. {
  231. Directory.Delete(DicLis, true);
  232. }
  233. if (Directory.Exists(DicPacs))
  234. {
  235. Directory.Delete(DicPacs, true);
  236. }
  237. DelPDF();
  238. return;
  239. }
  240. LogHelper.Info("zlhr=="+zlhr);
  241. string name = "LIS1" + Tools.GuidTo16String();
  242. Thread th = new Thread(new ParameterizedThreadStart(CountUpload));
  243. th.IsBackground = true;
  244. th.Name = name;
  245. th.Start(name);
  246. System.Threading.Thread.Sleep(5000);
  247. string name2 = "LIS2" + Tools.GuidTo16String();
  248. Thread th2 = new Thread(new ParameterizedThreadStart(LisUpload));
  249. th2.IsBackground = true;
  250. th2.Name = name2;
  251. th2.Start(name2);
  252. // 开启第二个上传
  253. if (1== open_multiple_upload_flag)
  254. {
  255. System.Threading.Thread.Sleep(5000);
  256. string name3 = "LIS3" + Tools.GuidTo16String();
  257. Thread th3 = new Thread(new ParameterizedThreadStart(LisUpload2));
  258. th3.IsBackground = true;
  259. th3.Name = name3;
  260. th3.Start(name3);
  261. }
  262. if (UploadPacs == 1)//没传影像云的需要上传检查
  263. {
  264. LogHelper.Info("没传影像云的需要上传检查");
  265. Thread thp = new Thread(new ThreadStart(PacsUpload));
  266. thp.IsBackground = true;
  267. thp.Name = "PACS" + Tools.GuidTo16String();
  268. thp.Start();
  269. }
  270. }
  271. private object CountLock = new object();
  272. private void CountUpload(object Thname)
  273. {
  274. try
  275. {
  276. lock (CountLock)
  277. {
  278. string Thread_name = "[" + Thname.ToString() + "]";
  279. string url = "http://40.26.204.3:8084/phimp-napi/qyhrApplyInfo/upload";
  280. int success_count = 0;
  281. LogHelper.Info(Thread_name + "上传开单合计开始");
  282. string count_sql = @"select * from bill_project_view"
  283. ;
  284. List<Count> list_count = OracleHelper<Count>.RunQueryList(count_sql);
  285. //LogHelper.Info("list_count" + list_count);
  286. if (list_count.Count < 1)
  287. {
  288. LogHelper.Info(Thread_name + "本次开单无数据,等待下一次轮询。");
  289. LogHelper.Info("执行sql:" + count_sql);
  290. }
  291. else
  292. {
  293. for (int i = 0; i < list_count.Count; i++)
  294. {
  295. if (!isAuthorization())
  296. {
  297. continue;
  298. }
  299. Dictionary<string, object> dic_pc = new Dictionary<string, object>();
  300. foreach (var property in list_count[i].GetType().GetProperties())
  301. {
  302. //LogHelper.Info("[count]Name:" + property.Name);
  303. //LogHelper.Info("[count]value:" + property.GetValue(list_count[i], null));
  304. dic_pc.Add(property.Name, property.GetValue(list_count[i], null));
  305. }
  306. string json_count = JsonConvert.SerializeObject(dic_pc);
  307. string json_count_log = json_count;
  308. string vi_count = Tools.GuidTo16String();
  309. json_count = Tools.AESEncrypt(json_count, Tools.pwd, vi_count);
  310. string res_pacs_pc = Tools.WSCenterData(url, json_count, vi_count, Tools.accessToken, 1);
  311. string res_aes_pacs_pc = Tools.AESDecrypt(res_pacs_pc, Tools.pwd, vi_count);
  312. ResPacs respacs_pc = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs_pc), Encoding.UTF8);
  313. if (respacs_pc.statusCode != "1")
  314. {
  315. ShowLog = respacs_pc.message + ",[LIS]清单数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_count;
  316. this.SetText(ShowLog);
  317. LogHelper.Info(ShowLog);
  318. LogHelper.Info("[count]出错入参:" + json_count_log);
  319. LogHelper.Info("[LIS]出错入参:" + json_count + "|....|" + Tools.accessToken);
  320. LogHelper.Info("[count]出错出参:" + res_aes_pacs_pc);
  321. continue;
  322. }
  323. else
  324. {
  325. // LogHelper.Info(success_count + "入参:" + json_count_log);
  326. //LogHelper.Info(success_count + "出参:" + respacs_pc.message);
  327. success_count++;
  328. }
  329. }
  330. LogHelper.Info("本次清单上传:" + success_count);
  331. }
  332. }
  333. }
  334. catch (Exception e)
  335. {
  336. LogHelper.Error(e);
  337. }
  338. }
  339. private object LisLock = new object();
  340. private void LisUpload(object Thname)
  341. {
  342. try
  343. {
  344. lock (LisLock)
  345. {
  346. string Thread_name = "[" + Thname.ToString() + "]";
  347. string url = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
  348. #region 1、单条上传lis文件及数据
  349. LogHelper.Info(Thread_name + "[LIS]开始");
  350. string lis_sql = @"select * from( Select rownum rn,b.* From (Select t.* from lis_upload t
  351. Where
  352. t.attachmentId Is Null
  353. Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
  354. ) b
  355. ) where rn <= 150 ";
  356. DataTable dt = new DataTable();
  357. if (zlhr == zlhrConstant_true)
  358. {
  359. lis_sql = @"Select t.* from lis_upload t Where t.attachmentId Is Null
  360. Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss') limit 100";
  361. dt = OracleHelper<object>.PgQueryDS(lis_sql);
  362. }
  363. else
  364. {
  365. dt = OracleHelper<object>.RunQueryDS(lis_sql);
  366. }
  367. LogHelper.Info("执行sql:" + lis_sql);
  368. if (dt.Rows.Count < 1)
  369. {
  370. LogHelper.Info(Thread_name + "本次[LIS]无数据,等待下一次轮询。");
  371. }
  372. else
  373. {
  374. ShowLog = Thread_name + "本次需上传[LIS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
  375. this.SetText(ShowLog);
  376. LogHelper.Info(ShowLog);
  377. int pdfcountAll = 0;
  378. int uploaded = 0;
  379. for (int i = 0; i < dt.Rows.Count; i++)
  380. {
  381. //获取标本号 和报表编号
  382. string reportNumber = dt.Rows[i]["reportNumber"].ToString(); //报告编号
  383. string bbid = dt.Rows[i]["bbid"].ToString(); // 标本id
  384. //生成pdf
  385. string GeneratePdfUrl = PdfUtils.GeneratePdf(lisSource, reportNumber, bbid);
  386. if (!GeneratePdfUrl.Contains(".pdf") )
  387. {
  388. LogHelper.Info("生成pdf失败,原因是 = " + GeneratePdfUrl);
  389. continue ;
  390. }
  391. LogHelper.Info("生成pdf成功,地址为 = " + GeneratePdfUrl);
  392. /*string orgName = dt.Rows[i]["orgName"].ToString();
  393. string name = dt.Rows[i]["patientName"].ToString();
  394. string sex = dt.Rows[i]["sex"].ToString();
  395. string ch = dt.Rows[i]["bedNo"].ToString();
  396. string zyh = dt.Rows[i]["zyh"].ToString();
  397. string mzh = dt.Rows[i]["mzh"].ToString();
  398. string age = dt.Rows[i]["age"].ToString();
  399. string dep = dt.Rows[i]["dep"].ToString();
  400. string type;
  401. string title = dt.Rows[i]["reportName"].ToString();
  402. string patientType = dt.Rows[i]["patientType"].ToString();
  403. if (patientType == "1")
  404. {
  405. type = "门诊";
  406. }
  407. else if (patientType == "2")
  408. {
  409. type = "住院";
  410. }
  411. else if (patientType == "3")
  412. {
  413. type = "体检";
  414. }
  415. else
  416. {
  417. type = "其他";
  418. }
  419. string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
  420. string signature = "签名:{0} 日期:{1}";
  421. string qname = dt.Rows[i]["auditorName"].ToString();
  422. string qdate = dt.Rows[i]["auditTime"].ToString();
  423. signature = string.Format(signature, qname, qdate);
  424. baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
  425. string reportId = dt.Rows[i]["reportId"].ToString();
  426. string dt_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + reportId+"'";
  427. LogHelper.Info("查询LIS项目指标数据执行sql:" + dt_sql);
  428. DataTable items = new DataTable();
  429. if (zlhr == zlhrConstant_true)
  430. {
  431. items = OracleHelper<object>.PgQueryDS(dt_sql);
  432. }
  433. else
  434. {
  435. items = OracleHelper<object>.RunQueryDS(dt_sql);
  436. }
  437. LogHelper.Info("查询LIS项目指标数据执行sql 条数=:" + items.Rows.Count);
  438. if (items.Rows.Count < 1)
  439. {
  440. LogHelper.Info("查询LIS项目指标数据为空,生成PDF失败,跳过本条数据生成下一条PDF。");
  441. continue;
  442. }
  443. string res = CreateLisPDF(orgName, baseInfo, items, signature, title);
  444. if (res == "")
  445. {
  446. ShowLog = "生成PDF文件失败,[LIS]上传失败!跳过本条数据上传下一条。";
  447. this.SetText(ShowLog);
  448. LogHelper.Info(ShowLog);
  449. continue;
  450. }*/
  451. //是否授权
  452. if (!isAuthorization())
  453. {
  454. continue;
  455. }
  456. //最新调整 需要获取 原始pdf 文件 存在场景 有三方lis、中联lis 、 以及专业版临生免 的报告 三种
  457. //上传文件
  458. string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检验报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + Tools.FileToBase64Str(GeneratePdfUrl) + "\"}";
  459. string file_vi = Tools.GuidTo16String();
  460. file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
  461. string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
  462. string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
  463. string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
  464. ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
  465. if (resfile.statusCode != "1")
  466. {
  467. LogHelper.Info(resfile.message + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。");
  468. LogHelper.Info("入参:" + file_json);
  469. LogHelper.Info("出参:" + file_res_aes);
  470. ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。";
  471. this.SetText(ShowLog);
  472. continue;
  473. }
  474. string sql = @"Insert Into 已上传PDF(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED,UPLOADE_TIME) Values('{0}','{1}',2,'{2}',0,to_date('{3}','yyyy/mm/dd hh24:mi:ss'))";
  475. sql = string.Format(sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString(), resfile.mainBody.attachmentId, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  476. int file_count = 0;
  477. if (zlhr == zlhrConstant_true)
  478. {
  479. LogHelper.Info("sql:" + sql);
  480. file_count = OracleHelper<object>.PgExecuteNonQuery(sql);
  481. }
  482. else
  483. {
  484. file_count = OracleHelper<object>.ExecuteNonQuery(sql);
  485. }
  486. if (file_count < 1)
  487. {
  488. LogHelper.Info("[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!");
  489. LogHelper.Info("执行sql:" + sql);
  490. ShowLog = "[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql;
  491. this.SetText(ShowLog);
  492. continue;
  493. }
  494. pdfcountAll += 1;
  495. //上传lis数据
  496. string item_sql = @"select a.orgCode,
  497. a.orgName,
  498. a.orgThrdCode,
  499. a.reportId,
  500. a.reportName,
  501. a.requestId,
  502. a.barcode,
  503. a.sampleNo,
  504. a.businessNumber,
  505. a.patientType,
  506. a.patientName,
  507. a.patientSex,
  508. a.patientBirthday,
  509. a.patientAge,
  510. a.ageUnit,
  511. a.patientIdCard,
  512. a.inpatientAreaName,
  513. a.roomNo,
  514. a.bedNo,
  515. a.phoneNo,
  516. a.address,
  517. a.reportType,
  518. a.reportTypeName,
  519. a.sampCode,
  520. a.sampName,
  521. a.diagnosisCode,
  522. a.diagnosisName,
  523. a.resultType,
  524. a.applyTime,
  525. a.applyerCode,
  526. a.applyerName,
  527. a.applyDeptCode,
  528. a.applyDeptName,
  529. a.collectTime,
  530. a.collectCode,
  531. a.collectName,
  532. a.transportCode,
  533. a.transportName,
  534. a.transportDeptCode,
  535. a.transportDeptName,
  536. a.transportOrgCode,
  537. a.transportOrgName,
  538. a.acceptTime,
  539. a.acceptorCode,
  540. a.acceptorName,
  541. a.receiveTime,
  542. a.receiverCode,
  543. a.receiverName,
  544. a.checkTime,
  545. a.checkerCode,
  546. a.checkerName,
  547. a.checkDeptCode,
  548. a.checkDeptName,
  549. a.auditTime,
  550. a.auditorCode,
  551. a.auditorName,
  552. a.reportTime,
  553. a.reportorCode,
  554. a.reportorName,
  555. a.sampleNotes,
  556. a.checkPrice,
  557. a.attachmentId,
  558. a.patientId ,
  559. a.healthNo ,
  560. a.medicareNo ,
  561. a.socialNo ,
  562. a.inpatientAreaCode ,
  563. a.sampleName ,
  564. a.execHospitalCode ,
  565. a.execHospitalName,
  566. a.sameHospital,
  567. a.projectCode,
  568. a.projectName
  569. from lis_upload a ,已上传PDF b
  570. where b.businessnumber = a.BUSINESSNUMBER
  571. and b.reportid = a.REPORTID
  572. and b.attachmentid is not null
  573. and b.uploaded = 0
  574. and b.type = 2
  575. and a.BUSINESSNUMBER = '{0}'
  576. and a.REPORTID = '{1}'";
  577. item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
  578. List<LIS> list = new List<LIS>();
  579. if (zlhr == zlhrConstant_true)
  580. {
  581. list = OracleHelper<LIS>.PgRunQueryList(item_sql);
  582. }
  583. else
  584. {
  585. list = OracleHelper<LIS>.RunQueryList(item_sql);
  586. }
  587. if (list.Count < 1)
  588. {
  589. LogHelper.Info("查询LIS数据为空,跳过本条数据上传下一条。");
  590. LogHelper.Info("执行sql:" + item_sql);
  591. continue;
  592. }
  593. List<Dictionary<string, object>> plist = new List<Dictionary<string, object>>();
  594. Dictionary<string, object> dic = new Dictionary<string, object>();
  595. foreach (var property in list[0].GetType().GetProperties())
  596. {
  597. dic.Add(property.Name, property.GetValue(list[0], null));
  598. }
  599. string lisitems_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + list[0].REPORTID + "'";
  600. List<LISITEMS> lisitems = new List<LISITEMS>();
  601. if (zlhr == zlhrConstant_true)
  602. {
  603. lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
  604. }
  605. else
  606. {
  607. lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
  608. }
  609. if (lisitems.Count < 1)
  610. {
  611. LogHelper.Info("查询LIS项目指标数据为空,跳过本条数据上传下一条。");
  612. LogHelper.Info("执行sql:" + lisitems_sql);
  613. continue;
  614. }
  615. if (zlhr == zlhrConstant_true)
  616. {
  617. //处理 互认编码的数据
  618. HandleLisItemData(lisitems);
  619. }
  620. dic.Add("DETAILLIST", lisitems);
  621. plist.Add(dic);
  622. //是否授权
  623. if (!isAuthorization())
  624. {
  625. continue;
  626. }
  627. string json_pacs = JsonConvert.SerializeObject(plist);
  628. json_pacs = "{\"mainBody\":" + json_pacs + "}";
  629. string json_pacs_log = json_pacs;
  630. string vi_pacs = Tools.GuidTo16String();
  631. json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
  632. string res_pacs = Tools.WSCenterData(url, json_pacs, vi_pacs, Tools.accessToken, 1);
  633. string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
  634. ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
  635. if (respacs.statusCode != "1")
  636. {
  637. ShowLog = respacs.message + ",[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
  638. this.SetText(ShowLog);
  639. LogHelper.Info(ShowLog);
  640. LogHelper.Info("[LIS]出错入参:" + json_pacs_log);
  641. LogHelper.Info("[LIS]出错出参:" + res_aes_pacs);
  642. continue;
  643. }
  644. else
  645. {
  646. Lis_total += 1;
  647. uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
  648. string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
  649. and BUSINESSNUMBER = '{0}'
  650. and REPORTID = '{1}'";
  651. sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  652. int upload_count = 0;
  653. if (zlhr == zlhrConstant_true)
  654. {
  655. upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
  656. }
  657. else
  658. {
  659. upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
  660. }
  661. if (upload_count < 1)
  662. {
  663. LogHelper.Info("[LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
  664. LogHelper.Info("执行sql:" + sql_upload);
  665. ShowLog = "[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
  666. this.SetText(ShowLog);
  667. continue;
  668. }
  669. }
  670. }
  671. ShowLog = Thread_name + "本次已生成、上传[LIS]PDF文件总条数为[" + pdfcountAll + "]条,上传[LIS]总条数为[" + uploaded + "]条。";
  672. this.SetText(ShowLog);
  673. LogHelper.Info(ShowLog);
  674. GetLisDefault();
  675. }
  676. #endregion
  677. #region 2、补传失败lis数据
  678. LogHelper.Info("补传失败lis数据开始");
  679. ShowLog = Thread_name + "补传失败lis数据开始";
  680. this.SetText(ShowLog);
  681. this.SetText("补传失败lis数据开始");
  682. int count_pc = 0;
  683. string pc_sql = @"select a.orgCode,
  684. a.orgName,
  685. a.orgThrdCode,
  686. a.reportId,
  687. a.reportName,
  688. a.requestId,
  689. a.barcode,
  690. a.sampleNo,
  691. a.businessNumber,
  692. a.patientType,
  693. a.patientName,
  694. a.patientSex,
  695. a.patientBirthday,
  696. a.patientAge,
  697. a.ageUnit,
  698. a.patientIdCard,
  699. a.inpatientAreaName,
  700. a.roomNo,
  701. a.bedNo,
  702. a.phoneNo,
  703. a.address,
  704. a.reportType,
  705. a.reportTypeName,
  706. a.sampCode,
  707. a.sampName,
  708. a.diagnosisCode,
  709. a.diagnosisName,
  710. a.resultType,
  711. a.applyTime,
  712. a.applyerCode,
  713. a.applyerName,
  714. a.applyDeptCode,
  715. a.applyDeptName,
  716. a.collectTime,
  717. a.collectCode,
  718. a.collectName,
  719. a.transportCode,
  720. a.transportName,
  721. a.transportDeptCode,
  722. a.transportDeptName,
  723. a.transportOrgCode,
  724. a.transportOrgName,
  725. a.acceptTime,
  726. a.acceptorCode,
  727. a.acceptorName,
  728. a.receiveTime,
  729. a.receiverCode,
  730. a.receiverName,
  731. a.checkTime,
  732. a.checkerCode,
  733. a.checkerName,
  734. a.checkDeptCode,
  735. a.checkDeptName,
  736. a.auditTime,
  737. a.auditorCode,
  738. a.auditorName,
  739. a.reportTime,
  740. a.reportorCode,
  741. a.reportorName,
  742. a.sampleNotes,
  743. a.checkPrice,
  744. a.attachmentId,
  745. a.patientId ,
  746. a.healthNo ,
  747. a.medicareNo ,
  748. a.socialNo ,
  749. a.inpatientAreaCode ,
  750. a.sampleName ,
  751. a.execHospitalCode ,
  752. a.execHospitalName,
  753. a.sameHospital,
  754. a.projectCode,
  755. a.projectName
  756. from lis_upload a ,已上传PDF b
  757. where b.businessnumber = a.BUSINESSNUMBER
  758. and b.reportid = a.REPORTID
  759. and b.attachmentid is not null
  760. and b.uploaded = 0
  761. and b.type = 2
  762. and b.uploade_time > sysdate -5 ";
  763. LogHelper.Info("补传lis数据执行sql:" + pc_sql);
  764. List<LIS> list_pc = new List<LIS>();
  765. if (zlhr == zlhrConstant_true)
  766. {
  767. list_pc = OracleHelper<LIS>.PgRunQueryList(pc_sql);
  768. }
  769. else
  770. {
  771. list_pc = OracleHelper<LIS>.RunQueryList(pc_sql);
  772. }
  773. if (list_pc.Count < 1)
  774. {
  775. LogHelper.Info("查询补传[LIS]数据为空,等待下一次轮询。"+ list_pc.Count);
  776. return;
  777. }
  778. for (int i = 0; i < list_pc.Count; i++)
  779. {
  780. List<Dictionary<string, object>> plist_pc = new List<Dictionary<string, object>>();
  781. Dictionary<string, object> dic_pc = new Dictionary<string, object>();
  782. foreach (var property in list_pc[i].GetType().GetProperties())
  783. {
  784. dic_pc.Add(property.Name, property.GetValue(list_pc[i], null));
  785. }
  786. string lisitems_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + list_pc[i].REPORTID +"'";
  787. List<LISITEMS> lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
  788. if (zlhr == zlhrConstant_true)
  789. {
  790. lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
  791. }
  792. else
  793. {
  794. lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
  795. }
  796. if (lisitems.Count < 1)
  797. {
  798. LogHelper.Info("补传查询LIS项目指标数据为空,跳过本条数据上传下一条。");
  799. LogHelper.Info("执行sql:" + lisitems_sql);
  800. continue;
  801. }
  802. if (zlhr == zlhrConstant_true)
  803. {
  804. //处理 互认编码的数据
  805. HandleLisItemData(lisitems);
  806. }
  807. dic_pc.Add("DETAILLIST", lisitems);
  808. plist_pc.Add(dic_pc);
  809. //是否授权
  810. if (!isAuthorization())
  811. {
  812. continue;
  813. }
  814. string json_pacs_pc = JsonConvert.SerializeObject(plist_pc);
  815. json_pacs_pc = "{\"mainBody\":" + json_pacs_pc + "}";
  816. string json_pacs_log_pc = json_pacs_pc;
  817. string vi_pacs_pc = Tools.GuidTo16String();
  818. json_pacs_pc = Tools.AESEncrypt(json_pacs_pc, Tools.pwd, vi_pacs_pc);
  819. //string url_pacs = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
  820. string res_pacs_pc = Tools.WSCenterData(url, json_pacs_pc, vi_pacs_pc, Tools.accessToken, 1);
  821. string res_aes_pacs_pc = Tools.AESDecrypt(res_pacs_pc, Tools.pwd, vi_pacs_pc);
  822. ResPacs respacs_pc = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs_pc), Encoding.UTF8);
  823. if (respacs_pc.statusCode != "1")
  824. {
  825. ShowLog = respacs_pc.message + ",补传[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs_pc;
  826. this.SetText(ShowLog);
  827. LogHelper.Info(ShowLog);
  828. LogHelper.Info("[LIS]出错入参:" + json_pacs_log_pc);
  829. LogHelper.Info("[LIS]出错出参:" + res_aes_pacs_pc);
  830. continue;
  831. }
  832. else
  833. {
  834. Lis_total += 1;
  835. count_pc += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
  836. string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
  837. and BUSINESSNUMBER = '{0}'
  838. and REPORTID = '{1}'";
  839. sql_upload = string.Format(sql_upload, list_pc[i].BUSINESSNUMBER, list_pc[i].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  840. int upload_count = 0;
  841. if (zlhr==zlhrConstant_true)
  842. {
  843. upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
  844. }
  845. else
  846. {
  847. upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
  848. }
  849. if (upload_count < 1)
  850. {
  851. LogHelper.Info("补传[LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
  852. LogHelper.Info("执行sql:" + sql_upload);
  853. ShowLog = "补传[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
  854. this.SetText(ShowLog);
  855. continue;
  856. }
  857. }
  858. ShowLog = Thread_name + "补传第"+i+"条数据成功:医嘱id=" + list_pc[i].REPORTID;
  859. this.SetText(ShowLog);
  860. }
  861. if (count_pc > 0)
  862. {
  863. ShowLog = Thread_name + "本次补传[LIS]数据为[" + count_pc + "]条,等待下一次轮询。";
  864. this.SetText(ShowLog);
  865. LogHelper.Info(ShowLog);
  866. GetLisDefault();
  867. }
  868. #endregion
  869. }
  870. }
  871. catch (Exception ex)
  872. {
  873. LogHelper.Error(ex);
  874. }
  875. }
  876. //处理编码的数据 为医保编码数据
  877. private void HandleLisItemData(List<LISITEMS> items)
  878. {
  879. //处理 互认编码的数据
  880. foreach (LISITEMS item in items)
  881. {
  882. string ITEMCODE = item.ITEMCODE;
  883. string sqlhis = @"Select l.医保编码 From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,互认项目清单 l
  884. Where y.诊疗项目id = x.id And z.id = y.收费项目id And m.收费细目id = z.Id And l.医保通用编码 = m.项目编码 And Rownum = 1
  885. And x.类别 = 'C' And m.险类 = 111
  886. And x.编码 ='{0}'";
  887. sqlhis = string.Format(sqlhis, ITEMCODE);
  888. DataTable dtYbCode = OracleHelper<object>.RunQueryDS(sqlhis);
  889. if (dtYbCode.Rows.Count > 0)
  890. {
  891. //取出诊疗项目id 取获取收费项目的医保编码 并赋值
  892. item.STANDARDITEMID = dtYbCode.Rows[0]["医保编码"].ToString();
  893. }
  894. // 复制 报告id
  895. /* string ITEMCODE = item.STANDARDITEMID;
  896. string sqlhis = @"Select l.医保编码 From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,互认项目清单 l
  897. Where y.诊疗项目id = x.id And z.id = y.收费项目id And m.收费细目id = z.Id And l.医保通用编码 = m.项目编码 And Rownum = 1
  898. And x.类别 = 'C' And m.险类 = 111
  899. And x.编码 ='{0}'";
  900. sqlhis = string.Format(sqlhis, ITEMCODE);
  901. DataTable dtYbCode = OracleHelper<object>.RunQueryDS(sqlhis);
  902. if (dtYbCode.Rows.Count > 0)
  903. {
  904. //取出诊疗项目id 取获取收费项目的医保编码 并赋值
  905. item.STANDARDITEMID = dtYbCode.Rows[0]["医保编码"].ToString();
  906. }*/
  907. }
  908. }
  909. private object LisLock2 = new object();
  910. private void LisUpload2(object Thname)
  911. {
  912. try
  913. {
  914. lock (LisLock2)
  915. {
  916. string Thread_name = "[" + Thname.ToString() + "]";
  917. string url = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
  918. #region 1、单条上传lis文件及数据
  919. LogHelper.Info(Thread_name + "[LIS]开始");
  920. string lis_sql = @"select * from( Select rownum rn,b.* From (Select t.* from lis_upload t
  921. Where
  922. t.attachmentId Is Null
  923. Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
  924. ) b
  925. ) where rn <300 and rn >150 ";
  926. DataTable dt = new DataTable();
  927. if (zlhr == zlhrConstant_true)
  928. {
  929. /*limit 100 offset 100*/
  930. lis_sql = @"Select t.* from lis_upload t Where t.attachmentId Is Null
  931. Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss') limit 100 offset 100";
  932. dt = OracleHelper<object>.PgQueryDS(lis_sql);
  933. }
  934. else
  935. {
  936. dt = OracleHelper<object>.RunQueryDS(lis_sql);
  937. }
  938. LogHelper.Info("thread2 " + lis_sql);
  939. if (dt.Rows.Count < 1)
  940. {
  941. LogHelper.Info(Thread_name + " thread2 本次[LIS]无数据,等待下一次轮询。");
  942. LogHelper.Info("thread2 执行sql:" + lis_sql);
  943. }
  944. else
  945. {
  946. ShowLog = Thread_name + "thread2 本次需上传[LIS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
  947. this.SetText(ShowLog);
  948. LogHelper.Info(ShowLog);
  949. int pdfcountAll = 0;
  950. int uploaded = 0;
  951. for (int i = 0; i < dt.Rows.Count; i++)
  952. {
  953. string orgName = dt.Rows[i]["orgName"].ToString();
  954. string name = dt.Rows[i]["patientName"].ToString();
  955. string sex = dt.Rows[i]["sex"].ToString();
  956. string ch = dt.Rows[i]["bedNo"].ToString();
  957. string zyh = dt.Rows[i]["zyh"].ToString();
  958. string mzh = dt.Rows[i]["mzh"].ToString();
  959. string age = dt.Rows[i]["age"].ToString();
  960. string dep = dt.Rows[i]["dep"].ToString();
  961. string type;
  962. string title = dt.Rows[i]["reportName"].ToString();
  963. string patientType = dt.Rows[i]["patientType"].ToString();
  964. if (patientType == "1")
  965. {
  966. type = "门诊";
  967. }
  968. else if (patientType == "2")
  969. {
  970. type = "住院";
  971. }
  972. else if (patientType == "3")
  973. {
  974. type = "体检";
  975. }
  976. else
  977. {
  978. type = "其他";
  979. }
  980. string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
  981. string signature = "签名:{0} 日期:{1}";
  982. string qname = dt.Rows[i]["auditorName"].ToString();
  983. string qdate = dt.Rows[i]["auditTime"].ToString();
  984. signature = string.Format(signature, qname, qdate);
  985. baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
  986. string reportId = dt.Rows[i]["reportId"].ToString();
  987. string dt_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + reportId + "'";
  988. LogHelper.Info("thread2 项目指标执行sql:" + dt_sql);
  989. DataTable items = new DataTable();
  990. if (zlhr==zlhrConstant_true)
  991. {
  992. items = OracleHelper<object>.PgQueryDS(dt_sql);
  993. }
  994. else
  995. {
  996. items = OracleHelper<object>.RunQueryDS(dt_sql);
  997. }
  998. LogHelper.Info("thread2 项目指标执行sql 条数:" + items.Rows.Count);
  999. if (items.Rows.Count < 1)
  1000. {
  1001. LogHelper.Info("查询LIS项目指标数据为空,生成PDF失败,跳过本条数据生成下一条PDF。");
  1002. continue;
  1003. }
  1004. string res = CreateLisPDF(orgName, baseInfo, items, signature, title);
  1005. if (res == "")
  1006. {
  1007. ShowLog = "生成PDF文件失败,[LIS]上传失败!跳过本条数据上传下一条。";
  1008. this.SetText(ShowLog);
  1009. LogHelper.Info(ShowLog);
  1010. continue;
  1011. }
  1012. //是否授权
  1013. if (!isAuthorization())
  1014. {
  1015. continue;
  1016. }
  1017. //上传文件
  1018. string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检验报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + Tools.FileToBase64Str(res) + "\"}";
  1019. string file_vi = Tools.GuidTo16String();
  1020. file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
  1021. string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
  1022. string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
  1023. string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
  1024. ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
  1025. if (resfile.statusCode != "1")
  1026. {
  1027. LogHelper.Info(resfile.message + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。thread2 ");
  1028. LogHelper.Info("入参:" + file_json);
  1029. LogHelper.Info("出参:" + file_res_aes);
  1030. ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。";
  1031. this.SetText(ShowLog);
  1032. continue;
  1033. }
  1034. string sql = @"Insert Into 已上传PDF(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED,UPLOADE_TIME) Values('{0}','{1}',2,'{2}',0,to_date('{3}','yyyy/mm/dd hh24:mi:ss'))";
  1035. sql = string.Format(sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString(), resfile.mainBody.attachmentId, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1036. int file_count = 0;
  1037. if (zlhr==zlhrConstant_true)
  1038. {
  1039. file_count = OracleHelper<object>.PgExecuteNonQuery(sql);
  1040. }
  1041. else
  1042. {
  1043. file_count = OracleHelper<object>.ExecuteNonQuery(sql);
  1044. }
  1045. if (file_count < 1)
  1046. {
  1047. LogHelper.Info("thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!");
  1048. LogHelper.Info("thread2 执行sql:" + sql);
  1049. ShowLog = "thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql;
  1050. this.SetText(ShowLog);
  1051. continue;
  1052. }
  1053. pdfcountAll += 1;
  1054. //上传lis数据
  1055. string item_sql = @"select a.orgCode,
  1056. a.orgName,
  1057. a.orgThrdCode,
  1058. a.reportId,
  1059. a.reportName,
  1060. a.requestId,
  1061. a.barcode,
  1062. a.sampleNo,
  1063. a.businessNumber,
  1064. a.patientType,
  1065. a.patientName,
  1066. a.patientSex,
  1067. a.patientBirthday,
  1068. a.patientAge,
  1069. a.ageUnit,
  1070. a.patientIdCard,
  1071. a.inpatientAreaName,
  1072. a.roomNo,
  1073. a.bedNo,
  1074. a.phoneNo,
  1075. a.address,
  1076. a.reportType,
  1077. a.reportTypeName,
  1078. a.sampCode,
  1079. a.sampName,
  1080. a.diagnosisCode,
  1081. a.diagnosisName,
  1082. a.resultType,
  1083. a.applyTime,
  1084. a.applyerCode,
  1085. a.applyerName,
  1086. a.applyDeptCode,
  1087. a.applyDeptName,
  1088. a.collectTime,
  1089. a.collectCode,
  1090. a.collectName,
  1091. a.transportCode,
  1092. a.transportName,
  1093. a.transportDeptCode,
  1094. a.transportDeptName,
  1095. a.transportOrgCode,
  1096. a.transportOrgName,
  1097. a.acceptTime,
  1098. a.acceptorCode,
  1099. a.acceptorName,
  1100. a.receiveTime,
  1101. a.receiverCode,
  1102. a.receiverName,
  1103. a.checkTime,
  1104. a.checkerCode,
  1105. a.checkerName,
  1106. a.checkDeptCode,
  1107. a.checkDeptName,
  1108. a.auditTime,
  1109. a.auditorCode,
  1110. a.auditorName,
  1111. a.reportTime,
  1112. a.reportorCode,
  1113. a.reportorName,
  1114. a.sampleNotes,
  1115. a.checkPrice,
  1116. a.attachmentId,
  1117. a.patientId ,
  1118. a.healthNo ,
  1119. a.medicareNo ,
  1120. a.socialNo ,
  1121. a.inpatientAreaCode ,
  1122. a.sampleName ,
  1123. a.execHospitalCode ,
  1124. a.execHospitalName,
  1125. a.sameHospital,
  1126. a.projectCode,
  1127. a.projectName
  1128. from lis_upload a ,已上传PDF b
  1129. where b.businessnumber = a.BUSINESSNUMBER
  1130. and b.reportid = a.REPORTID
  1131. and b.attachmentid is not null
  1132. and b.uploaded = 0
  1133. and b.type = 2
  1134. and a.BUSINESSNUMBER = '{0}'
  1135. and a.REPORTID = '{1}'";
  1136. item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
  1137. List<LIS> list = new List<LIS>();
  1138. if (zlhr==zlhrConstant_true)
  1139. {
  1140. list = OracleHelper<LIS>.PgRunQueryList(item_sql);
  1141. }
  1142. else
  1143. {
  1144. list = OracleHelper<LIS>.RunQueryList(item_sql);
  1145. }
  1146. if (list.Count < 1)
  1147. {
  1148. LogHelper.Info("thread2 查询LIS数据为空,跳过本条数据上传下一条。");
  1149. LogHelper.Info("thread2 执行sql:" + item_sql);
  1150. continue;
  1151. }
  1152. List<Dictionary<string, object>> plist = new List<Dictionary<string, object>>();
  1153. Dictionary<string, object> dic = new Dictionary<string, object>();
  1154. foreach (var property in list[0].GetType().GetProperties())
  1155. {
  1156. dic.Add(property.Name, property.GetValue(list[0], null));
  1157. }
  1158. string lisitems_sql = @"Select* From lis_upload_items t Where t.groupItemCode = '" + list[0].REPORTID + "'";
  1159. List<LISITEMS> lisitems = new List<LISITEMS>();
  1160. if (zlhr==zlhrConstant_true)
  1161. {
  1162. lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
  1163. }
  1164. else
  1165. {
  1166. lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
  1167. }
  1168. if (lisitems.Count < 1)
  1169. {
  1170. LogHelper.Info("查询LIS项目指标数据为空,跳过本条数据上传下一条。");
  1171. LogHelper.Info("执行sql:" + lisitems_sql);
  1172. continue;
  1173. }
  1174. if(zlhr == zlhrConstant_true)
  1175. {
  1176. //处理 互认编码的数据
  1177. HandleLisItemData(lisitems);
  1178. }
  1179. dic.Add("DETAILLIST", lisitems);
  1180. plist.Add(dic);
  1181. //是否授权
  1182. if (!isAuthorization())
  1183. {
  1184. continue;
  1185. }
  1186. string json_pacs = JsonConvert.SerializeObject(plist);
  1187. json_pacs = "{\"mainBody\":" + json_pacs + "}";
  1188. string json_pacs_log = json_pacs;
  1189. string vi_pacs = Tools.GuidTo16String();
  1190. json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
  1191. string res_pacs = Tools.WSCenterData(url, json_pacs, vi_pacs, Tools.accessToken, 1);
  1192. string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
  1193. ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
  1194. if (respacs.statusCode != "1")
  1195. {
  1196. ShowLog = respacs.message + ",thread2 ,[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
  1197. this.SetText(ShowLog);
  1198. LogHelper.Info(ShowLog);
  1199. LogHelper.Info("thread2 [LIS]出错入参:" + json_pacs_log);
  1200. LogHelper.Info("thread2 [LIS]出错出参:" + res_aes_pacs);
  1201. continue;
  1202. }
  1203. else
  1204. {
  1205. Lis_total += 1;
  1206. uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
  1207. string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
  1208. and BUSINESSNUMBER = '{0}'
  1209. and REPORTID = '{1}'";
  1210. sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1211. int upload_count = 0;
  1212. if (zlhr==zlhrConstant_true)
  1213. {
  1214. upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
  1215. }
  1216. else
  1217. {
  1218. upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
  1219. }
  1220. if (upload_count < 1)
  1221. {
  1222. LogHelper.Info("thread2 [LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
  1223. LogHelper.Info("thread2 执行sql:" + sql_upload);
  1224. ShowLog = "thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
  1225. this.SetText(ShowLog);
  1226. continue;
  1227. }
  1228. }
  1229. }
  1230. ShowLog = Thread_name + "thread2 本次已生成、上传[LIS]PDF文件总条数为[" + pdfcountAll + "]条,上传[LIS]总条数为[" + uploaded + "]条。";
  1231. this.SetText(ShowLog);
  1232. LogHelper.Info(ShowLog);
  1233. GetLisDefault();
  1234. }
  1235. #endregion
  1236. }
  1237. }
  1238. catch (Exception ex)
  1239. {
  1240. LogHelper.Error(ex);
  1241. }
  1242. }
  1243. private object PacsLock = new object();
  1244. private void PacsUpload()
  1245. {
  1246. try
  1247. {
  1248. lock (PacsLock)
  1249. {
  1250. int uploaded = 0;
  1251. string url_pacs = "http://40.26.204.3:8084/phimp-napi/qyhrpacscheckreportinfo/save";
  1252. #region 1、生成、上传单条PACS文件及数据
  1253. LogHelper.Info("[PACS]开始");
  1254. string sql_pdf = @"select * from (
  1255. Select rownum as rn,b.* From (select t.* from PACS_UPLOAD t
  1256. Where t.attachmentId Is Null
  1257. Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
  1258. ) b
  1259. ) Where rn <= 100";
  1260. DataTable dt = OracleHelper<object>.RunQueryDS(sql_pdf);
  1261. if (dt.Rows.Count < 1)
  1262. {
  1263. LogHelper.Info("本次无数据,或[PACS]PDF已生成并上传。");
  1264. LogHelper.Info("执行sql:" + sql_pdf);
  1265. }
  1266. else
  1267. {
  1268. ShowLog = "本次需上传[PACS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
  1269. this.SetText(ShowLog);
  1270. int countAll = 0;
  1271. for (int i = 0; i < dt.Rows.Count; i++)
  1272. {
  1273. string orgName = dt.Rows[i]["orgName"].ToString();
  1274. string name = dt.Rows[i]["patientName"].ToString();
  1275. string sex = dt.Rows[i]["sex"].ToString();
  1276. string ch = dt.Rows[i]["bedNo"].ToString();
  1277. string zyh = dt.Rows[i]["zyh"].ToString();
  1278. string mzh = dt.Rows[i]["mzh"].ToString();//patientType
  1279. string age = dt.Rows[i]["age"].ToString();
  1280. string type;
  1281. string patientType = dt.Rows[i]["patientType"].ToString();
  1282. string dep = dt.Rows[i]["dep"].ToString();
  1283. if (patientType == "1")
  1284. {
  1285. type = "门诊";
  1286. }
  1287. else if (patientType == "2")
  1288. {
  1289. type = "住院";
  1290. }
  1291. else if (patientType == "3")
  1292. {
  1293. type = "体检";
  1294. }
  1295. else
  1296. {
  1297. type = "其他";
  1298. }
  1299. string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
  1300. string findings = dt.Rows[i]["findings"].ToString();
  1301. string diagnosResult = dt.Rows[i]["diagnosResult"].ToString();
  1302. string signature = "签名:{0} 日期:{1}";
  1303. string qname = dt.Rows[i]["auditorName"].ToString();
  1304. string qdate = dt.Rows[i]["auditTime"].ToString();
  1305. signature = string.Format(signature, qname, qdate);
  1306. baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
  1307. string res = CreatePDF(orgName, baseInfo, findings, diagnosResult, signature);
  1308. if (res == "")
  1309. {
  1310. ShowLog = "生成PACS的PDF文件失败。[PACS]上传失败!跳过本条数据上传下一条。";
  1311. LogHelper.Info(ShowLog);
  1312. this.SetText(ShowLog);
  1313. continue;
  1314. }
  1315. //是否授权
  1316. if (!isAuthorization())
  1317. {
  1318. continue;
  1319. }
  1320. //string path = Application.StartupPath + "\\pacs.pdf";
  1321. //上传文件
  1322. string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检查报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + Tools.FileToBase64Str(res) + "\"}";
  1323. string file_vi = Tools.GuidTo16String();
  1324. file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
  1325. string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
  1326. string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
  1327. string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
  1328. ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
  1329. if (resfile.statusCode != "1")
  1330. {
  1331. //LogHelper.Info(resfile.message + ",[PACS]文件上传失败,跳过本条数据上传下一条。");
  1332. LogHelper.Info("入参:" + file_json);
  1333. LogHelper.Info("出参:" + file_res_aes);
  1334. ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[PACS]文件上传失败,跳过本条数据上传下一条。";
  1335. this.SetText(ShowLog);
  1336. continue;
  1337. }
  1338. string sql = @"Insert Into 已上传PDF(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED,UPLOADE_TIME) Values('{0}','{1}',1,'{2}',0, to_date('{3}','yyyy/mm/dd hh24:mi:ss'))";
  1339. sql = string.Format(sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString(), resfile.mainBody.attachmentId, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1340. int file_count = OracleHelper<object>.ExecuteNonQuery(sql);
  1341. if (file_count < 1)
  1342. {
  1343. ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条。!";
  1344. LogHelper.Info(ShowLog);
  1345. this.SetText(ShowLog);
  1346. continue;
  1347. }
  1348. countAll += 1;
  1349. //上传数据
  1350. string item_sql = @"select
  1351. a.patientAge ,
  1352. a.ageUnit ,
  1353. a.patientIdCard ,
  1354. a.inTime ,
  1355. a.inpatientAreaName ,
  1356. a.roomNo ,
  1357. a.bedNo ,
  1358. a.phoneNo ,
  1359. a.address ,
  1360. a.reportTypeName ,
  1361. a.reportTypeCode ,
  1362. a.diagnosisCode ,
  1363. a.diagnosisName ,
  1364. a.applyTime ,
  1365. a.applyerCode ,
  1366. a.applyerName ,
  1367. a.applyDeptCode ,
  1368. a.applyDeptName ,
  1369. a.applyOrgCode ,
  1370. a.applyOrgName ,
  1371. a.receiverTime ,
  1372. a.receiverCode ,
  1373. a.receiverName ,
  1374. a.checkTime ,
  1375. a.checkerCode ,
  1376. a.checkerName ,
  1377. a.checkDeptCode ,
  1378. a.checkDeptName ,
  1379. a.reportTime ,
  1380. a.reportorCode ,
  1381. a.reportorName ,
  1382. a.auditTime ,
  1383. a.auditorCode ,
  1384. a.auditorName ,
  1385. a.localItemId ,
  1386. a.standardItemId ,
  1387. a.itemName ,
  1388. a.purpose ,
  1389. a.testPrice ,
  1390. a.checkTypeCode ,
  1391. a.checkTypeName ,
  1392. a.positionCode ,
  1393. a.positionName ,
  1394. a.methodCode ,
  1395. a.methodName ,
  1396. a.isEnganced ,
  1397. a.isMakeShadow ,
  1398. a.process ,
  1399. a.findings ,
  1400. a.diagnosResult ,
  1401. a.resultType ,
  1402. a.unit ,
  1403. a.machineType ,
  1404. a.machineCode ,
  1405. a.machineName ,
  1406. a.attachmentId ,
  1407. a.studyInstanceUid ,
  1408. a.dicomImgFtpUrl ,
  1409. a.orgCode ,
  1410. a.orgName ,
  1411. a.pacsYunOrgCode ,
  1412. a.reportId ,
  1413. a.reportName ,
  1414. a.reportType ,
  1415. a.requestId ,
  1416. a.businessNumber ,
  1417. a.patientType ,
  1418. a.patientName ,
  1419. a.patientSex ,
  1420. a.patientBirthday ,
  1421. a.regionHr,
  1422. a.HEALTHNO,
  1423. a.MEDICARENO ,
  1424. a.ACCESSNUMBER,
  1425. a.CONCLUSION,
  1426. a.BRIEFHISTORY,
  1427. a.ISIMAGESERVICE,
  1428. a.STUDYUID
  1429. from pacs_upload a ,已上传PDF b
  1430. where b.businessnumber = a.BUSINESSNUMBER
  1431. and b.reportid = a.REPORTID
  1432. and b.attachmentid is not null
  1433. and b.uploaded = 0
  1434. and b.type = 1
  1435. and a.BUSINESSNUMBER = '{0}'
  1436. and a.REPORTID = '{1}'";
  1437. item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
  1438. List<PACS> list = OracleHelper<PACS>.RunQueryList(item_sql);
  1439. if (list.Count < 1)
  1440. {
  1441. LogHelper.Info("查询PACS数据为空,跳过本条数据上传下一条。");
  1442. LogHelper.Info("执行sql:" + item_sql);
  1443. continue;
  1444. }
  1445. string json_pacs = Tools.ObjectToJson<List<PACS>>(list, Encoding.UTF8);
  1446. json_pacs = "{\"mainBody\":" + json_pacs + "}";
  1447. if (!isAuthorization())
  1448. {
  1449. continue;
  1450. }
  1451. string json_pacs_log = json_pacs;
  1452. string vi_pacs = Tools.GuidTo16String();
  1453. json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
  1454. string res_pacs = Tools.WSCenterData(url_pacs, json_pacs, vi_pacs, Tools.accessToken, 1);
  1455. string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
  1456. //LogHelper.Info("[PACS]上传出参:" + res_aes_pacs);
  1457. ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
  1458. if (respacs.statusCode != "1")
  1459. {
  1460. ShowLog = respacs.message + ",[PACS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
  1461. this.SetText(ShowLog);
  1462. LogHelper.Info("[PACS]出错入参:" + json_pacs_log);
  1463. LogHelper.Info("[PACS]出错出参:" + res_aes_pacs);
  1464. continue;
  1465. }
  1466. else
  1467. {
  1468. pacs_total += 1;
  1469. uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
  1470. string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 1
  1471. and BUSINESSNUMBER = '{0}'
  1472. and REPORTID = '{1}'";
  1473. sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1474. int upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
  1475. if (upload_count < 1)
  1476. {
  1477. LogHelper.Info("[PACS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
  1478. LogHelper.Info("执行sql:" + sql_upload);
  1479. ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
  1480. this.SetText(ShowLog);
  1481. continue;
  1482. }
  1483. }
  1484. }
  1485. ShowLog = "本次已生成、上传[PACS]PDF文件总条数为[" + countAll + "]条,上传[PACS]总条数为[" + uploaded + "]条。";
  1486. this.SetText(ShowLog);
  1487. LogHelper.Info(ShowLog);
  1488. GetPacsDefault();
  1489. }
  1490. #endregion
  1491. #region 2、补传失败数据
  1492. //上传数据
  1493. LogHelper.Info("PACS补传失败数据");
  1494. string pc_sql = @"select
  1495. a.patientAge ,
  1496. a.ageUnit ,
  1497. a.patientIdCard ,
  1498. a.inTime ,
  1499. a.inpatientAreaName ,
  1500. a.roomNo ,
  1501. a.bedNo ,
  1502. a.phoneNo ,
  1503. a.address ,
  1504. a.reportTypeName ,
  1505. a.reportTypeCode ,
  1506. a.diagnosisCode ,
  1507. a.diagnosisName ,
  1508. a.applyTime ,
  1509. a.applyerCode ,
  1510. a.applyerName ,
  1511. a.applyDeptCode ,
  1512. a.applyDeptName ,
  1513. a.applyOrgCode ,
  1514. a.applyOrgName ,
  1515. a.receiverTime ,
  1516. a.receiverCode ,
  1517. a.receiverName ,
  1518. a.checkTime ,
  1519. a.checkerCode ,
  1520. a.checkerName ,
  1521. a.checkDeptCode ,
  1522. a.checkDeptName ,
  1523. a.reportTime ,
  1524. a.reportorCode ,
  1525. a.reportorName ,
  1526. a.auditTime ,
  1527. a.auditorCode ,
  1528. a.auditorName ,
  1529. a.localItemId ,
  1530. a.standardItemId ,
  1531. a.itemName ,
  1532. a.purpose ,
  1533. a.testPrice ,
  1534. a.checkTypeCode ,
  1535. a.checkTypeName ,
  1536. a.positionCode ,
  1537. a.positionName ,
  1538. a.methodCode ,
  1539. a.methodName ,
  1540. a.isEnganced ,
  1541. a.isMakeShadow ,
  1542. a.process ,
  1543. a.findings ,
  1544. a.diagnosResult ,
  1545. a.resultType ,
  1546. a.unit ,
  1547. a.machineType ,
  1548. a.machineCode ,
  1549. a.machineName ,
  1550. a.attachmentId ,
  1551. a.studyInstanceUid ,
  1552. a.dicomImgFtpUrl ,
  1553. a.orgCode ,
  1554. a.orgName ,
  1555. a.pacsYunOrgCode ,
  1556. a.reportId ,
  1557. a.reportName ,
  1558. a.reportType ,
  1559. a.requestId ,
  1560. a.businessNumber ,
  1561. a.patientType ,
  1562. a.patientName ,
  1563. a.patientSex ,
  1564. a.patientBirthday ,
  1565. a.regionHr,
  1566. a.HEALTHNO,
  1567. a.MEDICARENO ,
  1568. a.ACCESSNUMBER,
  1569. a.CONCLUSION,
  1570. a.BRIEFHISTORY,
  1571. a.ISIMAGESERVICE,
  1572. a.STUDYUID
  1573. from pacs_upload a ,已上传PDF b
  1574. where b.businessnumber = a.BUSINESSNUMBER
  1575. and b.reportid = a.REPORTID
  1576. and b.attachmentid is not null
  1577. and b.uploaded = 0
  1578. and b.type = 1";
  1579. List<PACS> list_pc = OracleHelper<PACS>.RunQueryList(pc_sql);
  1580. if (list_pc.Count < 1)
  1581. {
  1582. LogHelper.Info("查询补传PACS数据为空,等待下一次轮询。");
  1583. LogHelper.Info("执行sql:" + pc_sql);
  1584. return;
  1585. }
  1586. int count_pc = 0;
  1587. for (int i = 0; i < list_pc.Count; i++)
  1588. {
  1589. if (!isAuthorization())
  1590. {
  1591. continue;
  1592. }
  1593. string json_pacs = Tools.ObjectToJson<List<PACS>>(list_pc[i], Encoding.UTF8);
  1594. json_pacs = "{\"mainBody\":[" + json_pacs + "]}";
  1595. string json_pacs_log = json_pacs;
  1596. string vi_pacs = Tools.GuidTo16String();
  1597. json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
  1598. string res_pacs = Tools.WSCenterData(url_pacs, json_pacs, vi_pacs, Tools.accessToken, 1);
  1599. string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
  1600. //LogHelper.Info("[PACS]上传出参:" + res_aes_pacs);
  1601. ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
  1602. if (respacs.statusCode != "1")
  1603. {
  1604. ShowLog = respacs.message + ",[PACS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
  1605. this.SetText(ShowLog);
  1606. LogHelper.Info("[PACS]出错入参:" + json_pacs_log);
  1607. LogHelper.Info("[PACS]出错出参:" + res_aes_pacs);
  1608. continue;
  1609. }
  1610. else
  1611. {
  1612. pacs_total += 1;
  1613. count_pc += 1;
  1614. string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 1
  1615. and BUSINESSNUMBER = '{0}'
  1616. and REPORTID = '{1}'";
  1617. sql_upload = string.Format(sql_upload, list_pc[i].BUSINESSNUMBER, list_pc[i].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  1618. int upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
  1619. if (upload_count < 1)
  1620. {
  1621. LogHelper.Info("[PACS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
  1622. LogHelper.Info("执行sql:" + sql_upload);
  1623. ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
  1624. this.SetText(ShowLog);
  1625. continue;
  1626. }
  1627. }
  1628. }
  1629. if (count_pc > 0)
  1630. {
  1631. ShowLog = "本次补传[PACS]数据为[" + count_pc + "]条,等待下一次轮询。";
  1632. this.SetText(ShowLog);
  1633. LogHelper.Info(ShowLog);
  1634. GetPacsDefault();
  1635. }
  1636. #endregion
  1637. }
  1638. }
  1639. catch (Exception ex)
  1640. {
  1641. LogHelper.Error(ex);
  1642. }
  1643. }
  1644. /// <summary>
  1645. /// 生成pdf
  1646. /// </summary>
  1647. /// <param name="orgName">印江自治县人民医院</param>
  1648. /// <param name="baseInfo">"姓名:刘蚝 性别:男 年龄:20岁 床号:8床 住院号:20121545 门诊号:65478854"</param>
  1649. /// <param name="findings"></param>
  1650. /// <param name="diagnosResult"></param>
  1651. /// <param name="signature">签名:杨添红 日期:2022.9.7</param>
  1652. private string CreatePDF(string orgName, string baseInfo, string findings, string diagnosResult, string signature)
  1653. {
  1654. string res = "";
  1655. try
  1656. {
  1657. Document document = new Document(HeaderAndFooterEvent.rect);
  1658. //string dic = AppDomain.CurrentDomain.BaseDirectory + "Pacs\\";
  1659. if (!Directory.Exists(DicPacs))
  1660. {
  1661. Directory.CreateDirectory(DicPacs);
  1662. }
  1663. string path = DicPacs + Guid.NewGuid() + ".pdf";
  1664. //此处使用的是http请求的流,你也可以使用文件流Stream
  1665. FileStream str = new FileStream(path, FileMode.Create);
  1666. PdfWriter writer = PdfWriter.GetInstance(document, str);
  1667. document.Open();
  1668. writer.PageEvent = new HeaderAndFooterEvent();
  1669. HeaderAndFooterEvent.PAGE_NUMBER = false;//实现页眉跟页脚
  1670. HeaderAndFooterEvent.tpl = writer.DirectContent.CreateTemplate(500, 500); //定义模板
  1671. //印江自治县人民医院
  1672. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1673. document.Add(HeaderAndFooterEvent.AddParagraph(orgName, 1, 1.5f));
  1674. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1675. document.Add(HeaderAndFooterEvent.AddParagraph("检查报告单", 1, 1.5f));
  1676. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1677. document.Add(HeaderAndFooterEvent.AddParagraph(baseInfo, 0, 3f));
  1678. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1679. document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
  1680. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1681. document.Add(HeaderAndFooterEvent.AddParagraph(@"诊断意见:" + diagnosResult, 0, 1.5f));
  1682. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1683. document.Add(HeaderAndFooterEvent.AddParagraph(@"检查所见:" + findings, 0, 1.5f));
  1684. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1685. document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
  1686. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1687. document.Add(HeaderAndFooterEvent.AddParagraph(signature, 2, 1.5f));
  1688. writer.Flush();
  1689. writer.CloseStream = true;
  1690. document.Close();
  1691. //writer.Close();
  1692. //str.Close();
  1693. res = path;
  1694. }
  1695. catch (Exception ex)
  1696. {
  1697. res = "";
  1698. LogHelper.Error(ex);
  1699. }
  1700. return res;
  1701. }
  1702. private string CreateLisPDF(string orgName, string baseInfo, DataTable dt, string signature, string title)
  1703. {
  1704. string res = "";
  1705. try
  1706. {
  1707. Document document = new Document(HeaderAndFooterEvent.rect);
  1708. //此处使用的是http请求的流,你也可以使用文件流Stream
  1709. //string dic = AppDomain.CurrentDomain.BaseDirectory + "Lis\\";
  1710. if (!Directory.Exists(DicLis))
  1711. {
  1712. Directory.CreateDirectory(DicLis);
  1713. }
  1714. string path = DicLis + Guid.NewGuid() + ".pdf";
  1715. FileStream str = new FileStream(path, FileMode.Create);
  1716. PdfWriter writer = PdfWriter.GetInstance(document, str);
  1717. document.Open();
  1718. writer.PageEvent = new HeaderAndFooterEvent();
  1719. HeaderAndFooterEvent.PAGE_NUMBER = false;//实现页眉跟页脚
  1720. HeaderAndFooterEvent.tpl = writer.DirectContent.CreateTemplate(500, 500); //定义模板
  1721. //印江自治县人民医院
  1722. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1723. document.Add(HeaderAndFooterEvent.AddParagraph(orgName, 1, 1.5f));
  1724. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1725. document.Add(HeaderAndFooterEvent.AddParagraph(title + "报告单", 1, 1.5f));
  1726. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1727. document.Add(HeaderAndFooterEvent.AddParagraph(baseInfo, 0, 3f));
  1728. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1729. document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
  1730. //HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1731. //document.Add(HeaderAndFooterEvent.AddParagraph(@"序号 项目 结果 单位 参考区间", 0, 1.5f));
  1732. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1733. HeaderAndFooterEvent.CreateTable(dt, document);
  1734. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
  1735. document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
  1736. HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
  1737. document.Add(HeaderAndFooterEvent.AddParagraph(signature, 2, 1.5f));
  1738. writer.Flush();
  1739. writer.CloseStream = true;
  1740. document.Close();
  1741. res = path;
  1742. }
  1743. catch (Exception ex)
  1744. {
  1745. LogHelper.Info("CreateLisPDF 生成失败");
  1746. res = "";
  1747. LogHelper.Error(ex);
  1748. }
  1749. return res;
  1750. }
  1751. //token是否过期
  1752. private bool isAuthorization()
  1753. {
  1754. bool result = true;
  1755. if (string.IsNullOrWhiteSpace(Tools.accessToken) || Tools.DateTimes == null || Tools.DateTimes <= DateTime.Now)
  1756. {
  1757. //获取授权
  1758. string vi = Tools.GuidTo16String();
  1759. string url = "http://40.26.204.3:8084/phimp-napi/token";
  1760. string res = Tools.WSCenterData(url, "", vi);
  1761. string res_aes = Tools.AESDecrypt(res, Tools.pwd, vi);
  1762. Authorization ahz = Tools.JsonToObject<Authorization>(Tools.FormatStr(res_aes), Encoding.UTF8);
  1763. if (ahz.statusCode != "1")
  1764. {
  1765. ShowLog = ahz.message + ",获取Token授权失败!等待下一次轮询。";
  1766. this.SetText(ShowLog);
  1767. LogHelper.Info(ShowLog);
  1768. result = false;
  1769. }
  1770. Tools.accessToken = ahz.mainBody.accessToken;
  1771. Tools.DateTimes = DateTime.Now.AddSeconds(int.Parse(ahz.mainBody.expirationTime));
  1772. }
  1773. return result;
  1774. }
  1775. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  1776. {
  1777. if (e.CloseReason == CloseReason.UserClosing)
  1778. {
  1779. //是否取消close操作
  1780. e.Cancel = true;
  1781. this.WindowState = FormWindowState.Minimized;
  1782. }
  1783. }
  1784. private void checkBox1_Click(object sender, EventArgs e)
  1785. {
  1786. int hr = 0;
  1787. string sql = @"update 互认配置表 set 互认 = {0}";
  1788. bool bl = checkBox1.Checked;
  1789. if (checkBox1.Checked)
  1790. {
  1791. hr = 1;
  1792. }
  1793. sql = string.Format(sql, hr);
  1794. int res = OracleHelper<object>.ExecuteNonQuery(sql);
  1795. if (res > 0)
  1796. {
  1797. if (bl)
  1798. {
  1799. textBox1.Text = "已修改为互认!";
  1800. }
  1801. else
  1802. {
  1803. textBox1.Text = "已修改为不互认!";
  1804. }
  1805. }
  1806. else
  1807. {
  1808. textBox1.Text = "是否互认修改失败!";
  1809. if (bl)
  1810. {
  1811. checkBox1.Checked = false;
  1812. }
  1813. else
  1814. {
  1815. checkBox1.Checked = true;
  1816. }
  1817. }
  1818. }
  1819. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  1820. {
  1821. AutoStart();
  1822. }
  1823. public void GetLisDefault()
  1824. {
  1825. string sql = @"select count(1) listotal from lis_upload where attachmentId is null";
  1826. DataTable dt = new DataTable();
  1827. if (zlhr==zlhrConstant_true)
  1828. {
  1829. dt = OracleHelper<object>.PgQueryDS(sql);
  1830. }
  1831. else
  1832. {
  1833. dt = OracleHelper<object>.RunQueryDS(sql);
  1834. }
  1835. string label_lis = dt.Rows[0]["listotal"].ToString() + "条";
  1836. string lis_count = Lis_total + "条";
  1837. this.SetLisText(label_lis);
  1838. this.SetLisCountText(lis_count);
  1839. //获取待上传的数量
  1840. string waitsql = @"select count(1) listotal from lis_upload a ,已上传PDF b
  1841. where b.businessnumber = a.BUSINESSNUMBER
  1842. and b.reportid = a.REPORTID
  1843. and b.attachmentid is not null
  1844. and b.uploaded = 0
  1845. and b.type = 2";
  1846. DataTable waitdt = new DataTable();
  1847. if (zlhr == zlhrConstant_true)
  1848. {
  1849. waitdt = OracleHelper<object>.PgQueryDS(waitsql);
  1850. }
  1851. else
  1852. {
  1853. waitdt = OracleHelper<object>.RunQueryDS(sql);
  1854. }
  1855. LogHelper.Info("待上传数量为:" + waitdt.Rows[0]["listotal"].ToString() + "条");
  1856. }
  1857. public void GetPacsDefault()
  1858. {
  1859. string sql = @"select count(1) pacstotal from pacs_upload where attachmentId is null";
  1860. DataTable dt = OracleHelper<object>.RunQueryDS(sql);
  1861. string label_pacs = dt.Rows[0]["pacstotal"].ToString() + "条";
  1862. string pacs_count = pacs_total + "条";
  1863. this.SetPassText(label_pacs);
  1864. this.SetPacsCountText(pacs_count);
  1865. }
  1866. private void SetText(string text)
  1867. {
  1868. // InvokeRequired需要比较调用线程ID和创建线程ID
  1869. // 如果它们不相同则返回true
  1870. if (this.textBox1.InvokeRequired)
  1871. {
  1872. SetTextCallback d = new SetTextCallback(SetText);
  1873. this.Invoke(d, new object[] { text });
  1874. }
  1875. else
  1876. {
  1877. this.textBox1.Text = text;
  1878. }
  1879. }
  1880. private void SetLisText(string text)
  1881. {
  1882. // InvokeRequired需要比较调用线程ID和创建线程ID
  1883. // 如果它们不相同则返回true
  1884. if (this.textBox1.InvokeRequired)
  1885. {
  1886. SetTextCallback d = new SetTextCallback(SetLisText);
  1887. this.Invoke(d, new object[] { text });
  1888. }
  1889. else
  1890. {
  1891. this.label_lis.Text = text;
  1892. }
  1893. }
  1894. private void SetPassText(string text)
  1895. {
  1896. // InvokeRequired需要比较调用线程ID和创建线程ID
  1897. // 如果它们不相同则返回true
  1898. if (this.textBox1.InvokeRequired)
  1899. {
  1900. SetTextCallback d = new SetTextCallback(SetPassText);
  1901. this.Invoke(d, new object[] { text });
  1902. }
  1903. else
  1904. {
  1905. this.label_pacs.Text = text;
  1906. }
  1907. }
  1908. private void SetLisCountText(string text)
  1909. {
  1910. // InvokeRequired需要比较调用线程ID和创建线程ID
  1911. // 如果它们不相同则返回true
  1912. if (this.textBox1.InvokeRequired)
  1913. {
  1914. SetTextCallback d = new SetTextCallback(SetLisCountText);
  1915. this.Invoke(d, new object[] { text });
  1916. }
  1917. else
  1918. {
  1919. this.lis_count.Text = text;
  1920. }
  1921. }
  1922. private void SetPacsCountText(string text)
  1923. {
  1924. // InvokeRequired需要比较调用线程ID和创建线程ID
  1925. // 如果它们不相同则返回true
  1926. if (this.textBox1.InvokeRequired)
  1927. {
  1928. SetTextCallback d = new SetTextCallback(SetPacsCountText);
  1929. this.Invoke(d, new object[] { text });
  1930. }
  1931. else
  1932. {
  1933. this.pacs_count.Text = text;
  1934. }
  1935. }
  1936. private void DelPDF()
  1937. {
  1938. //每月1号删除
  1939. if (DateTime.Now.Day != 1)
  1940. {
  1941. return;
  1942. }
  1943. int month = OracleHelper<object>.UploadTime();
  1944. if (month < 1)
  1945. {
  1946. return;
  1947. }
  1948. string sql = @"delete from 已上传PDF a where a.uploaded = 1 And a.Uploade_Time < add_months(Sysdate,-{0})";
  1949. sql = string.Format(sql,month);
  1950. OracleHelper<object>.ExecuteNonQuery(sql);
  1951. }
  1952. }
  1953. }