annotate Plugins/CGet/Run.py @ 353:49f2943544eb

CheckFind on echo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Dec 2020 15:59:08 +0100
parents c56eaf5928f0
children 79ce0f7a9714
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # modify it under the terms of the GNU General Public License as
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # published by the Free Software Foundation, either version 3 of the
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # License, or (at your option) any later version.
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful, but
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # General Public License for more details.
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 #
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 import argparse
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import os
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import pprint
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import re
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import sys
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import unittest
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 from Toolbox import *
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ## Parse the command-line arguments
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 parser = argparse.ArgumentParser(description = 'Run the integration tests for the patient recycling behavior.')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 parser.add_argument('--server',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 default = 'localhost',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 help = 'Address of the Orthanc server to test')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 parser.add_argument('--aet',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 default = 'ORTHANC',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 help = 'AET of the Orthanc instance to test')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 parser.add_argument('--dicom',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 type = int,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 default = 4242,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 help = 'DICOM port of the Orthanc instance to test')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 parser.add_argument('--rest',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 type = int,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 default = 8042,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 help = 'Port to the REST API')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 parser.add_argument('--username',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 default = 'alice',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 help = 'Username to the REST API')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 parser.add_argument('--password',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 default = 'orthanctest',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 help = 'Password to the REST API')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 parser.add_argument('--force', help = 'Do not warn the user',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 action = 'store_true')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 parser.add_argument('options', metavar = 'N', nargs = '*',
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 help='Arguments to Python unittest')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 args = parser.parse_args()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ## Configure the testing context
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if not args.force:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 print("""
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 WARNING: This test will remove all the content of your
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 Orthanc instance running on %s!
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 Are you sure ["yes" to go on]?""" % args.server)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if sys.stdin.readline().strip() != 'yes':
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 print('Aborting...')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 exit(0)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ORTHANC = DefineOrthanc(server = args.server,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 username = args.username,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 password = args.password,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 restPort = args.rest,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 aet = args.aet,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 dicomPort = args.dicom)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ## pydicom toolbox
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 from pydicom.dataset import Dataset
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 from pynetdicom import (
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 AE,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 evt,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 build_role,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 debug_logger,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 )
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 from pynetdicom.sop_class import *
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 def ExecuteCGet(orthanc, dataset, sopClass, callback):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 handlers = [(evt.EVT_C_STORE, callback)]
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 ae = AE(ae_title = 'ORTHANCTEST')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ae.add_requested_context(PatientRootQueryRetrieveInformationModelGet)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ae.add_requested_context(sopClass)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 role = build_role(sopClass, scp_role = True, scu_role = True)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 assoc = ae.associate(orthanc['Server'], orthanc['DicomPort'],
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ext_neg = [role], evt_handlers = handlers)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if assoc.is_established:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 responses = assoc.send_c_get(
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 dataset,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 PatientRootQueryRetrieveInformationModelGet,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 msg_id = 9999,
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 )
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 # Only report the result of the last sub-operation
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 last = None
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 for (result, identifier) in responses:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 if result:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 last = result
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 else:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 assoc.release()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 raise Exception('Connection timed out, was aborted or received invalid response')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 assoc.release()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 return last
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 else:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 raise Exception('Association rejected, aborted or never connected')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ## The tests
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 ## IMPORTANT RESOURCES:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ## http://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.4.3.html#table_C.4-3
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ## http://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.4.3.3.html
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ##
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 def DefaultCallback(event):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 to_match = PatientRootQueryRetrieveInformationModelGet
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 cxs = [cx for cx in event.assoc.accepted_contexts if cx.abstract_syntax == to_match]
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if len(cxs) != 1:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 raise Exception()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 else:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 return 0x0000
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 class Orthanc(unittest.TestCase):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 def setUp(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 if (sys.version_info >= (3, 0)):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 # Remove annoying warnings about unclosed socket in Python 3
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 import warnings
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 warnings.simplefilter('ignore', ResourceWarning)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 DropOrthanc(ORTHANC)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 def test_success(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 dataset.StudyInstanceUID = '2.16.840.1.113669.632.20.1211.10000357775'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, DefaultCallback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 self.assertEqual(0x0000, result[0x00000900].value) # Status - Success
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 self.assertEqual(2, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 self.assertEqual(0, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 self.assertEqual(0, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 # "Warning, Failure, or Success shall not contain the Number
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 # of Remaining Sub-operations Attribute."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 self.assertFalse(0x00001020 in result) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 def test_some_failure(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 # Failure in 1 on 2 images
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 def Callback(event):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 Callback.count += 1
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 if Callback.count == 1:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 return 0xA702 # Refused: Out of resources - Unable to perform sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 elif Callback.count == 2:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return 0x0000
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 else:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 raise Exception('')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Callback.count = 0 # Static variable of function "Callback"
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0002.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 dataset.StudyInstanceUID = '2.16.840.1.113669.632.20.1211.10000357775'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 # Fixed in Orthanc 1.8.1. "From what I read from the DICOM
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 # standard the C-GET should at least return a warning
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 # (0xB000), see C.4.3.1.4 Status as one or more sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 # failed."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 # https://groups.google.com/g/orthanc-users/c/tS826iEzHb0/m/KzHZk61tAgAJ
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 # https://github.com/pydicom/pynetdicom/issues/552#issuecomment-712477451
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 self.assertEqual(0xB000, result[0x00000900].value) # Status - One or more Failures or Warnings
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 self.assertEqual(1, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 self.assertEqual(1, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 self.assertEqual(0, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 # "Warning, Failure, or Success shall not contain the Number
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 # of Remaining Sub-operations Attribute."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 self.assertFalse(0x00001020 in result) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 def test_all_failure(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 def Callback(event):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 return 0xA702 # Refused: Out of resources - Unable to perform sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0002.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 dataset.StudyInstanceUID = '2.16.840.1.113669.632.20.1211.10000357775'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 # Must return "Failure or Refused if all sub-operations were unsuccessful"
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 # http://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.4.3.3.html
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 self.assertEqual(0xA702, result[0x00000900].value) # Status - Unable to perform sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 self.assertEqual(0, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 self.assertEqual(2, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 self.assertEqual(0, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 # "Warning, Failure, or Success shall not contain the Number
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 # of Remaining Sub-operations Attribute."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 self.assertFalse(0x00001020 in result) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 def test_warning(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 def Callback(event):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 return 0xB000 # Sub-operations Complete - One or more Failures or Warnings
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 dataset.StudyInstanceUID = '2.16.840.1.113669.632.20.1211.10000357775'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 self.assertEqual(0xB000, result[0x00000900].value) # Status - One or more Failures or Warnings
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 self.assertEqual(0, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 self.assertEqual(0, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 self.assertEqual(1, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 # "Warning, Failure, or Success shall not contain the Number
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 # of Remaining Sub-operations Attribute."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 self.assertFalse(0x00001020 in result) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 def test_missing(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 dataset.StudyInstanceUID = 'nope'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 result = ExecuteCGet(ORTHANC, dataset, UltrasoundImageStorage, DefaultCallback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 self.assertEqual(0xC000, result[0x00000900].value) # Status - Failed: Unable to process
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 self.assertEqual(0, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 self.assertEqual(0, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 self.assertEqual(0, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 # "Warning, Failure, or Success shall not contain the Number
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 # of Remaining Sub-operations Attribute."
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 self.assertFalse(0x00001020 in result) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 def test_cancel(self):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 # Fixed in Orthanc 1.8.1.
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 # https://groups.google.com/g/orthanc-users/c/tS826iEzHb0/m/QbPw6XPZAgAJ
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 # https://github.com/pydicom/pynetdicom/issues/553#issuecomment-713164041
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 def Callback(event):
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 Callback.count += 1
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 if Callback.count == 1:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 return 0x0000
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 elif Callback.count == 2:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 to_match = PatientRootQueryRetrieveInformationModelGet
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 cxs = [cx for cx in event.assoc.accepted_contexts if cx.abstract_syntax == to_match]
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 cx_id = cxs[0].context_id
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 event.assoc.send_c_cancel(9999, cx_id)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 return 0x0000 # Success
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 else:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 raise Exception('')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 Callback.count = 0 # Static variable of function "Callback"
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 UploadInstance(ORTHANC, 'Brainix/Epi/IM-0001-0002.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 dataset = Dataset()
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 dataset.QueryRetrieveLevel = 'STUDY'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 dataset.StudyInstanceUID = '2.16.840.1.113669.632.20.1211.10000357775'
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 self.assertEqual(0xfe00, result[0x00000900].value) # Status - Sub-operations terminated due to Cancel Indication
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 self.assertEqual(2, result[0x00001020].value) # Remaining sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 self.assertEqual(1, result[0x00001021].value) # Completed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 self.assertEqual(0, result[0x00001022].value) # Failed sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 self.assertEqual(0, result[0x00001023].value) # Warning sub-operations
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 try:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 print('\nStarting the tests...')
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 unittest.main(argv = [ sys.argv[0] ] + args.options)
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 finally:
c56eaf5928f0 integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 print('\nDone')