Skip to Content
go-dicom(3)

Workflow services: MPPS, UPS and storage commitment

The services built on the N-DIMSE messages: Modality Performed Procedure Step, Unified Procedure Step and Storage Commitment, each as an SCU (in Go and with mppsscu, upsscu and commitscu) and as an SCP. It assumes Writing an SCU and Building an SCP.

Overview

ServiceSOP classMessagesSCUSCP
MPPS1.2.840.10008.3.1.2.3.3N‑CREATE, N‑SETSCU.CreateMPPS, SetMPPS; mppsscuMPPSHandler
UPS Push, Pull, Watch, Event1.2.840.10008.5.1.4.34.6.{1,3,2,4}N‑CREATE, N‑SET, N‑GET, N‑ACTION, N‑EVENT‑REPORTSCU.NCreate, ChangeUPSState, SubscribeUPS, ...; upsscuUPSHandler
Storage Commitment Push Model1.2.840.10008.1.20.1N‑ACTION, then N‑EVENT‑REPORTSCU.RequestStorageCommitment, ReceiveStorageCommitmentResult; commitscuStorageCommitmentProvider, StorageCommitmentHandler

The N-service calls return the response with its Status and Detail (StatusDetail: Error Comment, Error ID, Offending Element, Attribute Identifier List); the error is only for an exchange that failed. Check the status yourself.

The examples come from one program, compiled and run, that serves MPPS on port 41010, UPS on 41011 and storage commitment on 41012, and from the commands run against it.

Modality Performed Procedure Step

A modality tells the department what it performed: it creates a step when it starts, and sets it to COMPLETED or DISCONTINUED when it ends.

MPPSHandler enforces that state machine (PS3.4 F.7.2) before its store or callbacks see a request:

RequestAnswer
N‑CREATE without Performed Procedure Step Status0120 Missing attribute
N‑CREATE with a status other than IN PROGRESS0106 Invalid attribute value
N‑CREATE for a UID already held0111 Duplicate SOP Instance
N‑CREATE with no SOP Instance UIDa UID is assigned and returned
N‑SET to a UID not held0112 No such SOP Instance
N‑SET to a step COMPLETED or DISCONTINUED0110 Processing failure, Error ID A710
mpps, err := network.StartServer(ctx, network.SCPConfig{
	AETitle:     "MPPS",
	Port:        41010,
	BindAddress: "127.0.0.1",
}, &network.MPPSHandler{
	OnCreate: func(ctx context.Context, inst *network.MPPSInstance) uint16 {
		log.Printf("step %s started", inst.SOPInstanceUID)
		return network.StatusSuccess
	},
	OnSet: func(ctx context.Context, inst *network.MPPSInstance, mod *dataset.Dataset) uint16 {
		log.Printf("step %s is now %s", inst.SOPInstanceUID, inst.Status)
		return network.StatusSuccess
	},
})

Store is an MPPSStore; left nil it is an MPPSMemoryStore. On the default abstract syntaxes an SCP accepts the MPPS SOP class when its handler is, or embeds, an MPPSHandler.

As an SCU:

scu := network.NewSCU(network.SCUConfig{CallingAE: "MODALITY", CalledAE: "MPPS", Address: "127.0.0.1:41010"})
if err := scu.Associate(ctx, network.ModalityPerformedProcedurePresentationContexts()); err != nil {
	return err
}
defer scu.Release(ctx)

step := dataset.NewDataset()
if err := step.AddByKeyword("PerformedProcedureStepStatus", dataelem.CS, []byte("IN PROGRESS")); err != nil {
	return err
}
created, err := scu.CreateMPPS(ctx, "", step) // "": the SCP assigns the UID
if err != nil {
	return err
}
if !network.IsSuccess(created.Status) {
	return fmt.Errorf("N-CREATE refused: %s %s", network.FormatStatus(created.Status), created.Detail.ErrorComment)
}
uid := created.AffectedSOPInstance

and later scu.SetMPPS(ctx, uid, done) with a data set whose Performed Procedure Step Status is COMPLETED. A second N-SET after that came back 0x0110 (Failure), error ID A710. CreateMPPS refuses, before sending, a data set whose status is not IN PROGRESS.

$ go-dicom mppsscu -aec MPPS -patient-name "Doe^Jane" -patient-id P1 -modality CT 127.0.0.1:41010
Requesting Association with 127.0.0.1:41010 (AE: MPPS)
N-CREATE Success (status 0x0000)
Performed Procedure Step 2.25.330650434600354095511471779614059663081 is IN PROGRESS
End it with: mppsscu -complete 2.25.330650434600354095511471779614059663081 (or -discontinue) 127.0.0.1:41010
$ go-dicom mppsscu -aec MPPS -complete 2.25.330650434600354095511471779614059663081 -series 1.2.3.4.5 -protocol "CT HEAD" -instance 1.2.840.10008.5.1.4.1.1.2:1.2.3.4.5.6 127.0.0.1:41010
Requesting Association with 127.0.0.1:41010 (AE: MPPS)
N-SET Success (status 0x0000)
Performed Procedure Step 2.25.330650434600354095511471779614059663081 is COMPLETED
$ go-dicom mppsscu -aec MPPS -discontinue 2.25.330650434600354095511471779614059663081 127.0.0.1:41010
Requesting Association with 127.0.0.1:41010 (AE: MPPS)
N-SET Failure (status 0x0110)
Error: the SCP refused the N-SET: status 0x0110

