예제 #1
0
        public bool End(string uid, DataSet dicom)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClassUId);
            command.Add(t.CommandField, (ushort)CommandType.N_SET_RQ);
            command.Add(t.MessageId, (ushort)1);
            command.Add(t.Priority, (ushort)Priority.Medium);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
            command.Add(t.RequestedSOPInstanceUID, uid);

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            SendPdu("N-SET-RQ", pdu);
            SendDataPdu("N-SET-DATA", dicom);

            Dictionary <string, string> errors = new Dictionary <string, string>();

            errors.Add("0110", "Performed Procedure Step Object may no longer be updated");

            ProcessResponse("N-SET-RQ", 8000, errors, null);
            return(true);
        }
예제 #2
0
파일: CFind.cs 프로젝트: 1059444127/Dicom-4
        public RecordCollection CFind(DataSet dicom)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClassUId);
            command.Add(t.CommandField, (ushort)CommandType.C_FIND_RQ);
            command.Add(t.MessageId, (ushort)1);
            command.Add(t.Priority, (ushort)Priority.Medium);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            records = new RecordCollection();

            SendPdu("C-FIND-RQ", pdu);
            SendDataPdu("C-FIND-RQ DATA", dicom);

            Dictionary <string, string> errors = new Dictionary <string, string>();

            errors.Add("A700", "Refused: Out of Resources");
            errors.Add("A900", "Identifier does not match SOP Class");
            errors.Add("C", "Unable to process");

            ProcessResponse("C-FIND-RQ", 30000, errors, null);
            // it is figured that Status.Pending would not bee seen here

            return(records);
        }
예제 #3
0
        public bool Begin(string uid, DataSet dicom)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClassUId);
            command.Add(t.CommandField, (ushort)CommandType.N_CREATE_RQ);
            command.Add(t.MessageId, (ushort)1);
            command.Add(t.Priority, (ushort)Priority.Medium);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
            command.Add(t.AffectedSOPInstanceUID, uid);

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            SendPdu("N-CREATE-RQ", pdu);
            SendDataPdu("N-CREATE-DATA", dicom);

            ProcessResponse("N-CREATE-RQ", 8000, null, null);

            return(true);
        }
예제 #4
0
        private void NEventReport(MessageType control, DataSet dicom)
        {
            if (!MessageControl.IsCommand(control))
            {
                Logging.Log("<< N-EVENT-REPORT-DATA");

                if (StorageCommitReport != null)
                {
                    StorageCommitReport(this, new StorageCommitEventArgs(dicom, StorageCommitEventType.Report));
                }

                PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                DataSet fragment = new DataSet();
                fragment.Part10Header = false;

                fragment.Add(t.GroupLength(0), (uint)0);
                fragment.Add(t.AffectedSOPClassUID, SOPClass.StorageCommitmentPushModelSOPClass);
                fragment.Add(t.CommandField, (ushort)CommandType.N_EVENT_REPORT_RSP);
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);
                fragment.Add(t.Status, (ushort)0);
                fragment.Add(t.AffectedSOPInstanceUID, SOPClass.StorageCommitmentPushModelSOPInstance);
                fragment.Add(t.ActionTypeID, "1");

                pdv.Dicom = fragment;

                PresentationDataPdu request = new PresentationDataPdu(syntaxes[0]);
                request.Values.Add(pdv);

                SendPdu("N-EVENT-REPORT-RSP", request);
            }
        }
예제 #5
0
        internal bool SendPdu(ServiceClass service, MessageType type, string message, DataSet dicom)
        {
            bool result = true;

            if (State == State.Aborted)
            {
                throw AbortException;
            }
            if (service != null)
            {
                service.LastMessage = null;
            }

            dicom.Part10Header      = false;
            dicom.TransferSyntaxUID = MessageControl.IsCommand(type) ? Syntax.ImplicitVrLittleEndian : service.Syntaxes[0];

            MemoryStream memory = new MemoryStream();

            dicom.Write(memory);
            byte[] bytes = memory.ToArray();

            PresentationDataPdu   pdu = null;
            PresentationDataValue pdv = null;

            int index     = 0;
            int remaining = (int)memory.Length;
            int size      = this.packetSize - 128;

            State = (State != State.Closing) ? State.Waiting : State;
            while (remaining > this.packetSize && result)
            {
                pdu = new PresentationDataPdu(service.Syntaxes[0]);
                pdv = new PresentationDataValue(service.PresentationContextId, service.Syntaxes[0], type, bytes, index, size);
                pdu.Values.Add(pdv);

                result = Send(message, pdu);

                index     += size;
                remaining -= size;
            }

            if (result)
            {
                pdu = new PresentationDataPdu(service.Syntaxes[0]);
                pdv = new PresentationDataValue(service.PresentationContextId, service.Syntaxes[0], type + 2, bytes, index, remaining);
                pdu.Values.Add(pdv);
                result = Send(message, pdu);
            }

            return(result);
        }
