# HG changeset patch # User Sebastien Jodogne # Date 1403725696 -7200 # Node ID 1fbe89dc18b55a3d268fee58988dd00e46f00a70 # Parent 63973b76a51fd15222b4ab94ff90416d23bc0a3f extraction of the shared tags diff -r 63973b76a51f -r 1fbe89dc18b5 NEWS --- a/NEWS Wed Jun 25 21:21:18 2014 +0200 +++ b/NEWS Wed Jun 25 21:48:16 2014 +0200 @@ -2,6 +2,7 @@ =============================== * Official support of OS X (Darwin) +* Extraction of the tags shared by all the instances of a patient/study/series * Options to limit the number of results for an incoming C-FIND query * Support of kFreeBSD diff -r 63973b76a51f -r 1fbe89dc18b5 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Jun 25 21:21:18 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Jun 25 21:48:16 2014 +0200 @@ -591,6 +591,72 @@ + static void GetSharedTags(RestApi::GetCall& call) + { + 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; + context.GetIndex().GetChildInstances(instances, publicId); + + // Loop over the instances + bool isFirst = true; + Json::Value 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; + context.ReadJson(full, *it); + SimplifyTags(simplified, full); + + if (simplified.type() != Json::objectValue) + { + return; // Error + } + + // Only keep the tags that are mapped to a string + Json::Value::Members members = simplified.getMemberNames(); + for (size_t i = 0; i < members.size(); i++) + { + Json::ValueType type = simplified[members[i]].type(); + if (type != Json::stringValue) + { + simplified.removeMember(members[i]); + } + } + + if (isFirst) + { + // This is the first instance, keep its tags as such + shared = simplified; + isFirst = false; + } + else + { + // Loop over all the members of the shared tags extracted so + // far. If the value of one of these tags does not match its + // value in the current instance, remove it. + 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()) + { + shared.removeMember(members[i]); + } + } + } + } + + // Success: Send the value of the shared tags + call.GetOutput().AnswerJson(shared); + } + + void OrthancRestApi::RegisterResources() { Register("/instances", ListResources); @@ -612,6 +678,10 @@ 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("/instances/{id}/file", GetInstanceFile); Register("/instances/{id}/export", ExportInstanceFile); Register("/instances/{id}/tags", GetInstanceTags);