DICOM 测试工具

一个DICOM测试工具。

引用了 fo-dicom 。fo-dicom 算是比较好用的,我的另外一个项目也是用了它。

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dicom;
using Dicom.Log;
using Dicom.Network;
using Dicom.Serialization;
using Newtonsoft.Json;namespace DicomUtils
{public delegate void CStoreRequestHandler(TDicomServer Server, TDicomService service, string studyuid, string instuid, string tag, ref string fileid, ref string filename);public delegate void CStoreFileSavedHandler(TDicomServer Server, TDicomService service, string studyuid, string instuid, string tag, string fileid, string filename);public delegate void CFindHandler(TDicomServer Server, TDicomService service, string json,ref DataTable dt);public class TDicomServer{public IDicomServer Server = null;public ServerConfig Config = null;public List<TLogItem> Log = new List<TLogItem>();public void Start(){wirtelog("Server "+ "Start");Server = DicomServer.Create<TDicomService>(Config.Port, userState: this);}public void Stop(){if (Server != null){wirtelog("Server " + "Stop");Server.Stop();Server.Dispose();Server = null;}}public event CStoreRequestHandler EventCStoreRequest;public virtual void OnCStoreRequest(TDicomService service,string studyuid, string instuid, string tag, ref string fileid, ref string filename){if (filename == ""){string dir =get_storge_dir();string fn = System.IO.Path.Combine(dir, studyuid, instuid + ".dcm");filename = fn;}wirtelog("OnCStoreRequest " + filename);if (EventCStoreRequest != null){EventCStoreRequest(this, service, studyuid, instuid, tag, ref fileid, ref filename);}}public event CStoreFileSavedHandler EventCStoreFileSaved;public virtual void OnCStoreFileSaved(TDicomService service, string studyuid, string instuid, string tag, string fileid, string filename){wirtelog("OnCStoreFileSaved " + filename);string fn_json = System.IO.Path.ChangeExtension(filename,".json");System.IO.File.WriteAllText(fn_json, tag);if (EventCStoreFileSaved != null){EventCStoreFileSaved(this, service, studyuid, instuid, tag, fileid, filename);}}public event CFindHandler EventCFind;public virtual void OnCFindRequest(TDicomService service, DicomDataset request, string json, List<DicomDataset> list){wirtelog("OnCFindRequest " + json);if (EventCFind != null){DataTable dt = null;EventCFind(this, service, json,ref dt);if (dt != null){List<WorklistItem> worklists = WorklistHandler.dt2worklists(dt);List<DicomDataset> data= WorklistHandler.Worklist2DataSet(request,worklists);list.AddRange(data);}} }public void wirtelog(string msg){lock (Log)try{if (Log.Count > 1000){Log.RemoveRange(0,500);}Log.Add(TLogItem.new_item(msg));}catch{} }public string get_storge_dir(){return Config.get_storge_dir();}}public class TDicomService : DicomService, IDicomServiceProvider, IDicomCStoreProvider, IDicomCFindProvider, IDicomCMoveProvider, IDicomCGetProvider, IDicomCEchoProvider{private static readonly DicomTransferSyntax[] AcceptedTransferSyntaxes = new DicomTransferSyntax[]{DicomTransferSyntax.ExplicitVRLittleEndian,DicomTransferSyntax.ExplicitVRBigEndian,DicomTransferSyntax.ImplicitVRLittleEndian};private static readonly DicomTransferSyntax[] AcceptedImageTransferSyntaxes = new DicomTransferSyntax[]{// LosslessDicomTransferSyntax.JPEGLSLossless,DicomTransferSyntax.JPEG2000Lossless,DicomTransferSyntax.JPEGProcess14SV1,DicomTransferSyntax.JPEGProcess14,DicomTransferSyntax.RLELossless,// LossyDicomTransferSyntax.JPEGLSNearLossless,DicomTransferSyntax.JPEG2000Lossy,DicomTransferSyntax.JPEGProcess1,DicomTransferSyntax.JPEGProcess2_4,// UncompressedDicomTransferSyntax.ExplicitVRLittleEndian,DicomTransferSyntax.ExplicitVRBigEndian,DicomTransferSyntax.ImplicitVRLittleEndian};public TDicomService(INetworkStream stream, Encoding fallbackEncoding, Logger log): base(stream, fallbackEncoding, log){}public TDicomServer GetSCPServer(){return (TDicomServer)UserState;}public void wirtelog(string msg){TDicomServer Server = GetSCPServer();Server.wirtelog(msg);}public Task OnReceiveAssociationRequestAsync(DicomAssociation association){wirtelog("OnReceiveAssociationRequestAsync  IP:" + association.RemoteHost + " PORT:" + association.RemotePort.ToString() + " AE:" + association.CalledAE);TDicomServer Server = GetSCPServer();if (!Server.Config.isAllowAE(association.CalledAE)){wirtelog("SendAssociationRejectAsync  IP:" + association.RemoteHost + " PORT:" + association.RemotePort.ToString() + " AE:" + association.CalledAE);return SendAssociationRejectAsync(DicomRejectResult.Permanent,DicomRejectSource.ServiceUser,DicomRejectReason.CalledAENotRecognized);}foreach (var pc in association.PresentationContexts){if (pc.AbstractSyntax == DicomUID.Verification|| pc.AbstractSyntax == DicomUID.PatientRootQueryRetrieveInformationModelFind|| pc.AbstractSyntax == DicomUID.PatientRootQueryRetrieveInformationModelMove|| pc.AbstractSyntax == DicomUID.StudyRootQueryRetrieveInformationModelFind|| pc.AbstractSyntax == DicomUID.StudyRootQueryRetrieveInformationModelMove|| pc.AbstractSyntax == DicomUID.ModalityWorklistInformationModelFind|| pc.AbstractSyntax == DicomUID.ModalityPerformedProcedureStep|| pc.AbstractSyntax == DicomUID.ModalityPerformedProcedureStepNotification|| pc.AbstractSyntax == DicomUID.ModalityPerformedProcedureStepRetrieve){pc.AcceptTransferSyntaxes(AcceptedTransferSyntaxes);}if (pc.AbstractSyntax == DicomUID.Verification) pc.AcceptTransferSyntaxes(AcceptedTransferSyntaxes);else if (pc.AbstractSyntax.StorageCategory != DicomStorageCategory.None) pc.AcceptTransferSyntaxes(AcceptedImageTransferSyntaxes);}return SendAssociationAcceptAsync(association);}public Task OnReceiveAssociationReleaseRequestAsync(){wirtelog("OnReceiveAssociationReleaseRequestAsync");return SendAssociationReleaseResponseAsync();}public void OnReceiveAbort(DicomAbortSource source, DicomAbortReason reason){wirtelog("OnReceiveAbort  IP:" + source.ToString() + " reason:" + reason.ToString());}public void OnConnectionClosed(Exception exception){if (exception != null){wirtelog("OnConnectionClosed  exception:" + exception.ToString());}else{wirtelog("OnConnectionClosed");}}public DicomCStoreResponse OnCStoreRequest(DicomCStoreRequest request){TDicomServer Server = GetSCPServer();string studyUid = request.Dataset.GetSingleValue<string>(DicomTag.StudyInstanceUID);string instUid = request.SOPInstanceUID.UID;wirtelog("OnCStoreRequest  studyUid:" + studyUid + " instUid:" + instUid);string tag = "";if (request.HasDataset)tag=Pub.DicomDataset2json(request.Dataset); string filename = "";string fileid = "";Server.OnCStoreRequest(this, studyUid, instUid, tag, ref fileid, ref filename);string dir = System.IO.Path.GetDirectoryName(filename);if (!Directory.Exists(dir))Directory.CreateDirectory(dir);request.File.Save(filename);Server.OnCStoreFileSaved(this, studyUid, instUid, tag, fileid, filename);return new DicomCStoreResponse(request, DicomStatus.Success);}public void OnCStoreRequestException(string tempFileName, Exception e){wirtelog("OnCStoreRequest  tempFileName:" + tempFileName + " exception:" + e.Message);}public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request){wirtelog("OnCEchoRequest  MessageID:" + request.MessageID);return new DicomCEchoResponse(request, DicomStatus.Success);}public IEnumerable<DicomCFindResponse> OnCFindRequest(DicomCFindRequest request){wirtelog("OnCFindRequest  request:" + request.Type.ToString());string json = "";if (request.HasDataset)json =Pub.DicomDataset2json(request.Dataset);TDicomServer Server = GetSCPServer();List<DicomCFindResponse> responses = new List<DicomCFindResponse>();List<DicomDataset> list = new List<DicomDataset>();Server.OnCFindRequest(this, request.Dataset,json, list);foreach (DicomDataset result in list){responses.Add(new DicomCFindResponse(request, DicomStatus.Pending) { Dataset = result });}responses.Add(new DicomCFindResponse(request, DicomStatus.Success));return responses;}public IEnumerable<DicomCMoveResponse> OnCMoveRequest(DicomCMoveRequest request){wirtelog("OnCMoveRequest  request:" + request.Type.ToString());throw new NotImplementedException();}public IEnumerable<DicomCGetResponse> OnCGetRequest(DicomCGetRequest request){wirtelog("OnCGetRequest  request:" + request.Type.ToString());throw new NotImplementedException();}}public class TLogItem{public Int64 id = get_new_id();public DateTime time = DateTime.Now;public string msg = "";public static Int64 last_id = 0;public static Int64 get_new_id(){last_id = last_id + 1;return last_id;}public static TLogItem new_item(string msg){TLogItem i = new TLogItem();i.msg = msg;return i;}} 
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/661864.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【C++STL详解(四)】--------vector的模拟实现

前言 还是那句话&#xff1a;模拟实现不是为了比库里面更好&#xff0c;而是去学习它的一些底层&#xff0c;能够让自己有更深的了解&#xff0c;为了更好的熟用&#xff01; vector底层图 由上图可以看出&#xff0c;它的底层实际上就是原生的指针T*&#xff0c;只不过会存在三…

可视化大屏也在卷组件化,组件绝对是效率利器呀。

组件化设计在B端上应用十分普遍&#xff0c;其实可视化大屏组件更为规范&#xff0c;本期分享组件化设计的好处&#xff0c;至于组件源文件如何获取&#xff0c;大家都懂的。 组件化设计对可视化大屏设计有以下几个方面的帮助&#xff1a; 提高可重用性&#xff1a; 组件化设…

SpringBoot指标监控

一.SpringBoot指标监控_添加Actuator功能 Spring Boot Actuator可以帮助程序员监控和管理SpringBoot应用&#xff0c;比如健康检查、内存使用情况统计、线程使用情况统计等。我 们在SpringBoot项目中添加Actuator功能&#xff0c;即可使用Actuator监控 项目&#xff0c;用法如…

启明云端2.4寸屏+ESP32-S3+小型智能调速电动家用除草机案例 触控三档调速,能显示电压故障码

今天给大家分享个启明云端2.4寸屏ESP32-S3小型智能调速电动家用除草机案例&#xff0c;国外有草坪文化&#xff0c;这个机器能智能触控三档调速&#xff0c;带屏能显示电压故障码&#xff0c;数显档位&#xff08;3档最大&#xff09;&#xff0c;触控屏&#xff0c;长按3秒就能…

C#技巧之窗体去鼠标化

简介 在窗体程序中不用鼠标&#xff0c;直接使用键盘完成想要的操作。 实现的方法有两种&#xff0c;一种是使用键盘上的Tab键使控件获得焦点&#xff0c;然后用enter键触发该控件上的事件&#xff08;一般为click事件&#xff09;。另一种是&#xff0c;为控件添加快捷键&am…

附录6-1 黑马优购项目-组件与过滤器

目录 1 过滤器-格式化价格 2 组件-搜索框 3 组件-数量框 4 组件-商品概况 4.1 格式化价格 4.2 选择性使用勾选框和数量框 4.3 源码 1 过滤器-格式化价格 这个项目中仅用到格式化价格这一种过滤器。过滤器文件位置为store/filter.wxs 文件内容是这样的&#xf…

APT预警攻击平台截获Nday

APT预警攻击平台截获Nday 2024年4月26日 设备漏洞【漏洞利用】H3C Magic R100任意代码执行漏洞(CVE-2022-34598) 0000 &#xff1a; 0010 &#xff1a; 0020 &#xff1a; 0030 &#xff1a; 0040 &#xff1a; 0050 &#xff1a; 0060 &#xff1a; 0070 &#xff1a;6F 72…

MySQL基础学习(待整理)

MySQL 简介 学习路径 MySQL 安装 卸载预安装的mariadb rpm -qa | grep mariadb rpm -e --nodeps mariadb-libs安装网络工具 yum -y install net-tools yum -y install libaio下载rpm-bundle.tar安装包&#xff0c;并解压&#xff0c;使用rpm进行安装 rpm -ivh \ mysql-communi…

【热闻速递】Google 裁撤 Python研发团队

&#x1f308;个人主页: 鑫宝Code &#x1f525;热门专栏: 闲话杂谈&#xff5c; 炫酷HTML | JavaScript基础 ​&#x1f4ab;个人格言: "如无必要&#xff0c;勿增实体" 文章目录 【&#x1f525;热闻速递】Google 裁撤 Python研发团队引入研究结论 【&#x1f5…

Liunx发布tomcat项目

Liunx在Tomcat发布JavaWeb项目 1.问题2.下载JDK3.下载Tomcat4.Tomcat本地JavaWeb项目打war包、解压、发布5.重启Tomcat,查看项目 1.问题 1.JDK 与 Tomcat 版本需匹配&#xff0c;否则页面不能正确显示 报错相关&#xff1a;Caused by: java.lang.ClassNotFoundException: java…

通过Servlet和JSP,结合session和application实现简单网络聊天室(文末附源码)

目录 一.成品效果 二.代码部分 chat.jsp ChatServlet 一.成品效果 在启动成功后&#xff0c;我们就可以在任意俩个浏览器页面中相互发消息&#xff0c;如图所示左边屏幕使用的是Edge浏览器&#xff0c;右图使用的是火狐浏览器。当然笔者这里只是简单实现最基本的一些功能&…

企业如何通过定制AI智能名片B2B2C商城系统革新营销手段

在日新月异的商业环境中&#xff0c;企业想要立足并蓬勃发展&#xff0c;就必须紧跟时代的步伐&#xff0c;不断革新营销手段。而定制开发AI智能名片B2B2C商城系统正是企业实现这一目标的重要武器。接下来&#xff0c;我们将深入探讨企业如何通过这一系统&#xff0c;在与客户交…