# HG changeset patch # User Sebastien Jodogne # Date 1403786276 -7200 # Node ID abac5c83134f49150e53ac097d0fe3933dd200ae # Parent bd5659f2a50aef9d7d23462e0d550edda21c0af0 simplified and extensive shared-tags diff -r bd5659f2a50a -r abac5c83134f OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Jun 25 21:53:50 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Jun 26 14:37:56 2014 +0200 @@ -591,11 +591,10 @@ - static void GetSharedTags(RestApi::GetCall& call) + static bool ExtractSharedTags(Json::Value& shared, + ServerContext& context, + const std::string& publicId) { - ServerContext& context = OrthancRestApi::GetContext(call); - std::string publicId = call.GetUriComponent("id", ""); - // Retrieve all the instances of this patient/study/series typedef std::list Instances; Instances instances; @@ -603,17 +602,17 @@ // Loop over the instances bool isFirst = true; - Json::Value shared = Json::objectValue; + shared = Json::objectValue; for (Instances::const_iterator it = instances.begin(); it != instances.end(); it++) { // Get the tags of the current instance, in the simplified format - Json::Value full, simplified; + Json::Value tags; try { - context.ReadJson(full, *it); + context.ReadJson(tags, *it); } catch (OrthancException&) { @@ -622,28 +621,28 @@ continue; } - SimplifyTags(simplified, full); - - if (simplified.type() != Json::objectValue) + if (tags.type() != Json::objectValue) { - return; // Error + return false; // Error } // Only keep the tags that are mapped to a string - Json::Value::Members members = simplified.getMemberNames(); + Json::Value::Members members = tags.getMemberNames(); for (size_t i = 0; i < members.size(); i++) { - Json::ValueType type = simplified[members[i]].type(); - if (type != Json::stringValue) + const Json::Value& tag = tags[members[i]]; + if (tag.type() != Json::objectValue || + tag["Type"].type() != Json::stringValue || + tag["Type"].asString() != "String") { - simplified.removeMember(members[i]); + tags.removeMember(members[i]); } } if (isFirst) { // This is the first instance, keep its tags as such - shared = simplified; + shared = tags; isFirst = false; } else @@ -654,8 +653,8 @@ members = shared.getMemberNames(); for (size_t i = 0; i < members.size(); i++) { - if (!simplified.isMember(members[i]) || - simplified[members[i]].asString() != shared[members[i]].asString()) + if (!tags.isMember(members[i]) || + tags[members[i]]["Value"].asString() != shared[members[i]]["Value"].asString()) { shared.removeMember(members[i]); } @@ -663,8 +662,32 @@ } } - // Success: Send the value of the shared tags - call.GetOutput().AnswerJson(shared); + return true; + } + + + + template + static void GetSharedTags(RestApi::GetCall& call) + { + ServerContext& context = OrthancRestApi::GetContext(call); + std::string publicId = call.GetUriComponent("id", ""); + + Json::Value sharedTags; + if (ExtractSharedTags(sharedTags, context, publicId)) + { + // Success: Send the value of the shared tags + if (simplify) + { + Json::Value simplified; + SimplifyTags(simplified, sharedTags); + call.GetOutput().AnswerJson(simplified); + } + else + { + call.GetOutput().AnswerJson(sharedTags); + } + } } @@ -689,9 +712,12 @@ Register("/studies/{id}/statistics", GetResourceStatistics); Register("/series/{id}/statistics", GetResourceStatistics); - Register("/patients/{id}/shared-tags", GetSharedTags); - Register("/series/{id}/shared-tags", GetSharedTags); - Register("/studies/{id}/shared-tags", GetSharedTags); + Register("/patients/{id}/shared-tags", GetSharedTags); + Register("/patients/{id}/simplified-shared-tags", GetSharedTags); + Register("/series/{id}/shared-tags", GetSharedTags); + Register("/series/{id}/simplified-shared-tags", GetSharedTags); + Register("/studies/{id}/shared-tags", GetSharedTags); + Register("/studies/{id}/simplified-shared-tags", GetSharedTags); Register("/instances/{id}/file", GetInstanceFile); Register("/instances/{id}/export", ExportInstanceFile);