コード例 #1
0
 public virtual FileMetaInfo NewFileMetaInfo(DataSet ds, String transferSyntaxUID)
 {
     try {
         return new FileMetaInfo().Init(ds.GetString(Tags.SOPClassUniqueId, null),
                                        ds.GetString(Tags.SOPInstanceUniqueId, null), transferSyntaxUID,
                                        Implementation.ClassUID, Implementation.VersionName);
     }
     catch (DcmValueException ex) {
         throw new ArgumentException(ex.Message);
     }
 }
コード例 #2
0
ファイル: SQElement.cs プロジェクト: KnownSubset/DicomSharp
 public override void AddItem(DataSet item)
 {
     m_list.Add(item);
 }
コード例 #3
0
ファイル: SQElement.cs プロジェクト: KnownSubset/DicomSharp
 /// <summary>
 /// Creates a new instance of ElementImpl 
 /// </summary>
 public SQElement(uint tag, DataSet parent)
     : base(tag)
 {
     this.parent = parent;
 }
コード例 #4
0
 public FileDataSource(DcmParser parser, DataSet dataSet, byte[] buffer)
 {
     _parser = parser;
     _dataSet = dataSet;
     _buffer = buffer;
 }
コード例 #5
0
 /// <summary>
 /// Send C-FIND to find the series for the studies 
 /// <param name="studiesInstanceUniqueIds">The studies' instance UniqueIds</param>
 /// </summary>
 public IList<DataSet> CFindSeriesForStudies(IEnumerable<string> studiesInstanceUniqueIds)
 {
     var dataset = new DataSet();
     const string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelFIND;
     dataset.FileMetaInfo = GenerateFileMetaInfo(sopClassUniqueId);
     dataset.PutCS(Tags.QueryRetrieveLevel, "SERIES");
     dataset.PutCS(Tags.Modality);
     dataset.PutUI(Tags.StudyInstanceUniqueId, studiesInstanceUniqueIds.ToArray());
     dataset.PutUI(Tags.SeriesInstanceUniqueId);
     dataset.PutIS(Tags.SeriesNumber);
     dataset.PutDA(Tags.SeriesDate);
     dataset.PutTM(Tags.SeriesTime);
     dataset.PutLO(Tags.SeriesDescription);
     return studiesInstanceUniqueIds != null && studiesInstanceUniqueIds.Any() ? RetrieveDatasetsFromServiceClassProvider(dataset, sopClassUniqueId) : new List<DataSet>();
 }
コード例 #6
0
ファイル: DataSet.cs プロジェクト: KnownSubset/DicomSharp
 public DataSet(DataSet parentDataSet)
 {
     this._parentDataSet = parentDataSet;
 }
コード例 #7
0
 private void CMoveDataSet(DataSet dataset, string applicationEntityDestination)
 {
     int pcid = _presentationContextIdStart;
     _presentationContextIdStart += 2;
     IActiveAssociation activeAssociation = null;
     try
     {
         const string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelMOVE;
         _aAssociateRequest.AddPresContext(_associationFactory.NewPresContext(pcid, sopClassUniqueId, DefinedTransferSyntaxes));
         activeAssociation = OpenAssociation();
         if (activeAssociation != null)
         {
             IAssociation association = activeAssociation.Association;
             if (association.GetAcceptedPresContext(sopClassUniqueId, TransferSyntaxUniqueId) == null)
             {
                 Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
             }
             else
             {
                 string message = String.Format("CMove from {0} @ {1} {2}:{3} to {4}", _aAssociateRequest.Name, _aAssociateRequest.ApplicationEntityTitle, _hostName, _port, applicationEntityDestination);
                 Logger.Info(message);
                 IDicomCommand dicomCommand = _dcmObjectFactory.NewCommand();
                 IDicomCommand cMoveRequest = dicomCommand.InitCMoveRQ(association.NextMsgID(), sopClassUniqueId, Priority.HIGH, applicationEntityDestination);
                 IDimse dimseRequest = _associationFactory.NewDimse(pcid, cMoveRequest, dataset);
                 FutureDimseResponse dimseResponse = activeAssociation.Invoke(dimseRequest);
                 while (!dimseResponse.IsReady())
                 {
                     Thread.Sleep(0);
                 }
                 Logger.Info("Finished CMOVE");
             }
         }
     }
     finally
     {
         if (activeAssociation != null)
         {
             activeAssociation.Release(false);
         }
         _aAssociateRequest.RemovePresentationContext(pcid);
     }
 }
