Mercurial > hg > orthanc
comparison OrthancServer/ServerToolbox.cpp @ 1745:38dda23c7d7d db-changes
LookupIdentifierQuery
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 26 Oct 2015 13:47:50 +0100 |
parents | b3de74dec2d5 |
children | ca69082ab200 |
comparison
equal
deleted
inserted
replaced
1744:b3de74dec2d5 | 1745:38dda23c7d7d |
---|---|
36 #include "../Core/DicomFormat/DicomArray.h" | 36 #include "../Core/DicomFormat/DicomArray.h" |
37 #include "../Core/FileStorage/StorageAccessor.h" | 37 #include "../Core/FileStorage/StorageAccessor.h" |
38 #include "../Core/Logging.h" | 38 #include "../Core/Logging.h" |
39 #include "../Core/OrthancException.h" | 39 #include "../Core/OrthancException.h" |
40 #include "ParsedDicomFile.h" | 40 #include "ParsedDicomFile.h" |
41 #include "LookupIdentifierQuery.h" | |
41 | 42 |
42 #include <cassert> | 43 #include <cassert> |
43 | 44 |
44 namespace Orthanc | 45 namespace Orthanc |
45 { | 46 { |
191 } | 192 } |
192 } | 193 } |
193 } | 194 } |
194 | 195 |
195 | 196 |
196 static void SetIdentifierTagInternal(IDatabaseWrapper& database, | |
197 int64_t resource, | |
198 const DicomMap& tags, | |
199 const DicomTag& tag) | |
200 { | |
201 const DicomValue* value = tags.TestAndGetValue(tag); | |
202 if (value != NULL && | |
203 !value->IsNull() && | |
204 !value->IsBinary()) | |
205 { | |
206 std::string s = value->GetContent(); | |
207 | |
208 if (tag != DICOM_TAG_PATIENT_ID && | |
209 tag != DICOM_TAG_STUDY_INSTANCE_UID && | |
210 tag != DICOM_TAG_SERIES_INSTANCE_UID && | |
211 tag != DICOM_TAG_SOP_INSTANCE_UID && | |
212 tag != DICOM_TAG_ACCESSION_NUMBER) | |
213 { | |
214 s = NormalizeTagForWildcard(s); | |
215 } | |
216 | |
217 database.SetIdentifierTag(resource, tag, s); | |
218 } | |
219 } | |
220 | |
221 | |
222 static void AttachPatientInformation(IDatabaseWrapper& database, | |
223 int64_t resource, | |
224 const DicomMap& dicomSummary) | |
225 { | |
226 DicomMap tags; | |
227 dicomSummary.ExtractPatientInformation(tags); | |
228 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID); | |
229 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME); | |
230 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE); | |
231 SetMainDicomTagsInternal(database, resource, tags); | |
232 } | |
233 | |
234 | |
235 void SetMainDicomTags(IDatabaseWrapper& database, | 197 void SetMainDicomTags(IDatabaseWrapper& database, |
236 int64_t resource, | 198 int64_t resource, |
237 ResourceType level, | 199 ResourceType level, |
238 const DicomMap& dicomSummary) | 200 const DicomMap& dicomSummary) |
239 { | 201 { |
240 // WARNING: The database should be locked with a transaction! | 202 // WARNING: The database should be locked with a transaction! |
241 | 203 |
204 LookupIdentifierQuery::StoreIdentifiers(database, resource, level, dicomSummary); | |
205 | |
242 DicomMap tags; | 206 DicomMap tags; |
243 | 207 |
244 switch (level) | 208 switch (level) |
245 { | 209 { |
246 case ResourceType_Patient: | 210 case ResourceType_Patient: |
247 AttachPatientInformation(database, resource, dicomSummary); | 211 dicomSummary.ExtractPatientInformation(tags); |
248 break; | 212 break; |
249 | 213 |
250 case ResourceType_Study: | 214 case ResourceType_Study: |
251 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) | 215 // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) |
252 AttachPatientInformation(database, resource, dicomSummary); | 216 dicomSummary.ExtractPatientInformation(tags); |
217 SetMainDicomTagsInternal(database, resource, tags); | |
253 | 218 |
254 dicomSummary.ExtractStudyInformation(tags); | 219 dicomSummary.ExtractStudyInformation(tags); |
255 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_INSTANCE_UID); | |
256 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_ACCESSION_NUMBER); | |
257 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION); | |
258 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE); | |
259 break; | 220 break; |
260 | 221 |
261 case ResourceType_Series: | 222 case ResourceType_Series: |
262 dicomSummary.ExtractSeriesInformation(tags); | 223 dicomSummary.ExtractSeriesInformation(tags); |
263 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SERIES_INSTANCE_UID); | |
264 break; | 224 break; |
265 | 225 |
266 case ResourceType_Instance: | 226 case ResourceType_Instance: |
267 dicomSummary.ExtractInstanceInformation(tags); | 227 dicomSummary.ExtractInstanceInformation(tags); |
268 SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SOP_INSTANCE_UID); | |
269 break; | 228 break; |
270 | 229 |
271 default: | 230 default: |
272 throw OrthancException(ErrorCode_InternalError); | 231 throw OrthancException(ErrorCode_InternalError); |
273 } | 232 } |
372 | 331 |
373 database.ClearMainDicomTags(resource); | 332 database.ClearMainDicomTags(resource); |
374 Toolbox::SetMainDicomTags(database, resource, level, dicomSummary); | 333 Toolbox::SetMainDicomTags(database, resource, level, dicomSummary); |
375 } | 334 } |
376 } | 335 } |
377 | |
378 | |
379 std::string NormalizeTagForWildcard(const std::string& value) | |
380 { | |
381 std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value)); | |
382 Toolbox::ToUpperCase(s); | |
383 return s; | |
384 } | |
385 } | 336 } |
386 } | 337 } |