# HG changeset patch # User Sebastien Jodogne # Date 1446113340 -3600 # Node ID 51db4a25a741adf6d83946e83ab6588d23e6e662 # Parent e268412adcf18afa67b3954c8df31094d8ed7510 LookupIdentifier is plugins diff -r e268412adcf1 -r 51db4a25a741 OrthancServer/DatabaseWrapperBase.cpp --- a/OrthancServer/DatabaseWrapperBase.cpp Wed Oct 28 12:59:18 2015 +0100 +++ b/OrthancServer/DatabaseWrapperBase.cpp Thu Oct 29 11:09:00 2015 +0100 @@ -681,41 +681,6 @@ - /** - - TODO REMOVE THIS - - void DatabaseWrapperBase::LookupIdentifierExact(std::list& target, - ResourceType level, - const DicomTag& tag, - const std::string& value) - { - 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 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, level); - s.BindInt(1, tag.GetGroup()); - s.BindInt(2, tag.GetElement()); - s.BindString(3, value); - - target.clear(); - - while (s.Step()) - { - target.push_back(s.ColumnInt64(0)); - } - } - */ - - - void DatabaseWrapperBase::LookupIdentifier(std::list& target, ResourceType level, const DicomTag& tag, diff -r e268412adcf1 -r 51db4a25a741 Plugins/Engine/OrthancPluginDatabase.cpp --- a/Plugins/Engine/OrthancPluginDatabase.cpp Wed Oct 28 12:59:18 2015 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Thu Oct 29 11:09:00 2015 +0100 @@ -277,8 +277,15 @@ void OrthancPluginDatabase::GetAllInternalIds(std::list& target, ResourceType resourceType) { - // TODO - throw OrthancException(ErrorCode_NotImplemented); + if (extensions_.getAllInternalIds == NULL) + { + LOG(ERROR) << "The database plugin does not implement the GetAllInternalIds primitive"; + throw OrthancException(ErrorCode_DatabasePlugin); + } + + ResetAnswers(); + CheckSuccess(extensions_.getAllInternalIds(GetContext(), payload_, Plugins::Convert(resourceType))); + ForwardAnswers(target); } @@ -602,70 +609,27 @@ } - /* - - TODO REMOVE THIS - - void OrthancPluginDatabase::LookupIdentifierExact(std::list& target, - ResourceType level, - const DicomTag& tag, - const std::string& value) + void OrthancPluginDatabase::LookupIdentifier(std::list& result, + ResourceType level, + const DicomTag& tag, + IdentifierConstraintType type, + const std::string& value) { - ResetAnswers(); + if (extensions_.lookupIdentifier3 == NULL) + { + LOG(ERROR) << "The database plugin does not implement the GetAllInternalIds primitive"; + throw OrthancException(ErrorCode_DatabasePlugin); + } OrthancPluginDicomTag tmp; tmp.group = tag.GetGroup(); tmp.element = tag.GetElement(); tmp.value = value.c_str(); - 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); - } - - target.clear(); - - if (type_ == _OrthancPluginDatabaseAnswerType_Int64) - { - for (std::list::const_iterator - it = answerInt64_.begin(); it != answerInt64_.end(); ++it) - { - if (GetResourceType(*it) == level) - { - target.push_back(*it); - } - } - } - } - }*/ - - - void OrthancPluginDatabase::LookupIdentifier(std::list& result, - ResourceType level, - const DicomTag& tag, - IdentifierConstraintType type, - const std::string& value) - { - // TODO - throw OrthancException(ErrorCode_NotImplemented); + ResetAnswers(); + CheckSuccess(extensions_.lookupIdentifier3(GetContext(), payload_, Plugins::Convert(level), + &tmp, Plugins::Convert(type))); + ForwardAnswers(result); } diff -r e268412adcf1 -r 51db4a25a741 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Oct 28 12:59:18 2015 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Oct 29 11:09:00 2015 +0100 @@ -302,6 +302,7 @@ sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) || + sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || static_cast(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast(DicomToJsonFlags_IncludeBinary) || static_cast(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast(DicomToJsonFlags_IncludePrivateTags) || static_cast(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast(DicomToJsonFlags_IncludeUnknownTags) || diff -r e268412adcf1 -r 51db4a25a741 Plugins/Engine/PluginsEnumerations.cpp --- a/Plugins/Engine/PluginsEnumerations.cpp Wed Oct 28 12:59:18 2015 +0100 +++ b/Plugins/Engine/PluginsEnumerations.cpp Thu Oct 29 11:09:00 2015 +0100 @@ -229,6 +229,28 @@ } + OrthancPluginIdentifierConstraint Convert(IdentifierConstraintType constraint) + { + switch (constraint) + { + case IdentifierConstraintType_Equal: + return OrthancPluginIdentifierConstraint_Equal; + + case IdentifierConstraintType_GreaterOrEqual: + return OrthancPluginIdentifierConstraint_GreaterOrEqual; + + case IdentifierConstraintType_SmallerOrEqual: + return OrthancPluginIdentifierConstraint_SmallerOrEqual; + + case IdentifierConstraintType_Wildcard: + return OrthancPluginIdentifierConstraint_Wildcard; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0 DcmEVR Convert(OrthancPluginValueRepresentation vr) { diff -r e268412adcf1 -r 51db4a25a741 Plugins/Engine/PluginsEnumerations.h --- a/Plugins/Engine/PluginsEnumerations.h Wed Oct 28 12:59:18 2015 +0100 +++ b/Plugins/Engine/PluginsEnumerations.h Thu Oct 29 11:09:00 2015 +0100 @@ -61,6 +61,8 @@ DicomToJsonFormat Convert(OrthancPluginDicomToJsonFormat format); + OrthancPluginIdentifierConstraint Convert(IdentifierConstraintType constraint); + #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0 DcmEVR Convert(OrthancPluginValueRepresentation vr); #endif diff -r e268412adcf1 -r 51db4a25a741 Plugins/Include/orthanc/OrthancCDatabasePlugin.h --- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Wed Oct 28 12:59:18 2015 +0100 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Thu Oct 29 11:09:00 2015 +0100 @@ -522,7 +522,7 @@ void* payload, int32_t property); - /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier2" + /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier3" instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL. Output: Use OrthancPluginDatabaseAnswerInt64() */ OrthancPluginErrorCode (*lookupIdentifier) ( @@ -664,17 +664,23 @@ void* payload, int64_t id); -#if 0 /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*lookupIdentifier2) ( + OrthancPluginErrorCode (*getAllInternalIds) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifier3) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload, OrthancPluginResourceType resourceType, - const OrthancPluginDicomTag* tag); -#endif - + const OrthancPluginDicomTag* tag, + OrthancPluginIdentifierConstraint constraint); } OrthancPluginDatabaseExtensions; /*& target, + OrthancPluginResourceType resourceType) = 0; + virtual void GetAllPublicIds(std::list& target, OrthancPluginResourceType resourceType) = 0; @@ -403,17 +406,12 @@ virtual bool LookupGlobalProperty(std::string& target /*out*/, int32_t property) = 0; - /** - * "Identifiers" are necessarily one of the following tags: - * PatientID (0x0010, 0x0020), StudyInstanceUID (0x0020, 0x000d), - * SeriesInstanceUID (0x0020, 0x000e), SOPInstanceUID (0x0008, - * 0x0018) or AccessionNumber (0x0008, 0x0050). - **/ - virtual void LookupIdentifierExact(std::list& target /*out*/, - OrthancPluginResourceType resourceType, - uint16_t group, - uint16_t element, - const char* value) = 0; + virtual void LookupIdentifier(std::list& target /*out*/, + OrthancPluginResourceType resourceType, + uint16_t group, + uint16_t element, + OrthancPluginIdentifierConstraint constraint, + const char* value) = 0; virtual bool LookupMetadata(std::string& target /*out*/, int64_t id, @@ -684,6 +682,39 @@ } + static OrthancPluginErrorCode GetAllInternalIds(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType) + { + IDatabaseBackend* backend = reinterpret_cast(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list target; + backend->GetAllInternalIds(target, resourceType); + + for (std::list::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + static OrthancPluginErrorCode GetAllPublicIds(OrthancPluginDatabaseContext* context, void* payload, OrthancPluginResourceType resourceType) @@ -1296,10 +1327,11 @@ } - static OrthancPluginErrorCode LookupIdentifierExact(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType, - const OrthancPluginDicomTag* tag) + static OrthancPluginErrorCode LookupIdentifier3(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag, + OrthancPluginIdentifierConstraint constraint) { IDatabaseBackend* backend = reinterpret_cast(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1307,7 +1339,7 @@ try { std::list target; - backend->LookupIdentifierExact(target, resourceType, tag->group, tag->element, tag->value); + backend->LookupIdentifier(target, resourceType, tag->group, tag->element, constraint, tag->value); for (std::list::const_iterator it = target.begin(); it != target.end(); ++it) @@ -1848,7 +1880,8 @@ extensions.getDatabaseVersion = GetDatabaseVersion; extensions.upgradeDatabase = UpgradeDatabase; extensions.clearMainDicomTags = ClearMainDicomTags; - extensions.lookupIdentifierExact = LookupIdentifierExact; // New in Orthanc 0.9.5 (db v6) + extensions.getAllInternalIds = GetAllInternalIds; // New in Orthanc 0.9.5 (db v6) + extensions.lookupIdentifier3 = LookupIdentifier3; // New in Orthanc 0.9.5 (db v6) OrthancPluginDatabaseContext* database = OrthancPluginRegisterDatabaseBackendV2(context, ¶ms, &extensions, &backend); if (!context)