123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208 |
- using Common;
- using iTextSharp.text;
- using iTextSharp.text.pdf;
- using LisPacsDataUpload.business;
- using LisPacsDataUpload.Models;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Web.UI.WebControls;
- using System.Windows.Forms;
- using System.Xml;
- namespace LisPacsDataUpload
- {
- public partial class Form1 : Form
- {
- private static int zlhrConstant_true=1;// 是临生免 常量
- //定时器
- private System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
- //private DateTime Date;
- //private int PageSize = 10;
- //private int PageIndex = 0;
- //PageIndex = PageIndex + 1;
- // int PageStart = (PageIndex - 1) * PageSize + 1;
- //int PageEnd = PageSize * PageIndex;
- private int UploadPacs;//是否上传pacs
- private string ShowLog = "";
- private int Lis_total = 0;//今日lis上传总数
- private int pacs_total = 0;//今日pacs上传总数
- private string DicPacs = AppDomain.CurrentDomain.BaseDirectory + "Pacs\\";
- private string DicLis = AppDomain.CurrentDomain.BaseDirectory + "Lis\\";
- private int zlhr = 0;// 是否为临生免
- private int lisSource = 1;// 0中联老版lis 1 中联新版lis 2 专业版临生免 3 三方lis
- private int open_multiple_upload_flag = 0;// 开启多个线程上传
- private delegate void SetTextCallback(string text);
- //在给textBox1.text赋值的地方调用以下方法即可
- public Form1()
- {
- InitializeComponent();
- this.MinimumSize = new Size(0, 0);
- timer1.Interval = OracleHelper<object>.Time();
- timer1.Enabled = true;
- timer1.Tick += new EventHandler(DataUpload);//添加事件
- timer1.Start();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- ShowLog = "启动正常。";
- LogHelper.Info(ShowLog);
- this.SetText(ShowLog);
- ShowCheckBox1();
- ShowCheckBox2();
- UploadPacs = OracleHelper<object>.UploadPacs();
- GetLisDefault();
- if (UploadPacs == 1)
- {
- GetPacsDefault();
- }
- //AutoStart();
- DataUpload(sender, e);
- }
- private void ShowCheckBox1()
- {
- try
- {
- string sql_lis = @"select 互认,zlhr,open_multiple_upload,lis_source from 互认配置表";
- DataTable dt_lis = OracleHelper<object>.RunQueryDS(sql_lis);
- int total = int.Parse(dt_lis.Rows[0]["互认"].ToString());
- if (total == 1)
- {
- checkBox1.Checked = true;
- }
- else
- {
- checkBox1.Checked = false;
- }
- int zlhrValue = int.Parse(dt_lis.Rows[0]["zlhr"].ToString());
- if (zlhrValue == zlhrConstant_true)
- {
- zlhr = zlhrValue;
- }
- open_multiple_upload_flag = int.Parse(dt_lis.Rows[0]["open_multiple_upload"].ToString());
- lisSource = int.Parse(dt_lis.Rows[0]["lis_source"].ToString());
- }
- catch (Exception ex)
- {
- LogHelper.Info("ex===" + ex.Message);
- }
-
- }
- private void ShowCheckBox2()
- {
- XmlDocument xmldoc = new XmlDocument();
- string xmlpath = AppDomain.CurrentDomain.BaseDirectory + "Xml.xml";
- xmldoc.Load(xmlpath);
- string str = xmldoc.SelectSingleNode("/root/key").InnerXml;
- if (str == "0")
- {
- checkBox2.Checked = false;
- }
- else
- {
- checkBox2.Checked = true;
- }
- }
- /// <summary>
- /// 开机启动
- /// </summary>
- private void AutoStart()
- {
- try
- {
- XmlDocument xmldoc = new XmlDocument();
- string xmlpath = AppDomain.CurrentDomain.BaseDirectory + "Xml.xml";
- xmldoc.Load(xmlpath);
- string str = xmldoc.SelectSingleNode("/root/key").InnerXml;
- if (str == "0")
- {
- string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
- string path = Application.ExecutablePath.ToLower(); //将当前程序起动路径
- string name = System.IO.Path.GetFileName(path); //获得应用程序名称
- var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true);
- if (regKey != null && regKey.GetValue("LisPacsDataUpload") == null)
- {
- regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);
- regKey.SetValue("LisPacsDataUpload", path);
- regKey.Close();
- }
- XmlElement element = (XmlElement)xmldoc.SelectSingleNode("/root/key");
- element.InnerText = "1";
- xmldoc.Save(xmlpath);
- ShowLog = "写入注册表成功。";
- this.SetText(ShowLog);
- LogHelper.Info("写入注册表成功。");
- }
- else
- {
- ShowLog = "不允许此操作!";
- this.SetText(ShowLog);
- if (checkBox2.Checked)
- {
- checkBox2.Checked = false;
- }
- else
- {
- checkBox2.Checked = true;
- }
- }
- }
- catch (Exception ex)
- {
- //ShowLog = "不允许此操作!";
- //this.SetText(ShowLog);
- if (checkBox2.Checked)
- {
- checkBox2.Checked = false;
- }
- else
- {
- checkBox2.Checked = true;
- }
- ShowLog = "写入注册表异常:" + ex.Message;
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- }
- }
- private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
- {
- //switch (e.Button)
- //{
- // case System.Windows.Forms.MouseButtons.Left: //左击
- // //判断是否已经最小化于托盘
- // if (WindowState == FormWindowState.Minimized)
- // {
- // //还原窗体显示
- // WindowState = FormWindowState.Normal;
- // //激活窗体并给予它焦点
- // this.Activate();
- // //任务栏区显示图标
- // this.ShowInTaskbar = true;
- // //托盘区图标隐藏
- // notifyIcon1.Visible = false;
- // }
- // break;
- // case System.Windows.Forms.MouseButtons.Right:
- // //MessageBox.Show("右键");
- // break;
- //}
- }
- private void open_click(object sender, EventArgs e)
- {
- if (WindowState == FormWindowState.Minimized)
- {
- WindowState = FormWindowState.Normal;
- this.Activate();
- this.ShowInTaskbar = true;
- }
- }
- private void close_click(object sender, EventArgs e)
- {
- //this.Close();
- LogHelper.Info("程序退出。");
- System.Environment.Exit(0);
- }
- private void Form1_SizeChanged(object sender, EventArgs e)
- {
- //判断是否选择的是最小化按钮
- if (WindowState == FormWindowState.Minimized)
- {
- //托盘显示图标等于托盘图标对象
- //注意notifyIcon1是控件的名字而不是对象的名字
- //隐藏任务栏区图标
- this.ShowInTaskbar = false;
- //图标显示在托盘区
- notifyIcon1.Visible = true;
- }
- }
- private void DataUpload(object source, EventArgs e)
- {
- LogHelper.Info("开始轮询。");
- DateTime Date = DateTime.Now;
- int time = Date.Hour;
- int StartTime = OracleHelper<object>.StartTime();//18
- if (time == 0)
- {//今日上传数清零
- Lis_total = 0;
- pacs_total = 0;
- }
- else if (time < StartTime && time > 7)//
- {
- ShowLog = "开始轮询时间为[" + StartTime + "]点至明日早上7点,现在是" + time + "点。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- if (Directory.Exists(DicLis))
- {
- Directory.Delete(DicLis, true);
- }
- if (Directory.Exists(DicPacs))
- {
- Directory.Delete(DicPacs, true);
- }
- DelPDF();
- return;
- }
- LogHelper.Info("zlhr=="+zlhr);
- string name = "LIS1" + Tools.GuidTo16String();
- Thread th = new Thread(new ParameterizedThreadStart(CountUpload));
- th.IsBackground = true;
- th.Name = name;
- th.Start(name);
- System.Threading.Thread.Sleep(5000);
- string name2 = "LIS2" + Tools.GuidTo16String();
- Thread th2 = new Thread(new ParameterizedThreadStart(LisUpload));
- th2.IsBackground = true;
- th2.Name = name2;
- th2.Start(name2);
- // 开启第二个上传
- if (1== open_multiple_upload_flag)
- {
- System.Threading.Thread.Sleep(5000);
- string name3 = "LIS3" + Tools.GuidTo16String();
- Thread th3 = new Thread(new ParameterizedThreadStart(LisUpload2));
- th3.IsBackground = true;
- th3.Name = name3;
- th3.Start(name3);
- }
- if (UploadPacs == 1)//没传影像云的需要上传检查
- {
- LogHelper.Info("没传影像云的需要上传检查");
- Thread thp = new Thread(new ThreadStart(PacsUpload));
- thp.IsBackground = true;
- thp.Name = "PACS" + Tools.GuidTo16String();
- thp.Start();
- }
- }
- private object CountLock = new object();
- private void CountUpload(object Thname)
- {
- try
- {
- lock (CountLock)
- {
- string Thread_name = "[" + Thname.ToString() + "]";
- string url = "http://40.26.204.3:8084/phimp-napi/qyhrApplyInfo/upload";
- int success_count = 0;
- LogHelper.Info(Thread_name + "上传开单合计开始");
- string count_sql = @"select * from bill_project_view"
- ;
- List<Count> list_count = OracleHelper<Count>.RunQueryList(count_sql);
- LogHelper.Info("list_count" + list_count);
- if (list_count.Count < 1)
- {
- LogHelper.Info(Thread_name + "本次开单无数据,等待下一次轮询。");
- LogHelper.Info("执行sql:" + count_sql);
- }
- else
- {
- for (int i = 0; i < list_count.Count; i++)
- {
- if (!isAuthorization())
- {
- continue;
- }
- Dictionary<string, object> dic_pc = new Dictionary<string, object>();
- foreach (var property in list_count[i].GetType().GetProperties())
- {
- //LogHelper.Info("[count]Name:" + property.Name);
- //LogHelper.Info("[count]value:" + property.GetValue(list_count[i], null));
- dic_pc.Add(property.Name, property.GetValue(list_count[i], null));
- }
- string json_count = JsonConvert.SerializeObject(dic_pc);
- string json_count_log = json_count;
- string vi_count = Tools.GuidTo16String();
- json_count = Tools.AESEncrypt(json_count, Tools.pwd, vi_count);
- string res_pacs_pc = Tools.WSCenterData(url, json_count, vi_count, Tools.accessToken, 1);
- string res_aes_pacs_pc = Tools.AESDecrypt(res_pacs_pc, Tools.pwd, vi_count);
- ResPacs respacs_pc = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs_pc), Encoding.UTF8);
- if (respacs_pc.statusCode != "1")
- {
- ShowLog = respacs_pc.message + ",[LIS]清单数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_count;
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- LogHelper.Info("[count]出错入参:" + json_count_log);
- LogHelper.Info("[LIS]出错入参:" + json_count + "|....|" + Tools.accessToken);
- LogHelper.Info("[count]出错出参:" + res_aes_pacs_pc);
- continue;
- }
- else
- {
- // LogHelper.Info(success_count + "入参:" + json_count_log);
- //LogHelper.Info(success_count + "出参:" + respacs_pc.message);
- //修改状态
- string sql_upload = @"update 互认开单项目 set 是否上传 = 1,上传时间 = to_date('{1}','yyyy/mm/dd hh24:mi:ss') where 相关id = '{0}'";
- sql_upload = string.Format(sql_upload, list_count[i].HISAPPLYCODE, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- LogHelper.Info("清单上传"+ upload_count);
- success_count++;
- }
- }
- LogHelper.Info("本次清单上传:" + success_count);
- }
- }
- }
- catch (Exception e)
- {
- LogHelper.Error(e);
- }
- }
- private object LisLock = new object();
- private void LisUpload(object Thname)
- {
- try
- {
- lock (LisLock)
- {
- string Thread_name = "[" + Thname.ToString() + "]";
- string url = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
- #region 1、单条上传lis文件及数据
- LogHelper.Info(Thread_name + "[LIS]开始");
- string lis_sql = @"select * from( Select rownum rn,b.* From (Select t.* from lis_upload t
- Where
- t.attachmentId Is Null
- Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
- ) b
- ) where rn <= 150 ";
- DataTable dt = new DataTable();
- if (zlhr == zlhrConstant_true)
- {
- lis_sql = @"Select t.* from lis_upload t Where t.attachmentId Is Null
- Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss') limit 100";
- dt = OracleHelper<object>.PgQueryDS(lis_sql);
- }
- else
- {
- dt = OracleHelper<object>.RunQueryDS(lis_sql);
- }
- LogHelper.Info("执行sql:" + lis_sql);
- if (dt.Rows.Count < 1)
- {
- LogHelper.Info(Thread_name + "本次[LIS]无数据,等待下一次轮询。");
- }
- else
- {
- ShowLog = Thread_name + "本次需上传[LIS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- int pdfcountAll = 0;
- int uploaded = 0;
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- //生成pdf
- string generatePdfUrl = "未生成pdf成功";
- if (zlhr == zlhrConstant_true)
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 临生免报告id
- string sql_zlhr = @"select dr.id as id from specimen_rec sr, diagnosticreport_rec dr where sr.id = dr.specmids::int
- and dr.status in ('3003', '3004') and sr.id = " + requestId;
- DataTable dt_lis = OracleHelper<object>.PgQueryDS(sql_zlhr);
- string reportId = dt_lis.Rows[0]["id"].ToString();
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, reportId, reportId,null);
- }
- else if(lisSource==3){
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, requestId, requestId,null);
- if (!generatePdfUrl.Contains(".pdf"))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- }
- else if (lisSource == 10)
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- string pdfUrl = dt.Rows[i]["pdfUrl"].ToString(); // 三方pdf地址 需要下载
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, pdfUrl, requestId,null);
- if (string.IsNullOrEmpty(generatePdfUrl))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- }
- else
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- //获取标本号 和报表编号
- string reportNumber = dt.Rows[i]["reportNumber"].ToString(); //报告编号
- string bbid = dt.Rows[i]["bbid"].ToString(); // 标本id
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, reportNumber, bbid, requestId);
- if (!generatePdfUrl.Contains(".pdf"))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- LogHelper.Info("生成pdf成功,地址为 = " );
- }
- /*string orgName = dt.Rows[i]["orgName"].ToString();
- string name = dt.Rows[i]["patientName"].ToString();
- string sex = dt.Rows[i]["sex"].ToString();
- string ch = dt.Rows[i]["bedNo"].ToString();
- string zyh = dt.Rows[i]["zyh"].ToString();
- string mzh = dt.Rows[i]["mzh"].ToString();
- string age = dt.Rows[i]["age"].ToString();
- string dep = dt.Rows[i]["dep"].ToString();
- string type;
- string title = dt.Rows[i]["reportName"].ToString();
- string patientType = dt.Rows[i]["patientType"].ToString();
- if (patientType == "1")
- {
- type = "门诊";
- }
- else if (patientType == "2")
- {
- type = "住院";
- }
- else if (patientType == "3")
- {
- type = "体检";
- }
- else
- {
- type = "其他";
- }
- string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
- string signature = "签名:{0} 日期:{1}";
- string qname = dt.Rows[i]["auditorName"].ToString();
- string qdate = dt.Rows[i]["auditTime"].ToString();
- signature = string.Format(signature, qname, qdate);
- baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
- string reportId = dt.Rows[i]["reportId"].ToString();
- string dt_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + reportId+"'";
- LogHelper.Info("查询LIS项目指标数据执行sql:" + dt_sql);
- DataTable items = new DataTable();
- if (zlhr == zlhrConstant_true)
- {
- items = OracleHelper<object>.PgQueryDS(dt_sql);
- }
- else
- {
- items = OracleHelper<object>.RunQueryDS(dt_sql);
- }
- LogHelper.Info("查询LIS项目指标数据执行sql 条数=:" + items.Rows.Count);
- if (items.Rows.Count < 1)
- {
- LogHelper.Info("查询LIS项目指标数据为空,生成PDF失败,跳过本条数据生成下一条PDF。");
- continue;
- }
- string res = CreateLisPDF(orgName, baseInfo, items, signature, title);
- if (res == "")
- {
-
- ShowLog = "生成PDF文件失败,[LIS]上传失败!跳过本条数据上传下一条。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- continue;
- }*/
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- //最新调整 需要获取 原始pdf 文件 存在场景 有三方lis、中联lis 、 以及专业版临生免 的报告 三种
- LogHelper.Info("最后GeneratePdfUrl= ");
- string attachmentFile = "";
- if (zlhr == zlhrConstant_true)
- {
- attachmentFile = generatePdfUrl;
- }
- else
- {
- attachmentFile = Tools.FileToBase64Str(generatePdfUrl);
- }
- //LogHelper.Info("上传的文件类容==" + attachmentFile);
- //上传文件
- string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检验报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + attachmentFile + "\"}";
- string file_vi = Tools.GuidTo16String();
- file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
- string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
- string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
- string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
- ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
- if (resfile.statusCode != "1")
- {
- LogHelper.Info(resfile.message + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。");
- LogHelper.Info("入参:" + file_json);
- LogHelper.Info("出参:" + file_res_aes);
- ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。";
- this.SetText(ShowLog);
- continue;
- }
- 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'))";
- 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"));
- int file_count = 0;
- if (zlhr == zlhrConstant_true)
- {
- LogHelper.Info("sql:" + sql);
- file_count = OracleHelper<object>.PgExecuteNonQuery(sql);
- }
- else
- {
- file_count = OracleHelper<object>.ExecuteNonQuery(sql);
- }
- if (file_count < 1)
- {
- LogHelper.Info("[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("执行sql:" + sql);
- ShowLog = "[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql;
- this.SetText(ShowLog);
- continue;
- }
- pdfcountAll += 1;
- //上传lis数据
- string item_sql = @"select a.orgCode,
- a.orgName,
- a.orgThrdCode,
- a.reportId,
- a.reportName,
- a.requestId,
- a.barcode,
- a.sampleNo,
- a.businessNumber,
- a.patientType,
- a.patientName,
- a.patientSex,
- a.patientBirthday,
- a.patientAge,
- a.ageUnit,
- a.patientIdCard,
- a.inpatientAreaName,
- a.roomNo,
- a.bedNo,
- a.phoneNo,
- a.address,
- a.reportType,
- a.reportTypeName,
- a.sampCode,
- a.sampName,
- a.diagnosisCode,
- a.diagnosisName,
- a.resultType,
- a.applyTime,
- a.applyerCode,
- a.applyerName,
- a.applyDeptCode,
- a.applyDeptName,
- a.collectTime,
- a.collectCode,
- a.collectName,
- a.transportCode,
- a.transportName,
- a.transportDeptCode,
- a.transportDeptName,
- a.transportOrgCode,
- a.transportOrgName,
- a.acceptTime,
- a.acceptorCode,
- a.acceptorName,
- a.receiveTime,
- a.receiverCode,
- a.receiverName,
- a.checkTime,
- a.checkerCode,
- a.checkerName,
- a.checkDeptCode,
- a.checkDeptName,
- a.auditTime,
- a.auditorCode,
- a.auditorName,
- a.reportTime,
- a.reportorCode,
- a.reportorName,
- a.sampleNotes,
- a.checkPrice,
- a.attachmentId,
- a.patientId ,
- a.healthNo ,
- a.medicareNo ,
- a.socialNo ,
- a.inpatientAreaCode ,
- a.sampleName ,
- a.execHospitalCode ,
- a.execHospitalName,
- a.sameHospital,
- a.projectCode,
- a.projectName
- from lis_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 2
- and a.BUSINESSNUMBER = '{0}'
- and a.REPORTID = '{1}'";
- item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
- List<LIS> list = new List<LIS>();
- if (zlhr == zlhrConstant_true)
- {
- list = OracleHelper<LIS>.PgRunQueryList(item_sql);
- }
- else
- {
- list = OracleHelper<LIS>.RunQueryList(item_sql);
- }
- if (list.Count < 1)
- {
- LogHelper.Info("查询LIS数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("执行sql:" + item_sql);
- continue;
- }
- List<Dictionary<string, object>> plist = new List<Dictionary<string, object>>();
- Dictionary<string, object> dic = new Dictionary<string, object>();
- foreach (var property in list[0].GetType().GetProperties())
- {
- dic.Add(property.Name, property.GetValue(list[0], null));
- }
- string lisitems_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + list[0].REPORTID + "'";
- List<LISITEMS> lisitems = new List<LISITEMS>();
- if (zlhr == zlhrConstant_true)
- {
- lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
- }
- else
- {
- lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
- }
- if (lisitems.Count < 1)
- {
- LogHelper.Info("查询LIS项目指标数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("执行sql:" + lisitems_sql);
- continue;
- }
- if (zlhr == zlhrConstant_true)
- {
- //处理 互认编码的数据
- HandleLisItemDataForWebLis(lisitems);
- }
- dic.Add("DETAILLIST", lisitems);
- plist.Add(dic);
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- string json_pacs = JsonConvert.SerializeObject(plist);
- LogHelper.Info("lis 上传的json>>"+ json_pacs);
- json_pacs = "{\"mainBody\":" + json_pacs + "}";
- string json_pacs_log = json_pacs;
- string vi_pacs = Tools.GuidTo16String();
- json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
- string res_pacs = Tools.WSCenterData(url, json_pacs, vi_pacs, Tools.accessToken, 1);
- string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
- ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
- LogHelper.Info("上传检验报告的接口状态==" + JsonConvert.SerializeObject(respacs));
- if (respacs.statusCode != "1")
- {
- ShowLog = respacs.message + ",[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- LogHelper.Info("[LIS]出错入参:" + json_pacs_log);
- LogHelper.Info("[LIS]出错出参:" + res_aes_pacs);
- continue;
- }
- else
- {
- Lis_total += 1;
- uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
- string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
- and BUSINESSNUMBER = '{0}'
- and REPORTID = '{1}'";
- sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = 0;
- if (zlhr == zlhrConstant_true)
- {
- upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
- }
- else
- {
- upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- }
- if (upload_count < 1)
- {
- LogHelper.Info("[LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("执行sql:" + sql_upload);
- ShowLog = "[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
- this.SetText(ShowLog);
- continue;
- }
- }
- }
- ShowLog = Thread_name + "本次已生成、上传[LIS]PDF文件总条数为[" + pdfcountAll + "]条,上传[LIS]总条数为[" + uploaded + "]条。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- GetLisDefault();
- }
- #endregion
- #region 2、补传失败lis数据
- LogHelper.Info("补传失败lis数据开始");
- ShowLog = Thread_name + "补传失败lis数据开始";
- this.SetText(ShowLog);
- this.SetText("补传失败lis数据开始");
- int count_pc = 0;
- string pc_sql = @"select a.orgCode,
- a.orgName,
- a.orgThrdCode,
- a.reportId,
- a.reportName,
- a.requestId,
- a.barcode,
- a.sampleNo,
- a.businessNumber,
- a.patientType,
- a.patientName,
- a.patientSex,
- a.patientBirthday,
- a.patientAge,
- a.ageUnit,
- a.patientIdCard,
- a.inpatientAreaName,
- a.roomNo,
- a.bedNo,
- a.phoneNo,
- a.address,
- a.reportType,
- a.reportTypeName,
- a.sampCode,
- a.sampName,
- a.diagnosisCode,
- a.diagnosisName,
- a.resultType,
- a.applyTime,
- a.applyerCode,
- a.applyerName,
- a.applyDeptCode,
- a.applyDeptName,
- a.collectTime,
- a.collectCode,
- a.collectName,
- a.transportCode,
- a.transportName,
- a.transportDeptCode,
- a.transportDeptName,
- a.transportOrgCode,
- a.transportOrgName,
- a.acceptTime,
- a.acceptorCode,
- a.acceptorName,
- a.receiveTime,
- a.receiverCode,
- a.receiverName,
- a.checkTime,
- a.checkerCode,
- a.checkerName,
- a.checkDeptCode,
- a.checkDeptName,
- a.auditTime,
- a.auditorCode,
- a.auditorName,
- a.reportTime,
- a.reportorCode,
- a.reportorName,
- a.sampleNotes,
- a.checkPrice,
- a.attachmentId,
- a.patientId ,
- a.healthNo ,
- a.medicareNo ,
- a.socialNo ,
- a.inpatientAreaCode ,
- a.sampleName ,
- a.execHospitalCode ,
- a.execHospitalName,
- a.sameHospital,
- a.projectCode,
- a.projectName
- from lis_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 2 ";
- LogHelper.Info("补传lis数据执行sql:" + pc_sql);
- List<LIS> list_pc = new List<LIS>();
- if (zlhr == zlhrConstant_true)
- {
- list_pc = OracleHelper<LIS>.PgRunQueryList(pc_sql);
- }
- else
- {
- list_pc = OracleHelper<LIS>.RunQueryList(pc_sql);
- }
- if (list_pc.Count < 1)
- {
- LogHelper.Info("查询补传[LIS]数据为空,等待下一次轮询。"+ list_pc.Count);
- return;
- }
- for (int i = 0; i < list_pc.Count; i++)
- {
- List<Dictionary<string, object>> plist_pc = new List<Dictionary<string, object>>();
- Dictionary<string, object> dic_pc = new Dictionary<string, object>();
- foreach (var property in list_pc[i].GetType().GetProperties())
- {
- dic_pc.Add(property.Name, property.GetValue(list_pc[i], null));
- }
- string lisitems_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + list_pc[i].REPORTID +"'";
- List<LISITEMS> lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
- if (zlhr == zlhrConstant_true)
- {
- lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
- }
- else
- {
- lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
- }
- if (lisitems.Count < 1)
- {
- LogHelper.Info("补传查询LIS项目指标数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("执行sql:" + lisitems_sql);
- continue;
- }
- if (zlhr == zlhrConstant_true)
- {
- //处理 互认编码的数据
- HandleLisItemDataForWebLis(lisitems);
- }
-
- dic_pc.Add("DETAILLIST", lisitems);
- plist_pc.Add(dic_pc);
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- string json_pacs_pc = JsonConvert.SerializeObject(plist_pc);
- json_pacs_pc = "{\"mainBody\":" + json_pacs_pc + "}";
- string json_pacs_log_pc = json_pacs_pc;
- string vi_pacs_pc = Tools.GuidTo16String();
- json_pacs_pc = Tools.AESEncrypt(json_pacs_pc, Tools.pwd, vi_pacs_pc);
- //string url_pacs = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
- string res_pacs_pc = Tools.WSCenterData(url, json_pacs_pc, vi_pacs_pc, Tools.accessToken, 1);
- string res_aes_pacs_pc = Tools.AESDecrypt(res_pacs_pc, Tools.pwd, vi_pacs_pc);
- ResPacs respacs_pc = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs_pc), Encoding.UTF8);
- if (respacs_pc.statusCode != "1")
- {
- ShowLog = respacs_pc.message + ",补传[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs_pc;
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- LogHelper.Info("[LIS]出错入参:" + json_pacs_log_pc);
- LogHelper.Info("[LIS]出错出参:" + res_aes_pacs_pc);
- continue;
- }
- else
- {
- Lis_total += 1;
- count_pc += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
- string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
- and BUSINESSNUMBER = '{0}'
- and REPORTID = '{1}'";
- sql_upload = string.Format(sql_upload, list_pc[i].BUSINESSNUMBER, list_pc[i].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = 0;
- if (zlhr==zlhrConstant_true)
- {
- upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
- }
- else
- {
- upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- }
- if (upload_count < 1)
- {
- LogHelper.Info("补传[LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("执行sql:" + sql_upload);
- ShowLog = "补传[LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
- this.SetText(ShowLog);
- continue;
- }
- }
- ShowLog = Thread_name + "补传第"+i+"条数据成功:医嘱id=" + list_pc[i].REPORTID;
- this.SetText(ShowLog);
- }
- if (count_pc > 0)
- {
- ShowLog = Thread_name + "本次补传[LIS]数据为[" + count_pc + "]条,等待下一次轮询。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- GetLisDefault();
- }
- #endregion
- }
- }
- catch (Exception ex)
- {
- LogHelper.Error(ex);
- }
- }
- private void HandleLisItemDataForWebLis(List<LISITEMS> items)
- {
- //处理 互认编码的数据
- foreach (LISITEMS item in items)
- {
- string OBVID = item.OBVID;
- string sqlhis = @"select 代码 from zllpmr.字典对码表 where 分类 = '检验互认项目' and 编码 ='{0}'";
- sqlhis = string.Format(sqlhis, OBVID);
- DataTable dtYbCode = OracleHelper<object>.RunQueryDS(sqlhis);
- if (dtYbCode.Rows.Count > 0)
- {
- //取出诊疗项目id 取获取收费项目的医保编码 并赋值
- item.STANDARDITEMID = dtYbCode.Rows[0]["代码"].ToString();
- }
- }
- }
- //处理编码的数据 为医保编码数据
- private void HandleLisItemData(List<LISITEMS> items)
- {
- //处理 互认编码的数据
- foreach (LISITEMS item in items)
- {
- string ITEMCODE = item.ITEMCODE;
- string sqlhis = @"Select l.医保编码 From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,互认项目清单 l
- Where y.诊疗项目id = x.id And z.id = y.收费项目id And m.收费细目id = z.Id And l.医保通用编码 = m.项目编码 And Rownum = 1
- And x.类别 = 'C' And m.险类 = 111
- And x.编码 ='{0}'";
- sqlhis = string.Format(sqlhis, ITEMCODE);
- DataTable dtYbCode = OracleHelper<object>.RunQueryDS(sqlhis);
- if (dtYbCode.Rows.Count > 0)
- {
- //取出诊疗项目id 取获取收费项目的医保编码 并赋值
- item.STANDARDITEMID = dtYbCode.Rows[0]["医保编码"].ToString();
- }
- // 复制 报告id
- /* string ITEMCODE = item.STANDARDITEMID;
- string sqlhis = @"Select l.医保编码 From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,互认项目清单 l
- Where y.诊疗项目id = x.id And z.id = y.收费项目id And m.收费细目id = z.Id And l.医保通用编码 = m.项目编码 And Rownum = 1
- And x.类别 = 'C' And m.险类 = 111
- And x.编码 ='{0}'";
- sqlhis = string.Format(sqlhis, ITEMCODE);
- DataTable dtYbCode = OracleHelper<object>.RunQueryDS(sqlhis);
- if (dtYbCode.Rows.Count > 0)
- {
- //取出诊疗项目id 取获取收费项目的医保编码 并赋值
- item.STANDARDITEMID = dtYbCode.Rows[0]["医保编码"].ToString();
- }*/
- }
- }
- private object LisLock2 = new object();
- private void LisUpload2(object Thname)
- {
- try
- {
- lock (LisLock2)
- {
- string Thread_name = "[" + Thname.ToString() + "]";
- string url = "http://40.26.204.3:8084/phimp-napi/qyhrlischeckreportinfo/save";
- #region 1、单条上传lis文件及数据
- LogHelper.Info(Thread_name + "[LIS]开始");
- string lis_sql = @"select * from( Select rownum rn,b.* From (Select t.* from lis_upload t
- Where
- t.attachmentId Is Null
- Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
- ) b
- ) where rn <300 and rn >150 ";
- DataTable dt = new DataTable();
- if (zlhr == zlhrConstant_true)
- {
- /*limit 100 offset 100*/
- lis_sql = @"Select t.* from lis_upload t Where t.attachmentId Is Null
- Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss') limit 100 offset 100";
- dt = OracleHelper<object>.PgQueryDS(lis_sql);
- }
- else
- {
- dt = OracleHelper<object>.RunQueryDS(lis_sql);
- }
- LogHelper.Info("thread2 " + lis_sql);
- if (dt.Rows.Count < 1)
- {
- LogHelper.Info(Thread_name + " thread2 本次[LIS]无数据,等待下一次轮询。");
- LogHelper.Info("thread2 执行sql:" + lis_sql);
- }
- else
- {
- ShowLog = Thread_name + "thread2 本次需上传[LIS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- int pdfcountAll = 0;
- int uploaded = 0;
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- //生成pdf
- string generatePdfUrl = "未生成pdf成功";
- if (zlhr == zlhrConstant_true)
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 临生免报告id
- string sql_zlhr = @"select dr.id as id from specimen_rec sr, diagnosticreport_rec dr where sr.id = dr.specmids::int
- and dr.status in ('3003', '3004') and sr.id = " + requestId;
- DataTable dt_lis = OracleHelper<object>.PgQueryDS(sql_zlhr);
- string reportId = dt_lis.Rows[0]["id"].ToString();
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, reportId, reportId,null);
- }
- else if (lisSource == 3)
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, requestId, requestId, null);
- if (!generatePdfUrl.Contains(".pdf"))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- }
- else if (lisSource == 10)
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- string pdfUrl = dt.Rows[i]["pdfUrl"].ToString(); // 三方pdf地址 需要下载
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, pdfUrl, requestId, null);
- if (string.IsNullOrEmpty(generatePdfUrl))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- }
- else
- {
- string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
- //获取标本号 和报表编号
- string reportNumber = dt.Rows[i]["reportNumber"].ToString(); //报告编号
- string bbid = dt.Rows[i]["bbid"].ToString(); // 标本id
- generatePdfUrl = PdfUtils.GeneratePdf(lisSource, reportNumber, bbid, requestId);
- if (!generatePdfUrl.Contains(".pdf"))
- {
- LogHelper.Info("生成pdf失败,原因是 = " + generatePdfUrl);
- ShowLog = "生成pdf失败,原因是 =" + generatePdfUrl;
- this.SetText(ShowLog);
- continue;
- }
- LogHelper.Info("生成pdf成功,地址为 = " + generatePdfUrl);
- }
- /*string orgName = dt.Rows[i]["orgName"].ToString();
- string name = dt.Rows[i]["patientName"].ToString();
- string sex = dt.Rows[i]["sex"].ToString();
- string ch = dt.Rows[i]["bedNo"].ToString();
- string zyh = dt.Rows[i]["zyh"].ToString();
- string mzh = dt.Rows[i]["mzh"].ToString();
- string age = dt.Rows[i]["age"].ToString();
- string dep = dt.Rows[i]["dep"].ToString();
- string type;
- string title = dt.Rows[i]["reportName"].ToString();
- string patientType = dt.Rows[i]["patientType"].ToString();
- if (patientType == "1")
- {
- type = "门诊";
- }
- else if (patientType == "2")
- {
- type = "住院";
- }
- else if (patientType == "3")
- {
- type = "体检";
- }
- else
- {
- type = "其他";
- }
- string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
- string signature = "签名:{0} 日期:{1}";
- string qname = dt.Rows[i]["auditorName"].ToString();
- string qdate = dt.Rows[i]["auditTime"].ToString();
- signature = string.Format(signature, qname, qdate);
- baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
- string reportId = dt.Rows[i]["reportId"].ToString();
- string dt_sql = @"Select * From lis_upload_items t Where t.groupItemCode = '" + reportId + "'";
- LogHelper.Info("thread2 项目指标执行sql:" + dt_sql);
- DataTable items = new DataTable();
- if (zlhr==zlhrConstant_true)
- {
- items = OracleHelper<object>.PgQueryDS(dt_sql);
- }
- else
- {
- items = OracleHelper<object>.RunQueryDS(dt_sql);
- }
- LogHelper.Info("thread2 项目指标执行sql 条数:" + items.Rows.Count);
- if (items.Rows.Count < 1)
- {
- LogHelper.Info("查询LIS项目指标数据为空,生成PDF失败,跳过本条数据生成下一条PDF。");
- continue;
- }
- string res = CreateLisPDF(orgName, baseInfo, items, signature, title);
- if (res == "")
- {
- ShowLog = "生成PDF文件失败,[LIS]上传失败!跳过本条数据上传下一条。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- continue;
- }*/
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- LogHelper.Info("thread2 最后GeneratePdfUrl= " + generatePdfUrl);
- string attachmentFile = "";
- if (zlhr == zlhrConstant_true)
- {
- attachmentFile = generatePdfUrl;
- }
- else
- {
- attachmentFile = Tools.FileToBase64Str(generatePdfUrl);
- }
- //上传文件
- string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检验报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + attachmentFile + "\"}";
- string file_vi = Tools.GuidTo16String();
- file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
- string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
- string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
- string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
- ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
- if (resfile.statusCode != "1")
- {
- LogHelper.Info(resfile.message + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。thread2 ");
- LogHelper.Info("入参:" + file_json);
- LogHelper.Info("出参:" + file_res_aes);
- ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[LIS]PDF文件上传失败!跳过本条数据上传下一条。";
- this.SetText(ShowLog);
- continue;
- }
- 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'))";
- 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"));
- int file_count = 0;
- if (zlhr==zlhrConstant_true)
- {
- file_count = OracleHelper<object>.PgExecuteNonQuery(sql);
- }
- else
- {
- file_count = OracleHelper<object>.ExecuteNonQuery(sql);
- }
- if (file_count < 1)
- {
- LogHelper.Info("thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("thread2 执行sql:" + sql);
- ShowLog = "thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql;
- this.SetText(ShowLog);
- continue;
- }
- pdfcountAll += 1;
- //上传lis数据
- string item_sql = @"select a.orgCode,
- a.orgName,
- a.orgThrdCode,
- a.reportId,
- a.reportName,
- a.requestId,
- a.barcode,
- a.sampleNo,
- a.businessNumber,
- a.patientType,
- a.patientName,
- a.patientSex,
- a.patientBirthday,
- a.patientAge,
- a.ageUnit,
- a.patientIdCard,
- a.inpatientAreaName,
- a.roomNo,
- a.bedNo,
- a.phoneNo,
- a.address,
- a.reportType,
- a.reportTypeName,
- a.sampCode,
- a.sampName,
- a.diagnosisCode,
- a.diagnosisName,
- a.resultType,
- a.applyTime,
- a.applyerCode,
- a.applyerName,
- a.applyDeptCode,
- a.applyDeptName,
- a.collectTime,
- a.collectCode,
- a.collectName,
- a.transportCode,
- a.transportName,
- a.transportDeptCode,
- a.transportDeptName,
- a.transportOrgCode,
- a.transportOrgName,
- a.acceptTime,
- a.acceptorCode,
- a.acceptorName,
- a.receiveTime,
- a.receiverCode,
- a.receiverName,
- a.checkTime,
- a.checkerCode,
- a.checkerName,
- a.checkDeptCode,
- a.checkDeptName,
- a.auditTime,
- a.auditorCode,
- a.auditorName,
- a.reportTime,
- a.reportorCode,
- a.reportorName,
- a.sampleNotes,
- a.checkPrice,
- a.attachmentId,
- a.patientId ,
- a.healthNo ,
- a.medicareNo ,
- a.socialNo ,
- a.inpatientAreaCode ,
- a.sampleName ,
- a.execHospitalCode ,
- a.execHospitalName,
- a.sameHospital,
- a.projectCode,
- a.projectName
- from lis_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 2
- and a.BUSINESSNUMBER = '{0}'
- and a.REPORTID = '{1}'";
- item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
- List<LIS> list = new List<LIS>();
- if (zlhr==zlhrConstant_true)
- {
- list = OracleHelper<LIS>.PgRunQueryList(item_sql);
- }
- else
- {
- list = OracleHelper<LIS>.RunQueryList(item_sql);
- }
- if (list.Count < 1)
- {
- LogHelper.Info("thread2 查询LIS数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("thread2 执行sql:" + item_sql);
- continue;
- }
- List<Dictionary<string, object>> plist = new List<Dictionary<string, object>>();
- Dictionary<string, object> dic = new Dictionary<string, object>();
- foreach (var property in list[0].GetType().GetProperties())
- {
- dic.Add(property.Name, property.GetValue(list[0], null));
- }
- string lisitems_sql = @"Select* From lis_upload_items t Where t.groupItemCode = '" + list[0].REPORTID + "'";
-
- List<LISITEMS> lisitems = new List<LISITEMS>();
- if (zlhr==zlhrConstant_true)
- {
- lisitems = OracleHelper<LISITEMS>.PgRunQueryList(lisitems_sql);
- }
- else
- {
- lisitems = OracleHelper<LISITEMS>.RunQueryList(lisitems_sql);
- }
- if (lisitems.Count < 1)
- {
- LogHelper.Info("查询LIS项目指标数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("执行sql:" + lisitems_sql);
- continue;
- }
- if(zlhr == zlhrConstant_true)
- {
- //处理 互认编码的数据
- HandleLisItemDataForWebLis(lisitems);
- }
-
- dic.Add("DETAILLIST", lisitems);
- plist.Add(dic);
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- string json_pacs = JsonConvert.SerializeObject(plist);
- json_pacs = "{\"mainBody\":" + json_pacs + "}";
- string json_pacs_log = json_pacs;
- string vi_pacs = Tools.GuidTo16String();
- json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
- string res_pacs = Tools.WSCenterData(url, json_pacs, vi_pacs, Tools.accessToken, 1);
- string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
- ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
- if (respacs.statusCode != "1")
- {
- ShowLog = respacs.message + ",thread2 ,[LIS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- LogHelper.Info("thread2 [LIS]出错入参:" + json_pacs_log);
- LogHelper.Info("thread2 [LIS]出错出参:" + res_aes_pacs);
- continue;
- }
- else
- {
- Lis_total += 1;
- uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
- string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 2
- and BUSINESSNUMBER = '{0}'
- and REPORTID = '{1}'";
- sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = 0;
- if (zlhr==zlhrConstant_true)
- {
- upload_count = OracleHelper<object>.PgExecuteNonQuery(sql_upload);
- }
- else
- {
- upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- }
- if (upload_count < 1)
- {
- LogHelper.Info("thread2 [LIS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("thread2 执行sql:" + sql_upload);
- ShowLog = "thread2 [LIS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
- this.SetText(ShowLog);
- continue;
- }
- }
- }
- ShowLog = Thread_name + "thread2 本次已生成、上传[LIS]PDF文件总条数为[" + pdfcountAll + "]条,上传[LIS]总条数为[" + uploaded + "]条。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- GetLisDefault();
- }
- #endregion
-
- }
- }
- catch (Exception ex)
- {
- LogHelper.Error(ex);
- }
- }
- private object PacsLock = new object();
- private void PacsUpload()
- {
- try
- {
- lock (PacsLock)
- {
- int uploaded = 0;
- string url_pacs = "http://40.26.204.3:8084/phimp-napi/qyhrpacscheckreportinfo/save";
- #region 1、生成、上传单条PACS文件及数据
- LogHelper.Info("[PACS]开始");
- string sql_pdf = @"select * from (
- Select rownum as rn,b.* From (select t.* from PACS_UPLOAD t
- Where t.attachmentId Is Null
- Order By to_date(t.AUDITTIME,'yyyy-mm-dd hh24:mi:ss')
- ) b
- ) Where rn <= 100";
- DataTable dt = OracleHelper<object>.RunQueryDS(sql_pdf);
- if (dt.Rows.Count < 1)
- {
- LogHelper.Info("本次无数据,或[PACS]PDF已生成并上传。");
- LogHelper.Info("执行sql:" + sql_pdf);
- }
- else
- {
- ShowLog = "本次需上传[PACS]数据总条数为[" + dt.Rows.Count + "]条,逐条上传中,请耐心等待。";
- this.SetText(ShowLog);
- int countAll = 0;
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string orgName = dt.Rows[i]["orgName"].ToString();
- string name = dt.Rows[i]["patientName"].ToString();
- string sex = dt.Rows[i]["sex"].ToString();
- string ch = dt.Rows[i]["bedNo"].ToString();
- string zyh = dt.Rows[i]["zyh"].ToString();
- string mzh = dt.Rows[i]["mzh"].ToString();//patientType
- string age = dt.Rows[i]["age"].ToString();
- string type;
- string patientType = dt.Rows[i]["patientType"].ToString();
- string dep = dt.Rows[i]["dep"].ToString();
- if (patientType == "1")
- {
- type = "门诊";
- }
- else if (patientType == "2")
- {
- type = "住院";
- }
- else if (patientType == "3")
- {
- type = "体检";
- }
- else
- {
- type = "其他";
- }
- string baseInfo = "姓名:{0} 性别:{1} 年龄:{2} 病人来源:{3} 床号:{4} 住院号:{5} 门诊号:{6} 申请科室:{7}";
- string findings = dt.Rows[i]["findings"].ToString();
- string diagnosResult = dt.Rows[i]["diagnosResult"].ToString();
- string signature = "签名:{0} 日期:{1}";
- string qname = dt.Rows[i]["auditorName"].ToString();
- string qdate = dt.Rows[i]["auditTime"].ToString();
- signature = string.Format(signature, qname, qdate);
- baseInfo = string.Format(baseInfo, name, sex, age, type, ch, zyh, mzh, dep);
- string res = CreatePDF(orgName, baseInfo, findings, diagnosResult, signature);
- if (res == "")
- {
- ShowLog = "生成PACS的PDF文件失败。[PACS]上传失败!跳过本条数据上传下一条。";
- LogHelper.Info(ShowLog);
- this.SetText(ShowLog);
- continue;
- }
- //是否授权
- if (!isAuthorization())
- {
- continue;
- }
- //string path = Application.StartupPath + "\\pacs.pdf";
- //上传文件
- string file_json = "{\"attachmentType\":\".pdf\",\"attachmentName\":\"检查报告\",\"businessType\":\"A001\",\"attachmentFile\":\"" + Tools.FileToBase64Str(res) + "\"}";
- string file_vi = Tools.GuidTo16String();
- file_json = Tools.AESEncrypt(file_json, Tools.pwd, file_vi);
- string file_url = "http://40.26.204.3:8084/phimp-napi/attachMent/upload";
- string file_res = Tools.WSCenterData(file_url, file_json, file_vi, Tools.accessToken, 1);
- string file_res_aes = Tools.AESDecrypt(file_res, Tools.pwd, file_vi);
- ResFile resfile = Tools.JsonToObject<ResFile>(Tools.FormatStr(file_res_aes), Encoding.UTF8);
- if (resfile.statusCode != "1")
- {
- //LogHelper.Info(resfile.message + ",[PACS]文件上传失败,跳过本条数据上传下一条。");
- LogHelper.Info("入参:" + file_json);
- LogHelper.Info("出参:" + file_res_aes);
- ShowLog = "入参:" + file_json + ",出参:" + file_res_aes + ",[PACS]文件上传失败,跳过本条数据上传下一条。";
- this.SetText(ShowLog);
- continue;
- }
- 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'))";
- 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"));
- int file_count = OracleHelper<object>.ExecuteNonQuery(sql);
- if (file_count < 1)
- {
- ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条。!";
- LogHelper.Info(ShowLog);
- this.SetText(ShowLog);
- continue;
- }
- countAll += 1;
- //上传数据
- string item_sql = @"select
- a.patientAge ,
- a.ageUnit ,
- a.patientIdCard ,
- a.inTime ,
- a.inpatientAreaName ,
- a.roomNo ,
- a.bedNo ,
- a.phoneNo ,
- a.address ,
- a.reportTypeName ,
- a.reportTypeCode ,
- a.diagnosisCode ,
- a.diagnosisName ,
- a.applyTime ,
- a.applyerCode ,
- a.applyerName ,
- a.applyDeptCode ,
- a.applyDeptName ,
- a.applyOrgCode ,
- a.applyOrgName ,
- a.receiverTime ,
- a.receiverCode ,
- a.receiverName ,
- a.checkTime ,
- a.checkerCode ,
- a.checkerName ,
- a.checkDeptCode ,
- a.checkDeptName ,
- a.reportTime ,
- a.reportorCode ,
- a.reportorName ,
- a.auditTime ,
- a.auditorCode ,
- a.auditorName ,
- a.localItemId ,
- a.standardItemId ,
- a.itemName ,
- a.purpose ,
- a.testPrice ,
- a.checkTypeCode ,
- a.checkTypeName ,
- a.positionCode ,
- a.positionName ,
- a.methodCode ,
- a.methodName ,
- a.isEnganced ,
- a.isMakeShadow ,
- a.process ,
- a.findings ,
- a.diagnosResult ,
- a.resultType ,
- a.unit ,
- a.machineType ,
- a.machineCode ,
- a.machineName ,
- a.attachmentId ,
- a.studyInstanceUid ,
- a.dicomImgFtpUrl ,
- a.orgCode ,
- a.orgName ,
- a.pacsYunOrgCode ,
- a.reportId ,
- a.reportName ,
- a.reportType ,
- a.requestId ,
- a.businessNumber ,
- a.patientType ,
- a.patientName ,
- a.patientSex ,
- a.patientBirthday ,
- a.regionHr,
- a.HEALTHNO,
- a.MEDICARENO ,
- a.ACCESSNUMBER,
- a.CONCLUSION,
- a.BRIEFHISTORY,
- a.ISIMAGESERVICE,
- a.STUDYUID
- from pacs_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 1
- and a.BUSINESSNUMBER = '{0}'
- and a.REPORTID = '{1}'";
- item_sql = string.Format(item_sql, dt.Rows[i]["businessNumber"].ToString(), dt.Rows[i]["reportId"].ToString());
- List<PACS> list = OracleHelper<PACS>.RunQueryList(item_sql);
- if (list.Count < 1)
- {
- LogHelper.Info("查询PACS数据为空,跳过本条数据上传下一条。");
- LogHelper.Info("执行sql:" + item_sql);
- continue;
- }
- string json_pacs = Tools.ObjectToJson<List<PACS>>(list, Encoding.UTF8);
- json_pacs = "{\"mainBody\":" + json_pacs + "}";
- if (!isAuthorization())
- {
- continue;
- }
- string json_pacs_log = json_pacs;
- string vi_pacs = Tools.GuidTo16String();
- json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
- string res_pacs = Tools.WSCenterData(url_pacs, json_pacs, vi_pacs, Tools.accessToken, 1);
- string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
- //LogHelper.Info("[PACS]上传出参:" + res_aes_pacs);
- ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
- if (respacs.statusCode != "1")
- {
- ShowLog = respacs.message + ",[PACS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
- this.SetText(ShowLog);
- LogHelper.Info("[PACS]出错入参:" + json_pacs_log);
- LogHelper.Info("[PACS]出错出参:" + res_aes_pacs);
- continue;
- }
- else
- {
- pacs_total += 1;
- uploaded += 1;//(BUSINESSNUMBER,REPORTID,TYPE,ATTACHMENTID,UPLOADED) Values('{0}','{1}',2,'{2}',0)
- string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 1
- and BUSINESSNUMBER = '{0}'
- and REPORTID = '{1}'";
- sql_upload = string.Format(sql_upload, list[0].BUSINESSNUMBER, list[0].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- if (upload_count < 1)
- {
- LogHelper.Info("[PACS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("执行sql:" + sql_upload);
- ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
- this.SetText(ShowLog);
- continue;
- }
- }
- }
- ShowLog = "本次已生成、上传[PACS]PDF文件总条数为[" + countAll + "]条,上传[PACS]总条数为[" + uploaded + "]条。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- GetPacsDefault();
- }
- #endregion
- #region 2、补传失败数据
- //上传数据
- LogHelper.Info("PACS补传失败数据");
-
- string pc_sql = @"select
- a.patientAge ,
- a.ageUnit ,
- a.patientIdCard ,
- a.inTime ,
- a.inpatientAreaName ,
- a.roomNo ,
- a.bedNo ,
- a.phoneNo ,
- a.address ,
- a.reportTypeName ,
- a.reportTypeCode ,
- a.diagnosisCode ,
- a.diagnosisName ,
- a.applyTime ,
- a.applyerCode ,
- a.applyerName ,
- a.applyDeptCode ,
- a.applyDeptName ,
- a.applyOrgCode ,
- a.applyOrgName ,
- a.receiverTime ,
- a.receiverCode ,
- a.receiverName ,
- a.checkTime ,
- a.checkerCode ,
- a.checkerName ,
- a.checkDeptCode ,
- a.checkDeptName ,
- a.reportTime ,
- a.reportorCode ,
- a.reportorName ,
- a.auditTime ,
- a.auditorCode ,
- a.auditorName ,
- a.localItemId ,
- a.standardItemId ,
- a.itemName ,
- a.purpose ,
- a.testPrice ,
- a.checkTypeCode ,
- a.checkTypeName ,
- a.positionCode ,
- a.positionName ,
- a.methodCode ,
- a.methodName ,
- a.isEnganced ,
- a.isMakeShadow ,
- a.process ,
- a.findings ,
- a.diagnosResult ,
- a.resultType ,
- a.unit ,
- a.machineType ,
- a.machineCode ,
- a.machineName ,
- a.attachmentId ,
- a.studyInstanceUid ,
- a.dicomImgFtpUrl ,
- a.orgCode ,
- a.orgName ,
- a.pacsYunOrgCode ,
- a.reportId ,
- a.reportName ,
- a.reportType ,
- a.requestId ,
- a.businessNumber ,
- a.patientType ,
- a.patientName ,
- a.patientSex ,
- a.patientBirthday ,
- a.regionHr,
- a.HEALTHNO,
- a.MEDICARENO ,
- a.ACCESSNUMBER,
- a.CONCLUSION,
- a.BRIEFHISTORY,
- a.ISIMAGESERVICE,
- a.STUDYUID
- from pacs_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 1";
- List<PACS> list_pc = OracleHelper<PACS>.RunQueryList(pc_sql);
- if (list_pc.Count < 1)
- {
- LogHelper.Info("查询补传PACS数据为空,等待下一次轮询。");
- LogHelper.Info("执行sql:" + pc_sql);
- return;
- }
- int count_pc = 0;
- for (int i = 0; i < list_pc.Count; i++)
- {
- if (!isAuthorization())
- {
- continue;
- }
- string json_pacs = Tools.ObjectToJson<List<PACS>>(list_pc[i], Encoding.UTF8);
- json_pacs = "{\"mainBody\":[" + json_pacs + "]}";
- string json_pacs_log = json_pacs;
- string vi_pacs = Tools.GuidTo16String();
- json_pacs = Tools.AESEncrypt(json_pacs, Tools.pwd, vi_pacs);
- string res_pacs = Tools.WSCenterData(url_pacs, json_pacs, vi_pacs, Tools.accessToken, 1);
- string res_aes_pacs = Tools.AESDecrypt(res_pacs, Tools.pwd, vi_pacs);
- //LogHelper.Info("[PACS]上传出参:" + res_aes_pacs);
- ResPacs respacs = Tools.JsonToObject<ResPacs>(Tools.FormatStr(res_aes_pacs), Encoding.UTF8);
- if (respacs.statusCode != "1")
- {
- ShowLog = respacs.message + ",[PACS]数据上传异常!跳过本条数据上传下一条,偏移量为:" + vi_pacs;
- this.SetText(ShowLog);
- LogHelper.Info("[PACS]出错入参:" + json_pacs_log);
- LogHelper.Info("[PACS]出错出参:" + res_aes_pacs);
- continue;
- }
- else
- {
- pacs_total += 1;
- count_pc += 1;
- string sql_upload = @"update 已上传PDF set UPLOADED = 1,UPLOADE_TIME = to_date('{2}','yyyy/mm/dd hh24:mi:ss') where type = 1
- and BUSINESSNUMBER = '{0}'
- and REPORTID = '{1}'";
- sql_upload = string.Format(sql_upload, list_pc[i].BUSINESSNUMBER, list_pc[i].REPORTID, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
- int upload_count = OracleHelper<object>.ExecuteNonQuery(sql_upload);
- if (upload_count < 1)
- {
- LogHelper.Info("[PACS]更新表【已上传PDF】失败,跳过本条数据上传下一条!");
- LogHelper.Info("执行sql:" + sql_upload);
- ShowLog = "[PACS]新增表【已上传PDF】失败,跳过本条数据上传下一条!执行sql:" + sql_upload;
- this.SetText(ShowLog);
- continue;
- }
- }
- }
- if (count_pc > 0)
- {
- ShowLog = "本次补传[PACS]数据为[" + count_pc + "]条,等待下一次轮询。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- GetPacsDefault();
- }
- #endregion
- }
- }
- catch (Exception ex)
- {
- LogHelper.Error(ex);
- }
- }
- /// <summary>
- /// 生成pdf
- /// </summary>
- /// <param name="orgName">印江自治县人民医院</param>
- /// <param name="baseInfo">"姓名:刘蚝 性别:男 年龄:20岁 床号:8床 住院号:20121545 门诊号:65478854"</param>
- /// <param name="findings"></param>
- /// <param name="diagnosResult"></param>
- /// <param name="signature">签名:杨添红 日期:2022.9.7</param>
- private string CreatePDF(string orgName, string baseInfo, string findings, string diagnosResult, string signature)
- {
- string res = "";
- try
- {
- Document document = new Document(HeaderAndFooterEvent.rect);
- //string dic = AppDomain.CurrentDomain.BaseDirectory + "Pacs\\";
- if (!Directory.Exists(DicPacs))
- {
- Directory.CreateDirectory(DicPacs);
- }
- string path = DicPacs + Guid.NewGuid() + ".pdf";
- //此处使用的是http请求的流,你也可以使用文件流Stream
- FileStream str = new FileStream(path, FileMode.Create);
- PdfWriter writer = PdfWriter.GetInstance(document, str);
- document.Open();
- writer.PageEvent = new HeaderAndFooterEvent();
- HeaderAndFooterEvent.PAGE_NUMBER = false;//实现页眉跟页脚
- HeaderAndFooterEvent.tpl = writer.DirectContent.CreateTemplate(500, 500); //定义模板
- //印江自治县人民医院
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(orgName, 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph("检查报告单", 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(baseInfo, 0, 3f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(@"诊断意见:" + diagnosResult, 0, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(@"检查所见:" + findings, 0, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(signature, 2, 1.5f));
- writer.Flush();
- writer.CloseStream = true;
- document.Close();
- //writer.Close();
- //str.Close();
- res = path;
- }
- catch (Exception ex)
- {
- res = "";
- LogHelper.Error(ex);
- }
- return res;
- }
- private string CreateLisPDF(string orgName, string baseInfo, DataTable dt, string signature, string title)
- {
- string res = "";
- try
- {
- Document document = new Document(HeaderAndFooterEvent.rect);
- //此处使用的是http请求的流,你也可以使用文件流Stream
- //string dic = AppDomain.CurrentDomain.BaseDirectory + "Lis\\";
- if (!Directory.Exists(DicLis))
- {
- Directory.CreateDirectory(DicLis);
- }
- string path = DicLis + Guid.NewGuid() + ".pdf";
- FileStream str = new FileStream(path, FileMode.Create);
- PdfWriter writer = PdfWriter.GetInstance(document, str);
- document.Open();
- writer.PageEvent = new HeaderAndFooterEvent();
- HeaderAndFooterEvent.PAGE_NUMBER = false;//实现页眉跟页脚
- HeaderAndFooterEvent.tpl = writer.DirectContent.CreateTemplate(500, 500); //定义模板
- //印江自治县人民医院
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(orgName, 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(title + "报告单", 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(baseInfo, 0, 3f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
- //HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- //document.Add(HeaderAndFooterEvent.AddParagraph(@"序号 项目 结果 单位 参考区间", 0, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- HeaderAndFooterEvent.CreateTable(dt, document);
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 12);
- document.Add(HeaderAndFooterEvent.AddParagraph(" ", 1, 1.5f));
- HeaderAndFooterEvent.SetFont(BaseColor.DARK_GRAY, "宋体", 8);
- document.Add(HeaderAndFooterEvent.AddParagraph(signature, 2, 1.5f));
- writer.Flush();
- writer.CloseStream = true;
- document.Close();
- res = path;
- }
- catch (Exception ex)
- {
- LogHelper.Info("CreateLisPDF 生成失败");
- res = "";
- LogHelper.Error(ex);
- }
- return res;
- }
- //token是否过期
- private bool isAuthorization()
- {
- bool result = true;
- if (string.IsNullOrWhiteSpace(Tools.accessToken) || Tools.DateTimes == null || Tools.DateTimes <= DateTime.Now)
- {
- //获取授权
- string vi = Tools.GuidTo16String();
- string url = "http://40.26.204.3:8084/phimp-napi/token";
- string res = Tools.WSCenterData(url, "", vi);
- string res_aes = Tools.AESDecrypt(res, Tools.pwd, vi);
- Authorization ahz = Tools.JsonToObject<Authorization>(Tools.FormatStr(res_aes), Encoding.UTF8);
- if (ahz.statusCode != "1")
- {
- ShowLog = ahz.message + ",获取Token授权失败!等待下一次轮询。";
- this.SetText(ShowLog);
- LogHelper.Info(ShowLog);
- result = false;
- }
- Tools.accessToken = ahz.mainBody.accessToken;
- Tools.DateTimes = DateTime.Now.AddSeconds(int.Parse(ahz.mainBody.expirationTime));
- }
- return result;
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (e.CloseReason == CloseReason.UserClosing)
- {
- //是否取消close操作
- e.Cancel = true;
- this.WindowState = FormWindowState.Minimized;
- }
- }
- private void checkBox1_Click(object sender, EventArgs e)
- {
- int hr = 0;
- string sql = @"update 互认配置表 set 互认 = {0}";
- bool bl = checkBox1.Checked;
- if (checkBox1.Checked)
- {
- hr = 1;
- }
- sql = string.Format(sql, hr);
- int res = OracleHelper<object>.ExecuteNonQuery(sql);
- if (res > 0)
- {
- if (bl)
- {
- textBox1.Text = "已修改为互认!";
- }
- else
- {
- textBox1.Text = "已修改为不互认!";
- }
- }
- else
- {
- textBox1.Text = "是否互认修改失败!";
- if (bl)
- {
- checkBox1.Checked = false;
- }
- else
- {
- checkBox1.Checked = true;
- }
- }
- }
- private void checkBox2_CheckedChanged(object sender, EventArgs e)
- {
- AutoStart();
- }
- public void GetLisDefault()
- {
- string sql = @"select count(1) listotal from lis_upload where attachmentId is null";
- DataTable dt = new DataTable();
- if (zlhr==zlhrConstant_true)
- {
- dt = OracleHelper<object>.PgQueryDS(sql);
- }
- else
- {
- dt = OracleHelper<object>.RunQueryDS(sql);
- }
- string label_lis = dt.Rows[0]["listotal"].ToString() + "条";
- string lis_count = Lis_total + "条";
- this.SetLisText(label_lis);
- this.SetLisCountText(lis_count);
- //获取待上传的数量
- string waitsql = @"select count(1) listotal from lis_upload a ,已上传PDF b
- where b.businessnumber = a.BUSINESSNUMBER
- and b.reportid = a.REPORTID
- and b.attachmentid is not null
- and b.uploaded = 0
- and b.type = 2";
- DataTable waitdt = new DataTable();
- if (zlhr == zlhrConstant_true)
- {
- waitdt = OracleHelper<object>.PgQueryDS(waitsql);
- }
- else
- {
- waitdt = OracleHelper<object>.RunQueryDS(sql);
- }
- LogHelper.Info("待上传数量为:" + waitdt.Rows[0]["listotal"].ToString() + "条");
- }
- public void GetPacsDefault()
- {
- string sql = @"select count(1) pacstotal from pacs_upload where attachmentId is null";
- DataTable dt = OracleHelper<object>.RunQueryDS(sql);
- string label_pacs = dt.Rows[0]["pacstotal"].ToString() + "条";
- string pacs_count = pacs_total + "条";
- this.SetPassText(label_pacs);
- this.SetPacsCountText(pacs_count);
- }
- private void SetText(string text)
- {
- // InvokeRequired需要比较调用线程ID和创建线程ID
- // 如果它们不相同则返回true
- if (this.textBox1.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.textBox1.Text = text;
- }
- }
- private void SetLisText(string text)
- {
- // InvokeRequired需要比较调用线程ID和创建线程ID
- // 如果它们不相同则返回true
- if (this.textBox1.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetLisText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.label_lis.Text = text;
- }
- }
- private void SetPassText(string text)
- {
- // InvokeRequired需要比较调用线程ID和创建线程ID
- // 如果它们不相同则返回true
- if (this.textBox1.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetPassText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.label_pacs.Text = text;
- }
- }
- private void SetLisCountText(string text)
- {
- // InvokeRequired需要比较调用线程ID和创建线程ID
- // 如果它们不相同则返回true
- if (this.textBox1.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetLisCountText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.lis_count.Text = text;
- }
- }
- private void SetPacsCountText(string text)
- {
- // InvokeRequired需要比较调用线程ID和创建线程ID
- // 如果它们不相同则返回true
- if (this.textBox1.InvokeRequired)
- {
- SetTextCallback d = new SetTextCallback(SetPacsCountText);
- this.Invoke(d, new object[] { text });
- }
- else
- {
- this.pacs_count.Text = text;
- }
- }
- private void DelPDF()
- {
- //每月1号删除
- if (DateTime.Now.Day != 1)
- {
- return;
- }
- int month = OracleHelper<object>.UploadTime();
- if (month < 1)
- {
- return;
- }
- string sql = @"delete from 已上传PDF a where a.uploaded = 1 And a.Uploade_Time < add_months(Sysdate,-{0})";
- sql = string.Format(sql,month);
- OracleHelper<object>.ExecuteNonQuery(sql);
-
- }
- }
- }
|