体检系统架构
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

561 lines
25 KiB

// using System;
// using System.Collections.Generic;
// using System.Data.SqlClient;
// using System.Diagnostics;
// using System.IO;
// using System.Net;
// using System.Timers;
// using Dicom;
// using Dicom.Imaging;
// using DicomTool.Entity;
// using DicomTool.Utils;
//
// namespace DicomTool
// {
// internal class Program
// {
// private static void Main(string[] args)
// {
// // InsertPacsImgToPeis();
// // Console.ReadKey();
// // return;
// //
// // var basePath = "C://PACS/DICOM/";
// // var pacsReprot = DataModel.GetPacsReport();
// // var fileNameList = new List<string>()
// // {
// // "10011-164-1.DCM"
// // };
// // GetLocalFile(basePath, fileNameList);
// // return;
//
// Console.WriteLine($"【启动】{DateTime.Now:yyyy-MM-dd HH:mm}");
// /*
// * TEST
// // GetPacsReport();
// // InsertPacsImgToPeis();
// // Console.ReadKey();
// // return;
// */
//
// GetPacsReport();
// // 创建一个 Timer 实例
// var timer = new Timer();
// // 设置间隔时间为10分钟(以毫秒为单位)
// var intervalInMinutes = 30;
// timer.Interval = intervalInMinutes * 60 * 1000;
// // 设置为 true,使得 Timer 每隔设定的间隔时间自动触发一次 Elapsed 事件
// timer.AutoReset = true;
// // 绑定 Elapsed 事件处理程序
// timer.Elapsed += Timer_Elapsed;
// // 启动 Timer
// timer.Start();
// // 阻止控制台程序退出
// Console.ReadKey();
// // 停止 Timer
// timer.Stop();
//
//
// Console.WriteLine($"SUCCESS");
// Console.ReadKey();
// }
//
// #region Pacs TEST
//
// /// <summary>
// /// 定时执行任务
// /// </summary>
// /// <param name="sender"></param>
// /// <param name="e"></param>
// private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
// {
// GetPacsReport();
// }
//
// private static void GetPacsReport()
// {
// Console.WriteLine($"【查询】{DateTime.Now:yyyy-MM-dd HH:mm}");
// var basePath = "C://PACS/DICOM/";
// var pacsReprot = DataModel.GetPacsReport();
// var fileNameList = new List<string>();
// // 获取PACS数据
// foreach (var info in pacsReprot)
// {
// InsertInfo(info);
// // 得到DCM共享文件地址
// int i = 1;
// var dcmPaths = info.ImageFile.Split(';');
// foreach (var dcmPath in dcmPaths)
// {
// if (string.IsNullOrEmpty(dcmPath))
// {
// continue;
// }
// //获取远程共享文件
// var client = new WebClient();
// var userName = "XBDLISUser";
// var password = "BlueFlag.Lis!@#";
// // 配置授权账户密码
// var credentials = new NetworkCredential(userName, password);
// client.Credentials = credentials;
// //下载远程文件
// var buffer = client.DownloadData(dcmPath);
//
// // 保存本地
// Bytes2File(buffer, basePath, $"{info.PatientCode}-{info.ExamFeeitem_Code}-{i}.DCM");
// i++;
// fileNameList.Add($"{info.PatientCode}-{info.ExamFeeitem_Code}-{i}.DCM");
// Console.WriteLine($"下载:{info.PatientCode}-{info.ExamFeeitem_Code}-{i}.DCM");
// //continue;
// // // 读取DCM by byte[]
// // using (var streamDcm = new MemoryStream())
// // {
// // streamDcm.Write(buffer, 0, buffer.Length);
// // //fo-dicom类库 读取DCM
// // var file = DicomFile.Open(streamDcm);
// // if (file?.Dataset == null)
// // {
// // continue;//BUG
// // }
// // var image = new DicomImage(file.Dataset);
// // //image.NumberOfFrames 如果有多帧图片需要将每帧都转成jpeg
// // //DCM转Bitmap
// // var bitmap = image.RenderImage().AsBitmap();
// // using (var streamImg = new MemoryStream())
// // {
// // //Bitmap To byte[]
// // bitmap.Save(streamImg, System.Drawing.Imaging.ImageFormat.Jpeg);
// // var imgBytes = streamImg.ToArray();
// // InsertData(imgBytes, Convert.ToInt64(info.PatientCode), info.ExamFeeitem_Code);
// // // //byte[] To Base64String
// // // var img = Convert.ToBase64String(imgBytes);
// // // // 保存数据到PEIS DB
// // // var saveItem = info;
// // // saveItem.ImageFile = img;
// // // var i = DAOHelp.Save(saveItem);
// // }
// // //bitmap.Save("imageName", System.Drawing.Imaging.ImageFormat.Jpeg);
// // }
// }
// }
//
// if (pacsReprot.Count > 0)
// // 保存到本地后上传到服务器
// GetLocalFile(basePath, fileNameList);
//
// }
//
// /// <summary>
// /// 1、将本地文件PACS影像图片发送到服务器
// /// </summary>
// public static void GetLocalFile(string folderPath, List<string> fileNameList)
// {
// //var folderPath = "C:\\PACS\\DicomFile"; // 替换为实际的文件夹路径
// // 获取文件夹下所有文件的路径
// var files = Directory.GetFiles(folderPath);
// var i = 1;
// // 遍历文件路径并输出
// foreach (var filePath in files)
// {
//
// var fileName = Path.GetFileName(filePath);
// if (!fileNameList.Contains(fileName))
// {
// continue;
// }
// var eid = Convert.ToInt64(fileName.Split('-')[0]);
// var reportNo = fileName.Split('-')[1];
// var image = new DicomImage(filePath);
// //image.NumberOfFrames 如果有多帧图片需要将每帧都转成jpeg
// //DCM转Bitmap
// var bitmap = image.RenderImage().AsBitmap();
// using (var streamImg = new MemoryStream())
// {
// //Bitmap To byte[]
// bitmap.Save(streamImg, System.Drawing.Imaging.ImageFormat.Jpeg);
// var imgBytes = streamImg.ToArray();
// InsertData(imgBytes, eid, reportNo);
// // //byte[] To Base64String
// // var img = Convert.ToBase64String(imgBytes);
// // // 保存数据到PEIS DB
// // var j = DAOHelp.ExecuteSql($@"UPDATE Report_Pacs SET ImageFile='{img}' WHERE ID={i}");
// }
// i++;
// }
// }
//
// /// <summary>
// /// 2、将图片插入PEIS服务器
// /// </summary>
// /// <param name="img"></param>
// public static void InsertData(byte[] img, Int64 eid, string ReportNo)
// {
//
// Console.WriteLine($"【上传】{eid}-{ReportNo}-{DateTime.Now:yyyy-MM-dd HH:mm}");
// // 建立数据库连接
// //string connectionString = "Data Source=192.168.12.188;Initial Catalog=peisdb;User ID=sa;Password=000626; ";
// //盈江妇幼
// var connectionString = "Data Source=172.172.100.12;Initial Catalog=peisdb;User ID=sa;Password=xbdLis!@#77911; ";
// using (var connection = new SqlConnection(connectionString))
// {
// connection.Open();
// // 创建插入记录的 SQL 查询
// var insertQuery = "INSERT INTO Report_Pacs (Image,EID,ReportNo,InTime) VALUES (@ImageData,@EID,@ReportNo,@InTime)";
// // 创建命令对象
// using (var command = new SqlCommand(insertQuery, connection))
// {
// // 设置参数值
// command.Parameters.AddWithValue("@ImageData", img);
// command.Parameters.AddWithValue("@EID", eid);
// command.Parameters.AddWithValue("@ReportNo", ReportNo);
// command.Parameters.AddWithValue("@InTime", DateTime.Now);
// // 执行插入操作
// command.ExecuteNonQuery();
// }
// connection.Close();
// }
// }
// public static void InsertReportImg(byte[] img, Int64 eid, string ReportNo)
// {
//
// Console.WriteLine($"【上传】{eid}-{ReportNo}-{DateTime.Now:yyyy-MM-dd HH:mm}");
// // 建立数据库连接
// //string connectionString = "Data Source=192.168.12.188;Initial Catalog=peisdb;User ID=sa;Password=000626; ";
// //盈江妇幼
// var connectionString = "Data Source=172.172.100.12;Initial Catalog=peisdb;User ID=sa;Password=xbdLis!@#77911; ";
// using (var connection = new SqlConnection(connectionString))
// {
// connection.Open();
// // 创建插入记录的 SQL 查询
// var insertQuery = "UPDATE Report SET ReportImage = @ImageData WHERE EID=@EID AND ReportNo=@ReportNo";
// // 创建命令对象
// using (var command = new SqlCommand(insertQuery, connection))
// {
// // 设置参数值
// command.Parameters.AddWithValue("@ImageData", img);
// command.Parameters.AddWithValue("@EID", eid);
// command.Parameters.AddWithValue("@ReportNo", ReportNo);
// // 执行插入操作
// command.ExecuteNonQuery();
// }
// connection.Close();
// }
// }
//
// public static void InsertInfo(ReportPacs info)
// {
// var sql = $@"INSERT INTO [Report]
// ( [EID], [ReportNo], [Class], [Title], [Examer], [Reporter], [ReportTime], [Description], [Summary] ,[Positive], [InTime] )
// VALUES ({info.PatientCode},'{info.ExamFeeitem_Code}', '{info.TransfTertarget}','{info.ImageTitle}' , '{info.InputDoctor}', '{info.ExamDoctor}','{info.ExamDatetime}', '{info.ExamDesc}',
// '{info.ExamSummary}' ,'{info.ExamPositive}','{DateTime.Now}');";
// DAOHelp.ExecuteSql(sql);
// }
//
// public void GetPacsData()
// {
// // var data = DAOHelp.GetDataBySQL<Pacs>("select * from PacsTest").FirstOrDefault();
// //
// // var rtfData1 = data.Description; // 从文件或网络中读取字节数据
// //
// // if (rtfData1 != null && rtfData1.Length > 0)
// // {
// // using (var stream = new MemoryStream(rtfData1))
// // using (var reader = new StreamReader(stream))
// // {
// // string rtfText = reader.ReadToEnd();
// // Console.WriteLine(rtfText);
// // }
// // }
// // var rtfData2 = data.Diagnose;
// //
// // if (rtfData2 != null && rtfData2.Length > 0)
// // {
// // using (var stream = new MemoryStream(rtfData2))
// // using (var reader = new StreamReader(stream))
// // {
// // string rtfText = reader.ReadToEnd();
// // Console.WriteLine(rtfText);
// // }
// // }
// }
//
// public void GetPacs()
// {
// // var handler = new DicomHandler(filePath);
// // handler.readAndShow();
// // if (handler.getImg())
// //pictureBox1.Image = Image.FromFile(@"C:/Pacs/0.DCM");
//
// // string downloadPath = @"C:\PACS\2.DCM";
// // var handler = new DicomHandler(downloadPath);
// // handler.readAndShow();
// // if (handler.getImg())
// // pictureBox1.Image = handler.gdiImg;
//
// //DicomRead.Convert(@"C:\PACS\2.DCM", @"C:\PACS\2.jpg");
// string strFileName = @"C:\PACS\2.DCM";
// string strOutFileName = @"C:\PACS\2.jpg";
// // var img = new DicomImage(strFileName);
// // Bitmap bitmap = new Bitmap(img.RenderImage());
// // pictureBox1.Image = bitmap;
// //bitmap.Save(strOutFileName, ImageFormat.Jpeg);
//
// // string userName = "XBDLISUser";
// // string password = "BlueFlag.Lis!@#";
// // NetworkCredential credentials = new NetworkCredential(userName, password);
// // var path= @"
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090327573.DCM;
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090347743.DCM;
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090449223.DCM;
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090543067.DCM;
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090739127.DCM;
// // \\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090327573.DCM;";
// // var list = path.Split(';').ToList();
// // foreach (var item in list)
// // {
// // WebClient client = new WebClient();
// // client.Credentials = credentials;
// //
// // // 下载文件
// // client.DownloadFile(item.Trim(), @"C:\PACS\"+list.IndexOf(item)+".DCM");
// //
// // }
//
// //string sourceFile = @"\\172.172.100.11\DICOMFILES$\Data_2023.05.24\B超\B超.1.3.12.2.1107.5.1.4.50455.20230524090327573.DCM";
// // if (!File.Exists(sourceFile))
// // {
// // MessageBox.Show("File not found " );
// // return;
// // }
//
// // string downloadPath = @"C:\pacs.DCM";
// // WebClient client = new WebClient();
// // client.Credentials = credentials;
// //
// // // 下载文件
// // client.DownloadFile(sourceFile, downloadPath);
// //
// // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sourceFile);
// // request.Credentials = credentials;
// //
// // // 获取响应流并读取文件内容
// // using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
// // {
// // using (Stream stream = response.GetResponseStream())
// // {
// // StreamReader reader = new StreamReader(stream);
// // string content = reader.ReadToEnd();
// // }
// // }
// // // WebClient client = new WebClient();
// //
// // WebClient client = new WebClient();
// // client.Credentials = new NetworkCredential(userName, password);
// // client.DownloadFile(sourceFile, downloadPath);
// //client.DownloadFile(sourceFile, downloadPath);
//
// // if (!File.Exists(filePath))
// // {
// // MessageBox.Show("File not found: " + filePath);
// // return;
// // }
// // var handler = new DicomHandler(filePath);
// // handler.readAndShow();
// // if (handler.getImg())
// // pictureBox1.Image = handler.gdiImg;
// // FileStream stream = File.OpenRead(filePath);
// // byte[] data = new byte[stream.Length];
// // stream.Read(data, 0, data.Length);
// // stream.Close();
// }
//
// /// <summary>
// /// 将byte数组转换为文件并保存到指定地址
// /// </summary>
// /// <param name="buff">byte数组</param>
// /// <param name="savepath">保存地址</param>
// public static void Bytes2File(byte[] buff, string savepath, string fileName)
// {
// try
// {
//
// //如果不存在就创建Enclosure文件夹 
// if (Directory.Exists(savepath) == false)
// {
// Directory.CreateDirectory(savepath);
// }
//
// if (System.IO.File.Exists(savepath + fileName))
// {
// System.IO.File.Delete(savepath + fileName);
// }
// //创建Process命令
// var cmd = new Process();
// FileStream fs = new FileStream(savepath + fileName, FileMode.CreateNew);
// BinaryWriter bw = new BinaryWriter(fs);
// bw.Write(buff, 0, buff.Length);
// bw.Close();
// fs.Close();
// // //创建要运行的文件或者程序
// // var startfile = new ProcessStartInfo
// // {
// // FileName = savepath + fileName,//文件完全路径
// // WindowStyle = ProcessWindowStyle.Normal,//Windows窗口样式
// // UseShellExecute = true//为true,则用默认的打开方式打开
// // };
// // cmd.StartInfo = startfile;
// // cmd.Start(); //打开文件
// }
// catch (Exception e)
// {
// Console.WriteLine(fileName + "--" + e.Message);
// }
//
// }
//
//
// /*
// *
// // //icom 转 Jpeg
// // //fo-dicom类库
// // var dcmFile = @"C:/Pacs/DX.DCM";
// // string fullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", dcmFile);
//
// //生成设置要改为X64位
// //System.Reflection.Assembly.LoadFrom(Path.Combine(Application.StartupPath, "Dicom.Native.dll"));
//
// //file //= file.ChangeTransferSyntax(DicomTransferSyntax.ExplicitVRLittleEndian, new DicomJpegLsParams());
// // string path = AppDomain.CurrentDomain.BaseDirectory;
// // Dicom.Imaging.Codec.TranscoderManager.LoadCodecs(path, "Dicom.Native*.dll");
// // var image = new DicomImage(file.Dataset);
// // //image.NumberOfFrames 如果有多帧图片需要将每帧都转成jpeg
// // Bitmap bitmap = image.RenderImage().AsBitmap();
// // string imageName = $"{DateTime.Now.ToString("yyyy-MM-ddHHmmss")}DX.jpeg";
// //bitmap.Save(imageName);
// // 不行
// // ImageConverter converter = new ImageConverter();
// // var imgBytes= (byte[])converter.ConvertTo(bitmap, typeof(byte[]));
//
// // using (var stream = new MemoryStream())
// // {
// // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
// // var imgBytes =stream.ToArray();
// // var img=Convert.ToBase64String(imgBytes);
// // var i=DAOHelp.Save(new Pacs( img));
// // }
// //bitmap.Save(imageName, System.Drawing.Imaging.ImageFormat.Jpeg);
// // bitmap.Save(imageName, System.Drawing.Imaging.ImageFormat.Jpeg);
// */
// #endregion Pacs TEST
//
//
//
//
//
//
// /// <summary>
// /// 手动导入PACS数据到PEIS
// /// </summary>
// public static void InsertPacsImgToPeis()
// {
// var path = "C://PACS//DICOM//Manual//";
// var list = new List<ManualModel>()
// {
// new ManualModel()
// {
// Eid = 10002,
// ReportNo = "22",
// imgFile = @"\\172.172.100.11\DICOMFILES$\Data_2023.08.08\DX\DX.1.2.840.887072.1.9.1.1.20230808093901.4.220240230221.DCM;"
// },
// };
// //下载
// foreach (var item in list)
// {
// DownReportImg(path, item.imgFile, item.Eid, item.ReportNo);
// }
//
// //上传
// UploadReportImg(path);
// }
//
// /// <summary>
// /// 下载PACS检查文件到本地
// /// </summary>
// /// <param name="imgFile">DCM文件</param>
// /// <param name="eid">体检号</param>
// /// <param name="reportNo">收费项目ID</param>
// public static List<string> DownReportImg(string basePath, string imgFile, long eid, string reportNo)
// {
// var fileNameList = new List<string>();
// // 得到DCM共享文件地址
// int i = 1;
// var dcmPaths = imgFile.Split(';');
// foreach (var dcmPath in dcmPaths)
// {
// if (string.IsNullOrEmpty(dcmPath))
// {
// continue;
// }
// //获取远程共享文件
// var client = new WebClient();
// var userName = "XBDLISUser";
// var password = "BlueFlag.Lis!@#";
// // 配置授权账户密码
// var credentials = new NetworkCredential(userName, password);
// client.Credentials = credentials;
// //下载远程文件
// var buffer = client.DownloadData(dcmPath);
//
// // 保存本地
// Bytes2File(buffer, basePath, $"{eid}-{reportNo}-{i}.DCM");
// fileNameList.Add($"{eid}-{reportNo}-{i}.DCM");
// Console.WriteLine($"下载:{eid}-{reportNo}-{i}.DCM");
// i++;
// }
// return fileNameList;
// }
//
//
// /// <summary>
// /// 1、将本地文件PACS影像图片发送到服务器
// /// </summary>
// public static void UploadReportImg(string folderPath, List<string> fileNameList = null)
// {
// //var folderPath = "C:\\PACS\\DicomFile"; // 替换为实际的文件夹路径
// // 获取文件夹下所有文件的路径
// var files = Directory.GetFiles(folderPath);
// var i = 1;
// // 遍历文件路径并输出
// foreach (var filePath in files)
// {
//
// var fileName = Path.GetFileName(filePath);
// // if (!fileNameList.Contains(fileName))
// // {
// // continue;
// // }
// var eid = Convert.ToInt64(fileName.Split('-')[0]);
// var reportNo = fileName.Split('-')[1];
// var image = new DicomImage(filePath);
// //image.NumberOfFrames 如果有多帧图片需要将每帧都转成jpeg
// //DCM转Bitmap
// var bitmap = image.RenderImage().AsBitmap();
// using (var streamImg = new MemoryStream())
// {
// //Bitmap To byte[]
// bitmap.Save(streamImg, System.Drawing.Imaging.ImageFormat.Jpeg);
// var imgBytes = streamImg.ToArray();
// InsertData(imgBytes, eid, reportNo);
// // //byte[] To Base64String
// // var img = Convert.ToBase64String(imgBytes);
// // // 保存数据到PEIS DB
// // var j = DAOHelp.ExecuteSql($@"UPDATE Report_Pacs SET ImageFile='{img}' WHERE ID={i}");
// }
//
// Console.WriteLine($"上传:{eid}-{reportNo}");
// i++;
// }
// }
//
// }
// }