コード例 #1
0
        public DicomCStoreResponse OnCStoreRequest(DicomCStoreRequest request)
        {
            string prefix   = "[STORAGESCP] [" + session + "] ";
            var    studyUid = request.Dataset.Get <string>(DicomTag.StudyInstanceUID);
            var    instUid  = request.SOPInstanceUID.UID;

            Program.Log.Write(prefix + "Begin processing c-store request. " + request.SOPClassUID.UID);

            bool         res = true;
            DElementList iod = new DElementList(request.Dataset);

            if (Program.ConfigMgt.Config.SOAPEnable) //SOAP communication, 20121017
            {
                string requestDataSet = iod.ToDicomXMLString();
                string requestSoap    = string.Empty;
                string responseSoap   = string.Empty;

                string tick = DateTime.Now.Ticks.ToString();

                res = _reqTran.TransformString(requestDataSet, ref requestSoap);

                if (!res)
                {
                    Program.Log.Write(LogType.Error, "Transforming DICOM message to SOAP failed. ");
                    return(new DicomCStoreResponse(request, DicomStatus.ProcessingFailure));
                }

                res = _SOAPClient.SendMessage(requestSoap, out responseSoap);

                if (!res)
                {
                    Program.Log.Write(LogType.Error, "Sending SOAP message failed. ");
                    return(new DicomCStoreResponse(request, DicomStatus.ProcessingFailure));
                }
            }
            else
            {
                if (StorageSCPService.Service == null)
                {
                    Program.Log.Write(prefix + "[WARNING] SCP is not binded to GC Gateway, dump data to local folder only.");
                    iod.SaveXmlFile("StorageIOD_" + DateTime.Now.Ticks.ToString() + ".xml");
                }
                else
                {
                    DataSet dsIOD = DicomMappingHelper.CreateQCDataSet
                                    <StorageItem>(StorageSCPService.Service.StorageList, request.Dataset);

                    if (dsIOD == null)
                    {
                        Program.Log.Write(prefix + "[WARNING] Process storage IOD failed.");
                        return(new DicomCStoreResponse(request, DicomStatus.ProcessingFailure));
                    }

                    res = StorageSCPService.Service.SaveData(Program.ConfigMgt.Config.StorageRule, dsIOD);

                    if (!res)
                    {
                        Program.Log.Write(prefix + "[WARNING] Insert GC Gateway database failed.");
                        return(new DicomCStoreResponse(request, DicomStatus.ProcessingFailure));
                    }
                }
            }
            Program.Log.Write("[STORAGESCP] [" + session + "] Finish processing c-store request. Result:" + res.ToString());

            return(new DicomCStoreResponse(request, DicomStatus.Success));
        }
コード例 #2
0
        public IEnumerable <DicomCFindResponse> OnCFindRequest(DicomCFindRequest request)
        {
            string prefix = "[WorklistSCP] [" + session + "] ";

            Program.Log.Write(prefix + "Begin processing c-find request.");

            List <DicomCFindResponse> responses = new List <DicomCFindResponse>();

            if (request.Level == DicomQueryRetrieveLevel.Worklist || request.Level == DicomQueryRetrieveLevel.Patient)
            {
                DataSet dsQC = DicomMappingHelper.CreateQCDataSet
                               <MWLQueryCriteriaItem>(WorkListSCPService.Service.QCList, request.Dataset);
                WorklistSCPHelper.ModifyQCDataSet(WorkListSCPService.Service.QCList, dsQC);
                if (dsQC == null)
                {
                    Program.Log.Write(prefix + "[WARNING] Process query criteria failed.");
                    responses.Add(new DicomCFindResponse(request, DicomStatus.QueryRetrieveUnableToProcess));
                    return(responses);
                }

                DataSet dsQR = WorkListSCPService.Service.RequestData(Program.ConfigMgt.Config.Rule, dsQC);

                if (dsQR == null)
                {
                    Program.Log.Write(prefix + "[WARNING] Query GC Gateway database failed.");
                    responses.Add(new DicomCFindResponse(request, DicomStatus.QueryRetrieveUnableToProcess));
                    return(responses);
                }
                WorklistSCPHelper.GenerateRequestedProcedureID(dsQR, session);

                if (WorklistSCPHelper.SplitDataRow(dsQR))
                {
                    Program.Log.Write(prefix + "[INFORMATION] Found multiple values in code value and performed splitting.");
                }

                //fname = path + "\\DataSet_QR_2_SPLIT_" + DateTime.Now.Ticks.ToString() + ".xml";
                //dsQR.WriteXml(fname);

                DElementListWrapper[] resultList = null;

                if (Program.ConfigMgt.Config.MergeElementList)
                {
                    resultList = WorklistSCPHelper.CreateQRElementList
                                 <MWLQueryResultItem>(WorkListSCPService.Service.QRList, dsQR);
                }
                else
                {
                    resultList = DicomMappingHelper.CreateQRElementList
                                 <MWLQueryResultItem>(WorkListSCPService.Service.QRList, dsQR);
                }

                if (resultList == null)
                {
                    Program.Log.Write(prefix + "[WARNING] Process query result failed.");
                    responses.Add(new DicomCFindResponse(request, DicomStatus.QueryRetrieveUnableToProcess));
                    return(responses);
                }

                int count = resultList.Length;
                if (count < 1)
                {
                    Program.Log.Write(prefix + "[WARNING] No query result.");
                }
                else
                {
                    int index = 1;
                    foreach (DElementListWrapper eleList in resultList)
                    {
                        Program.Log.Write(prefix + "Sending query result " + (index++).ToString() + "/" + count.ToString());

                        DicomDataset result = new DicomDataset();
                        if (Program.ConfigMgt.Config.SendCharacterSetTag)
                        {
                            //eleList.List.Add(DHelper.CharacterSet);
                            if (DHelper.iCharacterSet != null)
                            {
                                for (int i = 0; i < DHelper.iCharacterSet.Length; i++)
                                {
                                    eleList.List.Add <string>(DicomTag.SpecificCharacterSet, DHelper.iCharacterSet[i]);
                                }
                            }
                        }

                        eleList.List.Add <string>(new DicomTag(0x0000, 0x0002), "1.2.840.10008.5.1.4.31");

                        DicomCFindResponse response = new DicomCFindResponse(request, DicomStatus.Pending);
                        response.Dataset = eleList.List;
                        responses.Add(response);
                    }
                }
            }
            responses.Add(new DicomCFindResponse(request, DicomStatus.Success));
            return(responses);
        }