Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomResponse"/> class.
        /// </summary>
        /// <param name="request">
        /// The request initiating the response.
        /// </param>
        /// <param name="status">
        /// Response status.
        /// </param>
        protected DicomResponse(DicomRequest request, DicomStatus status)
        {
            PresentationContext = request.PresentationContext;

            Type             = (DicomCommandField)(0x8000 | (int)request.Type);
            SOPClassUID      = request.SOPClassUID;
            RequestMessageID = request.MessageID;
            Status           = status;
        }
 /// <summary>
 /// Add Extended Negotiation obtained from DICOM request.
 /// Note: The extended negotiation will affect all requests that share the same SOP class within an association.
 /// </summary>
 /// <param name="dicomRequest">Request from which extended negotiation info should be obtained.</param>
 public void AddFromRequest(DicomRequest dicomRequest)
 {
     if (dicomRequest is DicomCStoreRequest cStoreRequest)
     {
         if (cStoreRequest.ApplicationInfo != null || cStoreRequest.CommonServiceClassUid != null)
         {
             AddOrUpdate(cStoreRequest.SOPClassUID, cStoreRequest.ApplicationInfo,
                         cStoreRequest.CommonServiceClassUid, cStoreRequest.RelatedGeneralSopClasses?.ToArray());
         }
     }
     else if (dicomRequest.ApplicationInfo != null)
     {
         AddOrUpdate(dicomRequest.SOPClassUID, dicomRequest.ApplicationInfo);
     }
 }
        /// <summary>
        /// Add presentation contexts obtained from DICOM request.
        /// </summary>
        /// <param name="request">Request from which presentation context(s) should be obtained.</param>
        public void AddFromRequest(DicomRequest request)
        {
            if (request is DicomCStoreRequest cstore)
            {
                var pcs = _pc.Values
                          .Where(x => x.AbstractSyntax == request.SOPClassUID)
                          .Where(x => x.HasTransferSyntax(cstore.TransferSyntax));

                var pc = pcs.FirstOrDefault();
                if (pc == null)
                {
                    // add a presentation context for the original transfer syntax
                    if (cstore.TransferSyntax != null)
                    {
                        Add(cstore.SOPClassUID, cstore.TransferSyntax);
                    }

                    // then add another for additional transfersyntaxes, if provided by the user,
                    // and for the mandatory ImplicitVRLittleEndian, if the original file was not implicitLittleEndian
                    var tx = new List <DicomTransferSyntax>();
                    if (cstore.AdditionalTransferSyntaxes != null)
                    {
                        tx.AddRange(cstore.AdditionalTransferSyntaxes);
                    }
                    if (cstore.TransferSyntax != DicomTransferSyntax.ImplicitVRLittleEndian)
                    {
                        tx.Add(DicomTransferSyntax.ImplicitVRLittleEndian);
                    }

                    if (tx.Any())
                    {
                        Add(cstore.SOPClassUID, tx.ToArray());
                    }
                }
            }
            else
            {
                if (request.PresentationContext != null)
                {
                    var pc =
                        _pc.Values.FirstOrDefault(
                            x =>
                            x.AbstractSyntax == request.PresentationContext.AbstractSyntax &&
                            request.PresentationContext.GetTransferSyntaxes().All(y => x.GetTransferSyntaxes().Contains(y)));

                    if (pc == null)
                    {
                        var transferSyntaxes = request.PresentationContext.GetTransferSyntaxes().ToArray();
                        if (!transferSyntaxes.Any())
                        {
                            transferSyntaxes = new[] { DicomTransferSyntax.ImplicitVRLittleEndian };
                        }

                        Add(
                            request.PresentationContext.AbstractSyntax,
                            request.PresentationContext.UserRole,
                            request.PresentationContext.ProviderRole,
                            transferSyntaxes);
                    }
                }
                else
                {
                    foreach (var sopclass in MetaSopClasses.GetMetaSopClass(request.SOPClassUID))
                    {
                        var pc = _pc.Values.FirstOrDefault(x => x.AbstractSyntax == sopclass);
                        if (pc == null)
                        {
                            Add(sopclass, DicomTransferSyntax.ImplicitVRLittleEndian);
                        }
                    }
                }
            }
        }