コード例 #8
0
ファイル: StoreSCP.cs プロジェクト: KnownSubset/DicomSharp
        private FileInfo ToFile(DataSet ds)
        {
            String studyInstanceUniqueId = null;
            try {
                studyInstanceUniqueId = ds.GetString(Tags.StudyInstanceUniqueId);
                if (studyInstanceUniqueId == null) {
                    throw new DcmServiceException(MISSING_UID, "Missing Study Instance UID");
                }
                if (ds.Vm(Tags.SeriesInstanceUniqueId) <= 0) {
                    throw new DcmServiceException(MISSING_UID, "Missing Series Instance UID");
                }
                String instanceUniqueId = ds.GetString(Tags.SOPInstanceUniqueId);
                if (instanceUniqueId == null) {
                    throw new DcmServiceException(MISSING_UID, "Missing SOP Instance UID");
                }
                String classUniqueId = ds.GetString(Tags.SOPClassUniqueId);
                if (classUniqueId == null) {
                    throw new DcmServiceException(MISSING_UID, "Missing SOP Class UID");
                }
                if (!instanceUniqueId.Equals(ds.FileMetaInfo.MediaStorageSOPInstanceUniqueId)) {
                    throw new DcmServiceException(MISMATCH_UID,
                                                  "SOP Instance UID in DataSet differs from Affected SOP Instance UID");
                }
                if (!classUniqueId.Equals(ds.FileMetaInfo.MediaStorageSOPClassUniqueId)) {
                    throw new DcmServiceException(MISMATCH_UID,
                                                  "SOP Class UID in DataSet differs from Affected SOP Class UID");
                }
            }
            catch (DcmValueException e) {
                throw new DcmServiceException(CANNOT_UNDERSTAND, e);
            }

            String pn = ToFileID(ds, Tags.PatientName) + "____";
            FileInfo dir = _archiveDirectory;
            for (int i = 0; i < dirSplitLevel; ++i) {
                dir = new FileInfo(dir.FullName + "\\" + pn.Substring(0, (i + 1) - (0)));
            }
            dir = new FileInfo(dir.FullName + "\\" + studyInstanceUniqueId);
            dir = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.SeriesNumber));
            var file = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.InstanceNumber) + ".dcm");
            return file;
        }
コード例 #9
0
        /// <summary>
        /// Send C-STORE
        /// </summary>
        /// <param name="dataSet"></param>
        public bool CStore(DataSet dataSet)
        {
            int pcid = _presentationContextIdStart;
            _presentationContextIdStart += 2;
            IActiveAssociation active = null;
            try
            {
                //
                // Prepare association
                //
                String classUniqueId = dataSet.GetString(Tags.SOPClassUniqueId);
                String tsUniqueId = dataSet.GetString(Tags.TransferSyntaxUniqueId);

                if (string.IsNullOrEmpty(tsUniqueId) && (dataSet.FileMetaInfo != null))
                {
                    tsUniqueId = dataSet.FileMetaInfo.GetString(Tags.TransferSyntaxUniqueId);
                }

                if (string.IsNullOrEmpty(tsUniqueId))
                {
                    tsUniqueId = UIDs.ImplicitVRLittleEndian;
                }

                _aAssociateRequest.AddPresContext(_associationFactory.NewPresContext(pcid, classUniqueId, new[] { tsUniqueId }));
                active = OpenAssociation();
                if (active != null)
                {
                    bool bResponse = false;
                    FutureDimseResponse frsp = SendDataset(active, null, dataSet);
                    if (frsp != null)
                    {
                        active.WaitOnResponse();
                        bResponse = true;
                    }
                    return bResponse;
                }
            }
            finally
            {
                if (active != null)
                {
                    active.Release(true);
                }
                _aAssociateRequest.RemovePresentationContext(pcid);
            }

            return false;
        }
