コード例 #1
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        private FutureRSP SendDataset(ActiveAssociation active, DcmParser parser, Dataset ds)
        {
            String sopInstUID = ds.GetString(Tags.SOPInstanceUID);
            if (sopInstUID == null)
            {
                log.Error( "SOP instance UID is null" );
                return null;
            }
            String sopClassUID = ds.GetString(Tags.SOPClassUID);
            if (sopClassUID == null)
            {
                log.Error( "SOP class UID is null" );
                return null;
            }
            PresContext pc = null;
            Association assoc = active.Association;

            if (parser != null)
            {
                if (parser.DcmDecodeParam.encapsulated)
                {
                    String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                    if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }
                }
                else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                {
                    log.Error( "SOP class UID not supported" );
                    return null;
                }

                return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), new FileDataSource(parser, ds, new byte[2048])));
            }
            else
            {
                if ((ds.GetFileMetaInfo() != null)
                &&	(ds.GetFileMetaInfo().TransferSyntaxUID != null))
                {
                    String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                    if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }
                }
                else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                {
                    log.Error( "SOP class UID not supported" );
                    return null;
                }

                return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), ds));
            }

            return null;
        }
コード例 #2
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        /// <summary>
        /// Send C-STORE
        /// </summary>
        /// <param name="ds"></param>
        public bool CStore( Dataset ds )
        {
            int pcid = PCID_START;
            PCID_START += 2;

            try
            {
                //
                // Prepare association
                //
                String classUID = ds.GetString( Tags.SOPClassUID);
                String tsUID = ds.GetString(Tags.TransferSyntaxUID);

                if( (tsUID == null || tsUID.Equals( "" )) && (ds.GetFileMetaInfo() != null) )
                    tsUID = ds.GetFileMetaInfo().GetString(Tags.TransferSyntaxUID);

                if( tsUID == null || tsUID.Equals( "" ) )
                    tsUID = UIDs.ImplicitVRLittleEndian;

                m_assocRQ.AddPresContext(aFact.NewPresContext(pcid,
                    classUID,
                    new String[]{ tsUID } ));
                ActiveAssociation active = OpenAssoc();
                if (active != null)
                {
                    bool bResponse = false;

                    FutureRSP frsp = SendDataset(active, null, ds);
                    if (frsp != null)
                    {
                        active.WaitOnRSP();

                        bResponse = true;
                    }

                    active.Release(true);

                    return bResponse;
                }
            }
            finally
            {
                m_assocRQ.RemovePresContext(pcid);
            }

            return false;
        }
コード例 #3
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        /// <summary>
        /// Send C-GET
        /// </summary>
        public Dataset[] CGet(string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID)
        {
            if ((studyInstanceUID == null)
            &&	(seriesInstanceUID == null)
            &&	(sopInstanceUID == null))
                return null;

            int pcid = PCID_START;
            PCID_START += 2;

            Dataset[] ret = null;

            try
            {
                string sopClassUID = UIDs.StudyRootQueryRetrieveInformationModelGET;

                m_assocRQ.AddPresContext(aFact.NewPresContext(pcid, sopClassUID, new String[]{ m_tsUID }));
                ActiveAssociation active = OpenAssoc();
                if (active != null)
                {
                    Dataset ds = new Dataset();

                    FileMetaInfo fmi = new FileMetaInfo();
                    fmi.PutOB(Tags.FileMetaInformationVersion, new byte[] {0, 1});
                    fmi.PutUI(Tags.MediaStorageSOPClassUID, sopClassUID);
                    fmi.PutUI(Tags.TransferSyntaxUID, m_tsUID);
                    fmi.PutSH(Tags.ImplementationVersionName, "dicomcs-SCU");

                    ds.SetFileMetaInfo(fmi);

                    if (studyInstanceUID != null)
                        ds.PutUI(Tags.StudyInstanceUID, studyInstanceUID);

                    if (seriesInstanceUID != null)
                        ds.PutUI(Tags.SeriesInstanceUID, seriesInstanceUID);

                    if (sopInstanceUID != null)
                        ds.PutUI(Tags.SOPInstanceUID, sopInstanceUID);

                    PresContext pc = null;
                    Association assoc = active.Association;

                    if ((ds.GetFileMetaInfo() != null)
                    &&	(ds.GetFileMetaInfo().TransferSyntaxUID != null))
                    {
                        String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                        if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                        {
                            log.Error( "SOP class UID not supported" );
                            return null;
                        }
                    }
                    else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }

                    Dimse rq = aFact.NewDimse(pcid, oFact.NewCommand().InitCGetRQ(assoc.NextMsgID(), sopClassUID, 0), ds);

                    FutureRSP rsp = active.Invoke(rq);
                    active.Release(true);

                    if (rsp.IsReady())
                    {
                        ArrayList al = rsp.ListPending();

                        if (al.Count > 0)
                        {
                            ret = new Dataset[al.Count];

                            for (int i=0;i < ret.Length;i++)
                                ret[i] = ((Dimse)al[i]).Dataset;
                        }
                        else
                        {
                            ret = new Dataset[1];
                            ret[0] = rsp.Get().Dataset;
                        }
                    }

                    m_assocRQ.RemovePresContext(pcid);
                }
            }
            catch
            {
            }
            finally
            {
                m_assocRQ.RemovePresContext(pcid);
            }

            return ret;
        }
