annotate Sphinx/source/plugins/python/accessing-new-instance.py @ 927:dfe96daba4f8

python in win installer
author Alain Mazy <am@osimis.io>
date Wed, 29 Mar 2023 11:54:58 +0200
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 orthanc
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import json
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 import pprint
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 OnStoredInstance(dicom, instanceId):
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 print('Received instance %s of size %d (transfer syntax %s, SOP class UID %s)' % (
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 instanceId, dicom.GetInstanceSize(),
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 dicom.GetInstanceMetadata('TransferSyntax'),
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 dicom.GetInstanceMetadata('SopClassUid')))
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # Print the origin information
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 if dicom.GetInstanceOrigin() == orthanc.InstanceOrigin.DICOM_PROTOCOL:
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 print('This instance was received through the DICOM protocol')
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 elif dicom.GetInstanceOrigin() == orthanc.InstanceOrigin.REST_API:
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 print('This instance was received through the REST API')
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # Print the DICOM tags
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 pprint.pprint(json.loads(dicom.GetInstanceSimplifiedJson()))
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
a589668768d7 moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 orthanc.RegisterOnStoredInstanceCallback(OnStoredInstance)