Mercurial > hg > orthanc
changeset 1744:b3de74dec2d5 db-changes
integration mainline->db-changes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 26 Oct 2015 12:30:34 +0100 |
parents | 54d78925cbb6 (diff) 8fc1d096aa38 (current diff) |
children | 38dda23c7d7d |
files | Core/DicomFormat/DicomNullValue.h Core/DicomFormat/DicomString.h OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerToolbox.cpp Plugins/Engine/OrthancPlugins.cpp UnitTestsSources/ServerIndexTests.cpp |
diffstat | 20 files changed, 192 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -373,7 +373,7 @@ boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";"); db_.CommitTransaction(); version_ = 6; - } + } }
--- a/OrthancServer/DatabaseWrapper.h Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.h Mon Oct 26 12:30:34 2015 +0100 @@ -315,11 +315,19 @@ return base_.IsExistingResource(internalId); } - virtual void LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value) + virtual void LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value) { - base_.LookupIdentifier(target, tag, value); + base_.LookupIdentifierExact(target, level, tag, value); + } + + virtual void LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value) + { + base_.LookupIdentifierWildcard(target, tag, value); } virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
--- a/OrthancServer/DatabaseWrapperBase.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -665,22 +665,25 @@ } - void DatabaseWrapperBase::LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value) + void DatabaseWrapperBase::LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value) { - assert(tag == DICOM_TAG_PATIENT_ID || - tag == DICOM_TAG_STUDY_INSTANCE_UID || - tag == DICOM_TAG_SERIES_INSTANCE_UID || - tag == DICOM_TAG_SOP_INSTANCE_UID || - tag == DICOM_TAG_ACCESSION_NUMBER); + assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || + (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || + (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || + (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || + (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?"); + "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " + "d.id = r.internalId AND r.resourceType=? AND d.tagGroup=? AND d.tagElement=? AND d.value=?"); - s.BindInt(0, tag.GetGroup()); - s.BindInt(1, tag.GetElement()); - s.BindString(2, value); + s.BindInt(0, level); + s.BindInt(1, tag.GetGroup()); + s.BindInt(2, tag.GetElement()); + s.BindString(3, value); target.clear(); @@ -689,4 +692,13 @@ target.push_back(s.ColumnInt64(0)); } } + + + void DatabaseWrapperBase::LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value) + { + // TODO + throw OrthancException(ErrorCode_NotImplemented); + } }
--- a/OrthancServer/DatabaseWrapperBase.h Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/DatabaseWrapperBase.h Mon Oct 26 12:30:34 2015 +0100 @@ -190,9 +190,14 @@ bool IsExistingResource(int64_t internalId); - void LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value); + void LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value); + + void LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value); }; }
--- a/OrthancServer/IDatabaseWrapper.h Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/IDatabaseWrapper.h Mon Oct 26 12:30:34 2015 +0100 @@ -146,9 +146,33 @@ virtual bool LookupGlobalProperty(std::string& target, GlobalProperty property) = 0; - virtual void LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value) = 0; + virtual void LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value) = 0; + + /** + * Primitive for wildcard matching, as defined in DICOM: + * http://dicom.nema.org/dicom/2013/output/chtml/part04/sect_C.2.html#sect_C.2.2.2.4 + * + * "Any occurrence of an "*" or a "?", then "*" shall match any + * sequence of characters (including a zero length value) and "?" + * shall match any single character. This matching is case + * sensitive, except for Attributes with an PN Value + * Representation (e.g., Patient Name (0010,0010))." + * + * Pay attention to the fact that "*" (resp. "?") generally + * corresponds to "%" (resp. "_") in primitive LIKE of SQL. The + * values "%", "_", "\" should in the user request should + * respectively be escaped as "\%", "\_" and "\\". + * + * This matching must be case sensitive: The special case of PN VR + * is taken into consideration by normalizing the query string in + * method "ServerIndex::LookupIdentifierWildcard()". + **/ + virtual void LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value) = 0; virtual bool LookupMetadata(std::string& target, int64_t id,
--- a/OrthancServer/OrthancMoveRequestHandler.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/OrthancMoveRequestHandler.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -148,7 +148,7 @@ const std::string& content = value.GetContent(); std::list<std::string> ids; - context_.GetIndex().LookupIdentifier(ids, tag, content, level); + context_.GetIndex().LookupIdentifierExact(ids, level, tag, content); if (ids.size() != 1) {
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -892,7 +892,7 @@ ResourceType level) { std::list<std::string> tmp; - index.LookupIdentifier(tmp, tag, value, level); + index.LookupIdentifierExact(tmp, level, tag, value); for (std::list<std::string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
--- a/OrthancServer/ResourceFinder.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/ResourceFinder.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -160,7 +160,7 @@ << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")"; std::list<std::string> resources; - index_.LookupIdentifier(resources, tag, value, level_); + index_.LookupIdentifierExact(resources, level_, tag, value); if (isFilterApplied_) {
--- a/OrthancServer/ServerIndex.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/ServerIndex.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -1895,31 +1895,28 @@ - void ServerIndex::LookupIdentifier(std::list<std::string>& result, - const DicomTag& tag, - const std::string& value, - ResourceType type) + void ServerIndex::LookupIdentifierExact(std::list<std::string>& result, + ResourceType level, + const DicomTag& tag, + const std::string& value) { - assert(tag == DICOM_TAG_PATIENT_ID || - tag == DICOM_TAG_STUDY_INSTANCE_UID || - tag == DICOM_TAG_SERIES_INSTANCE_UID || - tag == DICOM_TAG_SOP_INSTANCE_UID || - tag == DICOM_TAG_ACCESSION_NUMBER); + assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || + (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || + (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || + (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || + (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); result.clear(); boost::mutex::scoped_lock lock(mutex_); std::list<int64_t> id; - db_.LookupIdentifier(id, tag, value); + db_.LookupIdentifierExact(id, level, tag, value); for (std::list<int64_t>::const_iterator it = id.begin(); it != id.end(); ++it) { - if (db_.GetResourceType(*it) == type) - { - result.push_back(db_.GetPublicId(*it)); - } + result.push_back(db_.GetPublicId(*it)); } }
--- a/OrthancServer/ServerIndex.h Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/ServerIndex.h Mon Oct 26 12:30:34 2015 +0100 @@ -235,10 +235,10 @@ /* out */ unsigned int& countInstances, const std::string& publicId); - void LookupIdentifier(std::list<std::string>& result, - const DicomTag& tag, - const std::string& value, - ResourceType type); + void LookupIdentifierExact(std::list<std::string>& result, + ResourceType level, + const DicomTag& tag, + const std::string& value); StoreStatus AddAttachment(const FileInfo& attachment, const std::string& publicId);
--- a/OrthancServer/ServerToolbox.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/ServerToolbox.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -211,7 +211,7 @@ tag != DICOM_TAG_SOP_INSTANCE_UID && tag != DICOM_TAG_ACCESSION_NUMBER) { - s = NormalizeIdentifierTag(s); + s = NormalizeTagForWildcard(s); } database.SetIdentifierTag(resource, tag, s); @@ -376,7 +376,7 @@ } - std::string NormalizeIdentifierTag(const std::string& value) + std::string NormalizeTagForWildcard(const std::string& value) { std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value)); Toolbox::ToUpperCase(s);
--- a/OrthancServer/ServerToolbox.h Fri Oct 23 17:04:22 2015 +0200 +++ b/OrthancServer/ServerToolbox.h Mon Oct 26 12:30:34 2015 +0100 @@ -60,6 +60,6 @@ IStorageArea& storageArea, ResourceType level); - std::string NormalizeIdentifierTag(const std::string& value); + std::string NormalizeTagForWildcard(const std::string& value); } }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -594,9 +594,10 @@ } - void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value) + void OrthancPluginDatabase::LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value) { ResetAnswers(); @@ -605,9 +606,52 @@ tmp.element = tag.GetElement(); tmp.value = value.c_str(); - CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp)); + if (extensions_.lookupIdentifierExact != NULL) + { + CheckSuccess(extensions_.lookupIdentifierExact(GetContext(), payload_, Plugins::Convert(level), &tmp)); + ForwardAnswers(target); + } + else + { + // Emulate "lookupIdentifierExact" if unavailable + + if (backend_.lookupIdentifier == NULL) + { + LOG(ERROR) << "The plugin does not have the extension \"lookupIdentifierExact\""; + throw OrthancException(ErrorCode_DatabasePlugin); + } + + CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp)); + + if (type_ != _OrthancPluginDatabaseAnswerType_None && + type_ != _OrthancPluginDatabaseAnswerType_Int64) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } - ForwardAnswers(target); + target.clear(); + + if (type_ == _OrthancPluginDatabaseAnswerType_Int64) + { + for (std::list<int64_t>::const_iterator + it = answerInt64_.begin(); it != answerInt64_.end(); ++it) + { + if (GetResourceType(*it) == level) + { + target.push_back(*it); + } + } + } + } + } + + + void OrthancPluginDatabase::LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value) + { + // TODO + throw OrthancException(ErrorCode_NotImplemented); }
--- a/Plugins/Engine/OrthancPluginDatabase.h Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.h Mon Oct 26 12:30:34 2015 +0100 @@ -203,9 +203,14 @@ virtual bool LookupGlobalProperty(std::string& target, GlobalProperty property); - virtual void LookupIdentifier(std::list<int64_t>& target, - const DicomTag& tag, - const std::string& value); + virtual void LookupIdentifierExact(std::list<int64_t>& target, + ResourceType level, + const DicomTag& tag, + const std::string& value); + + virtual void LookupIdentifierWildcard(std::list<int64_t>& target, + const DicomTag& tag, + const std::string& value); virtual bool LookupMetadata(std::string& target, int64_t id,
--- a/Plugins/Engine/OrthancPlugins.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -911,7 +911,7 @@ CheckContextAvailable(); std::list<std::string> result; - pimpl_->context_->GetIndex().LookupIdentifier(result, tag, p.argument, level); + pimpl_->context_->GetIndex().LookupIdentifierExact(result, level, tag, p.argument); if (result.size() == 1) {
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Mon Oct 26 12:30:34 2015 +0100 @@ -522,7 +522,9 @@ void* payload, int32_t property); - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + /* Use "OrthancPluginDatabaseExtensions::lookupIdentifierExact" + instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL. + Output: Use OrthancPluginDatabaseAnswerInt64() */ OrthancPluginErrorCode (*lookupIdentifier) ( /* outputs */ OrthancPluginDatabaseContext* context, @@ -661,6 +663,15 @@ /* inputs */ void* payload, int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifierExact) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag); } OrthancPluginDatabaseExtensions; /*<! @endcond */
--- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Mon Oct 26 12:30:34 2015 +0100 @@ -409,10 +409,11 @@ * SeriesInstanceUID (0x0020, 0x000e), SOPInstanceUID (0x0008, * 0x0018) or AccessionNumber (0x0008, 0x0050). **/ - virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, - uint16_t group, - uint16_t element, - const char* value) = 0; + virtual void LookupIdentifierExact(std::list<int64_t>& target /*out*/, + OrthancPluginResourceType resourceType, + uint16_t group, + uint16_t element, + const char* value) = 0; virtual bool LookupMetadata(std::string& target /*out*/, int64_t id, @@ -1295,9 +1296,10 @@ } - static OrthancPluginErrorCode LookupIdentifier(OrthancPluginDatabaseContext* context, - void* payload, - const OrthancPluginDicomTag* tag) + static OrthancPluginErrorCode LookupIdentifierExact(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1305,7 +1307,7 @@ try { std::list<int64_t> target; - backend->LookupIdentifier(target, tag->group, tag->element, tag->value); + backend->LookupIdentifierExact(target, resourceType, tag->group, tag->element, tag->value); for (std::list<int64_t>::const_iterator it = target.begin(); it != target.end(); ++it) @@ -1824,7 +1826,7 @@ params.logExportedResource = LogExportedResource; params.lookupAttachment = LookupAttachment; params.lookupGlobalProperty = LookupGlobalProperty; - params.lookupIdentifier = LookupIdentifier; + params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) params.lookupMetadata = LookupMetadata; params.lookupParent = LookupParent; @@ -1846,6 +1848,7 @@ extensions.getDatabaseVersion = GetDatabaseVersion; extensions.upgradeDatabase = UpgradeDatabase; extensions.clearMainDicomTags = ClearMainDicomTags; + extensions.lookupIdentifierExact = LookupIdentifierExact; // New in Orthanc 0.9.5 (db v6) OrthancPluginDatabaseContext* database = OrthancPluginRegisterDatabaseBackendV2(context, ¶ms, &extensions, &backend); if (!context)
--- a/Plugins/Samples/DatabasePlugin/Database.h Fri Oct 23 17:04:22 2015 +0200 +++ b/Plugins/Samples/DatabasePlugin/Database.h Mon Oct 26 12:30:34 2015 +0100 @@ -187,12 +187,14 @@ return base_.LookupGlobalProperty(target, static_cast<Orthanc::GlobalProperty>(property)); } - virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, - uint16_t group, - uint16_t element, - const char* value) + virtual void LookupIdentifierExact(std::list<int64_t>& target /*out*/, + OrthancPluginResourceType level, + uint16_t group, + uint16_t element, + const char* value) { - base_.LookupIdentifier(target, Orthanc::DicomTag(group, element), value); + base_.LookupIdentifierExact(target, Orthanc::Plugins::Convert(level), + Orthanc::DicomTag(group, element), value); } virtual bool LookupMetadata(std::string& target /*out*/,
--- a/Resources/Configuration.json Fri Oct 23 17:04:22 2015 +0200 +++ b/Resources/Configuration.json Mon Oct 26 12:30:34 2015 +0100 @@ -258,8 +258,9 @@ // deleted as new requests are issued. "QueryRetrieveSize" : 10, - // When handling a C-Find SCP request, setting this flag to "false" - // will enable case-insensitive match for PN value representation - // (such as PatientName). By default, the search is case-insensitive. + // When handling a C-Find SCP request, setting this flag to "true" + // will enable case-sensitive match for PN value representation + // (such as PatientName). By default, the search is + // case-insensitive, which does not follow the DICOM standard. "CaseSensitivePN" : false }
--- a/UnitTestsSources/ServerIndexTests.cpp Fri Oct 23 17:04:22 2015 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Mon Oct 26 12:30:34 2015 +0100 @@ -692,29 +692,29 @@ std::list<int64_t> s; - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "0"); + index_->LookupIdentifierExact(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "0"); ASSERT_EQ(2u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[0]) != s.end()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[2]) != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "0"); + index_->LookupIdentifierExact(s, ResourceType_Series, DICOM_TAG_SERIES_INSTANCE_UID, "0"); ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[3]) != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); + index_->LookupIdentifierExact(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1"); + index_->LookupIdentifierExact(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, "1"); ASSERT_EQ(1u, s.size()); ASSERT_TRUE(std::find(s.begin(), s.end(), a[1]) != s.end()); - index_->LookupIdentifier(s, DICOM_TAG_SERIES_INSTANCE_UID, "1"); + index_->LookupIdentifierExact(s, ResourceType_Series, DICOM_TAG_SERIES_INSTANCE_UID, "1"); ASSERT_EQ(0u, s.size()); /*{ std::list<std::string> s; - context.GetIndex().LookupIdentifier(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); + context.GetIndex().LookupIdentifierExact(s, DICOM_TAG_STUDY_INSTANCE_UID, "1.2.250.1.74.20130819132500.29000036381059"); for (std::list<std::string>::iterator i = s.begin(); i != s.end(); i++) { std::cout << "*** " << *i << std::endl;;