Form1.cs 109 KB

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