mppsscu builds the step from flags (-patient-name, -patient-id, -accession, -modality, -scheduled-step-id, ...) and -json, a DICOM JSON object added on top; -complete takes -series, -protocol and -instance for the Performed Series Sequence.

Unified Procedure Step

A UPS is a work item any performer can claim. Claiming it takes a lock, the Transaction UID, which every later change must present.

UPSHandler answers N-CREATE, N-SET, N-GET and N-ACTION over a UPSStore, which you supply (three methods: FindUPS, CreateUPS, UpdateUPS). A request to cancel is passed to OnCancelRequested: the performer decides, with its own state change.

ups := &network.UPSHandler{
	Store:         &memoryUPS{steps: map[string]*network.UPSStep{}}, // a map behind a mutex
	Subscriptions: network.NewUPSMemorySubscriptions(),
	OnStateChange: func(ctx context.Context, step *network.UPSStep, from, to network.UPSState) {
		log.Printf("UPS %s: %s -> %s", step.SOPInstanceUID, from, to)
	},
	OnEventReportError: func(ctx context.Context, sub *network.UPSSubscription, ev *network.UPSEvent, err error) {
		log.Printf("event to %v not delivered: %v", sub, err)
	},
}
upsServer, err := network.StartServer(ctx, network.SCPConfig{
	AETitle:     "UPS",
	Port:        41011,
	BindAddress: "127.0.0.1",
	// Where subscribers are reached: the same map storage commitment uses.
	CommitmentRequestors: map[string]string{"WATCHER": "127.0.0.1:41013"},
	AbstractSyntaxes: []string{
		network.VerificationSOPClassUID,
		network.UnifiedProcedureStepPushUID, network.UnifiedProcedureStepPullUID,
		network.UnifiedProcedureStepWatchUID, network.UnifiedProcedureStepEventUID,
	},
}, ups)
if err != nil {
	return err
}
defer upsServer.Stop()
ups.Notifier = upsServer // events to subscribers on associations it opens
  • Subscriptions enables UPS Watch (subscribe, unsubscribe, suspend); without it those N-ACTIONs are refused.
  • Notifier delivers N-EVENT-REPORTs. A *Server delivers each on a new association to the subscriber's AE title, resolved through CommitmentRequestors or ResolveCommitmentRequestor. A failure to deliver does not fail the N-ACTION; OnEventReportError hears of it.

On the command line, a step is created, claimed, watched and completed:

$ go-dicom upsscu -aec UPS -create -patient-name "Doe^Jane" -patient-id P1 -label "CAD analysis" 127.0.0.1:41011
Requesting Association with 127.0.0.1:41011 (AE: UPS)
N-CREATE Success (status 0x0000)
Procedure step 2.25.333620337586942980735718631622079457991 is SCHEDULED
$ go-dicom upsscu -aec UPS -claim 2.25.333620337586942980735718631622079457991 127.0.0.1:41011
Requesting Association with 127.0.0.1:41011 (AE: UPS)
N-ACTION Success (status 0x0000)
Procedure step 2.25.333620337586942980735718631622079457991 is IN PROGRESS
Transaction UID 2.25.172877807215439431847192438397410679983: give it to -set, -complete or -cancel
$ go-dicom upsscu -aec UPS -complete 2.25.333620337586942980735718631622079457991 -transaction 2.25.172877807215439431847192438397410679983 127.0.0.1:41011
Requesting Association with 127.0.0.1:41011 (AE: UPS)
N-ACTION Success (status 0x0000)
Procedure step 2.25.333620337586942980735718631622079457991 is COMPLETED

A watcher subscribes and receives the reports on an association the SCP opens to it, here on port 41013 under the title WATCHER:

$ go-dicom upsscu -aec UPS -aet WATCHER -port 41013 -watch 2.25.130342006050906090723309308936015324233 -max-events 1 127.0.0.1:41011
Receiving event reports for WATCHER on port 41013 as well
Requesting Association with 127.0.0.1:41011 (AE: UPS)
N-ACTION subscribe Success (status 0x0000)
Subscribed to 2.25.130342006050906090723309308936015324233; waiting for event reports (interrupt to stop)

--- Event report 1: UPS State Report (1) for procedure step 2.25.130342006050906090723309308936015324233 ---
  Procedure Step State                     IN PROGRESS
...
Unsubscribed from 2.25.130342006050906090723309308936015324233 after 1 event report(s)

