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