Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 2409:e4045b3c9772
ignore-length argument if retrieving DICOM tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 27 Sep 2017 17:36:13 +0200 |
parents | 26a0cc24d48d |
children | 878b59270859 |
comparison
equal
deleted
inserted
replaced
2408:26a0cc24d48d | 2409:e4045b3c9772 |
---|---|
46 #include "../SliceOrdering.h" | 46 #include "../SliceOrdering.h" |
47 | 47 |
48 | 48 |
49 namespace Orthanc | 49 namespace Orthanc |
50 { | 50 { |
51 static void AnswerDicomAsJson(RestApiCall& call, | |
52 const Json::Value& dicom, | |
53 bool simplify) | |
54 { | |
55 if (simplify) | |
56 { | |
57 Json::Value simplified; | |
58 ServerToolbox::SimplifyTags(simplified, dicom, DicomToJsonFormat_Human); | |
59 call.GetOutput().AnswerJson(simplified); | |
60 } | |
61 else | |
62 { | |
63 call.GetOutput().AnswerJson(dicom); | |
64 } | |
65 } | |
66 | |
67 | |
68 static void ParseSetOfTags(std::set<DicomTag>& target, | |
69 const RestApiGetCall& call, | |
70 const std::string& argument) | |
71 { | |
72 target.clear(); | |
73 | |
74 if (call.HasArgument(argument)) | |
75 { | |
76 std::vector<std::string> tags; | |
77 Toolbox::TokenizeString(tags, call.GetArgument(argument, ""), ','); | |
78 | |
79 for (size_t i = 0; i < tags.size(); i++) | |
80 { | |
81 target.insert(FromDcmtkBridge::ParseTag(tags[i])); | |
82 } | |
83 } | |
84 } | |
85 | |
86 | |
51 // List all the patients, studies, series or instances ---------------------- | 87 // List all the patients, studies, series or instances ---------------------- |
52 | 88 |
53 static void AnswerListOfResources(RestApiOutput& output, | 89 static void AnswerListOfResources(RestApiOutput& output, |
54 ServerIndex& index, | 90 ServerIndex& index, |
55 const std::list<std::string>& resources, | 91 const std::list<std::string>& resources, |
204 static void GetInstanceTags(RestApiGetCall& call) | 240 static void GetInstanceTags(RestApiGetCall& call) |
205 { | 241 { |
206 ServerContext& context = OrthancRestApi::GetContext(call); | 242 ServerContext& context = OrthancRestApi::GetContext(call); |
207 | 243 |
208 std::string publicId = call.GetUriComponent("id", ""); | 244 std::string publicId = call.GetUriComponent("id", ""); |
245 | |
246 std::set<DicomTag> ignoreTagLength; | |
247 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | |
209 | 248 |
210 if (simplify) | 249 if (simplify || |
250 !ignoreTagLength.empty()) | |
211 { | 251 { |
212 Json::Value full; | 252 Json::Value full; |
213 context.ReadDicomAsJson(full, publicId); | 253 context.ReadDicomAsJson(full, publicId, ignoreTagLength); |
214 | 254 AnswerDicomAsJson(call, full, simplify); |
215 Json::Value simplified; | |
216 ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human); | |
217 call.GetOutput().AnswerJson(simplified); | |
218 } | 255 } |
219 else | 256 else |
220 { | 257 { |
258 // This path allows to avoid the JSON decoding if no | |
259 // simplification is asked, or if no "ignore-length" argument is | |
260 // present | |
221 std::string full; | 261 std::string full; |
222 context.ReadDicomAsJson(full, publicId); | 262 context.ReadDicomAsJson(full, publicId); |
223 call.GetOutput().AnswerBuffer(full, "application/json"); | 263 call.GetOutput().AnswerBuffer(full, "application/json"); |
224 } | 264 } |
225 } | 265 } |
1008 | 1048 |
1009 Json::Value sharedTags; | 1049 Json::Value sharedTags; |
1010 if (ExtractSharedTags(sharedTags, context, publicId)) | 1050 if (ExtractSharedTags(sharedTags, context, publicId)) |
1011 { | 1051 { |
1012 // Success: Send the value of the shared tags | 1052 // Success: Send the value of the shared tags |
1013 if (simplify) | 1053 AnswerDicomAsJson(call, sharedTags, simplify); |
1014 { | |
1015 Json::Value simplified; | |
1016 ServerToolbox::SimplifyTags(simplified, sharedTags, DicomToJsonFormat_Human); | |
1017 call.GetOutput().AnswerJson(simplified); | |
1018 } | |
1019 else | |
1020 { | |
1021 call.GetOutput().AnswerJson(sharedTags); | |
1022 } | |
1023 } | 1054 } |
1024 } | 1055 } |
1025 | 1056 |
1026 | 1057 |
1027 static void GetModuleInternal(RestApiGetCall& call, | 1058 static void GetModuleInternal(RestApiGetCall& call, |
1040 | 1071 |
1041 ServerContext& context = OrthancRestApi::GetContext(call); | 1072 ServerContext& context = OrthancRestApi::GetContext(call); |
1042 std::string publicId = call.GetUriComponent("id", ""); | 1073 std::string publicId = call.GetUriComponent("id", ""); |
1043 bool simplify = call.HasArgument("simplify"); | 1074 bool simplify = call.HasArgument("simplify"); |
1044 | 1075 |
1076 std::set<DicomTag> ignoreTagLength; | |
1077 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | |
1078 | |
1045 typedef std::set<DicomTag> ModuleTags; | 1079 typedef std::set<DicomTag> ModuleTags; |
1046 ModuleTags moduleTags; | 1080 ModuleTags moduleTags; |
1047 DicomTag::AddTagsForModule(moduleTags, module); | 1081 DicomTag::AddTagsForModule(moduleTags, module); |
1048 | 1082 |
1049 Json::Value tags; | 1083 Json::Value tags; |
1062 | 1096 |
1063 // Select one child instance | 1097 // Select one child instance |
1064 publicId = instances.front(); | 1098 publicId = instances.front(); |
1065 } | 1099 } |
1066 | 1100 |
1067 context.ReadDicomAsJson(tags, publicId); | 1101 context.ReadDicomAsJson(tags, publicId, ignoreTagLength); |
1068 | 1102 |
1069 // Filter the tags of the instance according to the module | 1103 // Filter the tags of the instance according to the module |
1070 Json::Value result = Json::objectValue; | 1104 Json::Value result = Json::objectValue; |
1071 for (ModuleTags::const_iterator tag = moduleTags.begin(); tag != moduleTags.end(); ++tag) | 1105 for (ModuleTags::const_iterator tag = moduleTags.begin(); tag != moduleTags.end(); ++tag) |
1072 { | 1106 { |
1075 { | 1109 { |
1076 result[s] = tags[s]; | 1110 result[s] = tags[s]; |
1077 } | 1111 } |
1078 } | 1112 } |
1079 | 1113 |
1080 if (simplify) | 1114 AnswerDicomAsJson(call, result, simplify); |
1081 { | |
1082 Json::Value simplified; | |
1083 ServerToolbox::SimplifyTags(simplified, result, DicomToJsonFormat_Human); | |
1084 call.GetOutput().AnswerJson(simplified); | |
1085 } | |
1086 else | |
1087 { | |
1088 call.GetOutput().AnswerJson(result); | |
1089 } | |
1090 } | 1115 } |
1091 | 1116 |
1092 | 1117 |
1093 | 1118 |
1094 template <enum ResourceType resourceType, | 1119 template <enum ResourceType resourceType, |
1281 { | 1306 { |
1282 ServerContext& context = OrthancRestApi::GetContext(call); | 1307 ServerContext& context = OrthancRestApi::GetContext(call); |
1283 std::string publicId = call.GetUriComponent("id", ""); | 1308 std::string publicId = call.GetUriComponent("id", ""); |
1284 bool simplify = call.HasArgument("simplify"); | 1309 bool simplify = call.HasArgument("simplify"); |
1285 | 1310 |
1311 std::set<DicomTag> ignoreTagLength; | |
1312 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | |
1313 | |
1286 // Retrieve all the instances of this patient/study/series | 1314 // Retrieve all the instances of this patient/study/series |
1287 typedef std::list<std::string> Instances; | 1315 typedef std::list<std::string> Instances; |
1288 Instances instances; | 1316 Instances instances; |
1289 | 1317 |
1290 context.GetIndex().GetChildInstances(instances, publicId); // (*) | 1318 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
1293 | 1321 |
1294 for (Instances::const_iterator it = instances.begin(); | 1322 for (Instances::const_iterator it = instances.begin(); |
1295 it != instances.end(); ++it) | 1323 it != instances.end(); ++it) |
1296 { | 1324 { |
1297 Json::Value full; | 1325 Json::Value full; |
1298 context.ReadDicomAsJson(full, *it); | 1326 context.ReadDicomAsJson(full, *it, ignoreTagLength); |
1299 | 1327 |
1300 if (simplify) | 1328 if (simplify) |
1301 { | 1329 { |
1302 Json::Value simplified; | 1330 Json::Value simplified; |
1303 ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human); | 1331 ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human); |
1392 ParsedDicomFile dicom(dicomContent); | 1420 ParsedDicomFile dicom(dicomContent); |
1393 | 1421 |
1394 Json::Value header; | 1422 Json::Value header; |
1395 dicom.HeaderToJson(header, DicomToJsonFormat_Full); | 1423 dicom.HeaderToJson(header, DicomToJsonFormat_Full); |
1396 | 1424 |
1397 if (simplify) | 1425 AnswerDicomAsJson(call, header, simplify); |
1398 { | |
1399 Json::Value simplified; | |
1400 ServerToolbox::SimplifyTags(simplified, header, DicomToJsonFormat_Human); | |
1401 call.GetOutput().AnswerJson(simplified); | |
1402 } | |
1403 else | |
1404 { | |
1405 call.GetOutput().AnswerJson(header); | |
1406 } | |
1407 } | 1426 } |
1408 | 1427 |
1409 | 1428 |
1410 static void InvalidateTags(RestApiPostCall& call) | 1429 static void InvalidateTags(RestApiPostCall& call) |
1411 { | 1430 { |