Inheritance: DicomDataset
Esempio n. 1
0
        public DicomNActionResponse OnNActionRequest(DicomNActionRequest request)
        {
            if (_filmSession == null)
            {
                this.Logger.Error("A basic film session does not exist for this association {0}", CallingAE);
                return new DicomNActionResponse(request, DicomStatus.InvalidObjectInstance);
            }

            lock (_synchRoot)
            {
                try
                {

                    var filmBoxList = new List<FilmBox>();
                    if (request.SOPClassUID == DicomUID.BasicFilmSessionSOPClass && request.ActionTypeID == 0x0001)
                    {
                        this.Logger.Info("Creating new print job for film session {0}", _filmSession.SOPInstanceUID.UID);
                        filmBoxList.AddRange(_filmSession.BasicFilmBoxes);
                    }
                    else if (request.SOPClassUID == DicomUID.BasicFilmBoxSOPClass && request.ActionTypeID == 0x0001)
                    {
                        this.Logger.Info("Creating new print job for film box {0}", request.SOPInstanceUID.UID);

                        var filmBox = _filmSession.FindFilmBox(request.SOPInstanceUID);
                        if (filmBox != null)
                        {
                            filmBoxList.Add(filmBox);
                        }
                        else
                        {
                            this.Logger.Error("Received N-ACTION request for invalid film box {0} from {1}", request.SOPInstanceUID.UID, CallingAE);
                            return new DicomNActionResponse(request, DicomStatus.NoSuchObjectInstance);
                        }
                    }
                    else
                    {
                        if (request.ActionTypeID != 0x0001)
                        {
                            this.Logger.Error("Received N-ACTION request for invalid action type {0} from {1}", request.ActionTypeID, CallingAE);
                            return new DicomNActionResponse(request, DicomStatus.NoSuchActionType);
                        }
                        else
                        {
                            this.Logger.Error("Received N-ACTION request for invalid SOP class {0} from {1}", request.SOPClassUID, CallingAE);
                            return new DicomNActionResponse(request, DicomStatus.NoSuchSOPClass);
                        }
                    }

                    var printJob = new PrintJob(null, Printer, CallingAE, this.Logger);
                    printJob.SendNEventReport = _sendEventReports;
                    printJob.StatusUpdate += OnPrintJobStatusUpdate;

                    printJob.Print(filmBoxList);

                    if (printJob.Error == null)
                    {

                        var result = new DicomDataset();
                        result.Add(new DicomSequence(new DicomTag(0x2100, 0x0500),
                            new DicomDataset(new DicomUniqueIdentifier(DicomTag.ReferencedSOPClassUID, DicomUID.PrintJobSOPClass)),
                            new DicomDataset(new DicomUniqueIdentifier(DicomTag.ReferencedSOPInstanceUID, printJob.SOPInstanceUID))));

                        var response = new DicomNActionResponse(request, DicomStatus.Success);
                        response.Command.Add(DicomTag.AffectedSOPInstanceUID, printJob.SOPInstanceUID);
                        response.Dataset = result;

                        return response;
                    }
                    else
                    {
                        throw printJob.Error;
                    }
                }
                catch (Exception ex)
                {
                    this.Logger.Error("Error occured during N-ACTION {0} for SOP class {1} and instance {2}",
                        request.ActionTypeID, request.SOPClassUID.UID, request.SOPInstanceUID.UID);
                    this.Logger.Error(ex.Message);
                    return new DicomNActionResponse(request, DicomStatus.ProcessingFailure);
                }
            }
        }
Esempio n. 2
0
        public DicomNActionResponse OnNActionRequest(DicomNActionRequest request)
        {
            if (_filmSession == null)
            {
                this.Logger.Error("A basic film session does not exist for this association {0}", CallingAE);
                return(new DicomNActionResponse(request, DicomStatus.InvalidObjectInstance));
            }

            lock (_synchRoot)
            {
                try
                {
                    var filmBoxList = new List <FilmBox>();
                    if (request.SOPClassUID == DicomUID.BasicFilmSessionSOPClass && request.ActionTypeID == 0x0001)
                    {
                        this.Logger.Info("Creating new print job for film session {0}", _filmSession.SOPInstanceUID.UID);
                        filmBoxList.AddRange(_filmSession.BasicFilmBoxes);
                    }
                    else if (request.SOPClassUID == DicomUID.BasicFilmBoxSOPClass && request.ActionTypeID == 0x0001)
                    {
                        this.Logger.Info("Creating new print job for film box {0}", request.SOPInstanceUID.UID);

                        var filmBox = _filmSession.FindFilmBox(request.SOPInstanceUID);
                        if (filmBox != null)
                        {
                            filmBoxList.Add(filmBox);
                        }
                        else
                        {
                            this.Logger.Error(
                                "Received N-ACTION request for invalid film box {0} from {1}",
                                request.SOPInstanceUID.UID,
                                CallingAE);
                            return(new DicomNActionResponse(request, DicomStatus.NoSuchObjectInstance));
                        }
                    }
                    else
                    {
                        if (request.ActionTypeID != 0x0001)
                        {
                            this.Logger.Error(
                                "Received N-ACTION request for invalid action type {0} from {1}",
                                request.ActionTypeID,
                                CallingAE);
                            return(new DicomNActionResponse(request, DicomStatus.NoSuchActionType));
                        }
                        else
                        {
                            this.Logger.Error(
                                "Received N-ACTION request for invalid SOP class {0} from {1}",
                                request.SOPClassUID,
                                CallingAE);
                            return(new DicomNActionResponse(request, DicomStatus.NoSuchSOPClass));
                        }
                    }

                    var printJob = new PrintJob(null, Printer, CallingAE, this.Logger);
                    printJob.SendNEventReport = _sendEventReports;
                    printJob.StatusUpdate    += OnPrintJobStatusUpdate;

                    printJob.Print(filmBoxList);

                    if (printJob.Error == null)
                    {
                        var result = new DicomDataset();
                        result.Add(
                            new DicomSequence(
                                new DicomTag(0x2100, 0x0500),
                                new DicomDataset(
                                    new DicomUniqueIdentifier(DicomTag.ReferencedSOPClassUID, DicomUID.PrintJobSOPClass)),
                                new DicomDataset(
                                    new DicomUniqueIdentifier(
                                        DicomTag.ReferencedSOPInstanceUID,
                                        printJob.SOPInstanceUID))));

                        var response = new DicomNActionResponse(request, DicomStatus.Success);
                        response.Command.Add(DicomTag.AffectedSOPInstanceUID, printJob.SOPInstanceUID);
                        response.Dataset = result;

                        return(response);
                    }
                    else
                    {
                        throw printJob.Error;
                    }
                }
                catch (Exception ex)
                {
                    this.Logger.Error(
                        "Error occured during N-ACTION {0} for SOP class {1} and instance {2}",
                        request.ActionTypeID,
                        request.SOPClassUID.UID,
                        request.SOPInstanceUID.UID);
                    this.Logger.Error(ex.Message);
                    return(new DicomNActionResponse(request, DicomStatus.ProcessingFailure));
                }
            }
        }