annotate Sphinx/source/plugins/python/pynetdicom.py @ 927:dfe96daba4f8

python in win installer
author Alain Mazy <am@osimis.io>
date Wed, 29 Mar 2023 11:54:58 +0200
parents 698eb280060a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
727
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import json
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import orthanc
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 import pynetdicom
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 def HandleStore(event):
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 orthanc.LogWarning('Handling C-STORE using pynetdicom')
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 orthanc.RestApiPost('/instances', event.request.DataSet.getvalue())
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 return 0x0000
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 ae = pynetdicom.AE()
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 ae.supported_contexts = pynetdicom.AllStoragePresentationContexts
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 SCP = None
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 def OnChange(changeType, level, resource):
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 global SCP
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 if changeType == orthanc.ChangeType.ORTHANC_STARTED:
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 port = json.loads(orthanc.GetConfiguration()).get('DicomPort', 4242)
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 SCP = ae.start_server(('', port), block = False, evt_handlers = [
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 (pynetdicom.evt.EVT_C_STORE, HandleStore),
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 ])
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 orthanc.LogWarning('DICOM server using pynetdicom has started')
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 elif changeType == orthanc.ChangeType.ORTHANC_STOPPED:
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 orthanc.LogWarning('Stopping pynetdicom')
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 SCP.shutdown()
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
698eb280060a pynetdicom sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 orthanc.RegisterOnChangeCallback(OnChange)