annotate Sphinx/source/plugins/python/pydicom.py @ 1113:a588960a72e5 default tip

spelling
author Alain Mazy <am@orthanc.team>
date Mon, 28 Oct 2024 09:23:08 +0100
parents a589668768d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
703
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import io
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import orthanc
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 import pydicom
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 def DecodeInstance(output, uri, **request):
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 if request['method'] == 'GET':
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # Retrieve the instance ID from the regular expression (*)
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 instanceId = request['groups'][0]
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # Get the content of the DICOM file
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 f = orthanc.GetDicomForInstance(instanceId)
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # Parse it using pydicom
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 dicom = pydicom.dcmread(io.BytesIO(f))
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # Return a string representation the dataset to the caller
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 output.AnswerBuffer(str(dicom), 'text/plain')
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 else:
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 output.SendMethodNotAllowed('GET')
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*)