예제 #6
0
        private void NCreate(MessageType control, DataSet dicom)
        {
            if (MessageControl.IsCommand(control))
            {
                Logging.Log("<< N-CREATE-RQ");

                AffectedSOPClassUID    = (string)dicom[t.AffectedSOPClassUID].Value;
                AffectedSOPInstanceUID = (string)dicom[t.AffectedSOPInstanceUID].Value;
                MessageId = (ushort)dicom[t.MessageId].Value;
            }
            else
            {
                Logging.Log("<< N-CREATE-DATA");

                if (AffectedSOPClassUID == SOPClass.PresentationLUTSOPClass)
                {
                    //PresentationLUT plut = new PresentationLUT();
                    //plut.Dicom = dicom;
                }
                else
                {
                    Logging.Log("N-SET: Unknown SOP class {0}", AffectedSOPClassUID);
                    return;
                }

                PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                DataSet fragment = new DataSet();

                fragment.Add(t.GroupLength(0), (uint)0);                                   //
                fragment.Add(t.AffectedSOPClassUID, AffectedSOPClassUID);                  //
                fragment.Add(t.CommandField, (ushort)CommandType.N_CREATE_RSP);            //
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent); //
                fragment.Add(t.Status, (ushort)0);
                fragment.Add(t.AffectedSOPInstanceUID, AffectedSOPInstanceUID);

                pdv.Dicom = fragment;

                PresentationDataPdu request = new PresentationDataPdu(syntaxes[0]);
                request.Values.Add(pdv);

                SendPdu("N-CREATE-RSP", request);
            }
        }
예제 #7
0
        private void NAction(MessageType control, DataSet dicom)
        {
            if (MessageControl.IsCommand(control))
            {
                Logging.Log("<< N-ACTION-RQ");

                RequestedSOPClassUID    = (string)dicom[t.RequestedSOPClassUID].Value;
                RequestedSOPInstanceUID = (string)dicom[t.RequestedSOPInstanceUID].Value;
                MessageId = (ushort)dicom[t.MessageId].Value;
            }
            else
            {
                Logging.Log("<< N-ACTION-DATA");

                if (StorageCommitRequest != null)
                {
                    var args = new StorageCommitEventArgs(dicom, StorageCommitEventType.Request)
                    {
                        CallingAeIpAddress = association.CallingAeIpAddress,
                        CallingAeTitle     = association.CallingAeTitle
                    };
                    StorageCommitRequest(this, args);
                }

                PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                DataSet fragment = new DataSet();
                fragment.Part10Header      = false;
                fragment.TransferSyntaxUID = Syntax.ImplicitVrLittleEndian;

                fragment.Add(t.GroupLength(0), (uint)0);                        //
                fragment.Add(t.CommandField, (ushort)CommandType.N_ACTION_RSP); //
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);
                fragment.Add(t.Status, (ushort)0);

                pdv.Dicom = fragment;

                PresentationDataPdu request = new PresentationDataPdu(syntaxes[0]);
                request.Values.Add(pdv);

                SendPdu("N-ACTION-RSP", request);
            }
        }
예제 #8
0
        /// <summary>
        /// Perform an N-ACTION Storage Commitment request over an established association
        /// </summary>
        /// <returns></returns>
        public bool Request(DataSet dicom)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.RequestedSOPClassUID, SOPClass.StorageCommitmentPushModelSOPClass);
            command.Add(t.CommandField, (ushort)CommandType.N_ACTION_RQ);
            command.Add(t.MessageId, (ushort)1);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
            command.Add(t.RequestedSOPInstanceUID, SOPClass.StorageCommitmentPushModelSOPInstance);
            command.Add(t.ActionTypeID, "1");

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            SendPdu("N-ACTION-RQ", pdu);

            DataSet data = new DataSet();

            data.Part10Header       = false;
            dicom.TransferSyntaxUID = Syntax.ImplicitVrLittleEndian;

            data.Set(t.SOPClassUID, SOPClass.StorageCommitmentPushModelSOPClass);
            data.Set(t.SOPInstanceUID, Element.UidRoot);
            data.Set(t.TransactionUID, Element.NewUid());

            Sequence sequence = new Sequence(t.ReferencedSOPSequence);

            data.Add(sequence);
            Elements item = sequence.NewItem();

            item.Set(t.ReferencedSOPClassUID, (string)dicom[t.SOPClassUID].Value);
            item.Set(t.ReferencedSOPInstanceUID, (string)dicom[t.SOPInstanceUID].Value);

            SendDataPdu("N-ACTION-RQ DATA", data);

            ProcessResponse("N-ACTION-RQ (Storage Commit)", 8000, null, null);
            return(true);
        }
