Mercurial > hg > orthanc-book
diff Sphinx/source/plugins/python/storage-commitment-default.py @ 973:2d817288cad4
added python storage commitment
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 28 Aug 2023 18:45:57 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/python/storage-commitment-default.py Mon Aug 28 18:45:57 2023 +0200 @@ -0,0 +1,34 @@ +import orthanc +import json + +# this plugins provides the same behavior as the default Orthanc implementation + +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.RegisterStorageCommitmentScpCallback(StorageCommitmentScpCallback, StorageCommitmentLookup) \ No newline at end of file