|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下载所有图片
|
|
|
|
|
/// </summary>
|
|
|
|
|
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<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 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<string>();
|
|
|
|
|
foreach (var report in reportList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var imageFiles = DAOHelp.GetDataBySQL<ReportPacs>
|
|
|
|
|
($@"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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|