コード例 #10
0
 private static void LogDataSetValues(DataSet seriesDataSets)
 {
     if (seriesDataSets == null)
     {
         return;
     }
     Logger.Info(seriesDataSets.GetElementsAsString());
 }
コード例 #11
0
 /// <summary>
 /// Send C-GET
 /// <param name="studyInstanceUniqueId">A study instance UniqueId</param>
 /// <param name="seriesInstanceUniqueId">A series instance UniqueId</param>
 /// <param name="sopInstanceUniqueId">A sop instance instance UniqueId</param>
 /// </summary>
 public IList<DataSet> CGet(string studyInstanceUniqueId, string seriesInstanceUniqueId, string sopInstanceUniqueId)
 {
     if ((studyInstanceUniqueId == null) && (seriesInstanceUniqueId == null) && (sopInstanceUniqueId == null))
     {
         return null;
     }
     int pcid = _presentationContextIdStart;
     _presentationContextIdStart += 2;
     var datasets = new List<DataSet>();
     IActiveAssociation active = null;
     try
     {
         string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelGET;
         _aAssociateRequest.AddPresContext(_associationFactory.NewPresContext(pcid, sopClassUniqueId, DefinedTransferSyntaxes));
         active = OpenAssociation();
         if (active != null)
         {
             var dataset = new DataSet();
             dataset.FileMetaInfo = GenerateFileMetaInfo(sopClassUniqueId);
             dataset.PutUI(Tags.StudyInstanceUniqueId, studyInstanceUniqueId);
             dataset.PutUI(Tags.SeriesInstanceUniqueId, seriesInstanceUniqueId);
             dataset.PutUI(Tags.SOPInstanceUniqueId, sopInstanceUniqueId);
             IAssociation association = active.Association;
             if ((association.GetAcceptedPresContext(sopClassUniqueId, TransferSyntaxUniqueId)) == null)
             {
                 Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
                 return null;
             }
             DicomCommand cGetDicomCommand = _dcmObjectFactory.NewCommand().InitCGetRQ(association.NextMsgID(), sopClassUniqueId, Priority.HIGH);
             IDimse dimseRequest = _associationFactory.NewDimse(pcid, cGetDicomCommand, dataset);
             FutureDimseResponse dimseResponse = active.Invoke(dimseRequest);
             while (!dimseResponse.IsReady())
             {
                 Thread.Sleep(0);
             }
             datasets.AddRange(dimseResponse.ListPending().Select(dimse => dimse.DataSet));
             _aAssociateRequest.RemovePresentationContext(pcid);
         }
     }
     finally
     {
         if (active != null)
         {
             active.Release(true);
         }
         _aAssociateRequest.RemovePresentationContext(pcid);
     }
     return datasets;
 }
