예제 #1
0
        private bool SendStorageCommit(string path, ApplicationEntity host, int status)
        {
            bool result = true;

            try
            {
                StorageCommitServiceSCU commit = new StorageCommitServiceSCU();
                commit.Syntaxes.Add(Syntax.ImplicitVrLittleEndian);
                commit.Role = Role.Scp;

                Association association = new Association();
                association.AddService(commit);

                if (association.Open(host))
                {
                    if (commit.Active)
                    {
                        try
                        {
                            EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                            dicom.Read(path);

                            if (status != 0)
                            {
                                dicom.Add(t.RetrieveAETitle, host.Title);
                                // add the FailedSOPSequence
                                Sequence sequence = new Sequence(t.FailedSOPSequence);
                                dicom.Add(sequence);
                                Elements item = sequence.NewItem();
                                item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPClassUID]);
                                item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPInstanceUID]);
                                item.Add(t.FailureReason, 274);
                                // remove the ReferencedSOPSequence
                                dicom.Remove(t.ReferencedSOPSequence);
                            }

                            result = commit.Report(dicom);
                            Debug.WriteLine("commit done!");
                        }
                        catch (Exception ex)
                        {
                            result = false;
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    result = false;
                    Debug.WriteLine("\ncan't Open.");
                }
                association.Close();
            }
            catch
            {
            }
            RefreshControls();
            return(result);
        }
예제 #2
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);
            }
        }
예제 #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
        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);
        }
예제 #5
0
        /// <summary>
        /// Perform a C-STORE request over an established association
        /// </summary>
        /// <returns></returns>
        public bool Store(DataSet dicom)
        {
            DataSet command = new DataSet();

            command.Add(t.GroupLength(0), (uint)0);
            command.Add(t.AffectedSOPClassUID, SOPClassUId);
            command.Add(t.CommandField, (ushort)CommandType.C_STORE_RQ);
            command.Add(t.MessageId, 1);
            command.Add(t.Priority, (ushort)Priority.Medium);
            command.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetPresent);
            string uid = (string)dicom[t.SOPInstanceUID].Value;

            command.Add(t.AffectedSOPInstanceUID, uid);

            SendCommand("C-STORE-RQ", command);
            SendData("C-STORE-RQ DATA", dicom);

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

            errors.Add("A7", "Refused: Out of Resources");
            errors.Add("A9", "Error: Data Set does not match SOP Class");
            errors.Add("C", "Error: Cannot understand");

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

            warnings.Add("B000", "Warning Coercion of Data Elements");
            warnings.Add("B007", "Data Set does not match SOP Class");
            warnings.Add("B006", "Elements Discarded");

            ProcessResponse("C-STORE-RQ", 30000, errors, warnings);
            return(true);
        }
예제 #6
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);
            }
        }
예제 #7
0
        public static DataSet Build(string iod)
        {
            Dictionary <string, Tag2> tags = GetTags(iod);

            DataSet elements = new DataSet();

            foreach (Tag2 tag in tags.Values)
            {
                elements.Add(tag.ToString(), null);
            }
            return(elements);
        }
예제 #8
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);
        }
예제 #9
0
        public unsafe static DataSet GetImage(Bitmap bitmap)
        {
            DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();

            int width  = (ushort)bitmap.Width;
            int height = (ushort)bitmap.Height;

            dicom.Add(t.Columns, width);
            dicom.Add(t.Rows, height);
            dicom.Add(t.PhotometricInterpretation, "MONOCHROME2");
            dicom.Add(t.BitsAllocated, 16);
            dicom.Add(t.BitsStored, 12);

            short[] pixels = new short[width * height];
            System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            PixelData *BitmapPtr = (PixelData *)data.Scan0.ToPointer();
            int        spacing   = data.Stride;
            int        n         = 0;

            for (int r = 0; r < height; r++)
            {
                for (int c = 0; c < width; c++)
                {
                    PixelData *pRGBPixel = (PixelData *)(BitmapPtr + c);
                    pixels[n++] = (short)((int)(pRGBPixel->blue * 0.11 + pRGBPixel->red * 0.3 + pRGBPixel->green * 0.59) << 4);
                }
                BitmapPtr = (PixelData *)((byte *)BitmapPtr + spacing);
            }
            dicom.Add(t.PixelData, pixels);

            return(dicom);
        }
예제 #10
0
        public StructuredReport(CodedEntry name)
        {
            dataset = new DataSet();

            dataset.Set(t.ValueType, ValueType.Container);

            Sequence sequence = (Sequence)dataset.Add(new Sequence(t.ConceptNameCodeSequence));

            sequence.AddItem(name.Elements);

            dataset.Set(t.ContinuityOfContent, "SEPARATE");

            root = Node.Factory(dataset.Elements);
        }
