Пример #1
0
        static void Main(string[] args)
        {
            //构造要发送的C-FIND-RQ消息,如果查看DicomCFindRequest类的话
            //可以看到其定义与DICOM3.0标准第7部分第9章中规定的编码格式一致

            //在构造Study级别的查询时,我们的参数patientID会被填充到消息的Indentifier部分,用来在SCP方进行匹配查询
            var cfind = DicomCFindRequest.CreateStudyQuery(patientId: "12345");


            //当接收到对方发挥的响应消息时,进行相应的操作【注】:该操作在DICOM3.0协议
            //第7部分第8章中有说明,DIMSE协议并未对其做出规定,而应该有用户自己设定

            cfind.OnResponseReceived = (rq, rsp) =>
            {
                //此处我们只是简单的将查询到的结果输出到屏幕
                Console.WriteLine("PatientAge:{0} PatientName:{1}", rsp.Dataset.Get <string>(DicomTag.PatientAge), rsp.Dataset.Get <string>(DicomTag.PatientName));
            };

            //发起C-FIND-RQ:
            //该部分就是利用A-ASSOCIATE服务来建立DICOM实体双方之间的连接。
            var client = new DicomClient();

            client.AddRequest(cfind);
            client.Send(host: "127.0.0.1", port: 12345, useTls: false, callingAe: "SCU-AE", calledAe: "SCP-AE");
            Console.ReadLine();
        }
Пример #2
0
        private void find_click(object sender, EventArgs e)
        {
            try
            {
                bool   findloop        = false;
                string scanresultsfile = Directory.GetCurrentDirectory() + "\\cfindresults.txt" + " ";

                var cfind = DicomCFindRequest.CreateStudyQuery(patientId: "*");
                cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => {
                    if (!findloop)
                    {
                        if (rp.Status == DicomStatus.Success || rp.Status == DicomStatus.Pending)
                        {
                            MessageBox.Show(string.Format("C-Find is sucess and the results are writeen into file: {0}", scanresultsfile));
                        }
                        else if (!(rp.Status == DicomStatus.Success || rp.Status == DicomStatus.Pending))
                        {
                            MessageBox.Show(string.Format("C-Find failure {0}", rp.Status.ToString()));
                            this.Close();
                        }

                        if (!(File.Exists(scanresultsfile)))
                        {
                            // Create a file to write to.
                            using (StreamWriter sw = File.CreateText(scanresultsfile))
                            {
                                sw.WriteLine("C-Find Results\n");
                            }
                        }
                        else if (File.Exists(scanresultsfile))
                        {
                            File.WriteAllText(scanresultsfile, String.Empty);
                        }
                    }


                    using (StreamWriter sw = File.AppendText(scanresultsfile))
                    {
                        sw.WriteLine(string.Format("Patient ID: {0}\t", rp.Dataset.Get <string>(DicomTag.PatientID)));
                        sw.WriteLine(string.Format("PatientName: {0}\n", rp.Dataset.Get <string>(DicomTag.PatientName)));
                    }
                    findstat = true;
                    findloop = true;
                };

                var client = new DicomClient();
                client.AddRequest(cfind);
                //client.Send("127.0.0.1", 11112, false, "SCU-AE", "SCP-AE");
                client.Send(Basic_called_ip, System.Convert.ToInt32(Basic_called_port), false, Basic_called_ae, Basic_calling_ae);
            }
            catch (Exception exc)
            {
                if (!(exc is DicomException))
                {
                    Console.WriteLine(exc.ToString());
                }
            }
        }
Пример #3
0
        public void autofind(string dt)
        {//string AutoscanLog = Directory.GetCurrentDirectory() + "\\Autoscan"+"--"+DateTime.Now.ToString()+".txt" + " ";
            bool   findloop        = false;
            string scanresultsfile = Directory.GetCurrentDirectory() + "\\autocfindresults.txt" + " ";

            var cfind = DicomCFindRequest.CreateStudyQuery(patientId: "*");

            cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => {
                if (!findloop)
                {
                    if (rp.Status == DicomStatus.Success || rp.Status == DicomStatus.Pending)
                    {
                        MessageBox.Show(string.Format("Patient details are writeen into file: {0}", scanresultsfile));
                        using (StreamWriter sw = File.AppendText(dt))
                        {
                            sw.WriteLine(string.Format("C-Find status: Pass \n"));
                        }
                    }
                    else if (!(rp.Status == DicomStatus.Success || rp.Status == DicomStatus.Pending))
                    {
                        MessageBox.Show("Cannot dump patient details");
                        this.Close();
                        using (StreamWriter sw = File.AppendText(dt))
                        {
                            sw.WriteLine(string.Format("C-Find status: Fail \n"));
                        }
                    }

                    if (!(File.Exists(scanresultsfile)))
                    {
                        // Create a file to write to.
                        using (StreamWriter sw = File.CreateText(scanresultsfile))
                        {
                            sw.WriteLine("Auto C-Find Results\n");
                        }
                    }
                    else if (File.Exists(scanresultsfile))
                    {
                        File.WriteAllText(scanresultsfile, String.Empty);
                    }
                }


                using (StreamWriter sw = File.AppendText(scanresultsfile))
                {
                    sw.WriteLine(string.Format("Patient ID: {0}\t", rp.Dataset.Get <string>(DicomTag.PatientID)));
                    sw.WriteLine(string.Format("PatientName: {0}\n", rp.Dataset.Get <string>(DicomTag.PatientName)));
                }
                findstat = true;
                findloop = true;
            };

            var client = new DicomClient();

            client.AddRequest(cfind);
            //client.Send("127.0.0.1", 11112, false, "SCU-AE", "SCP-AE");
            client.Send(Basic_called_ip, System.Convert.ToInt32(Basic_called_port), false, Basic_called_ae, Basic_calling_ae);
        }
