Mercurial > hg > orthanc-book
changeset 346:bdf8757449e3
more python samples
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Mar 2020 08:41:45 +0100 |
parents | f81b533a0fd0 |
children | 04fae9d4b65f |
files | Sphinx/source/plugins/python.rst |
diffstat | 1 files changed, 37 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Sphinx/source/plugins/python.rst Fri Mar 27 08:14:49 2020 +0100 +++ b/Sphinx/source/plugins/python.rst Fri Mar 27 08:41:45 2020 +0100 @@ -60,6 +60,8 @@ Listening to changes .................... +.. highlight:: python + This sample uploads a DICOM file as soon as Orthanc is started:: import orthanc @@ -81,7 +83,9 @@ Accessing the content of a new instance ---------------------------------------- +....................................... + +.. highlight:: python :: @@ -105,3 +109,35 @@ pprint.pprint(json.loads(dicom.GetInstanceSimplifiedJson())) orthanc.RegisterOnStoredInstanceCallback(OnStoredInstance) + + +Calling pydicom +............... + +.. highlight:: python + +Here is a sample Python plugin that registers a REST callback to dump +the content of the dataset of one given DICOM instance stored in +Orthanc, using `pydicom <https://pydicom.github.io/>`__:: + + import io + import orthanc + import pydicom + + def DecodeInstance(output, uri, **request): + if request['method'] == 'GET': + instanceId = request['groups'][0] + f = orthanc.GetDicomForInstance(instanceId) + dicom = pydicom.dcmread(io.BytesIO(f)) + output.AnswerBuffer(str(dicom), 'text/plain') + else: + output.SendMethodNotAllowed('GET') + + orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) + +.. highlight:: bash + +This can be called as follows:: + + $ curl http://localhost:8042/pydicom/19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5 +