Search code examples
c#dicomfo-dicom

Is there a built in way to reject certain SOP Classes on a fo-DICOM server?


I want to run a fo-DICOM server that returns the DicomStatus SOPClassNotSupported if for instance I try doing a CStoreRequest on it with the SOP class for Encapsulated PDF documents. Can I define the SOP classes to reject beforehand instead of having to explicitly reject it in the OnCStoreRequest() method?

What I have so far:

public DicomCStoreResponse OnCStoreRequest(DicomCStoreRequest request)
{
   DicomStatus dicomStatus = DicomStatus.Success;
   var SOPClassUID = request.Dataset.GetSingleValue<DicomUID>(DicomTag.SOPClassUID);
   if(SOPClassUID == DicomUID.EncapsulatedPDFStorage) {
      dicomStatus = DicomStatus.SOPClassNotSupported;
   }
   return new DicomCStoreResponse(request, dicomStatus);
}

The code above works, but I'd do it differently if there is some official/built in way to define which SOP classes to reject.


Solution

  • You can control this behavior on ASSOCIATION level. Validate the Abstract Syntax proposed before sending ASSOCIATE_ACCEPT.

    public Task OnReceiveAssociationRequestAsync(DicomAssociation association)
    {
        foreach(var pc in association.PresentationContexts)
        {
            if(pc.AbstractSyntax == DicomUID.EncapsulatedPDFStorage)
                pc.SetResult(DicomPresentationContextResult.RejectAbstractSyntaxNotSupported);
            else
            {
                pc.AcceptTransferSyntaxes(AcceptedImageTransferSyntaxes);
                pc.SetResult(DicomPresentationContextResult.Accept);
            }
        }
    
        return SendAssociationAcceptAsync(association);
    }
    

    The DicomAssociation association is ASSOCIATION_REQUEST you received. The association.PresentationContexts holds all proposed Presentation Contexts in received association. You enumerate through each of it. Each proposed Presentation Context contain Abstract Syntax and list of proposed Transfer Syntaxes. You can loop through list of transfer syntaxes and set the one you prefer; as your question is not about it, I skipped that part in code.

    If you can accept (receive/process) the pair of Abstract Syntax and Transfer Syntax that is proposed, you accept that specific Presentation Context by setting its result. If you don't, set the result accordingly with reason.

    Finally, send the ASSOCIATE_ACCEPT (or reject...).