1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191 |
- 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成功,地址为 = " + 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("查询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= " + 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)
- {
- //处理 互认编码的数据
- HandleLisItemData(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)
- {
- //处理 互认编码的数据
- HandleLisItemData(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 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)
- {
- //处理 互认编码的数据
- HandleLisItemData(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);
-
- }
- }
- }
|