Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi.cpp @ 213:4ce7fdcc8879
access to tags, simplified-tags and file of an instance
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 10:59:40 +0100 |
parents | f276b175dcaf |
children | 03817919169b |
comparison
equal
deleted
inserted
replaced
212:f276b175dcaf | 213:4ce7fdcc8879 |
---|---|
32 | 32 |
33 #include "OrthancRestApi.h" | 33 #include "OrthancRestApi.h" |
34 | 34 |
35 #include "OrthancInitialization.h" | 35 #include "OrthancInitialization.h" |
36 #include "FromDcmtkBridge.h" | 36 #include "FromDcmtkBridge.h" |
37 #include "ServerToolbox.h" | |
37 #include "../Core/Uuid.h" | 38 #include "../Core/Uuid.h" |
38 #include "../Core/HttpServer/FilesystemHttpSender.h" | 39 #include "../Core/HttpServer/FilesystemHttpSender.h" |
39 | 40 |
40 #include <dcmtk/dcmdata/dcistrmb.h> | 41 #include <dcmtk/dcmdata/dcistrmb.h> |
41 #include <dcmtk/dcmdata/dcfilefo.h> | 42 #include <dcmtk/dcmdata/dcfilefo.h> |
48 { | 49 { |
49 Json::StyledWriter writer; | 50 Json::StyledWriter writer; |
50 std::string s = writer.write(value); | 51 std::string s = writer.write(value); |
51 output.AnswerBufferWithContentType(s, "application/json"); | 52 output.AnswerBufferWithContentType(s, "application/json"); |
52 } | 53 } |
53 | |
54 | |
55 static void SimplifyTagsRecursion(Json::Value& target, | |
56 const Json::Value& source) | |
57 { | |
58 assert(source.isObject()); | |
59 | |
60 target = Json::objectValue; | |
61 Json::Value::Members members = source.getMemberNames(); | |
62 | |
63 for (size_t i = 0; i < members.size(); i++) | |
64 { | |
65 const Json::Value& v = source[members[i]]; | |
66 const std::string& name = v["Name"].asString(); | |
67 const std::string& type = v["Type"].asString(); | |
68 | |
69 if (type == "String") | |
70 { | |
71 target[name] = v["Value"].asString(); | |
72 } | |
73 else if (type == "TooLong" || | |
74 type == "Null") | |
75 { | |
76 target[name] = Json::nullValue; | |
77 } | |
78 else if (type == "Sequence") | |
79 { | |
80 const Json::Value& array = v["Value"]; | |
81 assert(array.isArray()); | |
82 | |
83 Json::Value children = Json::arrayValue; | |
84 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++) | |
85 { | |
86 Json::Value c; | |
87 SimplifyTagsRecursion(c, array[i]); | |
88 children.append(c); | |
89 } | |
90 | |
91 target[name] = children; | |
92 } | |
93 else | |
94 { | |
95 assert(0); | |
96 } | |
97 } | |
98 } | |
99 | |
100 | |
101 static void SimplifyTags(Json::Value& target, | |
102 const FileStorage& storage, | |
103 const std::string& fileUuid) | |
104 { | |
105 std::string s; | |
106 storage.ReadFile(s, fileUuid); | |
107 | |
108 Json::Value source; | |
109 Json::Reader reader; | |
110 if (!reader.parse(s, source)) | |
111 { | |
112 throw OrthancException("Corrupted JSON file"); | |
113 } | |
114 | |
115 SimplifyTagsRecursion(target, source); | |
116 } | |
117 | |
118 | 54 |
119 bool OrthancRestApi::Store(Json::Value& result, | 55 bool OrthancRestApi::Store(Json::Value& result, |
120 const std::string& postData) | 56 const std::string& postData) |
121 { | 57 { |
122 // Prepare an input stream for the memory buffer | 58 // Prepare an input stream for the memory buffer |
435 return; | 371 return; |
436 } | 372 } |
437 } | 373 } |
438 | 374 |
439 | 375 |
440 // Information about a single object ---------------------------------------- | |
441 | |
442 else if (uri.size() == 2 && | |
443 (uri[0] == "instances" || | |
444 uri[0] == "series" || | |
445 uri[0] == "studies" || | |
446 uri[0] == "patients")) | |
447 { | |
448 if (method == "GET") | |
449 { | |
450 if (uri[0] == "patients") | |
451 { | |
452 existingResource = index_.LookupResource(result, uri[1], ResourceType_Patient); | |
453 assert(!existingResource || result["Type"] == "Patient"); | |
454 } | |
455 else if (uri[0] == "studies") | |
456 { | |
457 existingResource = index_.LookupResource(result, uri[1], ResourceType_Study); | |
458 assert(!existingResource || result["Type"] == "Study"); | |
459 } | |
460 else if (uri[0] == "series") | |
461 { | |
462 existingResource = index_.LookupResource(result, uri[1], ResourceType_Series); | |
463 assert(!existingResource || result["Type"] == "Series"); | |
464 } | |
465 else if (uri[0] == "instances") | |
466 { | |
467 existingResource = index_.LookupResource(result, uri[1], ResourceType_Instance); | |
468 assert(!existingResource || result["Type"] == "Instance"); | |
469 } | |
470 } | |
471 else if (method == "DELETE") | |
472 { | |
473 if (uri[0] == "patients") | |
474 { | |
475 existingResource = index_.DeleteResource(result, uri[1], ResourceType_Patient); | |
476 } | |
477 else if (uri[0] == "studies") | |
478 { | |
479 existingResource = index_.DeleteResource(result, uri[1], ResourceType_Study); | |
480 } | |
481 else if (uri[0] == "series") | |
482 { | |
483 existingResource = index_.DeleteResource(result, uri[1], ResourceType_Series); | |
484 } | |
485 else if (uri[0] == "instances") | |
486 { | |
487 existingResource = index_.DeleteResource(result, uri[1], ResourceType_Instance); | |
488 } | |
489 | |
490 if (existingResource) | |
491 { | |
492 result["Status"] = "Success"; | |
493 } | |
494 } | |
495 else | |
496 { | |
497 output.SendMethodNotAllowedError("GET,DELETE"); | |
498 return; | |
499 } | |
500 } | |
501 | |
502 | |
503 // Get the DICOM or the JSON file of one instance --------------------------- | 376 // Get the DICOM or the JSON file of one instance --------------------------- |
504 | 377 |
505 else if (uri.size() == 3 && | 378 else if (uri.size() == 3 && |
506 uri[0] == "instances" && | 379 uri[0] == "instances" && |
507 (uri[2] == "file" || | 380 (uri[2] == "file" || |
526 | 399 |
527 if (existingResource) | 400 if (existingResource) |
528 { | 401 { |
529 if (uri[2] == "simplified-tags") | 402 if (uri[2] == "simplified-tags") |
530 { | 403 { |
531 Json::Value v; | 404 Json::Value simplified, full; |
532 SimplifyTags(v, storage_, fileUuid); | 405 ReadJson(full, storage_, fileUuid); |
533 SendJson(output, v); | 406 SimplifyTags(simplified, full); |
407 SendJson(output, simplified); | |
534 return; | 408 return; |
535 } | 409 } |
536 else | 410 else |
537 { | 411 { |
538 output.AnswerFile(storage_, fileUuid, contentType, filename.c_str()); | 412 output.AnswerFile(storage_, fileUuid, contentType, filename.c_str()); |