diff --git a/DcmToPng/DcmToPng.csproj b/DcmToPng/DcmToPng.csproj
new file mode 100644
index 0000000..b2ea723
--- /dev/null
+++ b/DcmToPng/DcmToPng.csproj
@@ -0,0 +1,17 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
diff --git a/DcmToPng/Helper/Constant.cs b/DcmToPng/Helper/Constant.cs
new file mode 100644
index 0000000..5b80a91
--- /dev/null
+++ b/DcmToPng/Helper/Constant.cs
@@ -0,0 +1,19 @@
+namespace DcmToPng.Helper
+{
+ public static class Constant
+ {
+ public static readonly string UserName = "XBDLISUser";
+ public static readonly string Password = "BlueFlag.Lis!@#";
+
+ public static readonly string DcmPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DicomFiles/");
+ public static readonly string ImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DicomImages/");
+
+ // 德宏中医
+ public static readonly string ConnectionString = @"Data Source=200.200.200.71;Initial Catalog=peisdb;User ID=sa;Password=wVJeC28@eY*&F#5NGL^eYC3m;";
+
+
+ // PACS报告中已选的图片
+ public static readonly string SqlInsert = @"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);";
+
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Helper/DataHelper.cs b/DcmToPng/Helper/DataHelper.cs
new file mode 100644
index 0000000..31f31b3
--- /dev/null
+++ b/DcmToPng/Helper/DataHelper.cs
@@ -0,0 +1,50 @@
+using DicomTool.Utils;
+using System.Net;
+
+namespace DcmToPng.Helper
+{
+ public static class DataHelper
+ {
+ public static Dictionary GetReports()
+ {
+ var data = new Dictionary();
+ int i = 1;
+ try
+ {
+ var reportList = PacsSqlHelper.GetPacsReportList();
+ foreach (var report in reportList)
+ {
+ // 已选图片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;
+
+ selectedList.ForEach(selected =>
+ {
+ var file = selected + ".DCM";
+ string downPath = dcmPaths[0].Substring(0, dcmPaths[0].Length - file.Length) + file;
+ if (Path.HasExtension(downPath))
+ {
+ var name = $"{report.PatientCode?.Trim()}-{report.ExamFeeitem_Code?.Trim()}-" + i;
+ if (data.ContainsKey(name)) name += "x";
+ data.Add($"{name}.DCM", downPath);
+ i++;
+ };
+ });
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"[GetReports][Error]" + e.Message);
+ Console.ReadKey();
+ }
+ return data;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Helper/DcmToPngHelper.cs b/DcmToPng/Helper/DcmToPngHelper.cs
new file mode 100644
index 0000000..024c70a
--- /dev/null
+++ b/DcmToPng/Helper/DcmToPngHelper.cs
@@ -0,0 +1,42 @@
+using System.Threading.Channels;
+using FellowOakDicom;
+using FellowOakDicom.Imaging;
+using SixLabors.ImageSharp;
+
+namespace DcmToPng.Helper
+{
+ public class DcmToPngHelper
+ {
+ public static void Convert()
+ {
+ new DicomSetupBuilder()
+ .RegisterServices(s => s.AddFellowOakDicom().AddImageManager())
+ .Build();
+
+ if (!Directory.Exists(Constant.ImgPath))
+ Directory.CreateDirectory(Constant.ImgPath);
+ var dicomFiles = Directory.GetFiles(Constant.DcmPath, "*.dcm"); // 获取所有.dcm
+ Console.WriteLine("[待转换的DCM文件]" + dicomFiles.Length);
+ int i=0;
+ foreach (var filePath in dicomFiles)
+ {
+ try
+ {
+ if (File.Exists(Path.GetFileNameWithoutExtension(filePath) + ".png"))
+ continue;
+ var image = new DicomImage(filePath);
+ var bitmap = image.RenderImage().AsSharpImage();
+ string outputPath = Path.Combine(Constant.ImgPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
+ bitmap.SaveAsJpeg(outputPath);
+ File.Delete(filePath);
+ i++;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("[Convert]" + e.Message);
+ }
+ }
+ Console.WriteLine("[转换成功]" + i);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Helper/DownloadHelper.cs b/DcmToPng/Helper/DownloadHelper.cs
new file mode 100644
index 0000000..bf8efa0
--- /dev/null
+++ b/DcmToPng/Helper/DownloadHelper.cs
@@ -0,0 +1,69 @@
+using System.Net;
+
+namespace DcmToPng.Helper
+{
+ public static class DownloadHelper
+ {
+ ///
+ /// 下载
+ ///
+ /// Dictionary(文件名称.dcm,共享文件夹路径)
+ public static void Down(Dictionary dcmPathList)
+ {
+ if (!Directory.Exists(Constant.DcmPath))
+ Directory.CreateDirectory(Constant.DcmPath);
+ var i = 0;
+ foreach (var item in dcmPathList)
+ {
+ try
+ {
+ if (File.Exists(Path.Combine(Constant.DcmPath, item.Key))) continue;
+ using var client = new WebClient();
+ // 配置授权账户密码
+ var credentials = new NetworkCredential(Constant.UserName, Constant.Password);
+ client.Credentials = credentials;
+ var buffer = client.DownloadData(item.Value);
+ var isSave = Bytes2File(buffer, Constant.DcmPath, item.Key);
+ if (isSave) i++;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"[Down][Error]" + item.Key + " | " + e.Message);
+ }
+ }
+
+ Console.WriteLine($"[DCM文件下载成功]" + i);
+ }
+
+ ///
+ /// 将byte数组转换为文件并保存到指定地址
+ ///
+ /// byte数组
+ /// 保存地址
+ ///
+ public static bool 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();
+ return true;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ return false;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Helper/ExecuteHelper.cs b/DcmToPng/Helper/ExecuteHelper.cs
new file mode 100644
index 0000000..7077da7
--- /dev/null
+++ b/DcmToPng/Helper/ExecuteHelper.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DcmToPng.Helper
+{
+ public static class ExecuteHelper
+ {
+ public static void Execute()
+ {
+ Console.WriteLine($"【开始同步】{DateTime.Now:yyyy-MM-dd HH:mm}");
+ var reports = DataHelper.GetReports();
+ if (reports.Count > 0)
+ {
+ Console.WriteLine("[下载]"); Console.WriteLine();
+ DownloadHelper.Down(reports);
+ Console.WriteLine("[转换]"); Console.WriteLine();
+ DcmToPngHelper.Convert();
+ Console.WriteLine("[上传]"); Console.WriteLine();
+ UploadHelper.Upload();
+ }
+ Console.WriteLine("--本次同步完成--"); Console.WriteLine();
+ }
+ }
+}
diff --git a/DcmToPng/Helper/UploadHelper.cs b/DcmToPng/Helper/UploadHelper.cs
new file mode 100644
index 0000000..67319dc
--- /dev/null
+++ b/DcmToPng/Helper/UploadHelper.cs
@@ -0,0 +1,65 @@
+using System.Data.SqlClient;
+using System.Drawing;
+using System.Drawing.Imaging;
+
+namespace DcmToPng.Helper
+{
+ public static class UploadHelper
+ {
+
+ public static void Upload()
+ {
+ var time = DateTime.Now;
+ // 获取文件夹下所有文件的路径
+ var files = Directory.GetFiles(Constant.ImgPath);
+ var i = 0;
+ // 建立数据库连接
+ using (var connection = new SqlConnection(Constant.ConnectionString))
+ {
+ // 遍历文件路径并输出
+ foreach (var filePath in files)
+ {
+ try
+ {
+ var fileName = Path.GetFileName(filePath);
+ var eid = Convert.ToInt64(fileName.Split('-')[0]);
+ var reportNo = fileName.Split('-')[1];
+
+ using (Image image = Image.FromFile(filePath))
+ {
+ using (MemoryStream memoryStream = new MemoryStream())
+ {
+ image.Save(memoryStream, ImageFormat.Png);
+ var imgBytes = memoryStream.ToArray();
+ //上传
+ {
+ connection.Open();
+ // 创建插入记录的 SQL 查询
+ // 创建命令对象
+ using (var command = new SqlCommand(Constant.SqlInsert, connection))
+ {
+ // 设置参数值
+ command.Parameters.AddWithValue("@ImageData", imgBytes);
+ command.Parameters.AddWithValue("@EID", eid);
+ command.Parameters.AddWithValue("@ReportNo", reportNo);
+ command.Parameters.AddWithValue("@InTime", time);
+ command.ExecuteNonQuery();
+ }
+ connection.Close();
+ }
+ }
+ }
+ i++;
+ // 删除上传成功的文件
+ File.Delete(filePath);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine ("[Upload][Error]" + Path.GetFileName(filePath) + " | " + e.Message);
+ }
+ }
+ }
+ Console.WriteLine("[图片上传成功]" + i);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Model/ReportEcg.cs b/DcmToPng/Model/ReportEcg.cs
new file mode 100644
index 0000000..51012fb
--- /dev/null
+++ b/DcmToPng/Model/ReportEcg.cs
@@ -0,0 +1,16 @@
+using PEIS.Utils;
+
+namespace DicomTool.Model
+{
+ public class ReportEcg : ObjectData
+ {
+ public override String TableName { get => "Report_GSEXD"; }
+
+ [KeyFlag(true)]
+ public Int64 ID { get; set; }
+
+ public String ReportUrl { get; set; }
+ // [RefFlag(true)]
+ // public String n { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Model/ReportPacs.cs b/DcmToPng/Model/ReportPacs.cs
new file mode 100644
index 0000000..3d8cf42
--- /dev/null
+++ b/DcmToPng/Model/ReportPacs.cs
@@ -0,0 +1,20 @@
+using PEIS.Utils;
+
+namespace DicomTool
+{
+ public class ReportPacs : ObjectData
+ {
+ public override String TableName { get => "Report_Pacs"; }
+
+ [KeyFlag(true)]
+ public Int64 ID { get; set; }
+
+ public String PatientCode { get; set; }
+ public String ImageFile { get; set; }
+ public String ExamFeeitem_Code { get; set; }
+ public String AccessionNumber { get; set; }
+
+ [RefFlag(true)]
+ public String SopInstanceUID { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Program.cs b/DcmToPng/Program.cs
new file mode 100644
index 0000000..83bdc71
--- /dev/null
+++ b/DcmToPng/Program.cs
@@ -0,0 +1,27 @@
+using DcmToPng.Helper;
+using Timer = System.Timers.Timer;
+
+Console.WriteLine(@"[--PACS检查报告图片转换同步工具--]");
+try
+{
+ ExecuteHelper.Execute();
+ Console.WriteLine("************");
+
+ var timer = new Timer();
+ timer.Interval = 60 * 60 * 1000; //min
+ timer.AutoReset = true;
+ timer.Elapsed += (s, e) =>
+ {
+ ExecuteHelper.Execute();
+ };
+ timer.Start();
+ Console.ReadKey();
+}
+catch (Exception e)
+{
+ Console.WriteLine(e.Message);
+ Console.ReadKey();
+}
+
+Console.WriteLine($"【停止】{DateTime.Now:yyyy-MM-dd HH:mm}");
+Console.ReadKey();
diff --git a/DcmToPng/Utils/DAOHelp.cs b/DcmToPng/Utils/DAOHelp.cs
new file mode 100644
index 0000000..8c9517b
--- /dev/null
+++ b/DcmToPng/Utils/DAOHelp.cs
@@ -0,0 +1,255 @@
+#region CopyRight
+
+/****************************************************************
+ * Project:健康体检信息管理系统(PEIS)
+ * Author:张剑峰
+ * CLR Version:4.0.30319.42000
+ * CreateTime:2023-05-01 14:43:04
+ * Version:v2.0
+ *
+ * Description:
+ *
+ * History:
+ *
+*****************************************************************
+ * Copyright @ 云南新八达科技有限公司 2023 All rights reserved
+*****************************************************************/
+
+#endregion CopyRight
+
+using PEIS.Utils;
+using System.Data;
+using System.Data.SqlClient;
+using System.Diagnostics;
+using System.Reflection;
+using DcmToPng.Helper;
+
+namespace DicomTool.Utils
+{
+ /*
+ * 操作数据库的方法
+ * 约定:
+ * 1)对象属性必须有public string TableName
+ * 2)属性名与字段名一样。
+ * 3)主键属性需标记自定义特性KeyFlagAttribute,表示此属性是数据表中的主键
+ * 4)数据表中每个表必须设有主键
+ */
+
+ public class DAOHelp
+ {
+ #region 属性
+
+ ///
+ /// 数据库连接字符串
+ ///
+
+ #endregion 属性
+
+ #region 数据库增、删、改、查
+
+ public static DataTable GetDataBySql(string sql)
+ {
+ DateTime startTime = DateTime.Now;
+ DataTable dt = new DataTable();
+ using (SqlConnection conn = new SqlConnection(Constant.ConnectionString))
+ {
+ try
+ {
+ conn.Open();
+ SqlCommand cmd = new SqlCommand(sql, conn);
+ cmd.CommandTimeout = Convert.ToInt32(60);
+ SqlDataAdapter adapter = new SqlDataAdapter(cmd);
+
+ foreach (DataColumn column in dt.Columns)
+ {
+ if (column.DataType == typeof(string))
+ {
+ column.DefaultValue = string.Empty;
+ }
+ }
+
+ adapter.Fill(dt);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("GetDataBySQL异常:" + sql + "," + e.Message);
+ Console.WriteLine("数据库连接失败,请检查网络,或联系管理员!" + e.Message);
+ }
+ }
+
+ // 数据库连接池
+ //DBConnectionSingletion pool = DBConnectionSingletion.Instance;
+ //DBConnectionSingletion.ConnectionString = connectionString;
+ //SqlConnection conn = pool.BorrowDBConnection();
+ //SqlCommand cmd = new SqlCommand(sql, conn);
+ //SqlDataAdapter adapter = new SqlDataAdapter(cmd);
+ //adapter.Fill(dt);
+ //pool.ReturnDBConnection(conn);
+
+ //Global.CostTime("conn.Open", StartTime);
+
+ return dt;
+ }
+
+ ///
+ /// 执行非查询SQL
+ ///
+ ///
+ ///
+ public static int ExecuteSql(String sql, Boolean startTrans = false)
+ {
+ //sql = sql.ToUpper();
+ Debug.WriteLine("执行SQL=>" + sql);
+ int n = 0;//影响的行数
+ DateTime StartTime = DateTime.Now;
+ DataTable dt = new DataTable();
+ using (SqlConnection conn = new SqlConnection(Constant.ConnectionString))
+ {
+ if (startTrans)
+ {
+ SqlTransaction trans = null;
+ try
+ {
+ conn.Open();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("数据库连接失败,请检查网络,或联系管理员!" + e.Message);
+ }
+ try
+ {
+ trans = conn.BeginTransaction();
+ SqlCommand cmd = new SqlCommand(sql, conn);
+ cmd.CommandTimeout = Convert.ToInt32(60);
+ n = cmd.ExecuteNonQuery();
+ trans.Commit();
+ }
+ catch
+ {
+ trans.Rollback();
+ Debug.WriteLine(sql);
+ Console.WriteLine("SQL执行错误!");
+ }
+ }
+ else
+ {
+ try
+ {
+ conn.Open();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("数据库连接失败,请检查网络,或联系管理员!" + e.Message);
+ }
+ try
+ {
+ SqlCommand cmd = new SqlCommand(sql, conn);
+ n = cmd.ExecuteNonQuery();
+ }
+ catch
+ {
+ Debug.WriteLine(sql);
+ Console.WriteLine("SQL执行错误!");
+ }
+ }
+ }
+ return n;
+ }
+
+ public static List GetDataBySQL(String sql) where T : class, new()
+ {
+ Debug.WriteLine("执行SQL=>" + sql);
+ Type type = typeof(T);
+ List list = new List();
+ DataTable dt = GetDataBySql(sql.ToUpper());
+
+ foreach (DataRow row in dt.Rows)
+ {
+ PropertyInfo[] pArray = type.GetProperties();
+ T entity = new T();
+ foreach (PropertyInfo p in pArray)
+ {
+ if (dt.Columns.IndexOf(p.Name) == -1)
+ {
+ continue;
+ }
+ if (p.Name == "TableName")
+ {
+ continue;
+ }
+ else
+ {
+ if (row[p.Name] is String)
+ {
+ p.SetValue(entity, row[p.Name], null);
+ continue;
+ }
+ if (row[p.Name] is Int32)
+ {
+ p.SetValue(entity, Convert.ToInt32(row[p.Name]), null);
+ continue;
+ }
+ if (row[p.Name] is Int64)
+ {
+ p.SetValue(entity, Convert.ToInt64(row[p.Name]), null);
+ continue;
+ }
+ if (row[p.Name] is DateTime)
+ {
+ p.SetValue(entity, Convert.ToDateTime(row[p.Name]), null);
+ continue;
+ }
+ if (row[p.Name] is byte[])
+ {
+ //Image image = Global.BytesToImage((byte[])row[p.Name]);
+ p.SetValue(entity, row[p.Name], null);
+ continue;
+ }
+ if (row[p.Name] is DBNull)
+ {
+ if (p.PropertyType.Name == "Int64" || p.PropertyType.Name == "Int32")
+ {
+ p.SetValue(entity, 0, null);
+ continue;
+ }
+ else if (p.PropertyType.Name == "Decimal")
+ {
+ p.SetValue(entity, Convert.ToDecimal(0), null);
+ continue;
+ }
+ else if (p.PropertyType.Name == "Boolean")
+ {
+ p.SetValue(entity, false, null);
+ continue;
+ }
+ else if (p.PropertyType.Name == "Image" || p.PropertyType.Name == "Byte[]")
+ {
+ p.SetValue(entity, null, null);
+ continue;
+ }
+ else
+ {
+ p.SetValue(entity, null, null);
+ }
+ continue;
+ }
+ //object[] attrs = p.GetCustomAttributes(false);
+ //if (attrs.Count() > 0)
+ //{
+ // if (attrs[0].GetType().Name.Equals("RefFlagAttribute"))
+ // {
+ // if (attrs.Count() == 1)
+ // continue;
+ // }
+ //}
+ p.SetValue(entity, row[p.Name], null);
+ }
+ }
+ list.Add(entity);
+ }
+ return list;
+ }
+
+ #endregion 数据库增、删、改、查
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Utils/MySecurity.cs b/DcmToPng/Utils/MySecurity.cs
new file mode 100644
index 0000000..5eadf05
--- /dev/null
+++ b/DcmToPng/Utils/MySecurity.cs
@@ -0,0 +1,267 @@
+#region CopyRight
+
+/****************************************************************
+ * Project:健康体检信息管理系统(PEIS)
+ * Author:张剑峰
+ * CLR Version:4.0.30319.42000
+ * CreateTime:2023-05-01 14:43:48
+ * Version:v2.0
+ *
+ * Description:
+ *
+ * History:
+ *
+*****************************************************************
+ * Copyright @ 云南新八达科技有限公司 2023 All rights reserved
+*****************************************************************/
+
+#endregion CopyRight
+
+using System.Security.Cryptography;
+using System.Text;
+
+namespace PEIS.Utils
+{
+ ///
+ /// MySecurity(安全类) 的摘要说明。
+ ///
+ public class MySecurity
+ {
+ ///
+ /// 初始化安全类
+ ///
+ public MySecurity()
+ {
+ ///默认密码
+ key = "peis77911@*71";
+ }
+
+ private string key; //默认密钥
+
+ private byte[] sKey;
+ private byte[] sIV;
+
+ #region 加密字符串
+
+ ///
+ /// 加密字符串
+ ///
+ /// 输入字符串
+ /// 密码,可以为“”
+ /// 输出加密后字符串
+ public static string SEncryptString(string inputStr, string keyStr)
+ {
+ MySecurity ws = new MySecurity();
+ return ws.EncryptString(inputStr, keyStr);
+ }
+
+ ///
+ /// 加密字符串
+ ///
+ /// 输入字符串
+ /// 密码,可以为“”
+ /// 输出加密后字符串
+ public string EncryptString(string inputStr, string keyStr)
+ {
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+ if (keyStr == "")
+ keyStr = key;
+ byte[] inputByteArray = Encoding.Default.GetBytes(inputStr);
+ byte[] keyByteArray = Encoding.Default.GetBytes(keyStr);
+ SHA1 ha = new SHA1Managed();
+ byte[] hb = ha.ComputeHash(keyByteArray);
+ sKey = new byte[8];
+ sIV = new byte[8];
+ for (int i = 0; i < 8; i++)
+ sKey[i] = hb[i];
+ for (int i = 8; i < 16; i++)
+ sIV[i - 8] = hb[i];
+ des.Key = sKey;
+ des.IV = sIV;
+ MemoryStream ms = new MemoryStream();
+ CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ StringBuilder ret = new StringBuilder();
+ foreach (byte b in ms.ToArray())
+ {
+ ret.AppendFormat("{0:X2}", b);
+ }
+ cs.Close();
+ ms.Close();
+ return ret.ToString();
+ }
+
+ #endregion 加密字符串
+
+ #region 加密字符串 密钥为系统默认 0123456789
+
+ ///
+ /// 加密字符串 密钥为系统默认
+ ///
+ /// 输入字符串
+ /// 输出加密后字符串
+ public static string SEncryptString(string inputStr)
+ {
+ MySecurity ws = new MySecurity();
+ return ws.EncryptString(inputStr, "");
+ }
+
+ #endregion 加密字符串 密钥为系统默认 0123456789
+
+ #region 加密文件
+
+ ///
+ /// 加密文件
+ ///
+ /// 输入文件路径
+ /// 加密后输出文件路径
+ /// 密码,可以为“”
+ ///
+ public bool EncryptFile(string filePath, string savePath, string keyStr)
+ {
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+ if (keyStr == "")
+ keyStr = key;
+ FileStream fs = File.OpenRead(filePath);
+ byte[] inputByteArray = new byte[fs.Length];
+ fs.Read(inputByteArray, 0, (int)fs.Length);
+ fs.Close();
+ byte[] keyByteArray = Encoding.Default.GetBytes(keyStr);
+ SHA1 ha = new SHA1Managed();
+ byte[] hb = ha.ComputeHash(keyByteArray);
+ sKey = new byte[8];
+ sIV = new byte[8];
+ for (int i = 0; i < 8; i++)
+ sKey[i] = hb[i];
+ for (int i = 8; i < 16; i++)
+ sIV[i - 8] = hb[i];
+ des.Key = sKey;
+ des.IV = sIV;
+ MemoryStream ms = new MemoryStream();
+ CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ fs = File.OpenWrite(savePath);
+ foreach (byte b in ms.ToArray())
+ {
+ fs.WriteByte(b);
+ }
+ fs.Close();
+ cs.Close();
+ ms.Close();
+ return true;
+ }
+
+ #endregion 加密文件
+
+ #region 解密字符串
+
+ ///
+ /// 解密字符串
+ ///
+ /// 要解密的字符串
+ /// 密钥
+ /// 解密后的结果
+ public static string SDecryptString(string inputStr, string keyStr)
+ {
+ MySecurity ws = new MySecurity();
+ return ws.DecryptString(inputStr, keyStr);
+ }
+
+ ///
+ /// 解密字符串 密钥为系统默认
+ ///
+ /// 要解密的字符串
+ /// 解密后的结果
+ public static string SDecryptString(string inputStr)
+ {
+ MySecurity ws = new MySecurity();
+ return ws.DecryptString(inputStr, "");
+ }
+
+ ///
+ /// 解密字符串
+ ///
+ /// 要解密的字符串
+ /// 密钥
+ /// 解密后的结果
+ public string DecryptString(string inputStr, string keyStr)
+ {
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+ if (keyStr == "")
+ keyStr = key;
+ byte[] inputByteArray = new byte[inputStr.Length / 2];
+ for (int x = 0; x < inputStr.Length / 2; x++)
+ {
+ int i = (Convert.ToInt32(inputStr.Substring(x * 2, 2), 16));
+ inputByteArray[x] = (byte)i;
+ }
+ byte[] keyByteArray = Encoding.Default.GetBytes(keyStr);
+ SHA1 ha = new SHA1Managed();
+ byte[] hb = ha.ComputeHash(keyByteArray);
+ sKey = new byte[8];
+ sIV = new byte[8];
+ for (int i = 0; i < 8; i++)
+ sKey[i] = hb[i];
+ for (int i = 8; i < 16; i++)
+ sIV[i - 8] = hb[i];
+ des.Key = sKey;
+ des.IV = sIV;
+ MemoryStream ms = new MemoryStream();
+ CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ StringBuilder ret = new StringBuilder();
+ return System.Text.Encoding.Default.GetString(ms.ToArray());
+ }
+
+ #endregion 解密字符串
+
+ #region 解密文件
+
+ ///
+ /// 解密文件
+ ///
+ /// 输入文件路径
+ /// 解密后输出文件路径
+ /// 密码,可以为“”
+ ///
+ public bool DecryptFile(string filePath, string savePath, string keyStr)
+ {
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+ if (keyStr == "")
+ keyStr = key;
+ FileStream fs = File.OpenRead(filePath);
+ byte[] inputByteArray = new byte[fs.Length];
+ fs.Read(inputByteArray, 0, (int)fs.Length);
+ fs.Close();
+ byte[] keyByteArray = Encoding.Default.GetBytes(keyStr);
+ SHA1 ha = new SHA1Managed();
+ byte[] hb = ha.ComputeHash(keyByteArray);
+ sKey = new byte[8];
+ sIV = new byte[8];
+ for (int i = 0; i < 8; i++)
+ sKey[i] = hb[i];
+ for (int i = 8; i < 16; i++)
+ sIV[i - 8] = hb[i];
+ des.Key = sKey;
+ des.IV = sIV;
+ MemoryStream ms = new MemoryStream();
+ CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ fs = File.OpenWrite(savePath);
+ foreach (byte b in ms.ToArray())
+ {
+ fs.WriteByte(b);
+ }
+ fs.Close();
+ cs.Close();
+ ms.Close();
+ return true;
+ }
+
+ #endregion 解密文件
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Utils/ObjectData.cs b/DcmToPng/Utils/ObjectData.cs
new file mode 100644
index 0000000..8162a1c
--- /dev/null
+++ b/DcmToPng/Utils/ObjectData.cs
@@ -0,0 +1,68 @@
+#region CopyRight
+
+/****************************************************************
+ * Project:健康体检信息管理系统(PEIS)
+ * Author:张剑峰
+ * CLR Version:4.0.30319.42000
+ * CreateTime:2023-05-01 14:41:54
+ * Version:v2.0
+ *
+ * Description:
+ *
+ * History:
+ *
+*****************************************************************
+ * Copyright @ 云南新八达科技有限公司 2023 All rights reserved
+*****************************************************************/
+
+#endregion CopyRight
+
+namespace PEIS.Utils
+{
+ public abstract class ObjectData
+ {
+ ///
+ /// 数据表名
+ ///
+ public abstract string TableName
+ {
+ get;
+ }
+ }
+
+ public class KeyFlagAttribute : Attribute
+ {
+ private bool _bIsKey;
+ public bool IsKey
+ { get { return _bIsKey; } }
+
+ public KeyFlagAttribute(bool bIsKey)
+ {
+ _bIsKey = bIsKey;
+ }
+ }
+
+ public class RefFlagAttribute : Attribute
+ {
+ private bool _bIsRef;
+ public bool IsRef
+ { get { return _bIsRef; } }
+
+ public RefFlagAttribute(bool bIsRef)
+ {
+ _bIsRef = bIsRef;
+ }
+ }
+
+ public class FixFlagAttribute : Attribute
+ {
+ private bool _blsFix;
+ public bool IsFix
+ { get { return _blsFix; } }
+
+ public FixFlagAttribute(bool blsFix)
+ {
+ _blsFix = blsFix;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DcmToPng/Utils/PacsSqlHelper.cs b/DcmToPng/Utils/PacsSqlHelper.cs
new file mode 100644
index 0000000..2e98a72
--- /dev/null
+++ b/DcmToPng/Utils/PacsSqlHelper.cs
@@ -0,0 +1,39 @@
+using System.Threading.Channels;
+
+namespace DicomTool.Utils
+{
+ public static class PacsSqlHelper
+ {
+ public static List GetPacsReportList()
+ {
+ var dayBetween = $@"> '{DateTime.Today.AddDays(-7):yyyy-MM-dd}'";
+ // var dayBetween = $@"BETWEEN '{DateTime.Today:yyyy-MM-dd}' AND '{DateTime.Today.AddDays(1):yyyy-MM-dd}'";
+ 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 EXISTS ( SELECT 1 FROM PACS.DICOMSERVER.DBO.ImgForReport WHERE AccessionNumber = A.AccessionNumber )
+ AND NOT EXISTS ( SELECT 1 FROM Exam_PacsImage WHERE EID = A.PatientCode AND ReportNo=A.ExamFeeitem_Code)
+ ");
+
+ Console.WriteLine($"【待同步的PACS报告】{dayBetween}至今,{reportList.Count}");
+ return reportList;
+ }
+
+ public static List GetReportUidList(string reportAccessionNumber)
+ {
+ // 已选图片UID
+ var selectedList = DAOHelp.GetDataBySQL
+ ($@"SELECT SopInstanceUID FROM PACS.DICOMSERVER.DBO.ImgForReport WHERE AccessionNumber='{reportAccessionNumber}'")
+ .Select(s => s.SopInstanceUID).ToList();
+ return selectedList;
+ }
+
+ public static string GetPacsImageFile(string reportPatientCode, string reportExamFeeitemCode)
+ {
+ return DAOHelp.GetDataBySQL
+ ($@"SELECT ImageFile FROM PACS.DICOMSERVER.DBO.PEIS_PacsResult WHERE PatientCode='{reportPatientCode}' and ExamFeeitem_Code='{reportExamFeeitemCode}'")
+ ?.FirstOrDefault()?.ImageFile;
+ }
+ }
+}
\ No newline at end of file