Mercurial > hg > orthanc
comparison OrthancServer/LookupIdentifierQuery.cpp @ 1745:38dda23c7d7d db-changes
LookupIdentifierQuery
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 26 Oct 2015 13:47:50 +0100 |
parents | |
children | d143db00a794 |
comparison
equal
deleted
inserted
replaced
1744:b3de74dec2d5 | 1745:38dda23c7d7d |
---|---|
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 | |
33 #include "PrecompiledHeadersServer.h" | |
34 #include "LookupIdentifierQuery.h" | |
35 | |
36 #include "../Core/OrthancException.h" | |
37 | |
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 | |
73 | |
74 LookupIdentifierQuery::~LookupIdentifierQuery() | |
75 { | |
76 for (Constraints::iterator it = constraints_.begin(); | |
77 it != constraints_.end(); ++it) | |
78 { | |
79 delete *it; | |
80 } | |
81 } | |
82 | |
83 | |
84 | |
85 void LookupIdentifierQuery::CheckIndex(size_t index) const | |
86 { | |
87 if (index >= constraints_.size()) | |
88 { | |
89 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
90 } | |
91 } | |
92 | |
93 | |
94 static void LoadIdentifiers(const DicomTag*& tags, | |
95 size_t& size, | |
96 ResourceType level) | |
97 { | |
98 switch (level) | |
99 { | |
100 case ResourceType_Patient: | |
101 tags = patientIdentifiers; | |
102 size = sizeof(patientIdentifiers) / sizeof(DicomTag); | |
103 break; | |
104 | |
105 case ResourceType_Study: | |
106 tags = studyIdentifiers; | |
107 size = sizeof(studyIdentifiers) / sizeof(DicomTag); | |
108 break; | |
109 | |
110 case ResourceType_Series: | |
111 tags = seriesIdentifiers; | |
112 size = sizeof(seriesIdentifiers) / sizeof(DicomTag); | |
113 break; | |
114 | |
115 case ResourceType_Instance: | |
116 tags = instanceIdentifiers; | |
117 size = sizeof(instanceIdentifiers) / sizeof(DicomTag); | |
118 break; | |
119 | |
120 default: | |
121 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
122 } | |
123 } | |
124 | |
125 | |
126 bool LookupIdentifierQuery::IsIdentifier(const DicomTag& tag) const | |
127 { | |
128 const DicomTag* tags; | |
129 size_t size; | |
130 | |
131 LoadIdentifiers(tags, size, level_); | |
132 | |
133 for (size_t i = 0; i < size; i++) | |
134 { | |
135 if (tag == tags[i]) | |
136 { | |
137 return true; | |
138 } | |
139 } | |
140 | |
141 return false; | |
142 } | |
143 | |
144 | |
145 void LookupIdentifierQuery::AddConstraint(DicomTag tag, | |
146 IdentifierConstraintType type, | |
147 const std::string& value) | |
148 { | |
149 assert(IsIdentifier(tag)); | |
150 constraints_.push_back(new Constraint(tag, type, NormalizeIdentifier(value))); | |
151 } | |
152 | |
153 | |
154 const DicomTag& LookupIdentifierQuery::GetTag(size_t index) const | |
155 { | |
156 CheckIndex(index); | |
157 return constraints_[index]->tag_; | |
158 } | |
159 | |
160 | |
161 IdentifierConstraintType LookupIdentifierQuery::GetType(size_t index) const | |
162 { | |
163 CheckIndex(index); | |
164 return constraints_[index]->type_; | |
165 } | |
166 | |
167 | |
168 const std::string& LookupIdentifierQuery::GetValue(size_t index) const | |
169 { | |
170 CheckIndex(index); | |
171 return constraints_[index]->value_; | |
172 } | |
173 | |
174 | |
175 std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value) | |
176 { | |
177 std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value)); | |
178 Toolbox::ToUpperCase(s); | |
179 return s; | |
180 } | |
181 | |
182 | |
183 void LookupIdentifierQuery::StoreIdentifiers(IDatabaseWrapper& database, | |
184 int64_t resource, | |
185 ResourceType level, | |
186 const DicomMap& map) | |
187 { | |
188 const DicomTag* tags; | |
189 size_t size; | |
190 | |
191 LoadIdentifiers(tags, size, level); | |
192 | |
193 for (size_t i = 0; i < size; i++) | |
194 { | |
195 const DicomValue* value = map.TestAndGetValue(tags[i]); | |
196 if (value != NULL && | |
197 !value->IsNull() && | |
198 !value->IsBinary()) | |
199 { | |
200 std::string s = NormalizeIdentifier(value->GetContent()); | |
201 database.SetIdentifierTag(resource, tags[i], s); | |
202 } | |
203 } | |
204 } | |
205 } |