Mercurial > hg > orthanc-book
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/python/pynetdicom.py Mon Jun 28 07:48:48 2021 +0200 @@ -0,0 +1,31 @@ +import json +import orthanc +import pynetdicom + +def HandleStore(event): + orthanc.LogWarning('Handling C-STORE using pynetdicom') + orthanc.RestApiPost('/instances', event.request.DataSet.getvalue()) + return 0x0000 + +ae = pynetdicom.AE() +ae.supported_contexts = pynetdicom.AllStoragePresentationContexts + +SCP = None + +def OnChange(changeType, level, resource): + global SCP + + if changeType == orthanc.ChangeType.ORTHANC_STARTED: + port = json.loads(orthanc.GetConfiguration()).get('DicomPort', 4242) + + SCP = ae.start_server(('', port), block = False, evt_handlers = [ + (pynetdicom.evt.EVT_C_STORE, HandleStore), + ]) + + orthanc.LogWarning('DICOM server using pynetdicom has started') + + elif changeType == orthanc.ChangeType.ORTHANC_STOPPED: + orthanc.LogWarning('Stopping pynetdicom') + SCP.shutdown() + +orthanc.RegisterOnChangeCallback(OnChange)