public async Task DicomCGetRequest_PickCTImagesInStudy_OnlyCTImagesRetrieved() { var client = DicomClientFactory.Create("localhost", 11112, false, "SCU", "COMMON"); var pc = DicomPresentationContext.GetScpRolePresentationContext(DicomUID.CTImageStorage); client.AdditionalPresentationContexts.Add(pc); var counter = 0; var locker = new object(); client.OnCStoreRequest = request => { lock (locker) { ++counter; } return(Task.FromResult(new DicomCStoreResponse(request, DicomStatus.Success))); }; var get = new DicomCGetRequest("1.2.840.113619.2.55.3.2609388324.145.1222836278.84"); var handle = new ManualResetEventSlim(); get.OnResponseReceived = (request, response) => { if (response.Remaining == 0) { handle.Set(); } }; await client.AddRequestAsync(get); await client.SendAsync().ConfigureAwait(false); handle.Wait(); Assert.Equal(140, counter); }
static void Main(string[] args) { var client = new DicomClient(); client.NegotiateAsyncOps(); // Find a list of Studies var request = CreateDummyRequest(); var studyUids = new List <string>(); request.OnResponseReceived += (req, response) => { DebugStudyResponse(response); studyUids.Add(response.Dataset?.Get <string>(DicomTag.StudyInstanceUID)); }; client.AddRequest(request); client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET); // find all series from a study that previous was returned var studyUID = studyUids[3]; request = CreateSeriesRequestByStudyUID(studyUID); var serieUids = new List <string>(); request.OnResponseReceived += (req, response) => { DebugSerieResponse(response); serieUids.Add(response.Dataset?.Get <string>(DicomTag.SeriesInstanceUID)); }; client.AddRequest(request); client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET); // now get all the images of a serie with cGet in the same association var cGetRequest = CreateCGetBySeriesUID(studyUID, serieUids.First()); client.OnCStoreRequest += (DicomCStoreRequest req) => { SaveImage(req.Dataset); return(new DicomCStoreResponse(req, DicomStatus.Success)); }; // the client has to accept storage of the images. We know that the requested images are of SOP class Secondary capture, // so we add the Secondary capture to the additional presentation context // a more general approach would be to mace a cfind-request on image level and to read a list of distinct SOP classes of all // the images. these SOP classes shall be added here. client.AdditionalPresentationContexts.Add(DicomPresentationContext.GetScpRolePresentationContext( DicomUID.SecondaryCaptureImageStorage, DicomTransferSyntax.ImplicitVRBigEndian, DicomTransferSyntax.ExplicitVRBigEndian, DicomTransferSyntax.ExplicitVRLittleEndian)); client.AddRequest(cGetRequest); client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET); // if the images shall be sent to an existing storescp and this storescp is configured on the QR SCP then a CMove could be performed: // here we want to see how a error case looks like - because the test QR Server does not know the node FODICOMSCP var cMoveRequest = CreateCMoveBySeriesUID("FODICOMSCP", studyUID, serieUids.First()); bool?moveSuccessfully = null; cMoveRequest.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) => { if (response.Status.State == DicomState.Pending) { Console.WriteLine("Sending is in progress. please wait"); } else if (response.Status.State == DicomState.Success) { Console.WriteLine("Sending successfully finished"); moveSuccessfully = true; } else if (response.Status.State == DicomState.Failure) { Console.WriteLine("Error sending datasets: " + response.Status.Description); moveSuccessfully = false; } Console.WriteLine(response.Status); }; client.AddRequest(cMoveRequest); client.Send(QRServerHost, QRServerPort, false, AET, QRServerAET); if (moveSuccessfully.GetValueOrDefault(false)) { // images sent successfully from QR Server to the store scp } Console.ReadLine(); }