Dimse.Association (Dimse v0.8.7)

Copy Markdown View Source

GenServer managing a single DICOM association lifecycle.

Implements the DICOM Upper Layer state machine defined in PS3.8 Section 9.2. Each TCP connection spawns one Association process that owns the socket and manages the full lifecycle: negotiation, message exchange, and release/abort.

Modes

  • SCP mode: Started by Dimse.ConnectionHandler when a TCP connection is accepted. Waits for A-ASSOCIATE-RQ, negotiates, then handles DIMSE commands.
  • SCU mode: Started by Dimse.Scu.open/3 to connect to a remote SCP. Sends A-ASSOCIATE-RQ, waits for AC, then executes DIMSE operations.

Summary

Functions

Sends an A-ABORT and terminates the association.

Sends a C-CANCEL-RQ to cancel a pending C-FIND operation.

Returns a specification to start this module under a supervisor.

Sends a DIMSE command that expects multiple responses (C-FIND).

Sends a DIMSE command that expects multiple responses with interleaved C-STORE sub-operations (C-GET).

Returns the negotiated contexts for this association.

Returns the negotiated role selections for this association.

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

Sends a DIMSE command on the association and waits for the response.

Functions

abort(pid)

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

Sends an A-ABORT and terminates the association.

cancel(pid, message_id)

@spec cancel(pid(), integer()) :: :ok

Sends a C-CANCEL-RQ to cancel a pending C-FIND operation.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

find_request(pid, command_set, data, timeout \\ 30000)

@spec find_request(pid(), map(), binary(), timeout()) ::
  {:ok, map(), [binary()]} | {:error, term()}

Sends a DIMSE command that expects multiple responses (C-FIND).

Accumulates all Pending responses and returns the collected data sets when the final Success/Error response arrives.

Returns {:ok, final_command, [binary()]} or {:error, term()}.

get_request(pid, command_set, data, timeout \\ 30000)

@spec get_request(pid(), map(), binary(), timeout()) ::
  {:ok, map(), [binary()]} | {:error, term()}

Sends a DIMSE command that expects multiple responses with interleaved C-STORE sub-operations (C-GET).

The SCU enters get_mode, which auto-accepts incoming C-STORE-RQ messages (sent by the SCP as sub-operations) and accumulates their data sets. The final C-GET-RSP ends the retrieval.

Returns {:ok, final_command, [binary()]} or {:error, term()}.

negotiated_contexts(pid)

@spec negotiated_contexts(pid()) :: %{
  required(pos_integer()) => {String.t(), String.t()}
}

Returns the negotiated contexts for this association.

negotiated_roles(pid)

@spec negotiated_roles(pid()) :: %{required(String.t()) => {boolean(), boolean()}}

Returns the negotiated role selections for this association.

Keys are SOP Class UIDs; values are {scu_role, scp_role} boolean tuples. Returns an empty map when no role selections were negotiated.

release(pid, timeout \\ 30000)

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

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

request(pid, command_set, data \\ nil, timeout \\ 30000)

@spec request(pid(), map(), binary() | nil, timeout()) ::
  {:ok, map(), binary() | nil} | {:error, term()}

Sends a DIMSE command on the association and waits for the response.

Used by SCU modules (e.g., Dimse.Scu.Echo) to execute operations.