예제 #9
0
        internal bool SendDataPdu(ServiceClass service, string message, DataSet dicom)
        {
            bool result = true;

            dicom.Part10Header      = false;
            dicom.TransferSyntaxUID = service.Syntaxes[0];

            MemoryStream memory = new MemoryStream();

            dicom.Write(memory);
            byte[] bytes = memory.ToArray();

            PresentationDataPdu   pdu = null;
            PresentationDataValue pdv = null;

            int index     = 0;
            int remaining = (int)memory.Length;
            int size      = this.packetSize - 128;

            while (remaining > this.packetSize && result)
            {
                pdu = new PresentationDataPdu(service.Syntaxes[0]);
                pdv = new PresentationDataValue(service.PresentationContextId, service.Syntaxes[0], MessageType.DataSet, bytes, index, size);
                pdu.Values.Add(pdv);

                result = SendPdu(service, message, pdu);

                index     += size;
                remaining -= size;
            }

            if (result)
            {
                pdu = new PresentationDataPdu(service.Syntaxes[0]);
                pdv = new PresentationDataValue(service.PresentationContextId, service.Syntaxes[0], MessageType.LastDataSet, bytes, index, remaining);
                pdu.Values.Add(pdv);
                result = SendPdu(service, message, pdu);
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Perform an N-EVENT-REPORT Storage Commitment report over an established association with the ScpScuRole of Scp.
        /// </summary>
        /// <returns></returns>
        public bool Report(DataSet dicom)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            // for storage commit, ScpScuRoleSelectionItem is mandatory and N_EVENT_REPORT_RQ generator is the SCP
            // perhaps move Report to StorageCommitServiceSCU, and move responses in here
            Role = Role.Scp;

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClass.StorageCommitmentPushModelSOPClass);
            command.Add(t.CommandField, (ushort)CommandType.N_EVENT_REPORT_RQ);
            command.Add(t.MessageId, (ushort)1);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
            command.Add(t.AffectedSOPInstanceUID, SOPClass.StorageCommitmentPushModelSOPInstance);
            command.Add(t.ActionTypeID, "1");

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            SendPdu("N_EVENT_REPORT_RQ", pdu);

            if (dicom.Contains(t.SOPClassUID))
            {
                dicom.Remove(t.SOPClassUID);
            }
            if (dicom.Contains(t.SOPInstanceUID))
            {
                dicom.Remove(t.SOPInstanceUID);
            }

            SendDataPdu("N_EVENT_REPORT_RQ DATA", dicom);

            ProcessResponse("N_EVENT_REPORT_RQ (Storage Commit)", 8000, null, null);
            return(true);
        }
예제 #11
0
        public void OnData(MessageType control, Message message)
        {
            Logging.Log("MppsServiceSCP.OnData");

            DataSet dicom = message.Dicom;

            if (MessageControl.IsCommand(control))
            {
                command        = (ushort)dicom[t.CommandField].Value;
                SOPInstanceUID = (command == (ushort)CommandType.N_CREATE_RQ) ?
                                 (string)dicom[t.AffectedSOPInstanceUID].Value :
                                 (string)dicom[t.RequestedSOPInstanceUID].Value;
                MessageId = (ushort)dicom[t.MessageId].Value;
            }
            else
            {
                dicom.Add(t.GroupLength(2), (ulong)0);
                dicom.Add(t.FileMetaInformationVersion, new byte[] { 0, 1 });
                dicom.Add(t.MediaStorageSOPClassUID, this.SOPClassUId);
                dicom.Add(t.MediaStorageSOPInstanceUID, this.SOPInstanceUID);
                dicom.Add(t.TransferSyntaxUID, this.syntaxes[0]);
                dicom.Add(t.ImplementationClassUID, "1.2.3.4");
                dicom.Add(t.ImplementationVersionName, "not specified");

                dicom.Part10Header      = true;
                dicom.TransferSyntaxUID = syntaxes[0];

                MppsEventArgs mpps = new MppsEventArgs(SOPInstanceUID, command, dicom);
                mpps.CallingAeTitle     = association.CallingAeTitle;
                mpps.CallingAeIpAddress = association.CallingAeIpAddress;
                if (command == (ushort)CommandType.N_CREATE_RQ && MppsCreate != null)
                {
                    MppsCreate(this, mpps);
                }
                else if (command == (ushort)CommandType.N_SET_RQ && MppsSet != null)
                {
                    MppsSet(this, mpps);
                }
                else
                {
                    string uid = (string)dicom[t.SOPInstanceUID].Value;
                    dicom.Write(uid + ".dcm");
                }

                PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                DataSet fragment = new DataSet();

                fragment.Add(t.GroupLength(0), (uint)144);                                 //
                fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);                     //
                fragment.Add(t.CommandField, (ushort)command | 0x8000);                    //
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent); //
                fragment.Add(t.Status, (int)((mpps.Cancel) ? 0xC000 : 0));
                fragment.Add(t.AffectedSOPInstanceUID, SOPInstanceUID);

                pdv.Dicom = fragment;

                PresentationDataPdu request = new PresentationDataPdu(syntaxes[0]);
                request.Values.Add(pdv);

                SendPdu((command == (ushort)CommandType.N_CREATE_RQ) ? "N-CREATE-RSP" : ">> N-SET-RSP", request);
            }
        }