コード例 #12
0
 /// <summary>
 /// Find all the studies for a specific patient
 /// <param name="patientId">The id of the patient</param>
 /// <param name="patientName">The name of the patient</param>
 /// </summary>
 public IList<DataSet> CFindStudy(string patientId, string patientName)
 {
     string queryKey = _aAssociateRequest.ApplicationEntityTitle + _port + _hostName + patientId + patientName;
     if (_cacheManager.ContainsKey(queryKey))
     {
         return _cacheManager[queryKey];
     }
     const string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelFIND;
     var dataset = new DataSet();
     dataset.FileMetaInfo = GenerateFileMetaInfo(sopClassUniqueId);
     dataset.PutDA(Tags.StudyDate);
     dataset.PutTM(Tags.StudyTime);
     dataset.PutSH(Tags.AccessionNumber);
     dataset.PutCS(Tags.QueryRetrieveLevel, "STUDY");
     dataset.PutCS(Tags.ModalitiesInStudy);
     dataset.PutLO(Tags.InstitutionName);
     dataset.PutPN(Tags.PerformingPhysicianName);
     dataset.PutPN(Tags.ReferringPhysicianName);
     dataset.PutLO(Tags.StudyDescription);
     dataset.PutPN(Tags.PatientName, patientName);
     dataset.PutLO(Tags.PatientID, patientId);
     dataset.PutDA(Tags.PatientBirthDate);
     dataset.PutCS(Tags.PatientSex);
     dataset.PutAS(Tags.PatientAge);
     dataset.PutUI(Tags.StudyInstanceUniqueId);
     dataset.PutSH(Tags.StudyID);
     List<DataSet> datasets = RetrieveDatasetsFromServiceClassProvider(dataset, sopClassUniqueId);
     if (datasets.Any())
     {
         _cacheManager.Add(queryKey, datasets);
     }
     return datasets;
 }
コード例 #13
0
 /// <summary>
 /// Find all the studies for the studies Instance UniqueIds
 /// <param name="studyInstanceUniqueIds">The studies' instance UniqueIds</param>
 /// </summary>
 public IList<DataSet> CFindStudies(IEnumerable<string> studyInstanceUniqueIds)
 {
     const string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelFIND;
     var dataset = new DataSet();
     dataset.FileMetaInfo = GenerateFileMetaInfo(sopClassUniqueId);
     dataset.PutDA(Tags.StudyDate);
     dataset.PutTM(Tags.StudyTime);
     dataset.PutSH(Tags.AccessionNumber);
     dataset.PutCS(Tags.QueryRetrieveLevel, "STUDY");
     dataset.PutCS(Tags.ModalitiesInStudy);
     dataset.PutLO(Tags.InstitutionName);
     dataset.PutPN(Tags.ReferringPhysicianName);
     dataset.PutLO(Tags.StudyDescription);
     dataset.PutPN(Tags.PatientName);
     dataset.PutLO(Tags.PatientID);
     dataset.PutDA(Tags.PatientBirthDate);
     dataset.PutCS(Tags.PatientSex);
     dataset.PutAS(Tags.PatientAge);
     dataset.PutUI(Tags.StudyInstanceUniqueId, studyInstanceUniqueIds.ToArray());
     dataset.PutSH(Tags.StudyID);
     return studyInstanceUniqueIds.Any() ? RetrieveDatasetsFromServiceClassProvider(dataset, sopClassUniqueId) : new List<DataSet>();
 }
コード例 #14
0
ファイル: SQElement.cs プロジェクト: KnownSubset/DicomSharp
 public override DataSet AddNewItem()
 {
     var item = new DataSet(parent);
     m_list.Add(item);
     return item;
 }
コード例 #15
0
 private List<DataSet> ExecuteCFindDicomCommand(IActiveAssociation active, DataSet dataSet, int pcid)
 {
     IAssociation association = active.Association;
     if (association.GetAcceptedPresContext(UIDs.StudyRootQueryRetrieveInformationModelFIND, TransferSyntaxUniqueId) == null)
     {
         Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
         return null;
     }
     IDicomCommand cFindDicomCommand = _dcmObjectFactory.NewCommand().InitCFindRQ(association.NextMsgID(), UIDs.StudyRootQueryRetrieveInformationModelFIND, Priority.HIGH);
     IDimse dimseRequest = _associationFactory.NewDimse(pcid, cFindDicomCommand, dataSet);
     string message = string.Format("{0} sending CFind request to {1} @ {2}:{3}", _aAssociateRequest.Name, _aAssociateRequest.ApplicationEntityTitle, _hostName, _port);
     Logger.Info(message);
     FutureDimseResponse dimseResponse = active.Invoke(dimseRequest);
     while (!dimseResponse.IsReady())
     {
         Thread.Sleep(0);
     }
     return dimseResponse.ListPending().Select(dimse => dimse.DataSet).ToList();
 }
