Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1023:226cfef3822e templating
integration mainline->templating
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jul 2014 11:42:32 +0200 |
parents | 83622b0f544c |
children | 1701dcb6f554 |
comparison
equal
deleted
inserted
replaced
945:427a1f996b7b | 1023:226cfef3822e |
---|---|
41 namespace Orthanc | 41 namespace Orthanc |
42 { | 42 { |
43 // List all the patients, studies, series or instances ---------------------- | 43 // List all the patients, studies, series or instances ---------------------- |
44 | 44 |
45 template <enum ResourceType resourceType> | 45 template <enum ResourceType resourceType> |
46 static void ListResources(RestApi::GetCall& call) | 46 static void ListResources(RestApiGetCall& call) |
47 { | 47 { |
48 Json::Value result; | 48 Json::Value result; |
49 OrthancRestApi::GetIndex(call).GetAllUuids(result, resourceType); | 49 OrthancRestApi::GetIndex(call).GetAllUuids(result, resourceType); |
50 call.GetOutput().AnswerJson(result); | 50 call.GetOutput().AnswerJson(result); |
51 } | 51 } |
52 | 52 |
53 template <enum ResourceType resourceType> | 53 template <enum ResourceType resourceType> |
54 static void GetSingleResource(RestApi::GetCall& call) | 54 static void GetSingleResource(RestApiGetCall& call) |
55 { | 55 { |
56 Json::Value result; | 56 Json::Value result; |
57 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType)) | 57 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType)) |
58 { | 58 { |
59 call.GetOutput().AnswerJson(result); | 59 call.GetOutput().AnswerJson(result); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 template <enum ResourceType resourceType> | 63 template <enum ResourceType resourceType> |
64 static void DeleteSingleResource(RestApi::DeleteCall& call) | 64 static void DeleteSingleResource(RestApiDeleteCall& call) |
65 { | 65 { |
66 Json::Value result; | 66 Json::Value result; |
67 if (OrthancRestApi::GetIndex(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType)) | 67 if (OrthancRestApi::GetIndex(call).DeleteResource(result, call.GetUriComponent("id", ""), resourceType)) |
68 { | 68 { |
69 call.GetOutput().AnswerJson(result); | 69 call.GetOutput().AnswerJson(result); |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 // Get information about a single patient ----------------------------------- | 74 // Get information about a single patient ----------------------------------- |
75 | 75 |
76 static void IsProtectedPatient(RestApi::GetCall& call) | 76 static void IsProtectedPatient(RestApiGetCall& call) |
77 { | 77 { |
78 std::string publicId = call.GetUriComponent("id", ""); | 78 std::string publicId = call.GetUriComponent("id", ""); |
79 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId); | 79 bool isProtected = OrthancRestApi::GetIndex(call).IsProtectedPatient(publicId); |
80 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain"); | 80 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain"); |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 static void SetPatientProtection(RestApi::PutCall& call) | 84 static void SetPatientProtection(RestApiPutCall& call) |
85 { | 85 { |
86 ServerContext& context = OrthancRestApi::GetContext(call); | 86 ServerContext& context = OrthancRestApi::GetContext(call); |
87 | 87 |
88 std::string publicId = call.GetUriComponent("id", ""); | 88 std::string publicId = call.GetUriComponent("id", ""); |
89 std::string s = Toolbox::StripSpaces(call.GetPutBody()); | 89 std::string s = Toolbox::StripSpaces(call.GetPutBody()); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 // Get information about a single instance ---------------------------------- | 108 // Get information about a single instance ---------------------------------- |
109 | 109 |
110 static void GetInstanceFile(RestApi::GetCall& call) | 110 static void GetInstanceFile(RestApiGetCall& call) |
111 { | 111 { |
112 ServerContext& context = OrthancRestApi::GetContext(call); | 112 ServerContext& context = OrthancRestApi::GetContext(call); |
113 | 113 |
114 std::string publicId = call.GetUriComponent("id", ""); | 114 std::string publicId = call.GetUriComponent("id", ""); |
115 context.AnswerDicomFile(call.GetOutput(), publicId, FileContentType_Dicom); | 115 context.AnswerDicomFile(call.GetOutput(), publicId, FileContentType_Dicom); |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 static void ExportInstanceFile(RestApi::PostCall& call) | 119 static void ExportInstanceFile(RestApiPostCall& call) |
120 { | 120 { |
121 ServerContext& context = OrthancRestApi::GetContext(call); | 121 ServerContext& context = OrthancRestApi::GetContext(call); |
122 | 122 |
123 std::string publicId = call.GetUriComponent("id", ""); | 123 std::string publicId = call.GetUriComponent("id", ""); |
124 | 124 |
130 call.GetOutput().AnswerBuffer("{}", "application/json"); | 130 call.GetOutput().AnswerBuffer("{}", "application/json"); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 template <bool simplify> | 134 template <bool simplify> |
135 static void GetInstanceTags(RestApi::GetCall& call) | 135 static void GetInstanceTags(RestApiGetCall& call) |
136 { | 136 { |
137 ServerContext& context = OrthancRestApi::GetContext(call); | 137 ServerContext& context = OrthancRestApi::GetContext(call); |
138 | 138 |
139 std::string publicId = call.GetUriComponent("id", ""); | 139 std::string publicId = call.GetUriComponent("id", ""); |
140 | 140 |
151 { | 151 { |
152 call.GetOutput().AnswerJson(full); | 152 call.GetOutput().AnswerJson(full); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 | |
157 static void GetInstanceTagsBis(RestApiGetCall& call) | |
158 { | |
159 bool simplify = call.HasArgument("simplify"); | |
160 | |
161 if (simplify) | |
162 { | |
163 GetInstanceTags<true>(call); | |
164 } | |
165 else | |
166 { | |
167 GetInstanceTags<false>(call); | |
168 } | |
169 } | |
170 | |
156 | 171 |
157 static void ListFrames(RestApi::GetCall& call) | 172 static void ListFrames(RestApiGetCall& call) |
158 { | 173 { |
159 Json::Value instance; | 174 Json::Value instance; |
160 if (OrthancRestApi::GetIndex(call).LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance)) | 175 if (OrthancRestApi::GetIndex(call).LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance)) |
161 { | 176 { |
162 unsigned int numberOfFrames = 1; | 177 unsigned int numberOfFrames = 1; |
180 } | 195 } |
181 } | 196 } |
182 | 197 |
183 | 198 |
184 template <enum ImageExtractionMode mode> | 199 template <enum ImageExtractionMode mode> |
185 static void GetImage(RestApi::GetCall& call) | 200 static void GetImage(RestApiGetCall& call) |
186 { | 201 { |
187 ServerContext& context = OrthancRestApi::GetContext(call); | 202 ServerContext& context = OrthancRestApi::GetContext(call); |
188 | 203 |
189 std::string frameId = call.GetUriComponent("frame", "0"); | 204 std::string frameId = call.GetUriComponent("frame", "0"); |
190 | 205 |
228 } | 243 } |
229 } | 244 } |
230 } | 245 } |
231 | 246 |
232 | 247 |
233 static void GetMatlabImage(RestApi::GetCall& call) | 248 static void GetMatlabImage(RestApiGetCall& call) |
234 { | 249 { |
235 ServerContext& context = OrthancRestApi::GetContext(call); | 250 ServerContext& context = OrthancRestApi::GetContext(call); |
236 | 251 |
237 std::string frameId = call.GetUriComponent("frame", "0"); | 252 std::string frameId = call.GetUriComponent("frame", "0"); |
238 | 253 |
262 call.GetOutput().AnswerBuffer(result, "text/plain"); | 277 call.GetOutput().AnswerBuffer(result, "text/plain"); |
263 } | 278 } |
264 | 279 |
265 | 280 |
266 | 281 |
267 static void GetResourceStatistics(RestApi::GetCall& call) | 282 static void GetResourceStatistics(RestApiGetCall& call) |
268 { | 283 { |
269 std::string publicId = call.GetUriComponent("id", ""); | 284 std::string publicId = call.GetUriComponent("id", ""); |
270 Json::Value result; | 285 Json::Value result; |
271 OrthancRestApi::GetIndex(call).GetStatistics(result, publicId); | 286 OrthancRestApi::GetIndex(call).GetStatistics(result, publicId); |
272 call.GetOutput().AnswerJson(result); | 287 call.GetOutput().AnswerJson(result); |
274 | 289 |
275 | 290 |
276 | 291 |
277 // Handling of metadata ----------------------------------------------------- | 292 // Handling of metadata ----------------------------------------------------- |
278 | 293 |
279 static void CheckValidResourceType(RestApi::Call& call) | 294 static void CheckValidResourceType(RestApiCall& call) |
280 { | 295 { |
281 std::string resourceType = call.GetUriComponent("resourceType", ""); | 296 std::string resourceType = call.GetUriComponent("resourceType", ""); |
282 StringToResourceType(resourceType.c_str()); | 297 StringToResourceType(resourceType.c_str()); |
283 } | 298 } |
284 | 299 |
285 | 300 |
286 static void ListMetadata(RestApi::GetCall& call) | 301 static void ListMetadata(RestApiGetCall& call) |
287 { | 302 { |
288 CheckValidResourceType(call); | 303 CheckValidResourceType(call); |
289 | 304 |
290 std::string publicId = call.GetUriComponent("id", ""); | 305 std::string publicId = call.GetUriComponent("id", ""); |
291 std::list<MetadataType> metadata; | 306 std::list<MetadataType> metadata; |
301 | 316 |
302 call.GetOutput().AnswerJson(result); | 317 call.GetOutput().AnswerJson(result); |
303 } | 318 } |
304 | 319 |
305 | 320 |
306 static void GetMetadata(RestApi::GetCall& call) | 321 static void GetMetadata(RestApiGetCall& call) |
307 { | 322 { |
308 CheckValidResourceType(call); | 323 CheckValidResourceType(call); |
309 | 324 |
310 std::string publicId = call.GetUriComponent("id", ""); | 325 std::string publicId = call.GetUriComponent("id", ""); |
311 std::string name = call.GetUriComponent("name", ""); | 326 std::string name = call.GetUriComponent("name", ""); |
317 call.GetOutput().AnswerBuffer(value, "text/plain"); | 332 call.GetOutput().AnswerBuffer(value, "text/plain"); |
318 } | 333 } |
319 } | 334 } |
320 | 335 |
321 | 336 |
322 static void DeleteMetadata(RestApi::DeleteCall& call) | 337 static void DeleteMetadata(RestApiDeleteCall& call) |
323 { | 338 { |
324 CheckValidResourceType(call); | 339 CheckValidResourceType(call); |
325 | 340 |
326 std::string publicId = call.GetUriComponent("id", ""); | 341 std::string publicId = call.GetUriComponent("id", ""); |
327 std::string name = call.GetUriComponent("name", ""); | 342 std::string name = call.GetUriComponent("name", ""); |
335 call.GetOutput().AnswerBuffer("", "text/plain"); | 350 call.GetOutput().AnswerBuffer("", "text/plain"); |
336 } | 351 } |
337 } | 352 } |
338 | 353 |
339 | 354 |
340 static void SetMetadata(RestApi::PutCall& call) | 355 static void SetMetadata(RestApiPutCall& call) |
341 { | 356 { |
342 CheckValidResourceType(call); | 357 CheckValidResourceType(call); |
343 | 358 |
344 std::string publicId = call.GetUriComponent("id", ""); | 359 std::string publicId = call.GetUriComponent("id", ""); |
345 std::string name = call.GetUriComponent("name", ""); | 360 std::string name = call.GetUriComponent("name", ""); |
358 | 373 |
359 | 374 |
360 | 375 |
361 // Handling of attached files ----------------------------------------------- | 376 // Handling of attached files ----------------------------------------------- |
362 | 377 |
363 static void ListAttachments(RestApi::GetCall& call) | 378 static void ListAttachments(RestApiGetCall& call) |
364 { | 379 { |
365 std::string resourceType = call.GetUriComponent("resourceType", ""); | 380 std::string resourceType = call.GetUriComponent("resourceType", ""); |
366 std::string publicId = call.GetUriComponent("id", ""); | 381 std::string publicId = call.GetUriComponent("id", ""); |
367 std::list<FileContentType> attachments; | 382 std::list<FileContentType> attachments; |
368 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); | 383 OrthancRestApi::GetIndex(call).ListAvailableAttachments(attachments, publicId, StringToResourceType(resourceType.c_str())); |
377 | 392 |
378 call.GetOutput().AnswerJson(result); | 393 call.GetOutput().AnswerJson(result); |
379 } | 394 } |
380 | 395 |
381 | 396 |
382 static bool GetAttachmentInfo(FileInfo& info, RestApi::Call& call) | 397 static bool GetAttachmentInfo(FileInfo& info, RestApiCall& call) |
383 { | 398 { |
384 CheckValidResourceType(call); | 399 CheckValidResourceType(call); |
385 | 400 |
386 std::string publicId = call.GetUriComponent("id", ""); | 401 std::string publicId = call.GetUriComponent("id", ""); |
387 std::string name = call.GetUriComponent("name", ""); | 402 std::string name = call.GetUriComponent("name", ""); |
389 | 404 |
390 return OrthancRestApi::GetIndex(call).LookupAttachment(info, publicId, contentType); | 405 return OrthancRestApi::GetIndex(call).LookupAttachment(info, publicId, contentType); |
391 } | 406 } |
392 | 407 |
393 | 408 |
394 static void GetAttachmentOperations(RestApi::GetCall& call) | 409 static void GetAttachmentOperations(RestApiGetCall& call) |
395 { | 410 { |
396 FileInfo info; | 411 FileInfo info; |
397 if (GetAttachmentInfo(info, call)) | 412 if (GetAttachmentInfo(info, call)) |
398 { | 413 { |
399 Json::Value operations = Json::arrayValue; | 414 Json::Value operations = Json::arrayValue; |
425 } | 440 } |
426 } | 441 } |
427 | 442 |
428 | 443 |
429 template <int uncompress> | 444 template <int uncompress> |
430 static void GetAttachmentData(RestApi::GetCall& call) | 445 static void GetAttachmentData(RestApiGetCall& call) |
431 { | 446 { |
432 ServerContext& context = OrthancRestApi::GetContext(call); | 447 ServerContext& context = OrthancRestApi::GetContext(call); |
433 | 448 |
434 CheckValidResourceType(call); | 449 CheckValidResourceType(call); |
435 | 450 |
442 | 457 |
443 call.GetOutput().AnswerBuffer(content, "application/octet-stream"); | 458 call.GetOutput().AnswerBuffer(content, "application/octet-stream"); |
444 } | 459 } |
445 | 460 |
446 | 461 |
447 static void GetAttachmentSize(RestApi::GetCall& call) | 462 static void GetAttachmentSize(RestApiGetCall& call) |
448 { | 463 { |
449 FileInfo info; | 464 FileInfo info; |
450 if (GetAttachmentInfo(info, call)) | 465 if (GetAttachmentInfo(info, call)) |
451 { | 466 { |
452 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), "text/plain"); | 467 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedSize()), "text/plain"); |
453 } | 468 } |
454 } | 469 } |
455 | 470 |
456 | 471 |
457 static void GetAttachmentCompressedSize(RestApi::GetCall& call) | 472 static void GetAttachmentCompressedSize(RestApiGetCall& call) |
458 { | 473 { |
459 FileInfo info; | 474 FileInfo info; |
460 if (GetAttachmentInfo(info, call)) | 475 if (GetAttachmentInfo(info, call)) |
461 { | 476 { |
462 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedSize()), "text/plain"); | 477 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedSize()), "text/plain"); |
463 } | 478 } |
464 } | 479 } |
465 | 480 |
466 | 481 |
467 static void GetAttachmentMD5(RestApi::GetCall& call) | 482 static void GetAttachmentMD5(RestApiGetCall& call) |
468 { | 483 { |
469 FileInfo info; | 484 FileInfo info; |
470 if (GetAttachmentInfo(info, call) && | 485 if (GetAttachmentInfo(info, call) && |
471 info.GetUncompressedMD5() != "") | 486 info.GetUncompressedMD5() != "") |
472 { | 487 { |
473 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedMD5()), "text/plain"); | 488 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetUncompressedMD5()), "text/plain"); |
474 } | 489 } |
475 } | 490 } |
476 | 491 |
477 | 492 |
478 static void GetAttachmentCompressedMD5(RestApi::GetCall& call) | 493 static void GetAttachmentCompressedMD5(RestApiGetCall& call) |
479 { | 494 { |
480 FileInfo info; | 495 FileInfo info; |
481 if (GetAttachmentInfo(info, call) && | 496 if (GetAttachmentInfo(info, call) && |
482 info.GetCompressedMD5() != "") | 497 info.GetCompressedMD5() != "") |
483 { | 498 { |
484 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedMD5()), "text/plain"); | 499 call.GetOutput().AnswerBuffer(boost::lexical_cast<std::string>(info.GetCompressedMD5()), "text/plain"); |
485 } | 500 } |
486 } | 501 } |
487 | 502 |
488 | 503 |
489 static void VerifyAttachment(RestApi::PostCall& call) | 504 static void VerifyAttachment(RestApiPostCall& call) |
490 { | 505 { |
491 ServerContext& context = OrthancRestApi::GetContext(call); | 506 ServerContext& context = OrthancRestApi::GetContext(call); |
492 CheckValidResourceType(call); | 507 CheckValidResourceType(call); |
493 | 508 |
494 std::string publicId = call.GetUriComponent("id", ""); | 509 std::string publicId = call.GetUriComponent("id", ""); |
538 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!"; | 553 LOG(INFO) << "The attachment " << name << " of resource " << publicId << " has bad MD5!"; |
539 } | 554 } |
540 } | 555 } |
541 | 556 |
542 | 557 |
543 static void UploadAttachment(RestApi::PutCall& call) | 558 static void UploadAttachment(RestApiPutCall& call) |
544 { | 559 { |
545 ServerContext& context = OrthancRestApi::GetContext(call); | 560 ServerContext& context = OrthancRestApi::GetContext(call); |
546 CheckValidResourceType(call); | 561 CheckValidResourceType(call); |
547 | 562 |
548 std::string publicId = call.GetUriComponent("id", ""); | 563 std::string publicId = call.GetUriComponent("id", ""); |
558 call.GetOutput().AnswerBuffer("{}", "application/json"); | 573 call.GetOutput().AnswerBuffer("{}", "application/json"); |
559 } | 574 } |
560 } | 575 } |
561 | 576 |
562 | 577 |
563 static void DeleteAttachment(RestApi::DeleteCall& call) | 578 static void DeleteAttachment(RestApiDeleteCall& call) |
564 { | 579 { |
565 CheckValidResourceType(call); | 580 CheckValidResourceType(call); |
566 | 581 |
567 std::string publicId = call.GetUriComponent("id", ""); | 582 std::string publicId = call.GetUriComponent("id", ""); |
568 std::string name = call.GetUriComponent("name", ""); | 583 std::string name = call.GetUriComponent("name", ""); |
578 } | 593 } |
579 | 594 |
580 | 595 |
581 // Raw access to the DICOM tags of an instance ------------------------------ | 596 // Raw access to the DICOM tags of an instance ------------------------------ |
582 | 597 |
583 static void GetRawContent(RestApi::GetCall& call) | 598 static void GetRawContent(RestApiGetCall& call) |
584 { | 599 { |
585 std::string id = call.GetUriComponent("id", ""); | 600 std::string id = call.GetUriComponent("id", ""); |
586 | 601 |
587 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); | 602 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); |
588 | 603 |
589 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | 604 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); |
590 } | 605 } |
591 | 606 |
607 | |
608 | |
609 static bool ExtractSharedTags(Json::Value& shared, | |
610 ServerContext& context, | |
611 const std::string& publicId) | |
612 { | |
613 // Retrieve all the instances of this patient/study/series | |
614 typedef std::list<std::string> Instances; | |
615 Instances instances; | |
616 context.GetIndex().GetChildInstances(instances, publicId); // (*) | |
617 | |
618 // Loop over the instances | |
619 bool isFirst = true; | |
620 shared = Json::objectValue; | |
621 | |
622 for (Instances::const_iterator it = instances.begin(); | |
623 it != instances.end(); it++) | |
624 { | |
625 // Get the tags of the current instance, in the simplified format | |
626 Json::Value tags; | |
627 | |
628 try | |
629 { | |
630 context.ReadJson(tags, *it); | |
631 } | |
632 catch (OrthancException&) | |
633 { | |
634 // Race condition: This instance has been removed since | |
635 // (*). Ignore this instance. | |
636 continue; | |
637 } | |
638 | |
639 if (tags.type() != Json::objectValue) | |
640 { | |
641 return false; // Error | |
642 } | |
643 | |
644 // Only keep the tags that are mapped to a string | |
645 Json::Value::Members members = tags.getMemberNames(); | |
646 for (size_t i = 0; i < members.size(); i++) | |
647 { | |
648 const Json::Value& tag = tags[members[i]]; | |
649 if (tag.type() != Json::objectValue || | |
650 tag["Type"].type() != Json::stringValue || | |
651 tag["Type"].asString() != "String") | |
652 { | |
653 tags.removeMember(members[i]); | |
654 } | |
655 } | |
656 | |
657 if (isFirst) | |
658 { | |
659 // This is the first instance, keep its tags as such | |
660 shared = tags; | |
661 isFirst = false; | |
662 } | |
663 else | |
664 { | |
665 // Loop over all the members of the shared tags extracted so | |
666 // far. If the value of one of these tags does not match its | |
667 // value in the current instance, remove it. | |
668 members = shared.getMemberNames(); | |
669 for (size_t i = 0; i < members.size(); i++) | |
670 { | |
671 if (!tags.isMember(members[i]) || | |
672 tags[members[i]]["Value"].asString() != shared[members[i]]["Value"].asString()) | |
673 { | |
674 shared.removeMember(members[i]); | |
675 } | |
676 } | |
677 } | |
678 } | |
679 | |
680 return true; | |
681 } | |
682 | |
683 | |
684 static void GetSharedTags(RestApiGetCall& call) | |
685 { | |
686 ServerContext& context = OrthancRestApi::GetContext(call); | |
687 std::string publicId = call.GetUriComponent("id", ""); | |
688 bool simplify = call.HasArgument("simplify"); | |
689 | |
690 Json::Value sharedTags; | |
691 if (ExtractSharedTags(sharedTags, context, publicId)) | |
692 { | |
693 // Success: Send the value of the shared tags | |
694 if (simplify) | |
695 { | |
696 Json::Value simplified; | |
697 SimplifyTags(simplified, sharedTags); | |
698 call.GetOutput().AnswerJson(simplified); | |
699 } | |
700 else | |
701 { | |
702 call.GetOutput().AnswerJson(sharedTags); | |
703 } | |
704 } | |
705 } | |
706 | |
707 | |
708 template <enum ResourceType resourceType> | |
709 static void GetModule(RestApiGetCall& call) | |
710 { | |
711 ServerContext& context = OrthancRestApi::GetContext(call); | |
712 std::string publicId = call.GetUriComponent("id", ""); | |
713 bool simplify = call.HasArgument("simplify"); | |
714 | |
715 typedef std::set<DicomTag> Module; | |
716 Module module; | |
717 DicomTag::GetTagsForModule(module, resourceType); | |
718 | |
719 Json::Value tags; | |
720 | |
721 if (resourceType != ResourceType_Instance) | |
722 { | |
723 // Retrieve all the instances of this patient/study/series | |
724 typedef std::list<std::string> Instances; | |
725 Instances instances; | |
726 context.GetIndex().GetChildInstances(instances, publicId); | |
727 | |
728 if (instances.empty()) | |
729 { | |
730 return; // Error: No instance (should never happen) | |
731 } | |
732 | |
733 // Select one child instance | |
734 publicId = instances.front(); | |
735 } | |
736 | |
737 context.ReadJson(tags, publicId); | |
738 | |
739 // Filter the tags of the instance according to the module | |
740 Json::Value result = Json::objectValue; | |
741 for (Module::const_iterator it = module.begin(); it != module.end(); it++) | |
742 { | |
743 std::string s = it->Format(); | |
744 if (tags.isMember(s)) | |
745 { | |
746 result[s] = tags[s]; | |
747 } | |
748 } | |
749 | |
750 if (simplify) | |
751 { | |
752 Json::Value simplified; | |
753 SimplifyTags(simplified, result); | |
754 call.GetOutput().AnswerJson(simplified); | |
755 } | |
756 else | |
757 { | |
758 call.GetOutput().AnswerJson(result); | |
759 } | |
760 } | |
592 | 761 |
593 | 762 |
594 void OrthancRestApi::RegisterResources() | 763 void OrthancRestApi::RegisterResources() |
595 { | 764 { |
596 Register("/instances", ListResources<ResourceType_Instance>); | 765 Register("/instances", ListResources<ResourceType_Instance>); |
610 Register("/instances/{id}/statistics", GetResourceStatistics); | 779 Register("/instances/{id}/statistics", GetResourceStatistics); |
611 Register("/patients/{id}/statistics", GetResourceStatistics); | 780 Register("/patients/{id}/statistics", GetResourceStatistics); |
612 Register("/studies/{id}/statistics", GetResourceStatistics); | 781 Register("/studies/{id}/statistics", GetResourceStatistics); |
613 Register("/series/{id}/statistics", GetResourceStatistics); | 782 Register("/series/{id}/statistics", GetResourceStatistics); |
614 | 783 |
784 Register("/patients/{id}/shared-tags", GetSharedTags); | |
785 Register("/series/{id}/shared-tags", GetSharedTags); | |
786 Register("/studies/{id}/shared-tags", GetSharedTags); | |
787 | |
788 Register("/instances/{id}/module", GetModule<ResourceType_Instance>); | |
789 Register("/patients/{id}/module", GetModule<ResourceType_Patient>); | |
790 Register("/series/{id}/module", GetModule<ResourceType_Series>); | |
791 Register("/studies/{id}/module", GetModule<ResourceType_Study>); | |
792 | |
615 Register("/instances/{id}/file", GetInstanceFile); | 793 Register("/instances/{id}/file", GetInstanceFile); |
616 Register("/instances/{id}/export", ExportInstanceFile); | 794 Register("/instances/{id}/export", ExportInstanceFile); |
617 Register("/instances/{id}/tags", GetInstanceTags<false>); | 795 Register("/instances/{id}/tags", GetInstanceTagsBis); |
618 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); | 796 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); |
619 Register("/instances/{id}/frames", ListFrames); | 797 Register("/instances/{id}/frames", ListFrames); |
620 | 798 |
621 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>); | 799 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>); |
622 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); | 800 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |