# HG changeset patch # User Sebastien Jodogne # Date 1422957215 -3600 # Node ID 8dac11c78d71775519169c17c80c168aa33857e7 # Parent d6a65dc6d0ac10042232041cd98a0bcffb9046dc URIs to get all the parents of a given resource in a single REST call diff -r d6a65dc6d0ac -r 8dac11c78d71 NEWS --- a/NEWS Tue Feb 03 10:25:56 2015 +0100 +++ b/NEWS Tue Feb 03 10:53:35 2015 +0100 @@ -4,6 +4,7 @@ General ------- +* URIs to get all the parents of a given resource in a single REST call * Support of HTTP proxy * Instances without PatientID are now allowed * Support of Tudor DICOM in Query/Retrieve diff -r d6a65dc6d0ac -r 8dac11c78d71 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Feb 03 10:25:56 2015 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Feb 03 10:53:35 2015 +0100 @@ -912,6 +912,47 @@ + template + static void GetParentResource(RestApiGetCall& call) + { + assert(start > end); + + ServerIndex& index = OrthancRestApi::GetIndex(call); + + std::string current = call.GetUriComponent("id", ""); + ResourceType currentType = start; + while (currentType > end) + { + std::string parent; + if (!index.LookupParent(parent, current)) + { + // Error that could happen if the resource gets deleted by + // another concurrent call + return; + } + + current = parent; + switch (currentType) + { + case ResourceType_Instance: currentType = ResourceType_Series; break; + case ResourceType_Series: currentType = ResourceType_Study; break; + case ResourceType_Study: currentType = ResourceType_Patient; break; + default: throw OrthancException(ErrorCode_InternalError); + } + } + + assert(currentType == end); + + Json::Value result; + if (index.LookupResource(result, current, end)) + { + call.GetOutput().AnswerJson(result); + } + } + + + void OrthancRestApi::RegisterResources() { Register("/instances", ListResources); @@ -989,6 +1030,13 @@ Register("/studies/{id}/instances", GetChildResources); Register("/series/{id}/instances", GetChildResources); + Register("/studies/{id}/patient", GetParentResource); + Register("/series/{id}/patient", GetParentResource); + Register("/series/{id}/study", GetParentResource); + Register("/instances/{id}/patient", GetParentResource); + Register("/instances/{id}/study", GetParentResource); + Register("/instances/{id}/series", GetParentResource); + Register("/patients/{id}/instances-tags", GetChildInstancesTags); Register("/studies/{id}/instances-tags", GetChildInstancesTags); Register("/series/{id}/instances-tags", GetChildInstancesTags);