Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 3029:ea653ec47f31 db-changes
new class: DatabaseConstraint
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Dec 2018 18:56:55 +0100 |
parents | fd587cf51a89 |
children | 25afa7b8cb51 |
comparison
equal
deleted
inserted
replaced
3027:fd587cf51a89 | 3029:ea653ec47f31 |
---|---|
2554 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; | 2554 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; |
2555 } | 2555 } |
2556 } | 2556 } |
2557 | 2557 |
2558 | 2558 |
2559 void ServerIndex::NormalizeLookup(DatabaseLookup& target, | 2559 |
2560 void ServerIndex::NormalizeLookup(std::vector<DatabaseConstraint>& target, | |
2560 const DatabaseLookup& source, | 2561 const DatabaseLookup& source, |
2561 ResourceType queryLevel) const | 2562 ResourceType queryLevel) const |
2562 { | 2563 { |
2563 assert(mainDicomTagsRegistry_.get() != NULL); | 2564 assert(mainDicomTagsRegistry_.get() != NULL); |
2565 | |
2566 target.clear(); | |
2567 target.reserve(source.GetConstraintsCount()); | |
2564 | 2568 |
2565 for (size_t i = 0; i < source.GetConstraintsCount(); i++) | 2569 for (size_t i = 0; i < source.GetConstraintsCount(); i++) |
2566 { | 2570 { |
2567 const DicomTagConstraint& constraint = source.GetConstraint(i); | 2571 const DicomTagConstraint& constraint = source.GetConstraint(i); |
2568 | 2572 |
2572 | 2576 |
2573 if (IsResourceLevelAboveOrEqual(tagLevel, queryLevel) && | 2577 if (IsResourceLevelAboveOrEqual(tagLevel, queryLevel) && |
2574 (tagType == DicomTagType_Identifier || | 2578 (tagType == DicomTagType_Identifier || |
2575 tagType == DicomTagType_Main)) | 2579 tagType == DicomTagType_Main)) |
2576 { | 2580 { |
2577 if (tagType == DicomTagType_Identifier) | 2581 // Use the fact that patient-level tags are copied at the study level |
2582 if (queryLevel != ResourceType_Patient && | |
2583 tagLevel == ResourceType_Patient) | |
2578 { | 2584 { |
2579 if (constraint.GetConstraintType() == ConstraintType_List) | 2585 tagLevel = ResourceType_Study; |
2580 { | |
2581 if (!constraint.GetValues().empty()) | |
2582 { | |
2583 std::auto_ptr<DicomTagConstraint> normalized( | |
2584 new DicomTagConstraint(constraint.GetTag(), | |
2585 ConstraintType_List, true, | |
2586 constraint.IsMandatory())); | |
2587 | |
2588 normalized->SetTagType(tagType); | |
2589 | |
2590 for (std::set<std::string>::const_iterator | |
2591 value = constraint.GetValues().begin(); | |
2592 value != constraint.GetValues().end(); ++value) | |
2593 { | |
2594 normalized->AddValue(ServerToolbox::NormalizeIdentifier(*value)); | |
2595 } | |
2596 | |
2597 target.AddConstraint(normalized.release()); | |
2598 } | |
2599 } | |
2600 else | |
2601 { | |
2602 std::string value = ServerToolbox::NormalizeIdentifier(constraint.GetValue()); | |
2603 | |
2604 std::auto_ptr<DicomTagConstraint> normalized( | |
2605 new DicomTagConstraint(constraint.GetTag(), | |
2606 constraint.GetConstraintType(), | |
2607 value, true, | |
2608 constraint.IsMandatory())); | |
2609 | |
2610 normalized->SetTagType(tagType); | |
2611 target.AddConstraint(normalized.release()); | |
2612 } | |
2613 } | 2586 } |
2614 else if (tagType == DicomTagType_Main) | 2587 |
2588 DatabaseConstraint c(constraint, tagLevel, tagType); | |
2589 | |
2590 // Avoid universal constraints | |
2591 if (!(c.GetConstraintType() == ConstraintType_Equal && | |
2592 c.GetSingleValue() == "") && | |
2593 !(c.GetConstraintType() == ConstraintType_Wildcard && | |
2594 c.GetSingleValue() == "*")) | |
2615 { | 2595 { |
2616 std::auto_ptr<DicomTagConstraint> clone(constraint.Clone()); | 2596 target.push_back(c); |
2617 clone->SetTagType(tagType); | |
2618 target.AddConstraint(clone.release()); | |
2619 } | |
2620 else if (tagType == DicomTagType_Generic) | |
2621 { | |
2622 // This tag is not indexed in the database, skip it | |
2623 } | |
2624 else | |
2625 { | |
2626 throw OrthancException(ErrorCode_InternalError); | |
2627 } | 2597 } |
2628 } | 2598 } |
2629 } | 2599 } |
2630 } | 2600 } |
2631 | 2601 |
2633 void ServerIndex::ApplyLookupPatients(std::vector<std::string>& patientsId, | 2603 void ServerIndex::ApplyLookupPatients(std::vector<std::string>& patientsId, |
2634 std::vector<std::string>& instancesId, | 2604 std::vector<std::string>& instancesId, |
2635 const DatabaseLookup& lookup, | 2605 const DatabaseLookup& lookup, |
2636 size_t limit) | 2606 size_t limit) |
2637 { | 2607 { |
2638 DatabaseLookup normalized; | 2608 std::vector<DatabaseConstraint> normalized; |
2639 NormalizeLookup(normalized, lookup, ResourceType_Patient); | 2609 NormalizeLookup(normalized, lookup, ResourceType_Patient); |
2640 | 2610 |
2641 { | 2611 { |
2642 boost::mutex::scoped_lock lock(mutex_); | 2612 boost::mutex::scoped_lock lock(mutex_); |
2643 db_.ApplyLookupPatients(patientsId, instancesId, normalized, limit); | 2613 db_.ApplyLookupPatients(patientsId, instancesId, normalized, limit); |
2649 std::vector<std::string>& instancesId, | 2619 std::vector<std::string>& instancesId, |
2650 const DatabaseLookup& lookup, | 2620 const DatabaseLookup& lookup, |
2651 ResourceType queryLevel, | 2621 ResourceType queryLevel, |
2652 size_t limit) | 2622 size_t limit) |
2653 { | 2623 { |
2654 DatabaseLookup normalized; | 2624 std::vector<DatabaseConstraint> normalized; |
2655 NormalizeLookup(normalized, lookup, queryLevel); | 2625 NormalizeLookup(normalized, lookup, queryLevel); |
2656 | 2626 |
2657 { | 2627 { |
2658 boost::mutex::scoped_lock lock(mutex_); | 2628 boost::mutex::scoped_lock lock(mutex_); |
2659 db_.ApplyLookupResources(resourcesId, instancesId, normalized, queryLevel, limit); | 2629 db_.ApplyLookupResources(resourcesId, instancesId, normalized, queryLevel, limit); |