コード例 #4
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        /// <summary>
        /// Send C-FIND for study
        /// </summary>
        public Dataset[] CFindStudy(string patid, string[] modalities)
        {
            int pcid = PCID_START;
            PCID_START += 2;

            Dataset[] ret = null;

            try
            {
                string sopClassUID = UIDs.StudyRootQueryRetrieveInformationModelFIND;

                m_assocRQ.AddPresContext(aFact.NewPresContext(pcid, sopClassUID, new String[]{ m_tsUID }));
                ActiveAssociation active = OpenAssoc();
                if (active != null)
                {
                    Dataset ds = new Dataset();

                    FileMetaInfo fmi = new FileMetaInfo();
                    fmi.PutOB(Tags.FileMetaInformationVersion, new byte[] {0, 1});
                    fmi.PutUI(Tags.MediaStorageSOPClassUID, sopClassUID);
                    fmi.PutUI(Tags.TransferSyntaxUID, m_tsUID);
                    fmi.PutSH(Tags.ImplementationVersionName, "dicomcs-SCU");

                    ds.SetFileMetaInfo(fmi);

                    ds.PutDA(Tags.StudyDate);
                    ds.PutTM(Tags.StudyTime);
                    ds.PutSH(Tags.AccessionNumber);
                    ds.PutCS(Tags.QueryRetrieveLevel, "STUDY");
                    ds.PutCS(Tags.ModalitiesInStudy, modalities);
                    ds.PutLO(Tags.InstitutionName);
                    ds.PutPN(Tags.ReferringPhysicianName);
                    ds.PutLO(Tags.StudyDescription);
                    ds.PutPN(Tags.PatientName);
                    ds.PutLO(Tags.PatientID, patid);
                    ds.PutDA(Tags.PatientBirthDate);
                    ds.PutCS(Tags.PatientSex);
                    ds.PutAS(Tags.PatientAge);
                    ds.PutUI(Tags.StudyInstanceUID);

                    PresContext pc = null;
                    Association assoc = active.Association;

                    if ((ds.GetFileMetaInfo() != null)
                    &&	(ds.GetFileMetaInfo().TransferSyntaxUID != null))
                    {
                        String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                        if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                        {
                            log.Error( "SOP class UID not supported" );
                            return null;
                        }
                    }
                    else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }

                    Dimse rq = aFact.NewDimse(pcid, oFact.NewCommand().InitCFindRQ(assoc.NextMsgID(), sopClassUID, 0), ds);

                    FutureRSP rsp = active.Invoke(rq);
                    active.Release(true);

                    if (rsp.IsReady())
                    {
                        ArrayList al = rsp.ListPending();

                        if (al.Count > 0)
                        {
                            int len = al.Count;

                            ret = new Dataset[len];

                            for (int i=0;i < len;i++)
                                ret[i] = (Dataset) ((Dimse) al[i]).Dataset;
                        }
                    }
                }
            }
            finally
            {
                m_assocRQ.RemovePresContext(pcid);
            }

            return ret;
        }
