Mercurial > hg > orthanc-book
view Sphinx/source/plugins/python/storage-commitment-default.py @ 1228:7035bf7ce6bc
python SCP callbacks update
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Wed, 26 Nov 2025 15:55:48 +0100 |
| parents | 2d817288cad4 |
| children |
line wrap: on
line source
import orthanc import json # this plugins provides the same behavior as the default Orthanc implementation # new callback format from v 7.0; to use with RegisterStorageCommitmentScpCallback2 def StorageCommitmentScpCallback(jobId, transactionUid, sopClassUids, sopInstanceUids, connection): # At the beginning of a Storage Commitment operation, you can build a custom data structure # that will be provided as the "data" argument in the StorageCommitmentLookup return None # old prototype to use with RegisterStorageCommitmentScpCallback # def StorageCommitmentScpCallback(jobId, transactionUid, sopClassUids, sopInstanceUids, remoteAet, calledAet): # # At the beginning of a Storage Commitment operation, you can build a custom data structure # # that will be provided as the "data" argument in the StorageCommitmentLookup # return None # Reference: `StorageCommitmentScpJob::Lookup` in `OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp` def StorageCommitmentLookup(sopClassUid, sopInstanceUid, data): success = False reason = orthanc.StorageCommitmentFailureReason.NO_SUCH_OBJECT_INSTANCE result = json.loads(orthanc.RestApiPost("/tools/lookup", sopInstanceUid)) if len(result) == 1: tags = json.loads(orthanc.RestApiGet(result[0]["Path"] + "/simplified-tags")) if all(tag in tags for tag in ["SOPClassUID", "SOPInstanceUID"]) and \ tags["SOPInstanceUID"] == sopInstanceUid: if tags["SOPClassUID"] == sopClassUid: success = True reason = orthanc.StorageCommitmentFailureReason.SUCCESS else: # Mismatch in the SOP class UID reason = orthanc.StorageCommitmentFailureReason.CLASS_INSTANCE_CONFLICT orthanc.LogInfo(" Storage commitment SCP job: " + ("Success" if success else "Failure") + \ " while looking for " + sopClassUid + " / " + sopInstanceUid) return reason orthanc.RegisterStorageCommitmentScpCallback2(StorageCommitmentScpCallback, StorageCommitmentLookup) # from v 7.0 # orthanc.RegisterStorageCommitmentScpCallback(StorageCommitmentScpCallback, StorageCommitmentLookup)
