Mercurial > hg > orthanc-book
comparison 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 |
comparison
equal
deleted
inserted
replaced
972:e72f8d52d94b | 973:2d817288cad4 |
---|---|
1 import orthanc | |
2 import json | |
3 | |
4 # this plugins provides the same behavior as the default Orthanc implementation | |
5 | |
6 def StorageCommitmentScpCallback(jobId, transactionUid, sopClassUids, sopInstanceUids, remoteAet, calledAet): | |
7 # At the beginning of a Storage Commitment operation, you can build a custom data structure | |
8 # that will be provided as the "data" argument in the StorageCommitmentLookup | |
9 return None | |
10 | |
11 | |
12 # Reference: `StorageCommitmentScpJob::Lookup` in `OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp` | |
13 def StorageCommitmentLookup(sopClassUid, sopInstanceUid, data): | |
14 success = False | |
15 reason = orthanc.StorageCommitmentFailureReason.NO_SUCH_OBJECT_INSTANCE | |
16 | |
17 result = json.loads(orthanc.RestApiPost("/tools/lookup", sopInstanceUid)) | |
18 if len(result) == 1: | |
19 tags = json.loads(orthanc.RestApiGet(result[0]["Path"] + "/simplified-tags")) | |
20 if all(tag in tags for tag in ["SOPClassUID", "SOPInstanceUID"]) and \ | |
21 tags["SOPInstanceUID"] == sopInstanceUid: | |
22 if tags["SOPClassUID"] == sopClassUid: | |
23 success = True | |
24 reason = orthanc.StorageCommitmentFailureReason.SUCCESS | |
25 else: | |
26 # Mismatch in the SOP class UID | |
27 reason = orthanc.StorageCommitmentFailureReason.CLASS_INSTANCE_CONFLICT | |
28 | |
29 orthanc.LogInfo(" Storage commitment SCP job: " + ("Success" if success else "Failure") + \ | |
30 " while looking for " + sopClassUid + " / " + sopInstanceUid) | |
31 | |
32 return reason | |
33 | |
34 orthanc.RegisterStorageCommitmentScpCallback(StorageCommitmentScpCallback, StorageCommitmentLookup) |