+新版Dicom转换同步工具,老版本部分文件无法转换

main
HI 11 months ago
parent 0208dea2c8
commit 1f5782e145
  1. 17
      DcmToPng/DcmToPng.csproj
  2. 19
      DcmToPng/Helper/Constant.cs
  3. 50
      DcmToPng/Helper/DataHelper.cs
  4. 42
      DcmToPng/Helper/DcmToPngHelper.cs
  5. 69
      DcmToPng/Helper/DownloadHelper.cs
  6. 27
      DcmToPng/Helper/ExecuteHelper.cs
  7. 65
      DcmToPng/Helper/UploadHelper.cs
  8. 16
      DcmToPng/Model/ReportEcg.cs
  9. 20
      DcmToPng/Model/ReportPacs.cs
  10. 27
      DcmToPng/Program.cs
  11. 255
      DcmToPng/Utils/DAOHelp.cs
  12. 267
      DcmToPng/Utils/MySecurity.cs
  13. 68
      DcmToPng/Utils/ObjectData.cs
  14. 39
      DcmToPng/Utils/PacsSqlHelper.cs

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="fo-dicom" Version="5.1.3" />
<PackageReference Include="fo-dicom.Imaging.ImageSharp" Version="5.1.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
</Project>

@ -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);";
}
}

@ -0,0 +1,50 @@
using DicomTool.Utils;
using System.Net;
namespace DcmToPng.Helper
{
public static class DataHelper
{
public static Dictionary<string, string> GetReports()
{
var data = new Dictionary<string, string>();
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;
}
}
}

@ -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<ImageSharpImageManager>())
.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);
}
}
}

@ -0,0 +1,69 @@
using System.Net;
namespace DcmToPng.Helper
{
public static class DownloadHelper
{
/// <summary>
/// 下载
/// </summary>
/// <param name="dcmPathList">Dictionary(文件名称.dcm,共享文件夹路径) </param>
public static void Down(Dictionary<string, string> 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);
}
/// <summary>
/// 将byte数组转换为文件并保存到指定地址
/// </summary>
/// <param name="buff">byte数组</param>
/// <param name="path">保存地址</param>
/// <param name="fileName"></param>
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;
}
}
}
}

@ -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();
}
}
}

@ -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);
}
}
}

@ -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; }
}
}

@ -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; }
}
}

@ -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();

@ -0,0 +1,255 @@
#region CopyRight
/****************************************************************
* ProjectPEIS
* Author
* CLR Version4.0.30319.42000
* CreateTime2023-05-01 14:43:04
* Versionv2.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 属性
/// <summary>
/// 数据库连接字符串
/// </summary>
#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;
}
/// <summary>
/// 执行非查询SQL
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
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<T> GetDataBySQL<T>(String sql) where T : class, new()
{
Debug.WriteLine("执行SQL=>" + sql);
Type type = typeof(T);
List<T> list = new List<T>();
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 数据库增、删、改、查
}
}

@ -0,0 +1,267 @@
#region CopyRight
/****************************************************************
* ProjectPEIS
* Author
* CLR Version4.0.30319.42000
* CreateTime2023-05-01 14:43:48
* Versionv2.0
*
* Description
*
* History
*
*****************************************************************
* Copyright @ 2023 All rights reserved
*****************************************************************/
#endregion CopyRight
using System.Security.Cryptography;
using System.Text;
namespace PEIS.Utils
{
/// <summary>
/// MySecurity(安全类) 的摘要说明。
/// </summary>
public class MySecurity
{
/// <summary>
/// 初始化安全类
/// </summary>
public MySecurity()
{
///默认密码
key = "peis77911@*71";
}
private string key; //默认密钥
private byte[] sKey;
private byte[] sIV;
#region 加密字符串
/// <summary>
/// 加密字符串
/// </summary>
/// <param name="inputStr">输入字符串</param>
/// <param name="keyStr">密码,可以为“”</param>
/// <returns>输出加密后字符串</returns>
public static string SEncryptString(string inputStr, string keyStr)
{
MySecurity ws = new MySecurity();
return ws.EncryptString(inputStr, keyStr);
}
/// <summary>
/// 加密字符串
/// </summary>
/// <param name="inputStr">输入字符串</param>
/// <param name="keyStr">密码,可以为“”</param>
/// <returns>输出加密后字符串</returns>
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
/// <summary>
/// 加密字符串 密钥为系统默认
/// </summary>
/// <param name="inputStr">输入字符串</param>
/// <returns>输出加密后字符串</returns>
public static string SEncryptString(string inputStr)
{
MySecurity ws = new MySecurity();
return ws.EncryptString(inputStr, "");
}
#endregion 加密字符串 密钥为系统默认 0123456789
#region 加密文件
/// <summary>
/// 加密文件
/// </summary>
/// <param name="filePath">输入文件路径</param>
/// <param name="savePath">加密后输出文件路径</param>
/// <param name="keyStr">密码,可以为“”</param>
/// <returns></returns>
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 解密字符串
/// <summary>
/// 解密字符串
/// </summary>
/// <param name="inputStr">要解密的字符串</param>
/// <param name="keyStr">密钥</param>
/// <returns>解密后的结果</returns>
public static string SDecryptString(string inputStr, string keyStr)
{
MySecurity ws = new MySecurity();
return ws.DecryptString(inputStr, keyStr);
}
/// <summary>
/// 解密字符串 密钥为系统默认
/// </summary>
/// <param name="inputStr">要解密的字符串</param>
/// <returns>解密后的结果</returns>
public static string SDecryptString(string inputStr)
{
MySecurity ws = new MySecurity();
return ws.DecryptString(inputStr, "");
}
/// <summary>
/// 解密字符串
/// </summary>
/// <param name="inputStr">要解密的字符串</param>
/// <param name="keyStr">密钥</param>
/// <returns>解密后的结果</returns>
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 解密文件
/// <summary>
/// 解密文件
/// </summary>
/// <param name="filePath">输入文件路径</param>
/// <param name="savePath">解密后输出文件路径</param>
/// <param name="keyStr">密码,可以为“”</param>
/// <returns></returns>
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 解密文件
}
}

@ -0,0 +1,68 @@
#region CopyRight
/****************************************************************
* ProjectPEIS
* Author
* CLR Version4.0.30319.42000
* CreateTime2023-05-01 14:41:54
* Versionv2.0
*
* Description
*
* History
*
*****************************************************************
* Copyright @ 2023 All rights reserved
*****************************************************************/
#endregion CopyRight
namespace PEIS.Utils
{
public abstract class ObjectData
{
/// <summary>
/// 数据表名
/// </summary>
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;
}
}
}

@ -0,0 +1,39 @@
using System.Threading.Channels;
namespace DicomTool.Utils
{
public static class PacsSqlHelper
{
public static List<ReportPacs> 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<ReportPacs>($@"
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<string> GetReportUidList(string reportAccessionNumber)
{
// 已选图片UID
var selectedList = DAOHelp.GetDataBySQL<ReportPacs>
($@"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<ReportPacs>
($@"SELECT ImageFile FROM PACS.DICOMSERVER.DBO.PEIS_PacsResult WHERE PatientCode='{reportPatientCode}' and ExamFeeitem_Code='{reportExamFeeitemCode}'")
?.FirstOrDefault()?.ImageFile;
}
}
}
Loading…
Cancel
Save