예제 #12
0
        private DataSet Execute(CommandType type, string destination, Element element)
        {
            PresentationDataPdu   pdu = new PresentationDataPdu(Syntaxes[0]);
            PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClassUId);
            command.Add(t.CommandField, (ushort)type);
            command.Add(t.MessageId, (ushort)1);
            if (destination != null)
            {
                command.Add(t.MoveDestination, destination);
            }
            command.Add(t.Priority, (ushort)Priority.Medium);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);

            pdv.Dicom = command;
            pdu.Values.Add(pdv);

            results = new DataSet();

            SendPdu(type.ToString(), pdu);

            DataSet dicom = new DataSet();

            dicom.Part10Header = false;

            if (element.Tag.Equals(t.PatientID))
            {
                dicom.Set(t.QueryRetrieveLevel, "PATIENT");
            }
            else if (element.Tag.Equals(t.StudyInstanceUID))
            {
                dicom.Set(t.QueryRetrieveLevel, "STUDY");
            }
            else if (element.Tag.Equals(t.SeriesInstanceUID))
            {
                dicom.Set(t.QueryRetrieveLevel, "SERIES");
            }
            else if (element.Tag.Equals(t.SOPInstanceUID))
            {
                dicom.Set(t.QueryRetrieveLevel, "IMAGE");
            }
            else
            {
                throw new Exception("Unsupported Unique Key Attribute.");
            }
            dicom.Add(element);

            SendDataPdu(type.ToString() + " DATA", dicom);

            Dictionary <string, string> errors = new Dictionary <string, string>();

            errors.Add("A701", "Refused: Out of Resources ?Unable to calculate number of matches");
            errors.Add("A702", "Refused: Out of Resources ?Unable to perform sub-operations");
            errors.Add("A801", "Refused: Move Destination unknown");
            errors.Add("A900", "Identifier does not match SOP Class");

            Dictionary <string, string> warnings = new Dictionary <string, string>();

            warnings.Add("B000", "Sub-operations Complete ?One or more Failures");

            ProcessResponse(type.ToString(), 30000, errors, warnings);

            return(results);
        }
