/// <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; }
/// <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; }