Пример #4
0
        public List <Study> GetStudiesStudyLevel(RetriveEntity RetriveFrom, string PatientId, string PatientName, DateTime?Fromdate, DateTime?Todate, string accession,
                                                 string studyId, string modalitiesInStudy, string studyInstanceUid)
        {
            DicomDateRange dcmdateRange = null;

            if (Fromdate.HasValue && Todate.HasValue)
            {
                dcmdateRange = new DicomDateRange(Fromdate.Value, Todate.Value);
            }
            var request = DicomCFindRequest.CreateStudyQuery(PatientId, PatientName, dcmdateRange, accession, studyId, modalitiesInStudy, studyInstanceUid);

            return(GetStudies(RetriveFrom, request));
        }
Пример #5
0
        /// <summary>
        /// Convenience method for creating a C-FIND study query.
        /// </summary>
        /// <param name="patientId">Patient ID.</param>
        /// <param name="patientName">Patient name.</param>
        /// <param name="studyDateTime">Time range of studies.</param>
        /// <param name="accession">Accession number.</param>
        /// <param name="studyId">Study ID.</param>
        /// <param name="modalitiesInStudy">Modalities in study.</param>
        /// <param name="studyInstanceUid">Study instance UID.</param>
        /// <returns>C-FIND study query object.</returns>
        public static DicomCFindRequest CreateStudyQuery(
            string patientId             = null,
            string patientName           = null,
            DicomDateRange studyDateTime = null,
            string accession             = null,
            string studyId           = null,
            string modalitiesInStudy = null,
            string studyInstanceUid  = null)
        {
            DicomCFindRequest dimse = DicomCFindRequest.CreateStudyQuery(patientId, patientName, studyDateTime, accession, studyId, modalitiesInStudy, studyInstanceUid);

            return(dimse);
        }
Пример #6
0
        public override async Task FindStudiesAsync(FindStudiesRequest request, CancellationToken ct)
        {
            var query = DicomCFindRequest.CreateStudyQuery();

            var patientName = string.Empty;

            if (!string.IsNullOrWhiteSpace(request.Family))
            {
                patientName += request.Family;
            }
            if (!string.IsNullOrWhiteSpace(request.FirstName))
            {
                if (string.IsNullOrWhiteSpace(patientName))
                {
                    patientName += '*';
                }

                patientName += '^' + request.FirstName;
            }

            if (!string.IsNullOrWhiteSpace(patientName))
            {
                query.Dataset.AddOrUpdate(DicomTag.PatientName, patientName);
            }

            if (!string.IsNullOrWhiteSpace(request.PatientId))
            {
                query.Dataset.AddOrUpdate(DicomTag.PatientID, request.PatientId);
            }

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                query.Dataset.AddOrUpdate(DicomTag.StudyDescription, request.Description);
            }

            if (request.From.HasValue || request.To.HasValue)
            {
                var from = request.From.GetValueOrDefault(DateTime.MinValue);
                var to   = request.To.GetValueOrDefault(DateTime.MaxValue);

                query.Dataset.AddOrUpdate(DicomTag.StudyDate, new DicomDateRange(from, to));
            }

            query.Dataset.AddOrUpdate(DicomTag.StudyID, string.Empty);

            query.OnResponseReceived += (req, resp) =>
            {
                if (!ct.IsCancellationRequested && resp.Dataset != null)
                {
                    var study = resp.Dataset.CreateObject <Study>();

                    if (study == null)
                    {
                        _logger.Error("Study creation failed");
                    }
                    else
                    {
                        request.RaiseStudyFound(study);
                    }
                }
            };

            await FindAsync <Study>(query, _settings, _findStudiesSemaphore, ct);
        }
