# HG changeset patch # User Sebastien Jodogne # Date 1527062884 -7200 # Node ID 3603a2e145921d70affc273fa11d05d4041f4990 # Parent c9bb0c89ccc13642d2e68915511cc015f620300c New option "?short" to list DICOM tags using their hexadecimal ID diff -r c9bb0c89ccc1 -r 3603a2e14592 NEWS --- a/NEWS Tue May 22 08:10:55 2018 +0200 +++ b/NEWS Wed May 23 10:08:04 2018 +0200 @@ -9,11 +9,19 @@ REST API -------- -* ".../tags" URI was returning only the first value of DicomTags containing - multiple numerical value. It now returns all values in a string separated - by \\ (i.e.: "1\\2\\3"). Note that, for data already in Orthanc, you'll need - to reconstruct the data by sending a POST request to the ".../reconstruct" URI. - This change triggered an update of ORTHANC_API_VERSION from 1.0 to 1.1 +* New option "?short" to list DICOM tags using their hexadecimal ID in: + - "/instances/.../tags?short" + - "/instances/.../header?short" + - "/{patients|studies|series}/.../instances-tags?short" + - "/{patients|studies|series}/.../shared-tags?short" + - "/{patients|studies|series|instances}/.../module?short" + - "/studies/.../module-patient?short" +* "/instances/.../tags" URI was returning only the first value of + DicomTags containing multiple numerical value. It now returns all + values in a string separated by \\ (i.e.: "1\\2\\3"). Note that, + for data already in Orthanc, you'll need to reconstruct the data by + sending a POST request to the ".../reconstruct" URI. This change + triggered an update of ORTHANC_API_VERSION from 1.0 to 1.1 Maintenance ----------- diff -r c9bb0c89ccc1 -r 3603a2e14592 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue May 22 08:10:55 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed May 23 10:08:04 2018 +0200 @@ -50,12 +50,12 @@ { static void AnswerDicomAsJson(RestApiCall& call, const Json::Value& dicom, - bool simplify) + DicomToJsonFormat mode) { - if (simplify) + if (mode != DicomToJsonFormat_Full) { Json::Value simplified; - ServerToolbox::SimplifyTags(simplified, dicom, DicomToJsonFormat_Human); + ServerToolbox::SimplifyTags(simplified, dicom, mode); call.GetOutput().AnswerJson(simplified); } else @@ -65,6 +65,30 @@ } + static DicomToJsonFormat GetDicomFormat(const RestApiGetCall& call) + { + if (call.HasArgument("simplify")) + { + return DicomToJsonFormat_Human; + } + else if (call.HasArgument("short")) + { + return DicomToJsonFormat_Short; + } + else + { + return DicomToJsonFormat_Full; + } + } + + + static void AnswerDicomAsJson(RestApiGetCall& call, + const Json::Value& dicom) + { + AnswerDicomAsJson(call, dicom, GetDicomFormat(call)); + } + + static void ParseSetOfTags(std::set& target, const RestApiGetCall& call, const std::string& argument) @@ -236,7 +260,7 @@ } - template + template static void GetInstanceTags(RestApiGetCall& call) { ServerContext& context = OrthancRestApi::GetContext(call); @@ -246,18 +270,18 @@ std::set ignoreTagLength; ParseSetOfTags(ignoreTagLength, call, "ignore-length"); - if (simplify || + if (format != DicomToJsonFormat_Full || !ignoreTagLength.empty()) { Json::Value full; context.ReadDicomAsJson(full, publicId, ignoreTagLength); - AnswerDicomAsJson(call, full, simplify); + AnswerDicomAsJson(call, full, format); } else { // This path allows to avoid the JSON decoding if no - // simplification is asked, or if no "ignore-length" argument is - // present + // simplification is asked, and if no "ignore-length" argument + // is present std::string full; context.ReadDicomAsJson(full, publicId); call.GetOutput().AnswerBuffer(full, "application/json"); @@ -267,15 +291,22 @@ static void GetInstanceTagsBis(RestApiGetCall& call) { - bool simplify = call.HasArgument("simplify"); - - if (simplify) + switch (GetDicomFormat(call)) { - GetInstanceTags(call); - } - else - { - GetInstanceTags(call); + case DicomToJsonFormat_Human: + GetInstanceTags(call); + break; + + case DicomToJsonFormat_Short: + GetInstanceTags(call); + break; + + case DicomToJsonFormat_Full: + GetInstanceTags(call); + break; + + default: + throw OrthancException(ErrorCode_InternalError); } } @@ -1044,13 +1075,12 @@ { ServerContext& context = OrthancRestApi::GetContext(call); std::string publicId = call.GetUriComponent("id", ""); - bool simplify = call.HasArgument("simplify"); Json::Value sharedTags; if (ExtractSharedTags(sharedTags, context, publicId)) { // Success: Send the value of the shared tags - AnswerDicomAsJson(call, sharedTags, simplify); + AnswerDicomAsJson(call, sharedTags); } } @@ -1071,7 +1101,6 @@ ServerContext& context = OrthancRestApi::GetContext(call); std::string publicId = call.GetUriComponent("id", ""); - bool simplify = call.HasArgument("simplify"); std::set ignoreTagLength; ParseSetOfTags(ignoreTagLength, call, "ignore-length"); @@ -1111,7 +1140,7 @@ } } - AnswerDicomAsJson(call, result, simplify); + AnswerDicomAsJson(call, result); } @@ -1306,7 +1335,7 @@ { ServerContext& context = OrthancRestApi::GetContext(call); std::string publicId = call.GetUriComponent("id", ""); - bool simplify = call.HasArgument("simplify"); + DicomToJsonFormat format = GetDicomFormat(call); std::set ignoreTagLength; ParseSetOfTags(ignoreTagLength, call, "ignore-length"); @@ -1325,10 +1354,10 @@ Json::Value full; context.ReadDicomAsJson(full, *it, ignoreTagLength); - if (simplify) + if (format != DicomToJsonFormat_Full) { Json::Value simplified; - ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human); + ServerToolbox::SimplifyTags(simplified, full, format); result[*it] = simplified; } else @@ -1409,7 +1438,6 @@ ServerContext& context = OrthancRestApi::GetContext(call); std::string publicId = call.GetUriComponent("id", ""); - bool simplify = call.HasArgument("simplify"); std::string dicomContent; context.ReadDicom(dicomContent, publicId); @@ -1422,7 +1450,7 @@ Json::Value header; dicom.HeaderToJson(header, DicomToJsonFormat_Full); - AnswerDicomAsJson(call, header, simplify); + AnswerDicomAsJson(call, header); } @@ -1495,7 +1523,7 @@ Register("/instances/{id}/file", GetInstanceFile); Register("/instances/{id}/export", ExportInstanceFile); Register("/instances/{id}/tags", GetInstanceTagsBis); - Register("/instances/{id}/simplified-tags", GetInstanceTags); + Register("/instances/{id}/simplified-tags", GetInstanceTags); Register("/instances/{id}/frames", ListFrames); Register("/instances/{id}/frames/{frame}/preview", GetImage);