Mercurial > hg > orthanc-book
comparison Sphinx/source/plugins/python/pynetdicom.py @ 727:698eb280060a
pynetdicom sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Jun 2021 07:48:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
726:26940c3246c3 | 727:698eb280060a |
---|---|
1 import json | |
2 import orthanc | |
3 import pynetdicom | |
4 | |
5 def HandleStore(event): | |
6 orthanc.LogWarning('Handling C-STORE using pynetdicom') | |
7 orthanc.RestApiPost('/instances', event.request.DataSet.getvalue()) | |
8 return 0x0000 | |
9 | |
10 ae = pynetdicom.AE() | |
11 ae.supported_contexts = pynetdicom.AllStoragePresentationContexts | |
12 | |
13 SCP = None | |
14 | |
15 def OnChange(changeType, level, resource): | |
16 global SCP | |
17 | |
18 if changeType == orthanc.ChangeType.ORTHANC_STARTED: | |
19 port = json.loads(orthanc.GetConfiguration()).get('DicomPort', 4242) | |
20 | |
21 SCP = ae.start_server(('', port), block = False, evt_handlers = [ | |
22 (pynetdicom.evt.EVT_C_STORE, HandleStore), | |
23 ]) | |
24 | |
25 orthanc.LogWarning('DICOM server using pynetdicom has started') | |
26 | |
27 elif changeType == orthanc.ChangeType.ORTHANC_STOPPED: | |
28 orthanc.LogWarning('Stopping pynetdicom') | |
29 SCP.shutdown() | |
30 | |
31 orthanc.RegisterOnChangeCallback(OnChange) |