Пример #7
0
        // 建立连接并查询
        async public void DicomCFindRequestFunct(ServerConfig OneServerConfig)
        {
            // 首先清空原来的查询结果
            Results.Clear();

            // 建立连接,查找病人下面的所有Study
            var client = new DicomClient(OneServerConfig.RemoteIp, OneServerConfig.RemotePort,
                                         false, OneServerConfig.LocalAeTitle, OneServerConfig.RemoteAeTitle);

            client.NegotiateAsyncOps();

            var patientRequest = DicomCFindRequest.CreateStudyQuery(
                patientId: ToQueryPatientId, patientName: ToQueryPatientName, studyDateTime: ToQueryStudyDateRange);

            // ATTENTION
            // 需要把DicomTag.StudyTime去除才能得到正确的查询结果,可能是fo-dicom程序的Bug
            // 注意这个StudyTime与查询里面的studyDateTime不是一个意思
            patientRequest.Dataset.Remove(DicomTag.StudyTime);

            var patientRequestResults = new List <ValuableResult>();

            patientRequest.OnResponseReceived += (req, response) =>
            {
                if (response.Status == DicomStatus.Pending)
                {
                    lock (patientRequestResults)
                    {
                        var patientId        = response.Dataset.GetSingleValueOrDefault(DicomTag.PatientID, string.Empty);
                        var studyInstanceUid = response.Dataset.GetSingleValueOrDefault(DicomTag.StudyInstanceUID, string.Empty);

                        if (!string.IsNullOrEmpty(patientId) && !string.IsNullOrEmpty(studyInstanceUid))
                        {
                            patientRequestResults.Add(new ValuableResult()
                            {
                                PatientId        = patientId,
                                StudyInstanceUid = studyInstanceUid
                            });

                            // 更新主界面显示
                            // OneServerConfig.AddLogStr($"Found {response.Dataset.GetSingleValueOrDefault(DicomTag.PatientName, string.Empty)} " +
                            //     $"{patientId} and the study instance id is {studyInstanceUid} which was created in " +
                            //     $"{response.Dataset.GetSingleValueOrDefault(DicomTag.StudyDate, string.Empty)}");
                            // OneServerConfig.AddLogStr($"Found: {response.Dataset.GetSingleValueOrDefault(DicomTag.PatientName, string.Empty)} ");
                        }
                    }
                }
                if (response.Status == DicomStatus.Success)
                {
                    // Console.WriteLine(response.Status.ToString());
                    //OneServerConfig.LogInfo += response.Status.ToString() + Environment.NewLine;
                }
            };

            await client.AddRequestAsync(patientRequest);

            await client.SendAsync();

            // 病人层次的查询结束
            // 得到需要的病人ID和Study的ID

            // 查询对应的序列
            var seriesRequestResults = new List <ValuableResult>();

            foreach (var patientRequestResult in patientRequestResults)
            {
                var seriesRequest = DicomCFindRequest.CreateSeriesQuery(patientRequestResult.StudyInstanceUid);
                seriesRequest.OnResponseReceived += (req, response) =>
                {
                    if (response.Status == DicomStatus.Pending)
                    {
                        var seriesUid = response.Dataset?.GetSingleValue <string>(DicomTag.SeriesInstanceUID);
                        if (!string.IsNullOrEmpty(seriesUid))
                        {
                            string modality = response.Dataset?.GetSingleValue <string>(DicomTag.Modality);
                            if ((IsCtSave && modality.ToUpper().Trim() == "CT") ||
                                (IsMrSave && modality.ToUpper().Trim() == "MR") ||
                                (IsPetSave && modality.ToUpper().Trim() == "PT") ||
                                (IsRtsSave && modality.ToUpper().Trim() == "RTSTRUCT") ||
                                (IsRtpSave && modality.ToUpper().Trim() == "PTPLAN") ||
                                (IsRtDoseSave && modality.ToUpper().Trim() == "RTDOSE"))
                            {
                                seriesRequestResults.Add(new ValuableResult()
                                {
                                    PatientId         = patientRequestResult.PatientId,
                                    StudyInstanceUid  = patientRequestResult.StudyInstanceUid,
                                    SeriesInstanceUid = seriesUid
                                });

                                OneServerConfig.AddLogStr($"Found: {patientRequestResult.PatientId} {modality}");
                            }
                        }
                    }
                    if (response.Status == DicomStatus.Success)
                    {
                        // Console.WriteLine(response.Status.ToString());
                        //OneServerConfig.LogInfo += response.Status.ToString() + Environment.NewLine;
                    }

                    // serieUids.Add(response.Dataset?.GetSingleValue<string>(DicomTag.SeriesInstanceUID));
                };
                await client.AddRequestAsync(seriesRequest);

                await client.SendAsync();
            }

            Results.AddRange(seriesRequestResults);
        }