diff --git a/DicomTool/DicomTool.csproj b/DicomTool/DicomTool.csproj index 23c5e8f..fbca2fe 100644 --- a/DicomTool/DicomTool.csproj +++ b/DicomTool/DicomTool.csproj @@ -72,7 +72,6 @@ - @@ -82,7 +81,6 @@ - diff --git a/DicomTool/FtpHelper.cs b/DicomTool/FtpHelper.cs deleted file mode 100644 index 7c89e6b..0000000 --- a/DicomTool/FtpHelper.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System; -using System.IO; -using System.Net; -using DicomTool.Model; - -namespace DicomTool -{ - public static class FtpHelper - { - - public static void DownloadFtpFile(List ftpUriList, string username, string password, string localFilePath) - { - // 确保本地文件路径是目录 - if (!Directory.Exists(localFilePath)) - { - Directory.CreateDirectory(localFilePath); - } - - foreach (var reportEcg in ftpUriList) - { - // 创建 FtpWebRequest 对象 - var request = (FtpWebRequest)WebRequest.Create(reportEcg.ReportUrl); - request.Method = WebRequestMethods.Ftp.DownloadFile; - request.Credentials = new NetworkCredential(username, password); - - try - { - // 获取响应并读取数据 - var response = (FtpWebResponse)request.GetResponse(); - var responseStream = response.GetResponseStream(); - - // 获取文件名 - // string fileName = Path.GetFileName(new Uri(reportEcg.ReportUrl).LocalPath); - var fileName = reportEcg.ID + ".jpg"; - Console.WriteLine("【下载】"+ reportEcg.ID + ".jpg"); - var localFileFullPath = Path.Combine(localFilePath, fileName); - - // 将 FTP 文件内容写入本地文件 - using (FileStream fileStream = new FileStream(localFileFullPath, FileMode.Create, FileAccess.Write)) - { - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) != 0) - { - fileStream.Write(buffer, 0, bytesRead); - } - } - - responseStream.Close(); - response.Close(); - } - catch (WebException ex) - { - // 处理异常,例如打印错误信息 - Console.WriteLine("Download failed for " + reportEcg + ": " + ex.Message); - } - } - } - } -} diff --git a/DicomTool/Program.cs b/DicomTool/Program.cs index 51d16fe..8393fc3 100644 --- a/DicomTool/Program.cs +++ b/DicomTool/Program.cs @@ -22,24 +22,10 @@ namespace DicomTool private const string Password = "BlueFlag.Lis!@#"; // DCM文件下载存放路径 private static readonly string DcmPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DicomFiles/"); - private static readonly string EcgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EcgFiles/"); + private static readonly string EcgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EcgFiles/"); - // 188 - //private const string connectionString = "Data Source=192.168.12.188;Initial Catalog=peisdb;User ID=sa;Password=000626;"; - // 盈江妇幼 - // private const string ConnectionString = @"Data Source=172.172.100.12;Initial Catalog=peisdb;User ID=sa;Password=xbdLis!@#77911;"; - // 芒市妇幼 - // private const string ConnectionString = @"Data Source=192.168.11.5;Initial Catalog=peisdb;User ID=XBDLISUser;Password=BlueFlag.Lis!@#;"; - // 德宏中医 private const string ConnectionString = @"Data Source=200.200.200.71;Initial Catalog=peisdb;User ID=sa;Password=wVJeC28@eY*&F#5NGL^eYC3m;"; - - /// - /// PACS报告中已选的图片 - /// - private const string InsertExamPacsImage = - @"INSERT INTO Exam_PacsImage (Image,EID,ReportNo,InTime) VALUES (@ImageData,@EID,@ReportNo,@InTime); - INSERT INTO Report_Pacs(Image, EID, ReportNo, InTime) VALUES(@ImageData, @EID, @ReportNo, @InTime);"; - + private static void Main(string[] args) { Console.WriteLine($"【启动】{DateTime.Now:yyyy-MM-dd HH:mm}"); @@ -47,8 +33,7 @@ namespace DicomTool var timer = new Timer(); try { - //DownEcgFtpImage(); - Execute(); + DownEcgFtpImage(); Console.ReadKey(); timer.Interval = intervalInMinutes * 60 * 1000; @@ -80,207 +65,10 @@ namespace DicomTool /// private static void Timer_Elapsed(object sender, ElapsedEventArgs e) { - Console.WriteLine($@"执行-{DateTime.Now:yyyy-MM-dd HH:mm}"); + Console.WriteLine($@"执行-{DateTime.Now:yyyy-MM-dd HH:mm}"); DownEcgFtpImage(); - Execute(); - SyncPacsReport(); - //DelDownFiles(); - } - - /// - /// 下载选择的 - /// - private static void Execute() - { - Console.WriteLine($"【开始同步PACS报告图片】{DateTime.Now:yyyy-MM-dd HH:mm}------------"); - //--将PACS检查报告同步到体检系统中 - if (!Directory.Exists(DcmPath)) - { - Directory.CreateDirectory(DcmPath); - } - var reportList = PacsSqlHelper.GetPacsReportList(); - var fileNameList = new List(); - int i = 1; - foreach (var report in reportList) - { - try - { - // 已选图片UID - var selectedList = PacsSqlHelper.GetReportUidList(report.AccessionNumber); - if (selectedList.Count <= 0) continue; - // DCM图片路径 - var imageFiles = PacsSqlHelper.GetPacsImageFile(report.PatientCode,report.ExamFeeitem_Code); - if (string.IsNullOrEmpty(imageFiles)) continue; - // 得到DCM共享文件地址 - var dcmPaths = imageFiles.Split(';'); - // 路径为空 - if (!(dcmPaths?.Length > 0)) continue; - - //获取远程共享文件 - using (var client = new WebClient()) - { - // 配置授权账户密码 - var credentials = new NetworkCredential(UserName, Password); - client.Credentials = credentials; - selectedList.ForEach(selected => - { - var file = selected + ".DCM"; - var dcmPacsDict = dcmPaths[0].Substring(dcmPaths[0].Length , file.Length); - string downPath = dcmPaths[0].Replace(dcmPacsDict, file); - if (Path.HasExtension(downPath)) - { - //下载远程文件 - var buffer = client.DownloadData(downPath); - // 保存本地 - var name = $"{report.PatientCode?.Trim()}-{report.ExamFeeitem_Code?.Trim()}-" + i; - Bytes2File(buffer, DcmPath, $"{name}.DCM"); - fileNameList.Add($"{name}.DCM"); - Console.WriteLine($"下载:{name}.DCM"); - i++; - }; - }); - // 循环路径 - for (var index = 0; index < dcmPaths.Count(); index++) - { - try - { - // 当前路径 - var dcmPath = dcmPaths[index]; - if (string.IsNullOrEmpty(dcmPath)) continue; - if (!Path.HasExtension(dcmPath) ) continue; - selectedList.ForEach(selected => - { - if (dcmPath.Contains(selected)) - { - //下载远程文件 - var buffer = client.DownloadData(dcmPath); - // 保存本地 - var name = $"{report.PatientCode?.Trim()}-{report.ExamFeeitem_Code?.Trim()}-" + i; - Bytes2File(buffer, DcmPath, $"{name}.DCM"); - fileNameList.Add($"{name}.DCM"); - Console.WriteLine($"下载:{name}.DCM"); - i++; - } - }); - } - catch (Exception e) - { - Console.WriteLine($"01." + e.Message); - } - } - } - } - catch (Exception e) - { - Console.WriteLine($"02." + e.Message); - } - } - - Console.WriteLine($@"【下载】{fileNameList.Count}"); - if (fileNameList.Count > 0) - // 保存到本地后上传到服务器 - UploadDcmImg(DcmPath, fileNameList, InsertExamPacsImage); - - Console.WriteLine($@"【等待】{intervalInMinutes}min"); - Console.WriteLine($"------------------------------------------"); - } - - /// - /// 1、将本地文件PACS影像图片发送到服务器 - /// - public static void UploadDcmImg(string folderPath, List fileNameList, string insertSql) - { - var time = DateTime.Now; - // 获取文件夹下所有文件的路径 - var files = Directory.GetFiles(folderPath); - var i = 0; - // 建立数据库连接 - using (var connection = new SqlConnection(ConnectionString)) - { - // 遍历文件路径并输出 - foreach (var filePath in files) - { - try - { - var fileName = System.IO.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(); - // File.WriteAllBytes(Path.Combine(DcmPath, i+".jpeg"), imgBytes); - //上传 - { - connection.Open(); - // 创建插入记录的 SQL 查询 - // 创建命令对象 - using (var command = new SqlCommand(insertSql, connection)) - { - // 设置参数值 - command.Parameters.AddWithValue("@ImageData", imgBytes); - command.Parameters.AddWithValue("@EID", eid); - command.Parameters.AddWithValue("@ReportNo", reportNo); - command.Parameters.AddWithValue("@InTime", time); - - Console.WriteLine($@"【上传】{fileName}"); - // 执行插入操作 - command.ExecuteNonQuery(); - i++; - } - - connection.Close(); - } - } - // 删除上传成功的文件 - File.Delete(filePath); - } - catch (Exception e) - { - Console.WriteLine(System.IO.Path.GetFileName(filePath)); - Console.WriteLine(e.Message); - } - } - } - - Console.WriteLine($@"【上传成功】{i}"); - } - - /// - /// 将byte数组转换为文件并保存到指定地址 - /// - /// byte数组 - /// 保存地址 - /// - public static void Bytes2File(byte[] buff, string path, string fileName) - { - try - { - //如果不存在就创建Enclosure文件夹  - if (Directory.Exists(path) == false) - Directory.CreateDirectory(path); - - if (File.Exists(path + fileName)) - File.Delete(path + fileName); - - var fs = new FileStream(path + fileName, FileMode.CreateNew); - var bw = new BinaryWriter(fs); - bw.Write(buff, 0, buff.Length); - bw.Close(); - fs.Close(); - } - catch (Exception e) - { - Console.WriteLine("【下载失败】" + fileName + "--" + e.Message); - } } - + public static void DownEcgFtpImage() { Console.WriteLine("-----------------------------------"); @@ -295,9 +83,8 @@ namespace DicomTool if (!Directory.Exists(EcgPath)) { Directory.CreateDirectory(EcgPath); - } - - FtpHelper.DownloadFtpFile(files, name, password, EcgPath); + } + DownloadFtpFile(files, name, password, EcgPath); UploadEcgImg(EcgPath, files.Select(s => s.ID.ToString()).ToList()); Console.WriteLine("ECG 下载完毕"); Console.WriteLine($"【ECG-END】{DateTime.Now:yyyy-MM-dd HH:mm}"); @@ -370,9 +157,58 @@ namespace DicomTool Console.WriteLine($@"【上传成功】{i}"); } - public static void SyncPacsReport() + /// + /// 下载ECG图片 + /// + /// + /// + /// + /// + public static void DownloadFtpFile(List ftpUriList, string username, string password, string localFilePath) { - DAOHelp.ExecuteSql("EXEC sp_PacsRptInsert;"); + // 确保本地文件路径是目录 + if (!Directory.Exists(localFilePath)) + { + Directory.CreateDirectory(localFilePath); + } + + foreach (var reportEcg in ftpUriList) + { + // 创建 FtpWebRequest 对象 + try + { + var request = (FtpWebRequest)WebRequest.Create(reportEcg.ReportUrl); + request.Method = WebRequestMethods.Ftp.DownloadFile; + request.Credentials = new NetworkCredential(username, password); + // 获取响应并读取数据 + var response = (FtpWebResponse)request.GetResponse(); + var responseStream = response.GetResponseStream(); + + // 获取文件名 + // string fileName = Path.GetFileName(new Uri(reportEcg.ReportUrl).LocalPath); + var fileName = reportEcg.ID + ".jpg"; + Console.WriteLine("【下载】" + reportEcg.ID + ".jpg"); + var localFileFullPath = Path.Combine(localFilePath, fileName); + // 将 FTP 文件内容写入本地文件 + using (FileStream fileStream = new FileStream(localFileFullPath, FileMode.Create, FileAccess.Write)) + { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) != 0) + { + fileStream.Write(buffer, 0, bytesRead); + } + } + responseStream.Close(); + response.Close(); + } + catch (WebException ex) + { + // 处理异常,例如打印错误信息 + Console.WriteLine("Download failed for " + reportEcg + ": " + ex.Message); + continue; + } + } } } } \ No newline at end of file diff --git a/DicomTool/Utils/Test.cs b/DicomTool/Utils/Test.cs deleted file mode 100644 index 4a8e253..0000000 --- a/DicomTool/Utils/Test.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Net; -using System.Timers; -using Dicom.Imaging; -using DicomTool.Model; -using DicomTool.Utils; - -namespace DicomTool.Utils -{ - public static class Test - { - private static string basePath = @"C:\Users\15012\Desktop\Tools"; - - public static void TestMethod() - { - var filePath = Path.Combine(basePath,"1.DCM"); - 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(); - // 将byte数组写入到文件 - File.WriteAllBytes(Path.Combine(basePath, "1.jpeg"), imgBytes); - - Console.WriteLine("数据已写入到文件:" + filePath); - } - } - } -} - - -/* - - /// - /// 下载所有图片 - /// - private static void Execute2() - { - Console.WriteLine($"【同步所有图片】{DateTime.Now:yyyy-MM-dd HH:mm}"); - // var dayBetween = $@"BETWEEN '2024-06-16' AND '2024-06-21'"; - var dayBetween = $@"BETWEEN '{DateTime.Today:yyyy-MM-dd}' AND '{DateTime.Today.AddDays(1):yyyy-MM-dd}'"; - Console.WriteLine($@"ExamDatetime {dayBetween}"); - var reportList = DAOHelp.GetDataBySQL($@" -SELECT A.PatientCode, A.ExamFeeitem_Code,A.AccessionNumber -FROM PACS.DICOMSERVER.DBO.PEIS_PacsResult A -where A.ExamDatetime IS NOT NULL and a.ExamDatetime {dayBetween} - AND NOT EXISTS ( SELECT 1 FROM PACS.DICOMSERVER.DBO.ImgForReport WHERE AccessionNumber = A.AccessionNumber ) - AND NOT EXISTS ( SELECT 1 FROM Report_Pacs WHERE EID = A.PatientCode AND ReportNo=A.ExamFeeitem_Code) - "); - Console.WriteLine($"【待下载报告】{reportList.Count}"); - var fileNameList = new List(); - foreach (var report in reportList) - { - try - { - var imageFiles = DAOHelp.GetDataBySQL - ($@"SELECT ImageFile FROM PACS.DICOMSERVER.DBO.PEIS_PacsResult WHERE PatientCode='{report.PatientCode}' and ExamFeeitem_Code='{report.ExamFeeitem_Code}'") - ?.FirstOrDefault()?.ImageFile; - if (string.IsNullOrEmpty(imageFiles)) - { - Console.WriteLine( - $@"[ERROR] EID={report.PatientCode} - FID={report.ExamFeeitem_Code} ImageFile为空"); - continue; - } - - // 得到DCM共享文件地址 - var dcmPaths = imageFiles.Split(';'); - // 路径为空 - if (!(dcmPaths?.Length > 0)) continue; - //获取远程共享文件 - using (var client = new WebClient()) - { - // 配置授权账户密码 - var credentials = new NetworkCredential(UserName, Password); - client.Credentials = credentials; - // 循环路径 - for (var index = 0; index < dcmPaths.Count(); index++) - { - try - { - // 当前路径 - var dcmPath = dcmPaths[index]; - if (string.IsNullOrEmpty(dcmPath)) continue; - var name = $"{report.PatientCode}-{report.ExamFeeitem_Code}-"; - //下载远程文件 - var buffer = client.DownloadData(dcmPath); - // 保存本地 - Bytes2File(buffer, DcmPath, $"{name}.DCM"); - fileNameList.Add($"{name}.DCM"); - Console.WriteLine($"下载:{name}.DCM"); - } - catch (Exception e) - { - Console.WriteLine($"1." + e.Message); - } - } - } - } - catch (Exception e) - { - Console.WriteLine($"2." + e.Message); - } - } - - Console.WriteLine($@"【下载】{fileNameList.Count}"); - if (fileNameList.Count > 0) - // 保存到本地后上传到服务器 - UploadDcmImg(DcmPath, fileNameList, InsertExamPacsImage); - - Console.WriteLine($@"【等待】{intervalInMinutes}min"); - // 删除文件夹下所有文件 - foreach (var filePath in Directory.GetFiles(DcmPath)) - { - File.Delete(filePath); - } - } - - */ diff --git a/PEIS/App.config b/PEIS/App.config index 7dea2e6..e1a080b 100644 --- a/PEIS/App.config +++ b/PEIS/App.config @@ -15,9 +15,9 @@ - + - + diff --git a/体检相关文档/神思/SynIDCardAPI.dll b/体检相关文档/神思/SynIDCardAPI.dll new file mode 100644 index 0000000..4133b21 Binary files /dev/null and b/体检相关文档/神思/SynIDCardAPI.dll differ diff --git a/体检相关文档/神思/WltRS.dll b/体检相关文档/神思/WltRS.dll new file mode 100644 index 0000000..37ad0b8 Binary files /dev/null and b/体检相关文档/神思/WltRS.dll differ diff --git a/体检相关文档/神思/sdtapi.dll b/体检相关文档/神思/sdtapi.dll new file mode 100644 index 0000000..4fa1804 Binary files /dev/null and b/体检相关文档/神思/sdtapi.dll differ diff --git a/体检相关文档/联机/Scale.exe b/体检相关文档/联机/Scale.exe new file mode 100644 index 0000000..9ad3844 Binary files /dev/null and b/体检相关文档/联机/Scale.exe differ diff --git a/体检相关文档/联机/commserver.exe b/体检相关文档/联机/commserver.exe new file mode 100644 index 0000000..b0fa81c Binary files /dev/null and b/体检相关文档/联机/commserver.exe differ