Beispiel #1
0
 internal void AddPresentationContext(byte pcid, DicomUid abstractSyntax, TransferSyntax transferSyntax, DicomPresContextResult result)
 {
     _presContexts.Add(pcid, new DicomPresContext(pcid, SopClass.GetSopClass(abstractSyntax.UID), transferSyntax, result));
 }
Beispiel #2
0
        public void Read(RawPDU raw)
        {
            uint l = raw.Length;

            raw.ReadUInt16("Version");
            raw.SkipBytes("Reserved", 2);
            _assoc.CalledAE  = raw.ReadString("Called AE", 16);
            _assoc.CallingAE = raw.ReadString("Calling AE", 16);
            raw.SkipBytes("Reserved", 32);
            l -= 2 + 2 + 16 + 16 + 32;

            while (l > 0)
            {
                byte type = raw.ReadByte("Item-Type");
                raw.SkipBytes("Reserved", 1);
                ushort il = raw.ReadUInt16("Item-Length");

                l -= 4 + (uint)il;

                if (type == 0x10)
                {
                    // Application Context
                    raw.SkipBytes("Application Context", il);
                }
                else

                if (type == 0x20)
                {
                    // Presentation Context
                    byte id = raw.ReadByte("Presentation Context ID");
                    raw.SkipBytes("Reserved", 3);
                    il -= 4;

                    while (il > 0)
                    {
                        byte pt = raw.ReadByte("Presentation Context Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort pl = raw.ReadUInt16("Presentation Context Item-Length");
                        string sx = raw.ReadString("Presentation Context Syntax UID", pl);
                        if (pt == 0x30)
                        {
                            SopClass sopClass = SopClass.GetSopClass(sx);
                            if (sopClass == null)
                            {
                                sopClass = new SopClass("Private SOP Class", sx, false);
                            }
                            _assoc.AddPresentationContext(id, sopClass);
                        }
                        else if (pt == 0x40)
                        {
                            TransferSyntax transferSyntax = TransferSyntax.GetTransferSyntax(sx);
                            if (transferSyntax == null)
                            {
                                transferSyntax = new TransferSyntax("Private Syntax", sx, true, false, true, false, false, false);
                            }
                            _assoc.AddTransferSyntax(id, transferSyntax);
                        }
                        il -= (ushort)(4 + pl);
                    }
                }
                else

                if (type == 0x50)
                {
                    // User Information
                    while (il > 0)
                    {
                        byte ut = raw.ReadByte("User Information Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort ul = raw.ReadUInt16("User Information Item-Length");
                        il -= (ushort)(4 + ul);
                        if (ut == 0x51)
                        {
                            _assoc.RemoteMaximumPduLength = raw.ReadUInt32("Max PDU Length");
                        }
                        else if (ut == 0x52)
                        {
                            _assoc.ImplementationClass = new DicomUid(raw.ReadString("Implementation Class UID", ul), "Implementation Class UID", UidType.Unknown);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.RemoteMaxOperationsInvoked   = raw.ReadUInt16("Max Operations Invoked");
                            _assoc.RemoteMaxOperationsPerformed = raw.ReadUInt16("Max Operations Performed");
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.ImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x54)
                        {
                            raw.SkipBytes("SCU/SCP Role Selection", ul);

                            /*
                             * ushort rsul = raw.ReadUInt16();
                             * if ((rsul + 4) != ul) {
                             *  throw new DicomNetworkException("SCU/SCP role selection length (" + ul + " bytes) does not match uid length (" + rsul + " + 4 bytes)");
                             * }
                             * raw.ReadChars(rsul);	// Abstract Syntax
                             * raw.ReadByte();		// SCU role
                             * raw.ReadByte();		// SCP role
                             */
                        }
                        else
                        {
                            Platform.Log(LogLevel.Error, "Unhandled user item: 0x{0:x2} ({1} + 4 bytes)", ut, ul);
                            raw.SkipBytes("Unhandled User Item", ul);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        protected override IEnumerable <TransferSyntax> GetProposedTransferSyntaxesForUncompressedObjects(string sopClassUid)
        {
            List <TransferSyntax> syntaxes;

            if (!_sopClassUncompressedProposedTransferSyntaxes.TryGetValue(sopClassUid, out syntaxes))
            {
                syntaxes = new List <TransferSyntax>();

                // Check the ServerSopClass table to see if only implicit LE should be used when handling the sop class
                var configuration     = new PartitionSopClassConfiguration();
                var partitionSopClass = configuration.GetPartitionSopClass(_partition, sopClassUid);
                if (partitionSopClass != null)
                {
                    if (partitionSopClass.ImplicitOnly)
                    {
                        Platform.Log(LogLevel.Info, "System is being configured to send {0} using Implicit LE.", SopClass.GetSopClass(partitionSopClass.SopClassUid));
                    }
                    else
                    {
                        syntaxes.Add(TransferSyntax.ExplicitVrLittleEndian);
                    }

                    syntaxes.Add(TransferSyntax.ImplicitVrLittleEndian);
                }

                _sopClassUncompressedProposedTransferSyntaxes.Add(sopClassUid, syntaxes);
            }

            return(syntaxes);
        }
        /// <summary>
        /// Constructs a deserialization-only DICOM softcopy presentation state object.
        /// </summary>
        /// <param name="psSopClass">The SOP class of this type of softcopy presentation state.</param>
        /// <param name="dicomFile">The presentation state file.</param>
        protected DicomSoftcopyPresentationState(SopClass psSopClass, DicomFile dicomFile)
        {
            if (dicomFile.MediaStorageSopClassUid != psSopClass.Uid)
            {
                string message = string.Format("Expected: {0}; Found: {1}", psSopClass, SopClass.GetSopClass(dicomFile.MediaStorageSopClassUid));
                throw new ArgumentException("The specified DICOM file is not of a compatible SOP Class. " + message, "dicomFile");
            }

            _presentationSopClass = psSopClass;
            _dicomFile            = dicomFile;

            _serialized                    = true;
            _sourceAETitle                 = _dicomFile.SourceApplicationEntityTitle;
            _stationName                   = _dicomFile.DataSet[DicomTags.StationName].ToString();
            _institution                   = Institution.GetInstitution(_dicomFile);
            _manufacturer                  = _dicomFile.DataSet[DicomTags.Manufacturer].ToString();
            _manufacturersModelName        = _dicomFile.DataSet[DicomTags.ManufacturersModelName].ToString();
            _deviceSerialNumber            = _dicomFile.DataSet[DicomTags.DeviceSerialNumber].ToString();
            _softwareVersions              = _dicomFile.DataSet[DicomTags.SoftwareVersions].ToString();
            _presentationInstanceNumber    = _dicomFile.DataSet[DicomTags.InstanceNumber].GetInt32(0, 0);
            _presentationSopInstanceUid    = _dicomFile.DataSet[DicomTags.SopInstanceUid].ToString();
            _presentationSeriesDateTime    = DateTimeParser.ParseDateAndTime(_dicomFile.DataSet, 0, DicomTags.SeriesDate, DicomTags.SeriesTime);
            _presentationSeriesNumber      = GetNullableInt32(_dicomFile.DataSet[DicomTags.SeriesNumber], 0);
            _presentationSeriesInstanceUid = _dicomFile.DataSet[DicomTags.SeriesInstanceUid].ToString();
            _presentationLabel             = _dicomFile.DataSet[DicomTags.ContentLabel].ToString();
        }
        public InstanceXml(XmlNode instanceNode, DicomAttributeCollection baseCollection)
        {
            InstanceXmlDicomAttributeCollection thisCollection = new InstanceXmlDicomAttributeCollection();

            _collection = thisCollection;
            _collection.ValidateVrValues  = false;
            _collection.ValidateVrLengths = false;

            if (baseCollection != null)
            {
                AddExcludedTagsFromBase(baseCollection);

                _baseCollectionEnumerator = baseCollection.GetEnumerator();
                if (!_baseCollectionEnumerator.MoveNext())
                {
                    _baseCollectionEnumerator = null;
                }
            }

            if (!instanceNode.HasChildNodes)
            {
                return;
            }

            _instanceXmlEnumerator = instanceNode.ChildNodes.GetEnumerator();
            if (!_instanceXmlEnumerator.MoveNext())
            {
                _instanceXmlEnumerator = null;
            }

            if (instanceNode.Attributes["UID"] != null)
            {
                _sopInstanceUid = instanceNode.Attributes["UID"].Value;
            }

            if (instanceNode.Attributes["SourceAETitle"] != null)
            {
                _sourceAETitle = XmlUnescapeString(instanceNode.Attributes["SourceAETitle"].Value);
            }

            if (instanceNode.Attributes["SopClassUID"] != null)
            {
                _sopClass = SopClass.GetSopClass(instanceNode.Attributes["SopClassUID"].Value);
            }

            _transferSyntax = instanceNode.Attributes["TransferSyntaxUID"] != null
                                ? TransferSyntax.GetTransferSyntax(instanceNode.Attributes["TransferSyntaxUID"].Value)
                                : TransferSyntax.ExplicitVrLittleEndian;

            if (instanceNode.Attributes["SourceFileName"] != null)
            {
                _sourceFileName = instanceNode.Attributes["SourceFileName"].Value;
            }

            if (instanceNode.Attributes["FileSize"] != null)
            {
                long.TryParse(instanceNode.Attributes["FileSize"].Value, out _fileSize);
            }

            // This should never happen
            if (_sopClass == null)
            {
                _sopClass = SopClass.GetSopClass(Collection[DicomTags.SopClassUid].GetString(0, String.Empty));
            }
        }