コード例 #5
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        /// <summary>
        /// Send C-FIND for series
        /// </summary>
        public Dataset[] CFindSeries(string studyInstanceUID, string[] modalities)
        {
            int pcid = PCID_START;
            PCID_START += 2;

            Dataset[] ret = null;

            try
            {
                string sopClassUID = UIDs.StudyRootQueryRetrieveInformationModelFIND;

                m_assocRQ.AddPresContext(aFact.NewPresContext(pcid, sopClassUID, new String[]{ m_tsUID }));
                ActiveAssociation active = OpenAssoc();
                if (active != null)
                {
                    Dataset ds = new Dataset();

                    FileMetaInfo fmi = new FileMetaInfo();
                    fmi.PutOB(Tags.FileMetaInformationVersion, new byte[] {0, 1});
                    fmi.PutUI(Tags.MediaStorageSOPClassUID, sopClassUID);
                    fmi.PutUI(Tags.TransferSyntaxUID, m_tsUID);
                    fmi.PutSH(Tags.ImplementationVersionName, "dicomcs-SCU");

                    ds.SetFileMetaInfo(fmi);

                    ds.PutCS(Tags.QueryRetrieveLevel, "SERIES");
                    ds.PutCS(Tags.Modality);
                    ds.PutUI(Tags.StudyInstanceUID, studyInstanceUID);
                    ds.PutUI(Tags.SeriesInstanceUID);

                    PresContext pc = null;
                    Association assoc = active.Association;

                    if ((ds.GetFileMetaInfo() != null)
                    &&	(ds.GetFileMetaInfo().TransferSyntaxUID != null))
                    {
                        String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID;
                        if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null)
                        {
                            log.Error( "SOP class UID not supported" );
                            return null;
                        }
                    }
                    else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null)
                    {
                        log.Error( "SOP class UID not supported" );
                        return null;
                    }

                    Dimse rq = aFact.NewDimse(pcid, oFact.NewCommand().InitCFindRQ(assoc.NextMsgID(), sopClassUID, 0), ds);

                    FutureRSP rsp = active.Invoke(rq);
                    active.Release(true);

                    if (rsp.IsReady())
                    {
                        ArrayList al = rsp.ListPending();

                        if ((al != null)
                        &&	(al.Count > 0)
                        &&	(modalities != null)
                        &&	(modalities.Length > 0))
                        {
                            for (int i=0;i < al.Count;i++)
                            {
                                try
                                {
                                    string mod = ((Dimse) al[i]).Dataset.GetString(Tags.Modality);
                                    int j=0;

                                    for (;j < modalities.Length;j++)
                                        if (string.Compare(modalities[j], mod) == 0)
                                            break;

                                    if (j == modalities.Length)
                                        al.RemoveAt(i--);
                                }
                                catch
                                {
                                    al.RemoveAt(i--);
                                }
                            }
                        }

                        if (al.Count > 0)
                        {
                            int len = al.Count;

                            ret = new Dataset[len];

                            for (int i=0;i < len;i++)
                                ret[i] = (Dataset) ((Dimse) al[i]).Dataset;
                        }
                    }
                }
            }
            finally
            {
                m_assocRQ.RemovePresContext(pcid);
            }

            return ret;
        }
コード例 #6
0
ファイル: StoreSCP.cs プロジェクト: sleighter/dicom-sharp
        private FileInfo toFile(Dataset ds)
        {
            String studyInstUID = null;
            try
            {
                studyInstUID = ds.GetString(Tags.StudyInstanceUID);
                if (studyInstUID == null)
                {
                    throw new DcmServiceException(MISSING_UID, "Missing Study Instance UID");
                }
                if (ds.vm(Tags.SeriesInstanceUID) <= 0)
                {
                    throw new DcmServiceException(MISSING_UID, "Missing Series Instance UID");
                }
                String instUID = ds.GetString(Tags.SOPInstanceUID);
                if (instUID == null)
                {
                    throw new DcmServiceException(MISSING_UID, "Missing SOP Instance UID");
                }
                String classUID = ds.GetString(Tags.SOPClassUID);
                if (classUID == null)
                {
                    throw new DcmServiceException(MISSING_UID, "Missing SOP Class UID");
                }
                if (!instUID.Equals(ds.GetFileMetaInfo().MediaStorageSOPInstanceUID))
                {
                    throw new DcmServiceException(MISMATCH_UID, "SOP Instance UID in Dataset differs from Affected SOP Instance UID");
                }
                if (!classUID.Equals(ds.GetFileMetaInfo().MediaStorageSOPClassUID))
                {
                    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 = archiveDir;
            for (int i = 0; i < dirSplitLevel; ++i)
            {
                dir = new FileInfo(dir.FullName + "\\" + pn.Substring(0, (i + 1) - (0)));
            }
            dir = new FileInfo(dir.FullName + "\\" + studyInstUID);
            dir = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.SeriesNumber));
            FileInfo file = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.InstanceNumber) + ".dcm");
            return file;
        }