Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.cpp @ 1752:c3d8ec63a179 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 27 Oct 2015 17:45:05 +0100 |
parents | fb569ee09a69 |
children | 318c2e83c2bd |
rev | line source |
---|---|
1745 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
1747 | 33 #include "../PrecompiledHeadersServer.h" |
1745 | 34 #include "LookupIdentifierQuery.h" |
35 | |
1747 | 36 #include "../../Core/OrthancException.h" |
1746 | 37 #include "SetOfResources.h" |
1745 | 38 |
39 #include <cassert> | |
40 | |
41 | |
42 | |
43 namespace Orthanc | |
44 { | |
45 static const DicomTag patientIdentifiers[] = | |
46 { | |
47 DICOM_TAG_PATIENT_ID, | |
48 DICOM_TAG_PATIENT_NAME, | |
49 DICOM_TAG_PATIENT_BIRTH_DATE | |
50 }; | |
51 | |
52 static const DicomTag studyIdentifiers[] = | |
53 { | |
54 DICOM_TAG_PATIENT_ID, | |
55 DICOM_TAG_PATIENT_NAME, | |
56 DICOM_TAG_PATIENT_BIRTH_DATE, | |
57 DICOM_TAG_STUDY_INSTANCE_UID, | |
58 DICOM_TAG_ACCESSION_NUMBER, | |
59 DICOM_TAG_STUDY_DESCRIPTION, | |
60 DICOM_TAG_STUDY_DATE | |
61 }; | |
62 | |
63 static const DicomTag seriesIdentifiers[] = | |
64 { | |
65 DICOM_TAG_SERIES_INSTANCE_UID | |
66 }; | |
67 | |
68 static const DicomTag instanceIdentifiers[] = | |
69 { | |
70 DICOM_TAG_SOP_INSTANCE_UID | |
71 }; | |
72 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
73 |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
74 void LookupIdentifierQuery::LoadIdentifiers(const DicomTag*& tags, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
75 size_t& size, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
76 ResourceType level) |
1745 | 77 { |
78 switch (level) | |
79 { | |
80 case ResourceType_Patient: | |
81 tags = patientIdentifiers; | |
82 size = sizeof(patientIdentifiers) / sizeof(DicomTag); | |
83 break; | |
84 | |
85 case ResourceType_Study: | |
86 tags = studyIdentifiers; | |
87 size = sizeof(studyIdentifiers) / sizeof(DicomTag); | |
88 break; | |
89 | |
90 case ResourceType_Series: | |
91 tags = seriesIdentifiers; | |
92 size = sizeof(seriesIdentifiers) / sizeof(DicomTag); | |
93 break; | |
94 | |
95 case ResourceType_Instance: | |
96 tags = instanceIdentifiers; | |
97 size = sizeof(instanceIdentifiers) / sizeof(DicomTag); | |
98 break; | |
99 | |
100 default: | |
101 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
102 } | |
103 } | |
104 | |
105 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
106 LookupIdentifierQuery::Disjunction::~Disjunction() |
1748 | 107 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
108 for (size_t i = 0; i < disjunction_.size(); i++) |
1748 | 109 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
110 delete disjunction_[i]; |
1748 | 111 } |
112 } | |
113 | |
114 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
115 void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
116 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
117 const std::string& value) |
1748 | 118 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
119 disjunction_.push_back(new Constraint(tag, type, value)); |
1748 | 120 } |
121 | |
1746 | 122 |
123 LookupIdentifierQuery::~LookupIdentifierQuery() | |
124 { | |
125 for (Constraints::iterator it = constraints_.begin(); | |
126 it != constraints_.end(); ++it) | |
127 { | |
128 delete *it; | |
129 } | |
130 } | |
131 | |
132 | |
133 | |
1748 | 134 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag, |
135 ResourceType level) | |
1745 | 136 { |
137 const DicomTag* tags; | |
138 size_t size; | |
139 | |
1748 | 140 LoadIdentifiers(tags, size, level); |
1745 | 141 |
142 for (size_t i = 0; i < size; i++) | |
143 { | |
144 if (tag == tags[i]) | |
145 { | |
146 return true; | |
147 } | |
148 } | |
149 | |
150 return false; | |
151 } | |
152 | |
153 | |
154 void LookupIdentifierQuery::AddConstraint(DicomTag tag, | |
155 IdentifierConstraintType type, | |
156 const std::string& value) | |
157 { | |
158 assert(IsIdentifier(tag)); | |
1751
fb569ee09a69
LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
159 constraints_.push_back(new Disjunction); |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
160 constraints_.back()->Add(tag, type, value); |
1745 | 161 } |
162 | |
163 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
164 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction() |
1745 | 165 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
166 constraints_.push_back(new Disjunction); |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
167 return *constraints_.back(); |
1745 | 168 } |
169 | |
170 | |
171 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value) | |
172 { | |
173 std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value)); | |
174 Toolbox::ToUpperCase(s); | |
175 return s; | |
176 } | |
177 | |
178 | |
179 void LookupIdentifierQuery::StoreIdentifiers(IDatabaseWrapper& database, | |
180 int64_t resource, | |
181 ResourceType level, | |
182 const DicomMap& map) | |
183 { | |
184 const DicomTag* tags; | |
185 size_t size; | |
186 | |
187 LoadIdentifiers(tags, size, level); | |
188 | |
189 for (size_t i = 0; i < size; i++) | |
190 { | |
191 const DicomValue* value = map.TestAndGetValue(tags[i]); | |
192 if (value != NULL && | |
193 !value->IsNull() && | |
194 !value->IsBinary()) | |
195 { | |
196 std::string s = NormalizeIdentifier(value->GetContent()); | |
197 database.SetIdentifierTag(resource, tags[i], s); | |
198 } | |
199 } | |
200 } | |
1746 | 201 |
202 | |
203 void LookupIdentifierQuery::Apply(std::list<std::string>& result, | |
204 IDatabaseWrapper& database) | |
205 { | |
206 SetOfResources resources(database, level_); | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
207 Apply(resources, database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
208 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
209 resources.Flatten(result); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
210 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
211 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
212 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
213 void LookupIdentifierQuery::Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
214 IDatabaseWrapper& database) |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
215 { |
1746 | 216 for (size_t i = 0; i < GetSize(); i++) |
217 { | |
1748 | 218 std::list<int64_t> a; |
219 | |
220 for (size_t j = 0; j < constraints_[i]->GetSize(); j++) | |
221 { | |
222 const Constraint& constraint = constraints_[i]->GetConstraint(j); | |
223 std::list<int64_t> b; | |
224 database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue()); | |
225 | |
226 a.splice(a.end(), b); | |
227 } | |
228 | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
229 result.Intersect(a); |
1746 | 230 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
231 } |
1746 | 232 |
1745 | 233 } |