# HG changeset patch # User Sebastien Jodogne # Date 1354900864 -3600 # Node ID 337c506461d208a76befb20c592ad002a0ee83e3 # Parent 98d78841066a0221bffbe7259bfe1b81428731f4 protection from rest api diff -r 98d78841066a -r 337c506461d2 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Fri Dec 07 15:03:31 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Fri Dec 07 18:21:04 2012 +0100 @@ -607,6 +607,40 @@ } + // Get information about a single patient ----------------------------------- + + static void IsProtectedPatient(RestApi::GetCall& call) + { + RETRIEVE_CONTEXT(call); + std::string publicId = call.GetUriComponent("id", ""); + bool isProtected = context.GetIndex().IsProtectedPatient(publicId); + call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain"); + } + + + static void SetPatientProtection(RestApi::PutCall& call) + { + RETRIEVE_CONTEXT(call); + std::string publicId = call.GetUriComponent("id", ""); + std::string s = Toolbox::StripSpaces(call.GetPutBody()); + + if (s == "0") + { + context.GetIndex().SetProtectedPatient(publicId, false); + call.GetOutput().AnswerBuffer("", "text/plain"); + } + else if (s == "1") + { + context.GetIndex().SetProtectedPatient(publicId, true); + call.GetOutput().AnswerBuffer("", "text/plain"); + } + else + { + // Bad request + } + } + + // Get information about a single instance ---------------------------------- static void GetInstanceFile(RestApi::GetCall& call) @@ -845,6 +879,8 @@ Register("/studies/{id}/archive", GetArchive); Register("/series/{id}/archive", GetArchive); + Register("/patients/{id}/protected", IsProtectedPatient); + Register("/patients/{id}/protected", SetPatientProtection); Register("/instances/{id}/file", GetInstanceFile); Register("/instances/{id}/tags", GetInstanceTags); Register("/instances/{id}/simplified-tags", GetInstanceTags); diff -r 98d78841066a -r 337c506461d2 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Dec 07 15:03:31 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Dec 07 18:21:04 2012 +0100 @@ -868,7 +868,7 @@ StandaloneRecycling(); } - void ServerIndex::StandaloneRecycling() + void ServerIndex::StandaloneRecycling() { // WARNING: No mutex here, do not include this as a public method std::auto_ptr t(db_->StartTransaction()); @@ -877,4 +877,46 @@ t->Commit(); listener_->CommitFilesToRemove(); } + + + bool ServerIndex::IsProtectedPatient(const std::string& publicId) + { + boost::mutex::scoped_lock lock(mutex_); + + // Lookup for the requested resource + int64_t id; + ResourceType type; + if (!db_->LookupResource(publicId, id, type) || + type != ResourceType_Patient) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + return db_->IsProtectedPatient(id); + } + + + void ServerIndex::SetProtectedPatient(const std::string& publicId, + bool isProtected) + { + boost::mutex::scoped_lock lock(mutex_); + + // Lookup for the requested resource + int64_t id; + ResourceType type; + if (!db_->LookupResource(publicId, id, type) || + type != ResourceType_Patient) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + // No need for a SQLite::Transaction here, as we only make 1 write to the DB + db_->SetProtectedPatient(id, isProtected); + + if (isProtected) + LOG(INFO) << "Patient " << publicId << " has been protected"; + else + LOG(INFO) << "Patient " << publicId << " has been unprotected"; + } + } diff -r 98d78841066a -r 337c506461d2 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Fri Dec 07 15:03:31 2012 +0100 +++ b/OrthancServer/ServerIndex.h Fri Dec 07 18:21:04 2012 +0100 @@ -137,5 +137,9 @@ bool GetLastExportedResource(Json::Value& target); + bool IsProtectedPatient(const std::string& publicId); + + void SetProtectedPatient(const std::string& publicId, + bool isProtected); }; }