# HG changeset patch # User Sebastien Jodogne # Date 1352802050 -3600 # Node ID b6cef9d45cc3ce35432f0a86246433d3c2a10df1 # Parent ccbc2cf64a0df45370a944a10f5bfb665fa0b505 getallpublicids diff -r ccbc2cf64a0d -r b6cef9d45cc3 NEWS --- a/NEWS Mon Nov 12 18:03:48 2012 +0100 +++ b/NEWS Tue Nov 13 11:20:50 2012 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Full refactoring of the DB schema * Generate a sample configuration file from command line diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Tue Nov 13 11:20:50 2012 +0100 @@ -469,6 +469,19 @@ return static_cast(s.ColumnInt64(0)); } + void DatabaseWrapper::GetAllPublicIds(Json::Value& target, + ResourceType resourceType) + { + SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?"); + s.BindInt(0, resourceType); + + target = Json::arrayValue; + while (s.Step()) + { + target.append(s.ColumnString(0)); + } + } + DatabaseWrapper::DatabaseWrapper(const std::string& path, IServerIndexListener& listener) : diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.h Tue Nov 13 11:20:50 2012 +0100 @@ -144,6 +144,9 @@ uint64_t GetTotalUncompressedSize(); + void GetAllPublicIds(Json::Value& target, + ResourceType resourceType); + DatabaseWrapper(const std::string& path, IServerIndexListener& listener); diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Tue Nov 13 11:20:50 2012 +0100 @@ -446,7 +446,7 @@ if (method == "GET") { result = Json::Value(Json::arrayValue); - index_.GetAllUuids(result, "Instances"); + index_.GetAllUuids(result, ResourceType_Instance); existingResource = true; } else if (method == "POST") @@ -483,13 +483,13 @@ result = Json::Value(Json::arrayValue); if (uri[0] == "instances") - index_.GetAllUuids(result, "Instances"); + index_.GetAllUuids(result, ResourceType_Instance); else if (uri[0] == "series") - index_.GetAllUuids(result, "Series"); + index_.GetAllUuids(result, ResourceType_Series); else if (uri[0] == "studies") - index_.GetAllUuids(result, "Studies"); + index_.GetAllUuids(result, ResourceType_Study); else if (uri[0] == "patients") - index_.GetAllUuids(result, "Patients"); + index_.GetAllUuids(result, ResourceType_Patient); existingResource = true; } diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/PrepareDatabase2.sql --- a/OrthancServer/PrepareDatabase2.sql Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/PrepareDatabase2.sql Tue Nov 13 11:20:50 2012 +0100 @@ -56,6 +56,7 @@ CREATE INDEX ChildrenIndex ON Resources(parentId); CREATE INDEX PublicIndex ON Resources(publicId); +CREATE INDEX ResourceTypeIndex ON Resources(resourceType); CREATE INDEX MainDicomTagsIndex1 ON MainDicomTags(id); CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement); diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Tue Nov 13 11:20:50 2012 +0100 @@ -537,13 +537,14 @@ return StoreStatus_AlreadyStored; } - // Create the patient/study/series/instance hierarchy + // Create the instance instance = db2_->CreateResource(hasher.HashInstance(), ResourceType_Instance); DicomMap dicom; dicomSummary.ExtractInstanceInformation(dicom); db2_->SetMainDicomTags(instance, dicom); + // Create the patient/study/series/instance hierarchy if (!db2_->LookupResource(hasher.HashSeries(), series, type)) { // This is a new series @@ -980,10 +981,35 @@ void ServerIndex::GetAllUuids(Json::Value& target, - const std::string& tableName) + ResourceType resourceType) { + boost::mutex::scoped_lock scoped_lock(mutex_); + + std::string tableName; + + switch (resourceType) + { + case ResourceType_Patient: + tableName = "Patients"; + break; + + case ResourceType_Study: + tableName = "Studies"; + break; + + case ResourceType_Series: + tableName = "Series"; + break; + + case ResourceType_Instance: + tableName = "Instances"; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + assert(target.type() == Json::arrayValue); - boost::mutex::scoped_lock scoped_lock(mutex_); std::string query = "SELECT uuid FROM " + tableName; SQLite::Statement s(db_, query); diff -r ccbc2cf64a0d -r b6cef9d45cc3 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Mon Nov 12 18:03:48 2012 +0100 +++ b/OrthancServer/ServerIndex.h Tue Nov 13 11:20:50 2012 +0100 @@ -163,7 +163,7 @@ const std::string& instanceUuid); void GetAllUuids(Json::Value& target, - const std::string& tableName); + ResourceType resourceType); bool DeletePatient(Json::Value& target, const std::string& patientUuid) diff -r ccbc2cf64a0d -r b6cef9d45cc3 UnitTests/ServerIndex.cpp --- a/UnitTests/ServerIndex.cpp Mon Nov 12 18:03:48 2012 +0100 +++ b/UnitTests/ServerIndex.cpp Tue Nov 13 11:20:50 2012 +0100 @@ -54,6 +54,24 @@ index.CreateResource("g", ResourceType_Study) // 6 }; + { + Json::Value t; + index.GetAllPublicIds(t, ResourceType_Patient); + + ASSERT_EQ(1, t.size()); + ASSERT_EQ("a", t[0u].asString()); + + index.GetAllPublicIds(t, ResourceType_Series); + ASSERT_EQ(1, t.size()); + ASSERT_EQ("c", t[0u].asString()); + + index.GetAllPublicIds(t, ResourceType_Study); + ASSERT_EQ(2, t.size()); + + index.GetAllPublicIds(t, ResourceType_Instance); + ASSERT_EQ(3, t.size()); + } + index.SetGlobalProperty("Hello", "World"); index.AttachChild(a[0], a[1]);