예제 #13
0
        public void OnData(MessageType control, Message message)
        {
            Logging.Log("\nCMoveServiceSCP({0}).OnData", Reflection.GetName(typeof(SOPClass), this.SOPClassUId));

            DataSet dicom = message.Dicom;

            if (MessageControl.IsCommand(control))
            {
                MessageId = (ushort)dicom[t.MessageId].Value;
                // TODO accomodate trailing spaces
                destination = ((string)dicom[t.MoveDestination].Value).TrimEnd();
            }
            else
            {
                PresentationDataValue pdv;
                PresentationDataPdu   command;
                DataSet fragment = new DataSet();

                if (!this.Association.Hosts.ContainsKey(destination))
                {
                    pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                    fragment.Part10Header      = false;
                    fragment.TransferSyntaxUID = syntaxes[0];

                    fragment.Add(t.GroupLength(0), (uint)0);
                    fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);
                    fragment.Add(t.CommandField, (ushort)CommandType.C_MOVE_RSP);
                    fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                    fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);
                    fragment.Add(t.Status, (ushort)0xA801);

                    pdv.Dicom = fragment;

                    command = new PresentationDataPdu(syntaxes[0]);
                    command.Values.Add(pdv);

                    SendPdu("C-MOVE-RSP", command);
                    return;
                }

                ApplicationEntity host = this.Association.Hosts[destination];

                List <string> imagelist = Query(dicom);

                int failed = 0;
                for (int n = 0; n < imagelist.Count; n++)
                {
                    if (!SendImage(host, imagelist[n]))
                    {
                        failed++;
                    }

                    pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                    fragment = new DataSet();

                    fragment.Part10Header      = false;
                    fragment.TransferSyntaxUID = syntaxes[0];

                    fragment.Add(t.GroupLength(0), (uint)0);
                    fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);
                    fragment.Add(t.CommandField, (ushort)CommandType.C_MOVE_RSP);
                    fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                    fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
                    fragment.Add(t.Status, (ushort)0xff00);

                    fragment.Set(t.NumberofRemainingSuboperations, imagelist.Count - n - 1);
                    fragment.Set(t.NumberofCompletedSuboperations, n + 1 - failed);
                    fragment.Set(t.NumberofFailedSuboperations, failed);
                    fragment.Set(t.NumberofWarningSuboperations, 0);

                    pdv.Dicom = fragment;

                    command = new PresentationDataPdu(syntaxes[0]);
                    command.Values.Add(pdv);

                    SendPdu("C-MOVE-RSP", command);
                }

                int status = (failed > 0) ? 0xB000 : 0x0000;

                pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                fragment = new DataSet();

                fragment.Part10Header      = false;
                fragment.TransferSyntaxUID = syntaxes[0];

                fragment.Add(t.GroupLength(0), (uint)0);
                fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);
                fragment.Add(t.CommandField, (ushort)CommandType.C_FIND_RSP);
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);
                fragment.Add(t.Status, (ushort)status);

                fragment.Set(t.NumberofCompletedSuboperations, imagelist.Count);
                fragment.Set(t.NumberofFailedSuboperations, 0);
                fragment.Set(t.NumberofWarningSuboperations, 0);

                pdv.Dicom = fragment;

                command = new PresentationDataPdu(syntaxes[0]);
                command.Values.Add(pdv);

                SendPdu("C-MOVE-RSP", command);
            }
        }
예제 #14
0
파일: CFind.cs 프로젝트: 1059444127/Dicom-4
        public void OnData(MessageType control, Message message)
        {
            Logging.Log("\nCFindServiceSCP({0}).OnData", Reflection.GetName(typeof(SOPClass), this.SOPClassUId));

            DataSet dicom = message.Dicom;

            if (MessageControl.IsCommand(control))
            {
                MessageId = (ushort)dicom[t.MessageId].Value;
            }
            else
            {
                PresentationDataValue pdv;
                PresentationDataPdu   command;

                DataSet fragment = new DataSet();


                RecordCollection worklist;
                if (Query != null)
                {
                    QueryEventArgs args = new QueryEventArgs(dicom);
                    Query(this, args);
                    if (args.Cancel)
                    {
                        association.Abort();
                        return;
                    }
                    worklist = args.Records;
                }
                else
                {
                    worklist = InternalQuery(dicom.Elements);
                }

                foreach (Elements procedure in worklist)
                {
                    fragment = new DataSet();
                    pdv      = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                    fragment.Add(t.GroupLength(0), (uint)0);
                    fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);
                    fragment.Add(t.CommandField, (ushort)CommandType.C_FIND_RSP);
                    fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                    fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
                    fragment.Add(t.Status, (ushort)0xff00);

                    pdv.Dicom = fragment;

                    command = new PresentationDataPdu(syntaxes[0]);
                    command.Values.Add(pdv);

                    PresentationDataValue response = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastDataSet);

                    DataSet temp = new DataSet();
                    temp.Elements = procedure;

                    temp.Part10Header      = false;
                    temp.TransferSyntaxUID = syntaxes[0];

                    response.Dicom = temp;
                    command.Values.Add(response);

                    Logging.Log(command.Dump());
                    SendPdu("C-FIND-RSP", command);
                }

                pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand);

                fragment = new DataSet();

                fragment.Add(t.GroupLength(0), (uint)0);
                fragment.Add(t.AffectedSOPClassUID, this.SOPClassUId);
                fragment.Add(t.CommandField, (ushort)CommandType.C_FIND_RSP);
                fragment.Add(t.MessageIdBeingRespondedTo, MessageId);
                fragment.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);
                fragment.Add(t.Status, (ushort)0x0000);

                pdv.Dicom = fragment;

                command = new PresentationDataPdu(syntaxes[0]);
                command.Values.Add(pdv);

                Logging.Log(command.Dump());
                SendPdu("C-FIND-RSP", command);
            }
        }