protected override void OnReceiveCFindRequest(byte presentationID, ushort messageID, DcmPriority priority, Dicom.Data.DcmDataset query) { TryInterpretStringsInDatasetUsingCorrectEncoding(query); Trace.WriteLine(String.Format("{0} Receive C-Find from {1} (marked as anonymous:{2})", DateTime.Now, this.Associate.CallingAE, _flagAnonymousAccess)); Trace.WriteLine(query.Dump()); using( var database = new MedicalISDataContext() ) { var queryLevel = query.GetString(DicomTags.QueryRetrieveLevel, null); if (queryLevel == "PATIENT") { IQueryable<Patient> patients = PatientQueries.GetMatchingPatients(database, query, _flagAnonymousAccess); patients = patients.Take(Settings.Default.MaxNumberOfStudiesReturned); foreach (var currentPatient in patients) { foreach (var currentStudy in currentPatient.Studies) { var p = currentPatient; var response = new DcmDataset { SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding }; // Map saved study tags to output response.AddElementWithValue(DicomTags.RetrieveAETitle, "CURAPACS"); response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "PATIENT"); response.AddElementWithValue(DicomTags.PatientID, p.ExternalPatientID); response.AddElementWithValue(DicomTags.PatientsName, p.LastName + "^" + p.FirstName); response.AddElementWithValue(DicomTags.PatientsBirthDate, p.BirthDateTime.Value); response.AddElementWithValue(DicomTags.StudyInstanceUID, currentStudy.StudyInstanceUid); response.AddElementWithValue(DicomTags.AccessionNumber, currentStudy.AccessionNumber); response.AddElementWithValue(DicomTags.StudyDescription, currentStudy.Description); response.AddElementWithValue(DicomTags.ModalitiesInStudy, currentStudy.ModalityAggregation); if (currentStudy.PerformedDateTime.HasValue) { response.AddElementWithValue(DicomTags.StudyDate, currentStudy.PerformedDateTime.Value); response.AddElementWithValue(DicomTags.StudyTime, currentStudy.PerformedDateTime.Value); } response.AddElementWithValue(DicomTags.NumberOfStudyRelatedSeries, currentStudy.Series.Count); response.AddElementWithValue(DicomTags.NumberOfStudyRelatedInstances, (from s in currentStudy.Series select s.Images.Count).Sum()); if (_flagAnonymousAccess) AnonymizeDatasetBasedOnStudyInfo(response); SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending); } } } else if (queryLevel == "STUDY") { IQueryable<Study> studies = StudyQueries.GetMatchingStudies(database, query, _flagAnonymousAccess); studies = studies.Take(Settings.Default.MaxNumberOfStudiesReturned); foreach (var currentStudy in studies) { var p = currentStudy.Patient; var response = new DcmDataset { SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding }; // Map saved study tags to output response.AddElementWithValue(DicomTags.RetrieveAETitle, "CURAPACS"); response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "STUDY"); response.AddElementWithValue(DicomTags.PatientID, p.ExternalPatientID); response.AddElementWithValue(DicomTags.PatientsName, p.LastName + "^" + p.FirstName); response.AddElementWithValue(DicomTags.PatientsBirthDate, p.BirthDateTime.Value); response.AddElementWithValue(DicomTags.StudyInstanceUID, currentStudy.StudyInstanceUid); response.AddElementWithValue(DicomTags.AccessionNumber, currentStudy.AccessionNumber); response.AddElementWithValue(DicomTags.StudyDescription, currentStudy.Description); response.AddElementWithValue(DicomTags.ModalitiesInStudy, currentStudy.ModalityAggregation); if (currentStudy.PerformedDateTime.HasValue) { response.AddElementWithValue(DicomTags.StudyDate, currentStudy.PerformedDateTime.Value); response.AddElementWithValue(DicomTags.StudyTime, currentStudy.PerformedDateTime.Value); } response.AddElementWithValue(DicomTags.NumberOfStudyRelatedSeries, currentStudy.Series.Count); response.AddElementWithValue(DicomTags.NumberOfStudyRelatedInstances, (from s in currentStudy.Series select s.Images.Count).Sum()); if (! String.IsNullOrEmpty(query.GetString(DicomTags.PatientsSex, null))) { response.AddElementWithValue(DicomTags.PatientsSex, Settings.Default.AlwaysRespondWithGender); } if(_flagAnonymousAccess) AnonymizeDatasetBasedOnStudyInfo(response); Trace.WriteLine("response (STUDY): > "); Trace.WriteLine(response.Dump()); SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending); } } else if (queryLevel == "SERIES") { IQueryable<Series> series = SeriesQueries.GetMatchingSeries(database, query); foreach (var currentSeries in series) { var response = new DcmDataset { SpecificCharacterSetEncoding = query.SpecificCharacterSetEncoding }; if (currentSeries.PerformedDateTime.HasValue) { response.AddElementWithValue(DicomTags.SeriesDate, currentSeries.PerformedDateTime.Value); response.AddElementWithValue(DicomTags.SeriesTime, currentSeries.PerformedDateTime.Value); } response.AddElementWithValue(DicomTags.QueryRetrieveLevel, "SERIES"); response.AddElementWithValue(DicomTags.StudyInstanceUID, currentSeries.StudyInstanceUid); response.AddElementWithValue(DicomTags.SeriesInstanceUID, currentSeries.SeriesInstanceUid); response.AddElementWithValue(DicomTags.SeriesNumber, currentSeries.SeriesNumber); response.AddElementWithValue(DicomTags.SeriesDescription, currentSeries.Description); response.AddElementWithValue(DicomTags.Modality, currentSeries.PerformedModalityType); response.AddElementWithValue(DicomTags.NumberOfSeriesRelatedInstances, currentSeries.Images.Count()); response.AddElementWithValue(DicomTags.ReferringPhysiciansName, ""); response.AddElementWithValue(DicomTags.StudyCommentsRETIRED, ""); SendCFindResponse(presentationID, messageID, response, DcmStatus.Pending); } } SendCFindResponse(presentationID, messageID, DcmStatus.Success); } }
public override bool ReceiveMessageAsFileStream(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { var sopClassUid = message.AffectedSopClassUid; if (sopClassUid.Equals(SopClass.BreastTomosynthesisImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedCtImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedMrColorImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedMrImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedPetImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedUsVolumeStorageUid) || sopClassUid.Equals(SopClass.EnhancedXaImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedXrfImageStorageUid) || sopClassUid.Equals(SopClass.UltrasoundMultiFrameImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameGrayscaleByteSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameGrayscaleWordSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameSingleBitSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameTrueColorSecondaryCaptureImageStorageUid)) { server.DimseDatasetStopTag = DicomTagDictionary.GetDicomTag(DicomTags.ReconstructionIndex); // Random tag at the end of group 20 server.StreamMessage = true; return true; } return false; }
public override bool OnReceiveRequest(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return true; }
public override IDicomFilestreamHandler OnStartFilestream(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { if (_importContext == null) { LoadImportContext(association); } return new StorageFilestreamHandler(Context, _importContext); }
public PrintService(System.IO.Stream stream, Dicom.Log.Logger log) : base(stream, log) { var pi = stream.GetType().GetProperty("Socket", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (pi != null) { var endPoint = ((System.Net.Sockets.Socket)pi.GetValue(stream, null)).RemoteEndPoint as System.Net.IPEndPoint; RemoteIP = endPoint.Address; } else { RemoteIP = new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }); } }
void dfs_FileFound(Dicom.Media.DicomFileScanner scanner, Dicom.DicomFile file, string fileName) { DicomDataset ds = file.Dataset; string modality = ds.Get<string>(DicomTag.Modality); if (modality == null) { // handle this? } else if (modality.CompareTo("RTSTRUCT") == 0) { StoreStructureSet(ds); } else if (modality.CompareTo("RTPLAN") == 0) { // process plan } else { StoreImage(ds, modality); } }
public override bool OnReceiveRequest(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { string studyInstanceUid; string seriesInstanceUid; DicomUid sopInstanceUid; bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid); if (ok) ok = message.DataSet[DicomTags.SeriesInstanceUid].TryGetString(0, out seriesInstanceUid); if (ok) ok = message.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid); if (!ok) { Platform.Log(LogLevel.Error, "Unable to retrieve UIDs from request message, sending failure status."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.ProcessingFailure); return true; } if (_importContext == null) { LoadImportContext(association); } var importer = new ImportFilesUtility(_importContext); var result = importer.Import(message, BadFileBehaviourEnum.Ignore, FileImportBehaviourEnum.Save); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.AccessionNumber, result.StudyInstanceUid); else Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.StudyInstanceUid); server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); } else { if (result.DicomStatus == DicomStatuses.ProcessingFailure) Platform.Log(LogLevel.Error, "Failure importing sop: {0}", result.ErrorMessage); //OnReceiveError(message, result.ErrorMessage, association.CallingAE); server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus, result.ErrorMessage); } return true; }
public override bool OnReceiveRequest(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { throw new System.NotImplementedException(); }
public bool CompleteStream(Dicom.Network.DicomServer server, ServerAssociationParameters assoc, byte presentationId, DicomMessage message) { DicomProcessingResult result; var importer = new ImportFilesUtility(_importContext); if (_rejectFile) { result = new DicomProcessingResult(); result.SetError(DicomStatuses.StorageStorageOutOfResources, string.Format("Import failed, disk space usage exceeded")); string studyInstanceUid = message.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty); WorkItem workItem; lock (_importContext.StudyWorkItemsSyncLock) _importContext.StudyWorkItems.TryGetValue(studyInstanceUid, out workItem); importer.InsertFailedWorkItemUid(workItem, message, result); _importContext.FatalError = true; importer.AuditFailure(result); Platform.Log(LogLevel.Warn, "Failure receiving sop, out of disk space: {0}", message.AffectedSopInstanceUid); server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return true; } try { if (_fileStream != null) { _fileStream.Flush(true); _fileStream.Close(); _fileStream.Dispose(); _fileStream = null; } // Convert to file to pass in the source filename var theFile = new DicomFile(message,_sourceFilename); result = importer.Import(theFile, BadFileBehaviourEnum.Delete, FileImportBehaviourEnum.Move); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.AccessionNumber, result.StudyInstanceUid); else Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.StudyInstanceUid); } } catch (Exception e) { result = new DicomProcessingResult { DicomStatus = DicomStatuses.ProcessingFailure, ErrorMessage = e.Message }; } if (!result.Successful) { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } CleanupFile(); server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return true; }
void scu_AssociationAccepted(object sender, Dicom.Network.AssociationParameters e) { _startTime = Environment.TickCount; }
void scu_AssociationRejected(object sender, Dicom.Network.AssociationParameters e) { MessageBox.Show("Association was rejected"); }
void dfs_Complete(Dicom.Media.DicomFileScanner scanner) { scanner.FileFound -= dfs_FileFound; scanner.Complete -= dfs_Complete; // don't currently support rescanning System.Diagnostics.Trace.Assert(!_rescan); }
void dfs_Progress(Dicom.Media.DicomFileScanner scanner, string directory, int count) { // only process if initial directory change if (directory.CompareTo(_currentDirectory) == 0) return; _currentDirectory = directory; // only process if there are series' if (_seriesInstanceUIDs.Count() == 0) return; // send out association complete event var proxy = ImageResponseClient.CreateProxy(); proxy.OnAssociationClosed(_seriesInstanceUIDs.Distinct().ToArray()); _seriesInstanceUIDs.Clear(); }
/// <summary> /// Construct new print job using specified SOP instance UID. If passed SOP instance UID is missing, new UID will /// be generated /// </summary> /// <param name="sopInstance">New print job SOP instance uID</param> public PrintJob(DicomUID sopInstance, Printer printer, string originator, Dicom.Log.Logger log) : base() { if (printer == null) { throw new ArgumentNullException("printer"); } Log = log; if (sopInstance == null || sopInstance.UID == string.Empty) { SOPInstanceUID = DicomUID.Generate(); } else { SOPInstanceUID = sopInstance; } this.Add(DicomTag.SOPClassUID, SOPClassUID); this.Add(DicomTag.SOPInstanceUID, SOPInstanceUID); Printer = printer; Status = PrintJobStatus.Pending; PrinterName = Printer.PrinterAet; Originator = originator; if (CreationDateTime == DateTime.MinValue) { CreationDateTime = DateTime.Now; } PrintJobFolder = SOPInstanceUID.UID; var receivingFolder = Environment.CurrentDirectory + @"\PrintJobs"; FullPrintJobFolder = string.Format(@"{0}\{1}", receivingFolder.TrimEnd('\\'), PrintJobFolder); FilmBoxFolderList = new List<string>(); }
protected override void OnReceiveCEchoRequest(byte presentationID, ushort messageID, Dicom.Network.DcmPriority priority) { Trace.WriteLine(String.Format("Receive C-Echo from {0} (marked as anonymous:{1})", this.Associate.CallingAE, _flagAnonymousAccess)); SendCEchoResponse(presentationID, messageID, DcmStatus.Success); }