# HG changeset patch # User Sebastien Jodogne # Date 1585304659 -3600 # Node ID 04fae9d4b65f0c5d1c1a12bbe4e600bc6c490595 # Parent bdf8757449e33d8e89b4b23eedf2e2910cd61185 auto-routing diff -r bdf8757449e3 -r 04fae9d4b65f Sphinx/source/plugins/python.rst --- a/Sphinx/source/plugins/python.rst Fri Mar 27 08:41:45 2020 +0100 +++ b/Sphinx/source/plugins/python.rst Fri Mar 27 11:24:19 2020 +0100 @@ -126,14 +126,18 @@ def DecodeInstance(output, uri, **request): if request['method'] == 'GET': + # Retrieve the instance ID from the regular expression (*) instanceId = request['groups'][0] + # Get the content of the DICOM file f = orthanc.GetDicomForInstance(instanceId) + # Parse it using pydicom dicom = pydicom.dcmread(io.BytesIO(f)) + # Return a string representation the dataset to the caller output.AnswerBuffer(str(dicom), 'text/plain') else: output.SendMethodNotAllowed('GET') - orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) + orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*) .. highlight:: bash @@ -141,3 +145,21 @@ $ curl http://localhost:8042/pydicom/19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5 + +Auto-routing studies +.................... + +.. highlight:: python + +Here is a sample Python plugin that routes any :ref:`stable study +` to a modality named ``samples`` (as declared in the +``DicomModalities`` configuration option):: + + import orthanc + + def OnChange(changeType, level, resourceId): + if changeType == orthanc.ChangeType.STABLE_STUDY: + print('Stable study: %s' % resourceId) + orthanc.RestApiPost('/modalities/sample/store', resourceId) + + orthanc.RegisterOnChangeCallback(OnChange)