Dimse.Scu (Dimse v0.8.7)

Copy Markdown View Source

SCU (Service Class User) client API.

Provides functions to establish outbound DICOM associations and execute DIMSE-C operations against remote SCPs. This is the client-side counterpart to the SCP behaviour defined in Dimse.Handler.

Usage

# Open an association
{:ok, assoc} = Dimse.Scu.open("192.168.1.10", 11112,
  calling_ae: "MY_SCU",
  called_ae: "REMOTE_SCP",
  abstract_syntaxes: ["1.2.840.10008.1.1"]  # Verification
)

# Execute operations
:ok = Dimse.Scu.Echo.verify(assoc)

# Release the association
:ok = Dimse.Scu.release(assoc)

Association Management

The SCU opens a TCP connection, sends an A-ASSOCIATE-RQ, waits for the A-ASSOCIATE-AC, and returns a Dimse.Association pid. All DIMSE operations are then sent as GenServer calls to this pid.

Error Handling

  • Connection refused → {:error, :econnrefused}
  • Association rejected → {:error, {:rejected, result, source, reason}}
  • Association establishment timeout → {:error, :timeout}
  • Unexpected abort → {:error, {:aborted, source, reason}}

Summary

Functions

Sends an A-ABORT to forcefully terminate the association.

Opens a DICOM association to a remote AE.

Sends an A-RELEASE-RQ and waits for A-RELEASE-RP.

Functions

abort(assoc)

@spec abort(pid()) :: :ok

Sends an A-ABORT to forcefully terminate the association.

open(host, port, opts \\ [])

@spec open(String.t(), pos_integer(), keyword()) :: {:ok, pid()} | {:error, term()}

Opens a DICOM association to a remote AE.

Returns {:ok, association_pid} or {:error, reason}.

Options

  • :calling_ae — local AE title (default: "DIMSE")
  • :called_ae — remote AE title (default: "ANY-SCP")
  • :abstract_syntaxes — list of SOP Class UIDs (default: Verification)
  • :transfer_syntaxes — list of Transfer Syntax UIDs
  • :max_pdu_length — max PDU length (default: 16_384)
  • :timeout — total association establishment timeout in ms (default: 30_000)
  • :tls — TLS options (keyword list). When present, the SCU connects via TLS instead of plain TCP. Accepts standard :ssl options:
    • :cacertfile — path to CA certificate for server verification
    • :verify — :verify_peer to verify the server certificate
    • :certfile — client certificate for mutual TLS
    • :keyfile — client private key for mutual TLS
  • :role_selections — list of Dimse.Pdu.RoleSelection structs proposing SCU/SCP roles for specific SOP classes (PS3.7 Annex D.3.3.4)
  • :user_identity — Dimse.Pdu.UserIdentity struct for SCU authentication (PS3.7 Annex D.3.3.7). The SCP handler's handle_authenticate/2 callback is called to accept or reject.

release(assoc, timeout \\ 30000)

@spec release(pid(), timeout()) :: :ok | {:error, term()}

Sends an A-RELEASE-RQ and waits for A-RELEASE-RP.