Form1.cs 107 KB

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