コード例 #16
0
ファイル: StoreSCP.cs プロジェクト: KnownSubset/DicomSharp
 private void StoreToFile(DcmParser parser, DataSet ds, FileInfo file, DcmEncodeParam encParam)
 {
     Stream outputStream = OpenOutputStream(file);
     try {
         ds.WriteFile(outputStream, encParam);
         if (parser.ReadTag == Tags.PixelData) {
             ds.WriteHeader(outputStream, encParam, parser.ReadTag, parser.ReadVR, parser.ReadLength);
             Copy(parser.InputStream, outputStream);
         }
     }
     finally {
         try {
             outputStream.Close();
         }
         catch (IOException ignore)
         {
             Logger.Error(ignore);
         }
     }
 }
コード例 #17
0
 private void MoveSeries(string studyInstanceUniqueId, IEnumerable<string> seriesInstanceUniqueIds, string applicationEntityDestination)
 {
     DataSet seriesCMoveDataset = new DataSet();
     seriesCMoveDataset.FileMetaInfo = GenerateFileMetaInfo(UIDs.StudyRootQueryRetrieveInformationModelMOVE);
     seriesCMoveDataset.PutCS(Tags.QueryRetrieveLevel, "SERIES");
     seriesCMoveDataset.PutUI(Tags.StudyInstanceUniqueId, studyInstanceUniqueId);
     seriesCMoveDataset.PutUI(Tags.SeriesInstanceUniqueId, seriesInstanceUniqueIds.Distinct().ToArray());
     LogDataSetValues(seriesCMoveDataset);
     CMoveDataSet(seriesCMoveDataset, applicationEntityDestination);
 }
コード例 #18
0
ファイル: StoreSCP.cs プロジェクト: KnownSubset/DicomSharp
 private String ToFileID(DataSet ds, uint tag)
 {
     try {
         String s = ds.GetString(tag);
         if (string.IsNullOrEmpty(s)) {
             return "__NULL__";
         }
         char[] ins = s.ToUpper().ToCharArray();
         var outs = new char[Math.Min(8, ins.Length)];
         for (int i = 0; i < outs.Length; ++i) {
             outs[i] = ins[i] >= '0' && ins[i] <= '9' || ins[i] >= 'A' && ins[i] <= 'Z' ? ins[i] : '_';
         }
         return new String(outs);
     }
     catch (DcmValueException dcmValueException) {
         Logger.Error(dcmValueException);
         return "__ERR__";
     }
 }
コード例 #19
0
 private List<DataSet> RetrieveDatasetsFromServiceClassProvider(DataSet dataSet, string sopClassUniqueId)
 {
     int pcid = _presentationContextIdStart;
     _presentationContextIdStart += 2;
     var datasets = new List<DataSet>();
     IActiveAssociation activeAssociation = null;
     try
     {
         _aAssociateRequest.AddPresContext(_associationFactory.NewPresContext(pcid, sopClassUniqueId, DefinedTransferSyntaxes));
         activeAssociation = OpenAssociation();
         if (activeAssociation != null)
         {
             datasets = ExecuteCFindDicomCommand(activeAssociation, dataSet, pcid);
         }
     }
     finally
     {
         if (activeAssociation != null)
         {
             activeAssociation.Release(true);
         }
         _aAssociateRequest.RemovePresentationContext(pcid);
     }
     return datasets;
 }
コード例 #20
0
 public virtual IDimse NewDimse(int presentationContextId, IDicomCommand dicomCommand, DataSet dataSet)
 {
     return new Dimse(presentationContextId, dicomCommand, dataSet, null);
 }
