Form1.cs 121 KB

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