Mercurial > hg > orthanc-tests
annotate Plugins/CGet/Run.py @ 488:e904b2282b0e
Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 08 Jul 2022 15:27:27 +0200 |
parents | 06eea14c5906 |
children | 933fe1bbce4f |
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 |
449
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
437
diff
changeset
|
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium |
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
437
diff
changeset
|
7 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
347
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # 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
|
10 # 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
|
11 # 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
|
12 # 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
|
13 # |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # 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
|
15 # 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
|
16 # 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
|
17 # General Public License for more details. |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # 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
|
20 # 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
|
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import argparse |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import os |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import pprint |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import re |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import sys |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import unittest |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 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
|
32 from Toolbox import * |
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 ## |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 ## Parse the command-line arguments |
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 |
375 | 39 parser = argparse.ArgumentParser(description = 'Run the integration tests for the C-GET SCP of Orthanc.') |
347
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 parser.add_argument('--server', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 default = 'localhost', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 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
|
44 parser.add_argument('--aet', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 default = 'ORTHANC', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 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
|
47 parser.add_argument('--dicom', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 type = int, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 default = 4242, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 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
|
51 parser.add_argument('--rest', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 type = int, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 default = 8042, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 help = 'Port to the REST API') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 parser.add_argument('--username', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 default = 'alice', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 help = 'Username to the REST API') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 parser.add_argument('--password', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 default = 'orthanctest', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 help = 'Password to the REST API') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 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
|
62 action = 'store_true') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 parser.add_argument('options', metavar = 'N', nargs = '*', |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 help='Arguments to Python unittest') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 args = parser.parse_args() |
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 ## |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 ## Configure the testing context |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 if not args.force: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 print(""" |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 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
|
76 Orthanc instance running on %s! |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 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
|
79 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 if sys.stdin.readline().strip() != 'yes': |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 print('Aborting...') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 exit(0) |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 ORTHANC = DefineOrthanc(server = args.server, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 username = args.username, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 password = args.password, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 restPort = args.rest, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 aet = args.aet, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 dicomPort = args.dicom) |
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 ## |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 ## pydicom toolbox |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 from pydicom.dataset import Dataset |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 from pynetdicom import ( |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 AE, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 evt, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 build_role, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 debug_logger, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 ) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 from pynetdicom.sop_class import * |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 def ExecuteCGet(orthanc, dataset, sopClass, callback): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 handlers = [(evt.EVT_C_STORE, callback)] |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 ae = AE(ae_title = 'ORTHANCTEST') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 ae.add_requested_context(PatientRootQueryRetrieveInformationModelGet) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 ae.add_requested_context(sopClass) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 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
|
114 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 assoc = ae.associate(orthanc['Server'], orthanc['DicomPort'], |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 ext_neg = [role], evt_handlers = handlers) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 if assoc.is_established: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 responses = assoc.send_c_get( |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 dataset, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 PatientRootQueryRetrieveInformationModelGet, |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 msg_id = 9999, |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 # 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
|
126 last = None |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 for (result, identifier) in responses: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 if result: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 last = result |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 else: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 assoc.release() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 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
|
134 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 assoc.release() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 return last |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 else: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 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
|
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 ## |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 ## The tests |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 ## |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 ## IMPORTANT RESOURCES: |
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.html#table_C.4-3 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 ## 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
|
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 def DefaultCallback(event): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 to_match = PatientRootQueryRetrieveInformationModelGet |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 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
|
156 if len(cxs) != 1: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 raise Exception() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 else: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 return 0x0000 |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 class Orthanc(unittest.TestCase): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 def setUp(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 if (sys.version_info >= (3, 0)): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 # 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
|
167 import warnings |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 warnings.simplefilter('ignore', ResourceWarning) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 DropOrthanc(ORTHANC) |
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 def test_success(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 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
|
175 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
|
176 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 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
|
180 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, DefaultCallback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 # "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
|
189 # of Remaining Sub-operations Attribute." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 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
|
191 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 def test_some_failure(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 # Failure in 1 on 2 images |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 def Callback(event): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 Callback.count += 1 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 if Callback.count == 1: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 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
|
200 elif Callback.count == 2: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 return 0x0000 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 else: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 raise Exception('') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 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
|
206 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 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
|
208 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
|
209 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 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
|
213 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 # 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
|
217 # 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
|
218 # (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
|
219 # failed." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 # 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
|
221 # 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
|
222 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 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
|
227 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 # "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
|
229 # of Remaining Sub-operations Attribute." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 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
|
231 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 def test_all_failure(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 def Callback(event): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 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
|
236 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 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
|
238 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
|
239 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 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
|
243 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 # 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
|
247 # 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
|
248 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 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
|
253 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 # "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
|
255 # of Remaining Sub-operations Attribute." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 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
|
257 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 def test_warning(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 def Callback(event): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 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
|
262 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 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
|
264 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 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
|
268 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 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
|
275 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 # "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
|
277 # of Remaining Sub-operations Attribute." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 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
|
279 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 def test_missing(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 dataset.StudyInstanceUID = 'nope' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 result = ExecuteCGet(ORTHANC, dataset, UltrasoundImageStorage, DefaultCallback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 # "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
|
294 # of Remaining Sub-operations Attribute." |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 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
|
296 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 def test_cancel(self): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 # Fixed in Orthanc 1.8.1. |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 # 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
|
301 # 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
|
302 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 def Callback(event): |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 Callback.count += 1 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 if Callback.count == 1: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 return 0x0000 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 elif Callback.count == 2: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 to_match = PatientRootQueryRetrieveInformationModelGet |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 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
|
311 cx_id = cxs[0].context_id |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 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
|
313 return 0x0000 # Success |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 else: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 raise Exception('') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 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
|
318 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 dataset = Dataset() |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 dataset.QueryRetrieveLevel = 'STUDY' |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 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
|
326 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 result = ExecuteCGet(ORTHANC, dataset, MRImageStorage, Callback) |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
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 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 try: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 print('\nStarting the tests...') |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 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
|
340 |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 finally: |
c56eaf5928f0
integration tests for c-get using pydicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 print('\nDone') |