コード例 #21
0
        private FutureDimseResponse SendDataset(IActiveAssociation activeAssociation, DcmParser parser, DataSet dataSet)
        {
            String sopInstUniqueId = dataSet.GetString(Tags.SOPInstanceUniqueId);
            if (string.IsNullOrEmpty(sopInstUniqueId))
            {
                Logger.Error("SOP instance UniqueId is null or empty");
                return null;
            }
            String sopClassUniqueId = dataSet.GetString(Tags.SOPClassUniqueId);
            if (string.IsNullOrEmpty(sopClassUniqueId))
            {
                Logger.Error("SOP class UniqueId is null or empty");
                return null;
            }
            PresentationContext pc = null;
            IAssociation association = activeAssociation.Association;

            if (parser != null)
            {
                if (parser.DcmDecodeParam.encapsulated)
                {
                    String tsUniqueId = dataSet.FileMetaInfo.TransferSyntaxUniqueId;
                    if ((pc = association.GetAcceptedPresContext(sopClassUniqueId, tsUniqueId)) == null)
                    {
                        Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
                        return null;
                    }
                }
                else if (IsSopClassUniqueIdNotSupported(association, sopClassUniqueId, out pc))
                {
                    Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
                    return null;
                }

                DicomCommand cStoreRequest = _dcmObjectFactory.NewCommand().InitCStoreRQ(association.NextMsgID(), sopClassUniqueId, sopInstUniqueId, Priority.HIGH);
                return activeAssociation.Invoke(_associationFactory.NewDimse(pc.pcid(), cStoreRequest, new FileDataSource(parser, dataSet, new byte[2048])));
            }
            if ((dataSet.FileMetaInfo != null) && (dataSet.FileMetaInfo.TransferSyntaxUniqueId != null))
            {
                String tsUniqueId = dataSet.FileMetaInfo.TransferSyntaxUniqueId;
                if ((pc = association.GetAcceptedPresContext(sopClassUniqueId, tsUniqueId)) == null)
                {
                    Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
                    return null;
                }
            }
            else if (IsSopClassUniqueIdNotSupported(association, sopClassUniqueId, out pc))
            {
                Logger.Error(SOP_CLASS_UNIQUEID_NOT_SUPPORTED);
                return null;
            }

            DicomCommand cStoreRq = _dcmObjectFactory.NewCommand().InitCStoreRQ(association.NextMsgID(), sopClassUniqueId, sopInstUniqueId, Priority.HIGH);
            IDimse dimse = _associationFactory.NewDimse(pc.pcid(), cStoreRq, dataSet);
            return activeAssociation.Invoke(dimse);
        }
コード例 #22
0
ファイル: DcmElement.cs プロジェクト: KnownSubset/DicomSharp
 public virtual void AddItem(DataSet item)
 {
     throw new NotSupportedException(ToString());
 }
コード例 #23
0
 /// <summary>
 /// Send C-FIND for instance
 /// <param name="studyInstanceUniqueIds">The studies' instance UniqueIds</param>
 /// <param name="seriesInstanceUniqueIds">The series' instance UniqueIds</param>
 /// </summary>
 public IList<DataSet> CFindInstance(IEnumerable<string> studyInstanceUniqueIds, IEnumerable<string> seriesInstanceUniqueIds)
 {
     const string sopClassUniqueId = UIDs.StudyRootQueryRetrieveInformationModelFIND;
     var datasets = new List<DataSet>();
     List<string> seriesNotCached = RetrieveItemsFromTheCache(seriesInstanceUniqueIds, datasets);
     List<string> studiesNotCached = RetrieveItemsFromTheCache(studyInstanceUniqueIds, datasets);
     var dataset = new DataSet();
     dataset.FileMetaInfo = GenerateFileMetaInfo(sopClassUniqueId);
     dataset.PutUI(Tags.SOPInstanceUniqueId);
     dataset.PutCS(Tags.QueryRetrieveLevel, "IMAGE");
     dataset.PutUI(Tags.SeriesInstanceUniqueId, seriesNotCached.ToArray());
     dataset.PutUI(Tags.StudyInstanceUniqueId, studiesNotCached.ToArray());
     datasets.AddRange(RetrieveDatasetsFromServiceClassProvider(dataset, sopClassUniqueId));
     return datasets;
 }