comparison OrthancServer/Search/LookupResource.cpp @ 1755:39c37a994b2f db-changes

handling of DICOM_TAG_MODALITIES_IN_STUDY
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2015 12:02:15 +0100
parents 3a4f7dc00f49
children 03b030680e3d
comparison
equal deleted inserted replaced
1754:3a4f7dc00f49 1755:39c37a994b2f
307 Levels::const_iterator it = levels_.find(level); 307 Levels::const_iterator it = levels_.find(level);
308 if (it != levels_.end()) 308 if (it != levels_.end())
309 { 309 {
310 it->second->Apply(candidates, database); 310 it->second->Apply(candidates, database);
311 } 311 }
312
313 if (level == ResourceType_Study &&
314 modalitiesInStudy_.get() != NULL)
315 {
316 // There is a constraint on the "ModalitiesInStudy" DICOM
317 // extension. Check out whether one child series has one of the
318 // allowed modalities
319 std::list<int64_t> allStudies, matchingStudies;
320 candidates.Flatten(allStudies);
321
322 for (std::list<int64_t>::const_iterator
323 study = allStudies.begin(); study != allStudies.end(); ++study)
324 {
325 std::list<int64_t> childrenSeries;
326 database.GetChildrenInternalId(childrenSeries, *study);
327
328 for (std::list<int64_t>::const_iterator
329 series = childrenSeries.begin(); series != childrenSeries.end(); ++series)
330 {
331 DicomMap tags;
332 database.GetMainDicomTags(tags, *series);
333
334 const DicomValue* value = tags.TestAndGetValue(DICOM_TAG_MODALITY);
335 if (value != NULL &&
336 !value->IsNull() &&
337 !value->IsBinary())
338 {
339 if (modalitiesInStudy_->Match(value->GetContent()))
340 {
341 matchingStudies.push_back(*study);
342 break;
343 }
344 }
345 }
346 }
347
348 candidates.Intersect(matchingStudies);
349 }
312 } 350 }
313 351
314 352
315 void LookupResource::FindCandidates(std::list<int64_t>& result, 353 void LookupResource::FindCandidates(std::list<int64_t>& result,
316 IDatabaseWrapper& database) const 354 IDatabaseWrapper& database) const
357 395
358 candidates.Flatten(result); 396 candidates.Flatten(result);
359 } 397 }
360 398
361 399
362 void LookupResource::Add(const DicomTag& tag, 400 void LookupResource::SetModalitiesInStudy(const std::string& modalities)
363 const std::string& dicomQuery, 401 {
364 bool caseSensitivePN) 402 modalitiesInStudy_.reset(new ListConstraint(DICOM_TAG_MODALITIES_IN_STUDY,
403 true /* case sensitive */));
404
405 std::vector<std::string> items;
406 Toolbox::TokenizeString(items, modalities, '\\');
407
408 for (size_t i = 0; i < items.size(); i++)
409 {
410 modalitiesInStudy_->AddAllowedValue(items[i]);
411 }
412 }
413
414
415 void LookupResource::AddDicomConstraint(const DicomTag& tag,
416 const std::string& dicomQuery,
417 bool caseSensitivePN)
365 { 418 {
366 ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag); 419 ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
367 420
368 bool sensitive = true; 421 bool sensitive = true;
369 if (vr == ValueRepresentation_PatientName) 422 if (vr == ValueRepresentation_PatientName)
372 } 425 }
373 426
374 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained 427 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
375 // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html 428 // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html
376 429
377 if ((vr == ValueRepresentation_Date || 430 if (tag == DICOM_TAG_MODALITIES_IN_STUDY)
378 vr == ValueRepresentation_DateTime || 431 {
379 vr == ValueRepresentation_Time) && 432 SetModalitiesInStudy(dicomQuery);
380 dicomQuery.find('-') != std::string::npos) 433 }
434 else if ((vr == ValueRepresentation_Date ||
435 vr == ValueRepresentation_DateTime ||
436 vr == ValueRepresentation_Time) &&
437 dicomQuery.find('-') != std::string::npos)
381 { 438 {
382 /** 439 /**
383 * Range matching is only defined for TM, DA and DT value 440 * Range matching is only defined for TM, DA and DT value
384 * representations. This code fixes issues 35 and 37. 441 * representations. This code fixes issues 35 and 37.
385 * 442 *