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 "gdcmFindStudyRootQuery.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 
TestFindStudyRootQuery(int,char * [])28 int TestFindStudyRootQuery(int , char *[])
29 {
30   //gdcm::Trace::DebugOn();
31   gdcm::Trace::WarningOff();
32 
33   // STUDY:
34   gdcm::ERootType theRoot = gdcm::eStudyRootType;
35   gdcm::EQueryLevel theLevel = gdcm::eStudy;
36 
37     {
38     std::vector< std::pair<gdcm::Tag, std::string> > keys;
39     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
40       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
41     if( theQuery->ValidateQuery( true ) )
42       {
43       // No key found is an error
44       return 1;
45       }
46     }
47     {
48     std::vector< std::pair<gdcm::Tag, std::string> > keys;
49     keys.emplace_back( gdcm::Tag(0x10,0x10), "PATIENT" ) ;
50     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
51       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
52     if( theQuery->ValidateQuery( true ) )
53       {
54       // Patient Id is a Required Key in Study
55       return 1;
56       }
57     }
58     {
59     std::vector< std::pair<gdcm::Tag, std::string> > keys;
60     keys.emplace_back( gdcm::Tag(0x20,0x10), "studyid" ) ;
61     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
62       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
63     if( theQuery->ValidateQuery( true ) )
64       {
65       // Study Id is a required tag
66       return 1;
67       }
68     }
69     {
70     std::vector< std::pair<gdcm::Tag, std::string> > keys;
71     keys.emplace_back( gdcm::Tag(0x8,0x90), "physician" ) ;
72     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
73       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
74     if( theQuery->ValidateQuery( true ) )
75       {
76       // ref physician's name is optional
77       return 1;
78       }
79     }
80     {
81     std::vector< std::pair<gdcm::Tag, std::string> > keys;
82     keys.emplace_back( gdcm::Tag(0x20,0xd), "studyuid" ) ;
83     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
84       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
85     if( !theQuery->ValidateQuery( true ) )
86       {
87       // Study UID is the unique tag
88       return 1;
89       }
90     }
91 
92   // SERIES:
93 
94   theLevel = gdcm::eSeries;
95 
96     {
97     std::vector< std::pair<gdcm::Tag, std::string> > keys;
98     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
99       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
100     if( theQuery->ValidateQuery( true ) )
101       {
102       // No key found is an error
103       return 1;
104       }
105     }
106     {
107     std::vector< std::pair<gdcm::Tag, std::string> > keys;
108     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
109     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
110       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
111     if( theQuery->ValidateQuery( true ) )
112       {
113       // No key at level Series
114       return 1;
115       }
116     }
117     {
118     std::vector< std::pair<gdcm::Tag, std::string> > keys;
119     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
120     keys.emplace_back( gdcm::Tag(0x8,0x60), "" ) ;
121     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
122       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
123     if( theQuery->ValidateQuery( true ) )
124       {
125       // missing unique at series level
126       return 1;
127       }
128     }
129     {
130     std::vector< std::pair<gdcm::Tag, std::string> > keys;
131     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
132     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
133     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
134       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
135     if( !theQuery->ValidateQuery( true ) )
136       {
137       // all unique keys present
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     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
145     keys.emplace_back( gdcm::Tag(0x8,0x60), "" ) ;
146     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
147       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
148     if( !theQuery->ValidateQuery( true ) )
149       {
150       // all unique keys present and required is correct level
151       return 1;
152       }
153     }
154     {
155     std::vector< std::pair<gdcm::Tag, std::string> > keys;
156     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
157     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
158     keys.emplace_back( gdcm::Tag(0x8,0x20), "" ) ;
159     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
160       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
161     if( theQuery->ValidateQuery( true ) )
162       {
163       // all unique keys present and required is incorrect level
164       return 1;
165       }
166     }
167 
168   // IMAGES:
169 
170   theLevel = gdcm::eImage;
171     {
172     std::vector< std::pair<gdcm::Tag, std::string> > keys;
173     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
174     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
175     keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
176     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
177       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
178     if( !theQuery->ValidateQuery( true ) )
179       {
180       // all unique keys present
181       return 1;
182       }
183     }
184 
185     {
186     std::vector< std::pair<gdcm::Tag, std::string> > keys;
187     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
188     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
189     keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
190     keys.emplace_back( gdcm::Tag(0x20,0x13), "" ) ;
191     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
192       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
193     if( !theQuery->ValidateQuery( true ) )
194       {
195       // all unique keys present + required correct level
196       return 1;
197       }
198     }
199 
200     {
201     std::vector< std::pair<gdcm::Tag, std::string> > keys;
202     keys.emplace_back( gdcm::Tag(0x20,0xd), "1.2.3" ) ;
203     keys.emplace_back( gdcm::Tag(0x20,0xe), "4.5.6" ) ;
204     keys.emplace_back( gdcm::Tag(0x8,0x18), "7.8.9" ) ;
205     keys.emplace_back( gdcm::Tag(0x20,0x13), "" ) ;
206     keys.emplace_back( gdcm::Tag(0x20,0x11), "" ) ; // series level
207     gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =
208       gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
209     if( theQuery->ValidateQuery( true ) )
210       {
211       // all unique keys present + required correct level + one incorrect
212       return 1;
213       }
214     }
215 
216   //std::cout << "success" << std::endl;
217   return 0;
218 }
219