Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 2622:3603a2e14592
New option "?short" to list DICOM tags using their hexadecimal ID
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 May 2018 10:08:04 +0200 |
parents | 878b59270859 |
children | 52217dc47a4e |
comparison
equal
deleted
inserted
replaced
2615:c9bb0c89ccc1 | 2622:3603a2e14592 |
---|---|
48 | 48 |
49 namespace Orthanc | 49 namespace Orthanc |
50 { | 50 { |
51 static void AnswerDicomAsJson(RestApiCall& call, | 51 static void AnswerDicomAsJson(RestApiCall& call, |
52 const Json::Value& dicom, | 52 const Json::Value& dicom, |
53 bool simplify) | 53 DicomToJsonFormat mode) |
54 { | 54 { |
55 if (simplify) | 55 if (mode != DicomToJsonFormat_Full) |
56 { | 56 { |
57 Json::Value simplified; | 57 Json::Value simplified; |
58 ServerToolbox::SimplifyTags(simplified, dicom, DicomToJsonFormat_Human); | 58 ServerToolbox::SimplifyTags(simplified, dicom, mode); |
59 call.GetOutput().AnswerJson(simplified); | 59 call.GetOutput().AnswerJson(simplified); |
60 } | 60 } |
61 else | 61 else |
62 { | 62 { |
63 call.GetOutput().AnswerJson(dicom); | 63 call.GetOutput().AnswerJson(dicom); |
64 } | 64 } |
65 } | |
66 | |
67 | |
68 static DicomToJsonFormat GetDicomFormat(const RestApiGetCall& call) | |
69 { | |
70 if (call.HasArgument("simplify")) | |
71 { | |
72 return DicomToJsonFormat_Human; | |
73 } | |
74 else if (call.HasArgument("short")) | |
75 { | |
76 return DicomToJsonFormat_Short; | |
77 } | |
78 else | |
79 { | |
80 return DicomToJsonFormat_Full; | |
81 } | |
82 } | |
83 | |
84 | |
85 static void AnswerDicomAsJson(RestApiGetCall& call, | |
86 const Json::Value& dicom) | |
87 { | |
88 AnswerDicomAsJson(call, dicom, GetDicomFormat(call)); | |
65 } | 89 } |
66 | 90 |
67 | 91 |
68 static void ParseSetOfTags(std::set<DicomTag>& target, | 92 static void ParseSetOfTags(std::set<DicomTag>& target, |
69 const RestApiGetCall& call, | 93 const RestApiGetCall& call, |
234 | 258 |
235 call.GetOutput().AnswerBuffer("{}", "application/json"); | 259 call.GetOutput().AnswerBuffer("{}", "application/json"); |
236 } | 260 } |
237 | 261 |
238 | 262 |
239 template <bool simplify> | 263 template <DicomToJsonFormat format> |
240 static void GetInstanceTags(RestApiGetCall& call) | 264 static void GetInstanceTags(RestApiGetCall& call) |
241 { | 265 { |
242 ServerContext& context = OrthancRestApi::GetContext(call); | 266 ServerContext& context = OrthancRestApi::GetContext(call); |
243 | 267 |
244 std::string publicId = call.GetUriComponent("id", ""); | 268 std::string publicId = call.GetUriComponent("id", ""); |
245 | 269 |
246 std::set<DicomTag> ignoreTagLength; | 270 std::set<DicomTag> ignoreTagLength; |
247 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | 271 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); |
248 | 272 |
249 if (simplify || | 273 if (format != DicomToJsonFormat_Full || |
250 !ignoreTagLength.empty()) | 274 !ignoreTagLength.empty()) |
251 { | 275 { |
252 Json::Value full; | 276 Json::Value full; |
253 context.ReadDicomAsJson(full, publicId, ignoreTagLength); | 277 context.ReadDicomAsJson(full, publicId, ignoreTagLength); |
254 AnswerDicomAsJson(call, full, simplify); | 278 AnswerDicomAsJson(call, full, format); |
255 } | 279 } |
256 else | 280 else |
257 { | 281 { |
258 // This path allows to avoid the JSON decoding if no | 282 // This path allows to avoid the JSON decoding if no |
259 // simplification is asked, or if no "ignore-length" argument is | 283 // simplification is asked, and if no "ignore-length" argument |
260 // present | 284 // is present |
261 std::string full; | 285 std::string full; |
262 context.ReadDicomAsJson(full, publicId); | 286 context.ReadDicomAsJson(full, publicId); |
263 call.GetOutput().AnswerBuffer(full, "application/json"); | 287 call.GetOutput().AnswerBuffer(full, "application/json"); |
264 } | 288 } |
265 } | 289 } |
266 | 290 |
267 | 291 |
268 static void GetInstanceTagsBis(RestApiGetCall& call) | 292 static void GetInstanceTagsBis(RestApiGetCall& call) |
269 { | 293 { |
270 bool simplify = call.HasArgument("simplify"); | 294 switch (GetDicomFormat(call)) |
271 | 295 { |
272 if (simplify) | 296 case DicomToJsonFormat_Human: |
273 { | 297 GetInstanceTags<DicomToJsonFormat_Human>(call); |
274 GetInstanceTags<true>(call); | 298 break; |
275 } | 299 |
276 else | 300 case DicomToJsonFormat_Short: |
277 { | 301 GetInstanceTags<DicomToJsonFormat_Short>(call); |
278 GetInstanceTags<false>(call); | 302 break; |
303 | |
304 case DicomToJsonFormat_Full: | |
305 GetInstanceTags<DicomToJsonFormat_Full>(call); | |
306 break; | |
307 | |
308 default: | |
309 throw OrthancException(ErrorCode_InternalError); | |
279 } | 310 } |
280 } | 311 } |
281 | 312 |
282 | 313 |
283 static void ListFrames(RestApiGetCall& call) | 314 static void ListFrames(RestApiGetCall& call) |
1042 | 1073 |
1043 static void GetSharedTags(RestApiGetCall& call) | 1074 static void GetSharedTags(RestApiGetCall& call) |
1044 { | 1075 { |
1045 ServerContext& context = OrthancRestApi::GetContext(call); | 1076 ServerContext& context = OrthancRestApi::GetContext(call); |
1046 std::string publicId = call.GetUriComponent("id", ""); | 1077 std::string publicId = call.GetUriComponent("id", ""); |
1047 bool simplify = call.HasArgument("simplify"); | |
1048 | 1078 |
1049 Json::Value sharedTags; | 1079 Json::Value sharedTags; |
1050 if (ExtractSharedTags(sharedTags, context, publicId)) | 1080 if (ExtractSharedTags(sharedTags, context, publicId)) |
1051 { | 1081 { |
1052 // Success: Send the value of the shared tags | 1082 // Success: Send the value of the shared tags |
1053 AnswerDicomAsJson(call, sharedTags, simplify); | 1083 AnswerDicomAsJson(call, sharedTags); |
1054 } | 1084 } |
1055 } | 1085 } |
1056 | 1086 |
1057 | 1087 |
1058 static void GetModuleInternal(RestApiGetCall& call, | 1088 static void GetModuleInternal(RestApiGetCall& call, |
1069 throw OrthancException(ErrorCode_NotImplemented); | 1099 throw OrthancException(ErrorCode_NotImplemented); |
1070 } | 1100 } |
1071 | 1101 |
1072 ServerContext& context = OrthancRestApi::GetContext(call); | 1102 ServerContext& context = OrthancRestApi::GetContext(call); |
1073 std::string publicId = call.GetUriComponent("id", ""); | 1103 std::string publicId = call.GetUriComponent("id", ""); |
1074 bool simplify = call.HasArgument("simplify"); | |
1075 | 1104 |
1076 std::set<DicomTag> ignoreTagLength; | 1105 std::set<DicomTag> ignoreTagLength; |
1077 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | 1106 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); |
1078 | 1107 |
1079 typedef std::set<DicomTag> ModuleTags; | 1108 typedef std::set<DicomTag> ModuleTags; |
1109 { | 1138 { |
1110 result[s] = tags[s]; | 1139 result[s] = tags[s]; |
1111 } | 1140 } |
1112 } | 1141 } |
1113 | 1142 |
1114 AnswerDicomAsJson(call, result, simplify); | 1143 AnswerDicomAsJson(call, result); |
1115 } | 1144 } |
1116 | 1145 |
1117 | 1146 |
1118 | 1147 |
1119 template <enum ResourceType resourceType, | 1148 template <enum ResourceType resourceType, |
1304 | 1333 |
1305 static void GetChildInstancesTags(RestApiGetCall& call) | 1334 static void GetChildInstancesTags(RestApiGetCall& call) |
1306 { | 1335 { |
1307 ServerContext& context = OrthancRestApi::GetContext(call); | 1336 ServerContext& context = OrthancRestApi::GetContext(call); |
1308 std::string publicId = call.GetUriComponent("id", ""); | 1337 std::string publicId = call.GetUriComponent("id", ""); |
1309 bool simplify = call.HasArgument("simplify"); | 1338 DicomToJsonFormat format = GetDicomFormat(call); |
1310 | 1339 |
1311 std::set<DicomTag> ignoreTagLength; | 1340 std::set<DicomTag> ignoreTagLength; |
1312 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); | 1341 ParseSetOfTags(ignoreTagLength, call, "ignore-length"); |
1313 | 1342 |
1314 // Retrieve all the instances of this patient/study/series | 1343 // Retrieve all the instances of this patient/study/series |
1323 it != instances.end(); ++it) | 1352 it != instances.end(); ++it) |
1324 { | 1353 { |
1325 Json::Value full; | 1354 Json::Value full; |
1326 context.ReadDicomAsJson(full, *it, ignoreTagLength); | 1355 context.ReadDicomAsJson(full, *it, ignoreTagLength); |
1327 | 1356 |
1328 if (simplify) | 1357 if (format != DicomToJsonFormat_Full) |
1329 { | 1358 { |
1330 Json::Value simplified; | 1359 Json::Value simplified; |
1331 ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human); | 1360 ServerToolbox::SimplifyTags(simplified, full, format); |
1332 result[*it] = simplified; | 1361 result[*it] = simplified; |
1333 } | 1362 } |
1334 else | 1363 else |
1335 { | 1364 { |
1336 result[*it] = full; | 1365 result[*it] = full; |
1407 static void GetInstanceHeader(RestApiGetCall& call) | 1436 static void GetInstanceHeader(RestApiGetCall& call) |
1408 { | 1437 { |
1409 ServerContext& context = OrthancRestApi::GetContext(call); | 1438 ServerContext& context = OrthancRestApi::GetContext(call); |
1410 | 1439 |
1411 std::string publicId = call.GetUriComponent("id", ""); | 1440 std::string publicId = call.GetUriComponent("id", ""); |
1412 bool simplify = call.HasArgument("simplify"); | |
1413 | 1441 |
1414 std::string dicomContent; | 1442 std::string dicomContent; |
1415 context.ReadDicom(dicomContent, publicId); | 1443 context.ReadDicom(dicomContent, publicId); |
1416 | 1444 |
1417 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to | 1445 // TODO Consider using "DicomMap::ParseDicomMetaInformation()" to |
1420 ParsedDicomFile dicom(dicomContent); | 1448 ParsedDicomFile dicom(dicomContent); |
1421 | 1449 |
1422 Json::Value header; | 1450 Json::Value header; |
1423 dicom.HeaderToJson(header, DicomToJsonFormat_Full); | 1451 dicom.HeaderToJson(header, DicomToJsonFormat_Full); |
1424 | 1452 |
1425 AnswerDicomAsJson(call, header, simplify); | 1453 AnswerDicomAsJson(call, header); |
1426 } | 1454 } |
1427 | 1455 |
1428 | 1456 |
1429 static void InvalidateTags(RestApiPostCall& call) | 1457 static void InvalidateTags(RestApiPostCall& call) |
1430 { | 1458 { |
1493 Register("/studies/{id}/module-patient", GetModule<ResourceType_Study, DicomModule_Patient>); | 1521 Register("/studies/{id}/module-patient", GetModule<ResourceType_Study, DicomModule_Patient>); |
1494 | 1522 |
1495 Register("/instances/{id}/file", GetInstanceFile); | 1523 Register("/instances/{id}/file", GetInstanceFile); |
1496 Register("/instances/{id}/export", ExportInstanceFile); | 1524 Register("/instances/{id}/export", ExportInstanceFile); |
1497 Register("/instances/{id}/tags", GetInstanceTagsBis); | 1525 Register("/instances/{id}/tags", GetInstanceTagsBis); |
1498 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); | 1526 Register("/instances/{id}/simplified-tags", GetInstanceTags<DicomToJsonFormat_Human>); |
1499 Register("/instances/{id}/frames", ListFrames); | 1527 Register("/instances/{id}/frames", ListFrames); |
1500 | 1528 |
1501 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>); | 1529 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>); |
1502 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); | 1530 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
1503 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); | 1531 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |