# HG changeset patch # User Sebastien Jodogne # Date 1410362456 -7200 # Node ID 94c5f6623b3a684706f59a7cb1de505dc01e525f # Parent f167b672db9413c32ebe63472cd7428250f7f048 URIs to get all the children of a given resource in a single REST call diff -r f167b672db94 -r 94c5f6623b3a NEWS --- a/NEWS Wed Sep 10 16:38:28 2014 +0200 +++ b/NEWS Wed Sep 10 17:20:56 2014 +0200 @@ -5,9 +5,10 @@ ------- * Creation of ZIP archives for media storage, with DICOMDIR +* URIs to get all the children of a given resource in a single REST call +* "/tools/lookup" URI to map DICOM UIDs to Orthanc identifiers * Support of index-only mode (using the "StoreDicom" option) * Plugins can implement a custom storage area -* "/tools/lookup" URI to map DICOM UIDs to Orthanc identifiers Minor ----- diff -r f167b672db94 -r 94c5f6623b3a OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Sep 10 16:38:28 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Sep 10 17:20:56 2014 +0200 @@ -810,6 +810,67 @@ } + template + static void GetChildResources(RestApiGetCall& call) + { + ServerIndex& index = OrthancRestApi::GetIndex(call); + + std::list a, b, c; + a.push_back(call.GetUriComponent("id", "")); + + ResourceType type = start; + while (type != end) + { + b.clear(); + + for (std::list::const_iterator + it = a.begin(); it != a.end(); it++) + { + index.GetChildren(c, *it); + b.splice(b.begin(), c); + } + + switch (type) + { + case ResourceType_Patient: + type = ResourceType_Study; + break; + + case ResourceType_Study: + type = ResourceType_Series; + break; + + case ResourceType_Series: + type = ResourceType_Instance; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + a.clear(); + a.splice(a.begin(), b); + } + + Json::Value result = Json::arrayValue; + + for (std::list::const_iterator + it = a.begin(); it != a.end(); it++) + { + Json::Value item; + + if (OrthancRestApi::GetIndex(call).LookupResource(item, *it, end)) + { + result.append(item); + } + } + + call.GetOutput().AnswerJson(result); + } + + + void OrthancRestApi::RegisterResources() { Register("/instances", ListResources); @@ -880,6 +941,13 @@ Register("/tools/lookup", Lookup); + Register("/patients/{id}/studies", GetChildResources); + Register("/patients/{id}/series", GetChildResources); + Register("/patients/{id}/instances", GetChildResources); + Register("/studies/{id}/series", GetChildResources); + Register("/studies/{id}/instances", GetChildResources); + Register("/series/{id}/instances", GetChildResources); + Register("/instances/{id}/content/*", GetRawContent); } }