public void OnData(MessageType control, Message message) { // TODO put a lock on the pdu array // TODO interpret the commands Logging.Log("CMoveServiceSCU({0}).OnData", Reflection.GetName(typeof(SOPClass), this.SOPClassUId)); DataSet dicom = message.Dicom; if (MessageControl.IsCommand(control)) { ushort status = (ushort)dicom[t.Status].Value; bool last = !(status == 0xFF00); DataSetType present = (DataSetType)dicom[t.CommandDataSetType].Value; Logging.Log("<< {0} {1},{2}", Enum.Parse(typeof(CommandType), dicom[t.CommandField].Value.ToString()), (last) ? "LAST FRAGMENT" : "NOT-LAST FRAGMENT", present.ToString()); //dicom.Dump(); string text = String.Empty; if (dicom.Contains(t.NumberofRemainingSuboperations)) { text += String.Format("remaining={0} ", dicom[t.NumberofRemainingSuboperations].Value); results.Set(t.NumberofRemainingSuboperations, dicom[t.NumberofRemainingSuboperations].Value); } if (dicom.Contains(t.NumberofCompletedSuboperations)) { text += String.Format("completed={0} ", dicom[t.NumberofCompletedSuboperations].Value); results.Set(t.NumberofCompletedSuboperations, dicom[t.NumberofCompletedSuboperations].Value); } if (dicom.Contains(t.NumberofFailedSuboperations)) { text += String.Format("failed={0} ", dicom[t.NumberofFailedSuboperations].Value); results.Set(t.NumberofFailedSuboperations, dicom[t.NumberofFailedSuboperations].Value); } if (dicom.Contains(t.NumberofWarningSuboperations)) { text += String.Format("warning={0} ", dicom[t.NumberofWarningSuboperations].Value); results.Set(t.NumberofWarningSuboperations, dicom[t.NumberofWarningSuboperations].Value); } if (this.ImageMoved != null) { ImageMoved(this, new CMoveEventArgs(dicom)); } Logging.Log(text); if (last) { dicom.Remove(t.NumberofRemainingSuboperations); // TODO do we reset the state to Open here completeEvent.Set(); } } else { Logging.Log("<< P-DATA-TF"); } }
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); }
/// <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); }
private void Shift(string filename) { using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)) { EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet(); dicom.Read(stream); stream.Close(); // apply the shift to the image pixels ushort[] pixels = (ushort[])dicom[t.PixelData].Value; for (int n = 0; n < pixels.Length; n++) { pixels[n] = lut[pixels[n]]; } if (AddPixelValuesCheckBox.Checked) { pixels[0] = 0; pixels[1] = (ushort)(maxvalue - 1); } dicom.Set(t.BitsStored, N); dicom.Set(t.HighBit, N - 1); if (AddPixelValuesCheckBox.Checked) { pixels[0] = 0; pixels[1] = (ushort)(maxvalue - 1); dicom.Set(t.SmallestImagePixelValue, (ushort)0); dicom.Set(t.LargestImagePixelValue, (ushort)(maxvalue - 1)); } else { dicom.Set(t.SmallestImagePixelValue, (ushort)(maxvalue / 4)); dicom.Set(t.LargestImagePixelValue, maxvalue - maxvalue / 4); } dicom.Set(t.WindowWidth, maxvalue / 2); dicom.Set(t.WindowCenter, maxvalue / 2); FileInfo info = new FileInfo(filename); String text = filename.Replace(info.Extension, ""); text += "a" + info.Extension; dicom.Write(text); } }
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); }
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); } }