Other upsscu actions: -get (with -attrs), -set with -json, -cancel, -request-cancel, -query (C-FIND on UPS Query) and -watch global. In Go the same are SCU.NCreate on UnifiedProcedureStepPushUID, ChangeUPSState, NGetAttributes, NSet, RequestUPSCancel, SubscribeUPS, SubscribeUPSFiltered, UnsubscribeUPS, and ReceiveUPSEvent or ServeUPSEvents for reports sent on the SCU's own association.

Storage commitment

A sender asks an archive to take responsibility for instances it stored, so it may delete its own copies. The answer is a separate message, which may come at once, later on the same association, or on a new association the archive opens back.

An SCP answers with a handler that implements StorageCommitmentProvider, or a StorageCommitmentHandler with an OnCommit function. Without one, Storage Commitment is withdrawn during negotiation. A handler that is not sure yet returns a result marked Deferred and reports later, on the same association with the StorageCommitmentReporter from its context:

commit, err := network.StartServer(ctx, network.SCPConfig{
	AETitle:          "ARCHIVE",
	Port:             41012,
	BindAddress:      "127.0.0.1",
	AbstractSyntaxes: []string{network.VerificationSOPClassUID, network.StorageCommitmentPushModelUID},
}, &network.StorageCommitmentHandler{
	OnCommit: func(ctx context.Context, req *network.StorageCommitmentRequest) (*network.StorageCommitmentResult, error) {
		reporter := network.StorageCommitmentReporterFromContext(ctx)
		go func() {
			// Check the instances are durably kept, then report.
			time.Sleep(100 * time.Millisecond)
			result := &network.StorageCommitmentResult{
				TransactionUID: req.TransactionUID,
				Successful:     req.Instances,
			}
			if err := reporter.Report(context.Background(), result); err != nil {
				log.Printf("report: %v", err)
			}
		}()
		return &network.StorageCommitmentResult{Deferred: true}, nil
	},
})
  • Taking the reporter holds the association open until Report delivers the result, the requestor ends the association, Release is called, or SCPConfig.StorageCommitmentReportWait (one minute) passes.
  • Server.ReportStorageCommitment(ctx, requestorAE, result) sends a deferred result on a new association instead, to the address CommitmentRequestors, ResolveCommitmentRequestor or ResolveOutbound gives for the requestor's AE title. It proposes the SCP role for Storage Commitment.
  • Every failure after the result is checked is a *StorageCommitmentReportError, whose Stage says where (unreachable, not associated, not sent, refused); a requestor that refused the report gives a *StatusError inside it.
  • Put every instance you do not commit in Failed with a reason. One in neither list leaves the requestor with no answer about it.

The requestor sends the N-ACTION and waits for the report on its association:

rsp, err := c.RequestStorageCommitment(ctx, &network.StorageCommitmentRequest{
	TransactionUID: network.GenerateUID(),
	Instances: []network.SOPInstanceReference{{
		SOPClassUID:    network.CTImageStorageSOP,
		SOPInstanceUID: "1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322",
	}},
})
if err != nil {
	return err
}
if !network.IsSuccess(rsp.Status) {
	return fmt.Errorf("N-ACTION refused: %s", network.FormatStatus(rsp.Status))
}
waitCtx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
result, err := c.ReceiveStorageCommitmentResult(waitCtx)
if err != nil {
	return err
}
fmt.Printf("committed %d, failed %d\n", len(result.Successful), len(result.Failed))

c is an SCU associated with network.StorageCommitmentPresentationContexts() (or the defaults, which include it). To receive a report on a new association, run an SCP whose handler implements StorageCommitmentResultReceiver, or use StorageCommitmentResultHandler.

qrscp commits an instance when it holds it under the SOP class named and its file is on disk, and reports on the same association:

$ go-dicom commitscu -aec QRSCP -wait -instance 1.2.840.10008.5.1.4.1.1.2:1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322 -instance 1.2.840.10008.5.1.4.1.1.2:1.2.3.4.5 127.0.0.1:41003
Requesting Association with 127.0.0.1:41003 (AE: QRSCP)
Association accepted
N-ACTION accepted (status 0x0000), transaction 2.25.149253148839082152189043741077863880733
Requested commitment for 2 instance(s)

Result for transaction 2.25.149253148839082152189043741077863880733
  committed: 1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322
  FAILED:    1.2.3.4.5 (reason 0x0112)
Error: 1 instance(s) were not committed

0112 is "no such object instance". Without -wait, commitscu sends the request and exits; the result then needs a server of your own to arrive on.

Limits and gotchas

  • The N-service calls do not turn a failure status into an error. Read Status on every response.
  • There is no MPPS or UPS server command. Both are Go handlers; the commands are clients.
  • UPSHandler answers N-GET with every attribute of the step, whatever the request's attribute list names.
  • UPSHandler sends event reports on new associations only, through its Notifier. A subscriber whose AE title the SCP cannot resolve gets none: against it, upsscu -watch needs -port, and the SCP an address for the watcher's title. Other SCPs may report on the subscription's own association, which upsscu -watch also reads.
  • A deferred commitment nobody reports leaves the requestor waiting.
  • CONFORMANCE.md §2.6 describes storage commitment, and §8.5 the service classes' limits.

See also

On this page