예제 #11
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);
            }
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
0
        private void NewTagToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                TreeNode node = this.TreeView.SelectedNode;
                if (node != null)
                {
                    if (node.Name.Contains(" tag") && node.Text.Contains(" SQ "))
                    {
                        Sequence sequence = dicom[Key(node.Name)] as Sequence;
                        sequence.NewItem();

                        TreeNode child = node.Nodes.Add(sequence.GetPath() + " item" + node.Nodes.Count.ToString(), "Item");
                        TreeView.SelectedNode = child;
                    }
                    else
                    {
                        NewTagForm   dialog = new NewTagForm();
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            if (node.Name.Contains(" item") || node.Name.Contains("root"))
                            {
                                TreeNode child = null;
                                foreach (string selection in dialog.Selection)
                                {
                                    Tag tag = EK.Capture.Dicom.DicomToolKit.Tag.Parse(selection);
                                    if ((tag.IsPrivate && !tag.IsPrivateCreator) || (tag.IsStandard && !Dictionary.Contains(selection)))
                                    {
                                        VRForm form = new VRForm();
                                        result = form.ShowDialog();
                                        if (result == DialogResult.OK)
                                        {
                                            // automatically add the Private Creator if not found
                                            if (tag.IsPrivate)
                                            {
                                                // e.g., (0029,1000)
                                                string creator = selection.Substring(0, 6) + "00" + selection.Substring(6, 2) + ")";
                                                if (!dicom.Contains(creator))
                                                {
                                                    dicom.Add(creator, null);

                                                    Element temp = dicom[Key(node.Name) + creator];
                                                    int     i    = FindInsertionIndex(creator, node.Nodes);
                                                    if (i <= node.Nodes.Count || node.Nodes.Count == 0)
                                                    {
                                                        child = node.Nodes.Insert(i, temp.GetPath() + " tag", Title(temp));
                                                        child.Nodes.Add(temp.GetPath() + " value", String.Empty);
                                                        child.Expand();
                                                    }
                                                }
                                            }/**/
                                            dicom.Add(selection, form.VR, null);
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    else if (node.Name.Contains("root"))
                                    {
                                        dicom.Add(selection, null);
                                    }
                                    else
                                    {
                                        Sequence sequence = dicom[Key(node.Name)] as Sequence;
                                        int      item     = 0;
                                        sequence.Items[item].Add(selection, null);
                                    }
                                    Element element = dicom[Key(node.Name) + selection];

                                    int n = FindInsertionIndex(selection, node.Nodes);

                                    if (n <= node.Nodes.Count || node.Nodes.Count == 0)
                                    {
                                        child = node.Nodes.Insert(n, element.GetPath() + " tag", Title(element));
                                        if (element.VR != "SQ")
                                        {
                                            child = child.Nodes.Add(element.GetPath() + " value", String.Empty);
                                        }
                                    }
                                }
                                if (child != null)
                                {
                                    TreeView.SelectedNode = child;
                                    TreeView.SelectedNode.BeginEdit();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Logging.Log(ex));
            }
        }
예제 #15
0
        public void OnData(MessageType control, Message message)
        {
            Logging.Log("StorageServiceSCP.OnData");

            DataSet dicom = message.Dicom;

            if (MessageControl.IsCommand(control))
            {
                AffectedSOPInstanceUID = (string)dicom[t.AffectedSOPInstanceUID].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.AffectedSOPInstanceUID);
                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];

                int status = 0x0000;
                ImageStoredEventArgs image = new ImageStoredEventArgs(dicom);
                image.CallingAeTitle     = association.CallingAeTitle;
                image.CallingAeIpAddress = association.CallingAeIpAddress;

                if (ImageStored != null)
                {
                    try
                    {
                        ImageStored(this, image);
                        if (image.Cancel)
                        {
                            status = 0xC000;
                        }
                    }
                    catch (Exception ex)
                    {
                        status = 0xA700;
                        Logging.Log(LogLevel.Error, String.Format("Exception caught from ImageStored, {0}", ex.Message));
                    }
                }

#if DEBUG
                else
                {
                    string uid = (string)dicom[t.SOPInstanceUID].Value;
                    dicom.Write(uid + ".dcm");
                }
#endif

                DataSet response = new DataSet();

                response.Add(t.GroupLength(0), (uint)144);                                 // the number is calculated later anyway
                response.Add(t.AffectedSOPClassUID, this.SOPClassUId);                     //
                response.Add(t.CommandField, (ushort)CommandType.C_STORE_RSP);             //
                response.Add(t.MessageIdBeingRespondedTo, MessageId);
                response.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent); //
                response.Add(t.Status, status);
                response.Add(t.AffectedSOPInstanceUID, AffectedSOPInstanceUID);

                SendCommand("C-STORE-RSP", response);
            }
        }
예제 #16
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);
            }
        }
예제 #17
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);
        }
예제 #18
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);
            }
        }
예제 #19
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);
            }
        }