1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14 #include "gdcmFindPatientRootQuery.h"
15
16 #include "gdcmCompositeNetworkFunctions.h"
17 #include "gdcmTrace.h"
18
19 /*
20 * STUDY:
21 * $ findscu --call GDCM_STORE --aetitle GDCMDASH -P server 11112 -k 8,52="PATIENT" -k 10,20="1*"
22 * $ findscu --call GDCM_STORE --aetitle GDCMDASH -S server 11112 -k 8,52="STUDY" -k 10,20="FOO"
23 *
24 * SERIES:
25 * $ findscu --call GDCM_STORE --aetitle GDCMDASH -S lirispat 11112 -k 8,52="SERIES" -k 20,d="1.2.3" -k 8,60
26 */
27
TestFindPatientRootQuery(int,char * [])28 int TestFindPatientRootQuery(int , char *[])
29 {
30 //gdcm::Trace::DebugOn();
31 gdcm::Trace::WarningOff();
32
33 // PATIENT:
34 gdcm::ERootType theRoot = gdcm::ePatientRootType;
35 gdcm::EQueryLevel theLevel = gdcm::ePatient;
36 {
37 std::vector< std::pair<gdcm::Tag, std::string> > keys;
38 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
39 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
40 if( theQuery->ValidateQuery( true ) )
41 {
42 // No key found is an error
43 return 1;
44 }
45 }
46 {
47 std::vector< std::pair<gdcm::Tag, std::string> > keys;
48 keys.emplace_back( gdcm::Tag(0x10,0x10), "patient" ) ;
49 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
50 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
51 if( theQuery->ValidateQuery( true ) )
52 {
53 // required key
54 return 1;
55 }
56 }
57 {
58 std::vector< std::pair<gdcm::Tag, std::string> > keys;
59 keys.emplace_back( gdcm::Tag(0x10,0x20), "patientid" ) ;
60 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
61 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
62 if( !theQuery->ValidateQuery( true ) )
63 {
64 // unique key
65 return 1;
66 }
67 }
68 {
69 std::vector< std::pair<gdcm::Tag, std::string> > keys;
70 keys.emplace_back( gdcm::Tag(0x10,0x20), "patientid" ) ;
71 keys.emplace_back( gdcm::Tag(0x10,0x10), "patient" ) ;
72 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
73 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
74 if( !theQuery->ValidateQuery( true ) )
75 {
76 // unique key + required
77 return 1;
78 }
79 }
80
81 // STUDY:
82 theLevel = gdcm::eStudy;
83 {
84 std::vector< std::pair<gdcm::Tag, std::string> > keys;
85 keys.emplace_back( gdcm::Tag(0x10,0x10), "PATIENT" ) ;
86 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
87 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
88 if( theQuery->ValidateQuery( true ) )
89 {
90 // Patient Id is a Required Key in Study
91 return 1;
92 }
93 }
94 {
95 std::vector< std::pair<gdcm::Tag, std::string> > keys;
96 keys.emplace_back( gdcm::Tag(0x20,0x10), "studyid" ) ;
97 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
98 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
99 if( theQuery->ValidateQuery( true ) )
100 {
101 // Study Id is a required tag
102 return 1;
103 }
104 }
105 {
106 std::vector< std::pair<gdcm::Tag, std::string> > keys;
107 keys.emplace_back( gdcm::Tag(0x8,0x90), "physician" ) ;
108 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
109 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
110 if( theQuery->ValidateQuery( true ) )
111 {
112 // ref physician's name is optional
113 return 1;
114 }
115 }
116 {
117 std::vector< std::pair<gdcm::Tag, std::string> > keys;
118 keys.emplace_back( gdcm::Tag(0x10,0x20), "patientid" ) ;
119 keys.emplace_back( gdcm::Tag(0x20,0xd), "studyuid" ) ;
120 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
121 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
122 if( !theQuery->ValidateQuery( true ) )
123 {
124 // Study UID is the unique tag
125 return 1;
126 }
127 }
128
129 // SERIES:
130 theLevel = gdcm::eSeries;
131 {
132 std::vector< std::pair<gdcm::Tag, std::string> > keys;
133 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
134 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
135 if( theQuery->ValidateQuery( true ) )
136 {
137 // No key found is an error
138 return 1;
139 }
140 }
141 {
142 std::vector< std::pair<gdcm::Tag, std::string> > keys;
143 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
144 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
145 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
146 if( theQuery->ValidateQuery( true ) )
147 {
148 // No key at level Series
149 return 1;
150 }
151 }
152 {
153 std::vector< std::pair<gdcm::Tag, std::string> > keys;
154 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
155 keys.emplace_back( gdcm::Tag(0x8,0x60), "" ) ;
156 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
157 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
158 if( theQuery->ValidateQuery( true ) )
159 {
160 // missing unique at series level
161 return 1;
162 }
163 }
164 {
165 std::vector< std::pair<gdcm::Tag, std::string> > keys;
166 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
167 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
168 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
169 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
170 if( !theQuery->ValidateQuery( true ) )
171 {
172 // all unique keys present
173 return 1;
174 }
175 }
176 {
177 std::vector< std::pair<gdcm::Tag, std::string> > keys;
178 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
179 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
180 keys.emplace_back( gdcm::Tag(0x8,0x60), "" ) ;
181 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
182 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
183 if( !theQuery->ValidateQuery( true ) )
184 {
185 // all unique keys present and required is correct level
186 return 1;
187 }
188 }
189 {
190 std::vector< std::pair<gdcm::Tag, std::string> > keys;
191 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
192 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
193 keys.emplace_back( gdcm::Tag(0x8,0x20), "" ) ;
194 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
195 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
196 if( theQuery->ValidateQuery( true ) )
197 {
198 // all unique keys present and required is incorrect level
199 return 1;
200 }
201 }
202
203 // IMAGES:
204
205 theLevel = gdcm::eImage;
206 {
207 std::vector< std::pair<gdcm::Tag, std::string> > keys;
208 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
209 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
210 keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
211 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
212 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
213 if( !theQuery->ValidateQuery( true ) )
214 {
215 // all unique keys present
216 return 1;
217 }
218 }
219
220 {
221 std::vector< std::pair<gdcm::Tag, std::string> > keys;
222 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
223 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
224 keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
225 keys.emplace_back( gdcm::Tag(0x20,0x13), "" ) ;
226 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
227 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
228 if( !theQuery->ValidateQuery( true ) )
229 {
230 // all unique keys present + required correct level
231 return 1;
232 }
233 }
234
235 {
236 std::vector< std::pair<gdcm::Tag, std::string> > keys;
237 keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
238 keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
239 keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
240 keys.emplace_back( gdcm::Tag(0x20,0x13), "" ) ;
241 keys.emplace_back( gdcm::Tag(0x20,0x11), "" ) ; // series level
242 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
243 gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
244 if( theQuery->ValidateQuery( true ) )
245 {
246 // all unique keys present + required correct level + one incorrect
247 return 1;
248 }
249 }
250
251 //std::cout << "success" << std::endl;
252 return 0;
253 }
254