Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi.cpp @ 613:60d90e48e809 find-move-scp
query/retrieve
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Oct 2013 17:27:26 +0200 |
parents | d5043ff68d58 |
children | fb49bf72ac2d |
rev | line source |
---|---|
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
399 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Belgium |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * License, or (at your option) any later version. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * program give permission to link the code of its release with the |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * in the program, then also delete it here. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 **/ |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
230 | 33 #include "OrthancRestApi.h" |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
35 #include "../Core/Compression/HierarchicalZipWriter.h" |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
36 #include "../Core/HttpClient.h" |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
37 #include "../Core/HttpServer/FilesystemHttpSender.h" |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
38 #include "../Core/Uuid.h" |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
39 #include "DicomProtocol/DicomUserConnection.h" |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include "FromDcmtkBridge.h" |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
41 #include "OrthancInitialization.h" |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
42 #include "ServerToolbox.h" |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 #include <dcmtk/dcmdata/dcistrmb.h> |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 #include <dcmtk/dcmdata/dcfilefo.h> |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 #include <boost/lexical_cast.hpp> |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
47 #include <glog/logging.h> |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
50 #define RETRIEVE_CONTEXT(call) \ |
230 | 51 OrthancRestApi& contextApi = \ |
52 dynamic_cast<OrthancRestApi&>(call.GetContext()); \ | |
225 | 53 ServerContext& context = contextApi.GetContext() |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
55 #define RETRIEVE_MODALITIES(call) \ |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
56 const OrthancRestApi::SetOfStrings& modalities = \ |
230 | 57 dynamic_cast<OrthancRestApi&>(call.GetContext()).GetModalities(); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
58 |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
59 #define RETRIEVE_PEERS(call) \ |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
60 const OrthancRestApi::SetOfStrings& peers = \ |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
61 dynamic_cast<OrthancRestApi&>(call.GetContext()).GetPeers(); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
62 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
63 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 namespace Orthanc |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
315 | 67 // TODO IMPROVE MULTITHREADING |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
68 // Every call to "ParsedDicomFile" must lock this mutex!!! |
315 | 69 static boost::mutex cacheMutex_; |
70 | |
71 | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
72 // DICOM SCU ---------------------------------------------------------------- |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
73 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
74 static bool MergeQueryAndTemplate(DicomMap& result, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
75 const std::string& postData) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
76 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
77 Json::Value query; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
78 Json::Reader reader; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
79 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
80 if (!reader.parse(postData, query) || |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
81 query.type() != Json::objectValue) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
82 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
83 return false; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
84 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
85 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
86 Json::Value::Members members = query.getMemberNames(); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
87 for (size_t i = 0; i < members.size(); i++) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
88 { |
304 | 89 DicomTag t = FromDcmtkBridge::ParseTag(members[i]); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
90 result.SetValue(t, query[members[i]].asString()); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
91 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
92 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
93 return true; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
94 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
95 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
96 static void DicomFindPatient(RestApi::PostCall& call) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
97 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
98 DicomMap m; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
99 DicomMap::SetupFindPatientTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
100 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
101 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
102 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
103 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
104 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
105 DicomUserConnection connection; |
613 | 106 ConnectToModalityUsingSymbolicName(connection, call.GetUriComponent("id", "")); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
107 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
108 DicomFindAnswers answers; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
109 connection.FindPatient(answers, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
110 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
111 Json::Value result; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
112 answers.ToJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
113 call.GetOutput().AnswerJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
114 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
115 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
116 static void DicomFindStudy(RestApi::PostCall& call) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
117 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
118 DicomMap m; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
119 DicomMap::SetupFindStudyTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
120 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
121 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
122 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
123 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
124 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
125 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
126 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
127 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
128 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
129 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
130 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
131 DicomUserConnection connection; |
613 | 132 ConnectToModalityUsingSymbolicName(connection, call.GetUriComponent("id", "")); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
133 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
134 DicomFindAnswers answers; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
135 connection.FindStudy(answers, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
136 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
137 Json::Value result; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
138 answers.ToJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
139 call.GetOutput().AnswerJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
140 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
141 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
142 static void DicomFindSeries(RestApi::PostCall& call) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
143 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
144 DicomMap m; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
145 DicomMap::SetupFindSeriesTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
146 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
147 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
148 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
149 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
150 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
151 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
152 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) || |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
153 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
154 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
155 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
156 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
157 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
158 DicomUserConnection connection; |
613 | 159 ConnectToModalityUsingSymbolicName(connection, call.GetUriComponent("id", "")); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
160 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
161 DicomFindAnswers answers; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
162 connection.FindSeries(answers, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
163 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
164 Json::Value result; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
165 answers.ToJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
166 call.GetOutput().AnswerJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
167 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
168 |
499
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
169 static void DicomFindInstance(RestApi::PostCall& call) |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
170 { |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
171 DicomMap m; |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
172 DicomMap::SetupFindInstanceTemplate(m); |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
173 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
174 { |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
175 return; |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
176 } |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
177 |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
178 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
179 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) || |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
180 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2 || |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
181 m.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString().size() <= 2) |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
182 { |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
183 return; |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
184 } |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
185 |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
186 DicomUserConnection connection; |
613 | 187 ConnectToModalityUsingSymbolicName(connection, call.GetUriComponent("id", "")); |
499
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
188 |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
189 DicomFindAnswers answers; |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
190 connection.FindInstance(answers, m); |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
191 |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
192 Json::Value result; |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
193 answers.ToJson(result); |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
194 call.GetOutput().AnswerJson(result); |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
195 } |
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
196 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
197 static void DicomFind(RestApi::PostCall& call) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
198 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
199 DicomMap m; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
200 DicomMap::SetupFindPatientTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
201 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
202 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
203 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
204 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
205 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
206 DicomUserConnection connection; |
613 | 207 ConnectToModalityUsingSymbolicName(connection, call.GetUriComponent("id", "")); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
208 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
209 DicomFindAnswers patients; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
210 connection.FindPatient(patients, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
211 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
212 // Loop over the found patients |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
213 Json::Value result = Json::arrayValue; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
214 for (size_t i = 0; i < patients.GetSize(); i++) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
215 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
216 Json::Value patient(Json::objectValue); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
217 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i)); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
218 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
219 DicomMap::SetupFindStudyTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
220 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
221 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
222 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
223 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
224 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
225 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
226 DicomFindAnswers studies; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
227 connection.FindStudy(studies, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
228 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
229 patient["Studies"] = Json::arrayValue; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
230 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
231 // Loop over the found studies |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
232 for (size_t j = 0; j < studies.GetSize(); j++) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
233 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
234 Json::Value study(Json::objectValue); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
235 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j)); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
236 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
237 DicomMap::SetupFindSeriesTemplate(m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
238 if (!MergeQueryAndTemplate(m, call.GetPostBody())) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
239 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
240 return; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
241 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
242 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
243 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
244 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
245 DicomFindAnswers series; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
246 connection.FindSeries(series, m); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
247 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
248 // Loop over the found series |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
249 study["Series"] = Json::arrayValue; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
250 for (size_t k = 0; k < series.GetSize(); k++) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
251 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
252 Json::Value series2(Json::objectValue); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
253 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k)); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
254 study["Series"].append(series2); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
255 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
256 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
257 patient["Studies"].append(study); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
258 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
259 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
260 result.append(patient); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
261 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
262 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
263 call.GetOutput().AnswerJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
264 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
265 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
266 |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
267 static bool GetInstancesToExport(std::list<std::string>& instances, |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
268 const std::string& remote, |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
269 RestApi::PostCall& call) |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
270 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
271 RETRIEVE_CONTEXT(call); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
272 |
402 | 273 std::string stripped = Toolbox::StripSpaces(call.GetPostBody()); |
274 | |
275 Json::Value request; | |
276 if (Toolbox::IsSHA1(stripped)) | |
277 { | |
278 // This is for compatibility with Orthanc <= 0.5.1. | |
279 request = stripped; | |
280 } | |
281 else if (!call.ParseJsonRequest(request)) | |
282 { | |
283 // Bad JSON request | |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
284 return false; |
402 | 285 } |
286 | |
287 if (request.isString()) | |
288 { | |
289 context.GetIndex().LogExportedResource(request.asString(), remote); | |
290 context.GetIndex().GetChildInstances(instances, request.asString()); | |
291 } | |
292 else if (request.isArray()) | |
293 { | |
294 for (Json::Value::ArrayIndex i = 0; i < request.size(); i++) | |
295 { | |
296 if (!request[i].isString()) | |
297 { | |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
298 return false; |
402 | 299 } |
300 | |
301 std::string stripped = Toolbox::StripSpaces(request[i].asString()); | |
302 if (!Toolbox::IsSHA1(stripped)) | |
303 { | |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
304 return false; |
402 | 305 } |
306 | |
307 context.GetIndex().LogExportedResource(stripped, remote); | |
308 | |
309 std::list<std::string> tmp; | |
310 context.GetIndex().GetChildInstances(tmp, stripped); | |
311 instances.merge(tmp); | |
312 assert(tmp.size() == 0); | |
313 } | |
314 } | |
315 else | |
316 { | |
317 // Neither a string, nor a list of strings. Bad request. | |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
318 return false; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
319 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
320 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
321 return true; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
322 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
323 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
324 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
325 static void DicomStore(RestApi::PostCall& call) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
326 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
327 RETRIEVE_CONTEXT(call); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
328 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
329 std::string remote = call.GetUriComponent("id", ""); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
330 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
331 std::list<std::string> instances; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
332 if (!GetInstancesToExport(instances, remote, call)) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
333 { |
402 | 334 return; |
335 } | |
336 | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
337 DicomUserConnection connection; |
613 | 338 ConnectToModalityUsingSymbolicName(connection, remote); |
231 | 339 |
402 | 340 for (std::list<std::string>::const_iterator |
341 it = instances.begin(); it != instances.end(); it++) | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
342 { |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
343 LOG(INFO) << "Sending resource " << *it << " to modality \"" << remote << "\""; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
344 |
402 | 345 std::string dicom; |
346 context.ReadFile(dicom, *it, FileContentType_Dicom); | |
347 connection.Store(dicom); | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
348 } |
231 | 349 |
402 | 350 call.GetOutput().AnswerBuffer("{}", "application/json"); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
351 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
352 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
353 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
354 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 // System information ------------------------------------------------------- |
211 | 356 |
357 static void ServeRoot(RestApi::GetCall& call) | |
358 { | |
359 call.GetOutput().Redirect("app/explorer.html"); | |
360 } | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 static void GetSystemInformation(RestApi::GetCall& call) |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 { |
238 | 364 Json::Value result = Json::objectValue; |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 result["Version"] = ORTHANC_VERSION; |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 result["Name"] = GetGlobalStringParameter("Name", ""); |
238 | 368 |
369 call.GetOutput().AnswerJson(result); | |
370 } | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
371 |
238 | 372 static void GetStatistics(RestApi::GetCall& call) |
373 { | |
374 RETRIEVE_CONTEXT(call); | |
375 Json::Value result = Json::objectValue; | |
376 context.GetIndex().ComputeStatistics(result); | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 call.GetOutput().AnswerJson(result); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 |
342
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
380 static void GenerateUid(RestApi::GetCall& call) |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
381 { |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
382 std::string level = call.GetArgument("level", ""); |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
383 if (level == "patient") |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
384 { |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
385 call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient), "text/plain"); |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
386 } |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
387 else if (level == "study") |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
388 { |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
389 call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study), "text/plain"); |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
390 } |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
391 else if (level == "series") |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
392 { |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
393 call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series), "text/plain"); |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
394 } |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
395 else if (level == "instance") |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
396 { |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
397 call.GetOutput().AnswerBuffer(FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance), "text/plain"); |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
398 } |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
399 } |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
400 |
418
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
401 static void ExecuteScript(RestApi::PostCall& call) |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
402 { |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
403 std::string result; |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
404 RETRIEVE_CONTEXT(call); |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
405 context.GetLuaContext().Execute(result, call.GetPostBody()); |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
406 call.GetOutput().AnswerBuffer(result, "text/plain"); |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
407 } |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
408 |
446 | 409 static void GetNowIsoString(RestApi::GetCall& call) |
410 { | |
411 call.GetOutput().AnswerBuffer(Toolbox::GetNowIsoString(), "text/plain"); | |
412 } | |
413 | |
414 | |
415 | |
418
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
416 |
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
417 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 |
211 | 419 // List all the patients, studies, series or instances ---------------------- |
420 | |
421 template <enum ResourceType resourceType> | |
422 static void ListResources(RestApi::GetCall& call) | |
423 { | |
424 RETRIEVE_CONTEXT(call); | |
425 | |
426 Json::Value result; | |
427 context.GetIndex().GetAllUuids(result, resourceType); | |
428 call.GetOutput().AnswerJson(result); | |
429 } | |
430 | |
212 | 431 template <enum ResourceType resourceType> |
432 static void GetSingleResource(RestApi::GetCall& call) | |
433 { | |
434 RETRIEVE_CONTEXT(call); | |
435 | |
436 Json::Value result; | |
437 if (context.GetIndex().LookupResource(result, call.GetUriComponent("id", ""), resourceType)) | |
438 { | |
439 call.GetOutput().AnswerJson(result); | |
440 } | |
441 } | |
442 | |
443 template <enum ResourceType resourceType> | |
444 static void DeleteSingleResource(RestApi::DeleteCall& call) | |
445 { | |
446 RETRIEVE_CONTEXT(call); | |
447 | |
448 Json::Value result; | |
449 if (context.GetIndex().DeleteResource(result, call.GetUriComponent("id", ""), resourceType)) | |
450 { | |
451 call.GetOutput().AnswerJson(result); | |
452 } | |
453 } | |
454 | |
211 | 455 |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
456 // Download of ZIP files ---------------------------------------------------- |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
457 |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
458 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
459 static std::string GetDirectoryNameInArchive(const Json::Value& resource, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
460 ResourceType resourceType) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
461 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
462 switch (resourceType) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
463 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
464 case ResourceType_Patient: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
465 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
466 std::string p = resource["MainDicomTags"]["PatientID"].asString(); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
467 std::string n = resource["MainDicomTags"]["PatientName"].asString(); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
468 return p + " " + n; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
469 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
470 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
471 case ResourceType_Study: |
253 | 472 { |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
473 return resource["MainDicomTags"]["StudyDescription"].asString(); |
253 | 474 } |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
475 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
476 case ResourceType_Series: |
253 | 477 { |
478 std::string d = resource["MainDicomTags"]["SeriesDescription"].asString(); | |
479 std::string m = resource["MainDicomTags"]["Modality"].asString(); | |
480 return m + " " + d; | |
481 } | |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
482 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
483 default: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
484 throw OrthancException(ErrorCode_InternalError); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
485 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
486 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
487 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
488 static bool CreateRootDirectoryInArchive(HierarchicalZipWriter& writer, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
489 ServerContext& context, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
490 const Json::Value& resource, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
491 ResourceType resourceType) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
492 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
493 if (resourceType == ResourceType_Patient) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
494 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
495 return true; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
496 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
497 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
498 ResourceType parentType = GetParentResourceType(resourceType); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
499 Json::Value parent; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
500 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
501 switch (resourceType) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
502 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
503 case ResourceType_Study: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
504 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
505 if (!context.GetIndex().LookupResource(parent, resource["ParentPatient"].asString(), parentType)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
506 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
507 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
508 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
509 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
510 break; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
511 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
512 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
513 case ResourceType_Series: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
514 if (!context.GetIndex().LookupResource(parent, resource["ParentStudy"].asString(), parentType) || |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
515 !CreateRootDirectoryInArchive(writer, context, parent, parentType)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
516 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
517 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
518 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
519 break; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
520 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
521 default: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
522 throw OrthancException(ErrorCode_NotImplemented); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
523 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
524 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
525 writer.OpenDirectory(GetDirectoryNameInArchive(parent, parentType).c_str()); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
526 return true; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
527 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
528 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
529 static bool ArchiveInstance(HierarchicalZipWriter& writer, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
530 ServerContext& context, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
531 const std::string& instancePublicId) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
532 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
533 Json::Value instance; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
534 if (!context.GetIndex().LookupResource(instance, instancePublicId, ResourceType_Instance)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
535 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
536 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
537 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
538 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
539 std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm"; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
540 writer.OpenFile(filename.c_str()); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
541 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
542 std::string dicom; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
543 context.ReadFile(dicom, instancePublicId, FileContentType_Dicom); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
544 writer.Write(dicom); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
545 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
546 return true; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
547 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
548 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
549 static bool ArchiveInternal(HierarchicalZipWriter& writer, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
550 ServerContext& context, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
551 const std::string& publicId, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
552 ResourceType resourceType, |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
553 bool isFirstLevel) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
554 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
555 Json::Value resource; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
556 if (!context.GetIndex().LookupResource(resource, publicId, resourceType)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
557 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
558 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
559 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
560 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
561 if (isFirstLevel && |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
562 !CreateRootDirectoryInArchive(writer, context, resource, resourceType)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
563 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
564 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
565 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
566 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
567 writer.OpenDirectory(GetDirectoryNameInArchive(resource, resourceType).c_str()); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
568 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
569 switch (resourceType) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
570 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
571 case ResourceType_Patient: |
299 | 572 for (Json::Value::ArrayIndex i = 0; i < resource["Studies"].size(); i++) |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
573 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
574 std::string studyId = resource["Studies"][i].asString(); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
575 if (!ArchiveInternal(writer, context, studyId, ResourceType_Study, false)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
576 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
577 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
578 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
579 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
580 break; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
581 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
582 case ResourceType_Study: |
299 | 583 for (Json::Value::ArrayIndex i = 0; i < resource["Series"].size(); i++) |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
584 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
585 std::string seriesId = resource["Series"][i].asString(); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
586 if (!ArchiveInternal(writer, context, seriesId, ResourceType_Series, false)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
587 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
588 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
589 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
590 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
591 break; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
592 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
593 case ResourceType_Series: |
299 | 594 for (Json::Value::ArrayIndex i = 0; i < resource["Instances"].size(); i++) |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
595 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
596 if (!ArchiveInstance(writer, context, resource["Instances"][i].asString())) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
597 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
598 return false; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
599 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
600 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
601 break; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
602 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
603 default: |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
604 throw OrthancException(ErrorCode_InternalError); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
605 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
606 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
607 writer.CloseDirectory(); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
608 return true; |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
609 } |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
610 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
611 template <enum ResourceType resourceType> |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
612 static void GetArchive(RestApi::GetCall& call) |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
613 { |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
614 RETRIEVE_CONTEXT(call); |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
615 |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
616 // Create a RAII for the temporary file to manage the ZIP file |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
617 Toolbox::TemporaryFile tmp; |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
618 std::string id = call.GetUriComponent("id", ""); |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
619 |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
620 { |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
621 // Create a ZIP writer |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
622 HierarchicalZipWriter writer(tmp.GetPath().c_str()); |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
623 |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
624 // Store the requested resource into the ZIP |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
625 if (!ArchiveInternal(writer, context, id, resourceType, true)) |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
626 { |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
627 return; |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
628 } |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
629 } |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
630 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
631 // Prepare the sending of the ZIP file |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
632 FilesystemHttpSender sender(tmp.GetPath().c_str()); |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
633 sender.SetContentType("application/zip"); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
634 sender.SetDownloadFilename(id + ".zip"); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
635 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
636 // Send the ZIP |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
637 call.GetOutput().AnswerFile(sender); |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
638 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
639 // The temporary file is automatically removed thanks to the RAII |
248
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
640 } |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
641 |
2442033911d6
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
642 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
643 // Changes API -------------------------------------------------------------- |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
644 |
231 | 645 static void GetSinceAndLimit(int64_t& since, |
646 unsigned int& limit, | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
647 bool& last, |
231 | 648 const RestApi::GetCall& call) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
649 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
650 static const unsigned int MAX_RESULTS = 100; |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
651 |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
652 if (call.HasArgument("last")) |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
653 { |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
654 last = true; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
655 return; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
656 } |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
657 |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
658 last = false; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
659 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
660 try |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
661 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
662 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0")); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
663 limit = boost::lexical_cast<unsigned int>(call.GetArgument("limit", "0")); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
664 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
665 catch (boost::bad_lexical_cast) |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
666 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
667 return; |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
668 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
669 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
670 if (limit == 0 || limit > MAX_RESULTS) |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
671 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
672 limit = MAX_RESULTS; |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
673 } |
231 | 674 } |
675 | |
676 static void GetChanges(RestApi::GetCall& call) | |
677 { | |
678 RETRIEVE_CONTEXT(call); | |
679 | |
680 //std::string filter = GetArgument(getArguments, "filter", ""); | |
681 int64_t since; | |
682 unsigned int limit; | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
683 bool last; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
684 GetSinceAndLimit(since, limit, last, call); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
685 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
686 Json::Value result; |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
687 if ((!last && context.GetIndex().GetChanges(result, since, limit)) || |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
688 ( last && context.GetIndex().GetLastChange(result))) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
689 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
690 call.GetOutput().AnswerJson(result); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
691 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
692 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
693 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
694 |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
695 static void DeleteChanges(RestApi::DeleteCall& call) |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
696 { |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
697 RETRIEVE_CONTEXT(call); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
698 context.GetIndex().DeleteChanges(); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
699 call.GetOutput().AnswerBuffer("", "text/plain"); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
700 } |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
701 |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
702 |
231 | 703 static void GetExports(RestApi::GetCall& call) |
704 { | |
705 RETRIEVE_CONTEXT(call); | |
706 | |
707 int64_t since; | |
708 unsigned int limit; | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
709 bool last; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
710 GetSinceAndLimit(since, limit, last, call); |
231 | 711 |
712 Json::Value result; | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
713 if ((!last && context.GetIndex().GetExportedResources(result, since, limit)) || |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
714 ( last && context.GetIndex().GetLastExportedResource(result))) |
231 | 715 { |
716 call.GetOutput().AnswerJson(result); | |
717 } | |
718 } | |
719 | |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
720 |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
721 static void DeleteExports(RestApi::DeleteCall& call) |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
722 { |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
723 RETRIEVE_CONTEXT(call); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
724 context.GetIndex().DeleteExportedResources(); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
725 call.GetOutput().AnswerBuffer("", "text/plain"); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
726 } |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
727 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
728 |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
729 // Get information about a single patient ----------------------------------- |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
730 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
731 static void IsProtectedPatient(RestApi::GetCall& call) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
732 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
733 RETRIEVE_CONTEXT(call); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
734 std::string publicId = call.GetUriComponent("id", ""); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
735 bool isProtected = context.GetIndex().IsProtectedPatient(publicId); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
736 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain"); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
737 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
738 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
739 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
740 static void SetPatientProtection(RestApi::PutCall& call) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
741 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
742 RETRIEVE_CONTEXT(call); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
743 std::string publicId = call.GetUriComponent("id", ""); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
744 std::string s = Toolbox::StripSpaces(call.GetPutBody()); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
745 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
746 if (s == "0") |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
747 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
748 context.GetIndex().SetProtectedPatient(publicId, false); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
749 call.GetOutput().AnswerBuffer("", "text/plain"); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
750 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
751 else if (s == "1") |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
752 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
753 context.GetIndex().SetProtectedPatient(publicId, true); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
754 call.GetOutput().AnswerBuffer("", "text/plain"); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
755 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
756 else |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
757 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
758 // Bad request |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
759 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
760 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
761 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
762 |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
763 // Get information about a single instance ---------------------------------- |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
764 |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
765 static void GetInstanceFile(RestApi::GetCall& call) |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
766 { |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
767 RETRIEVE_CONTEXT(call); |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
768 |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
769 std::string publicId = call.GetUriComponent("id", ""); |
233 | 770 context.AnswerFile(call.GetOutput(), publicId, FileContentType_Dicom); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
771 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
772 |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
773 |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
774 static void ExportInstanceFile(RestApi::PostCall& call) |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
775 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
776 RETRIEVE_CONTEXT(call); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
777 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
778 std::string publicId = call.GetUriComponent("id", ""); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
779 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
780 std::string dicom; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
781 context.ReadFile(dicom, publicId, FileContentType_Dicom); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
782 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
783 Toolbox::WriteFile(dicom, call.GetPostBody()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
784 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
785 call.GetOutput().AnswerBuffer("{}", "application/json"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
786 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
787 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
788 |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
789 template <bool simplify> |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
790 static void GetInstanceTags(RestApi::GetCall& call) |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
791 { |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
792 RETRIEVE_CONTEXT(call); |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
793 |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
794 std::string publicId = call.GetUriComponent("id", ""); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
795 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
796 Json::Value full; |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
797 context.ReadJson(full, publicId); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
798 |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
799 if (simplify) |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
800 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
801 Json::Value simplified; |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
802 SimplifyTags(simplified, full); |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
803 call.GetOutput().AnswerJson(simplified); |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
804 } |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
805 else |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
806 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
807 call.GetOutput().AnswerJson(full); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
808 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
809 } |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
810 |
214 | 811 |
812 static void ListFrames(RestApi::GetCall& call) | |
813 { | |
814 RETRIEVE_CONTEXT(call); | |
815 | |
816 Json::Value instance; | |
817 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance)) | |
818 { | |
819 unsigned int numberOfFrames = 1; | |
820 | |
821 try | |
822 { | |
823 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"]; | |
824 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString()); | |
825 } | |
826 catch (...) | |
827 { | |
828 } | |
829 | |
830 Json::Value result = Json::arrayValue; | |
831 for (unsigned int i = 0; i < numberOfFrames; i++) | |
832 { | |
833 result.append(i); | |
834 } | |
835 | |
836 call.GetOutput().AnswerJson(result); | |
837 } | |
838 } | |
839 | |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
840 |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
841 template <enum ImageExtractionMode mode> |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
842 static void GetImage(RestApi::GetCall& call) |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
843 { |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
844 RETRIEVE_CONTEXT(call); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
845 |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
846 std::string frameId = call.GetUriComponent("frame", "0"); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
847 |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
848 unsigned int frame; |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
849 try |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
850 { |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
851 frame = boost::lexical_cast<unsigned int>(frameId); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
852 } |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
853 catch (boost::bad_lexical_cast) |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
854 { |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
855 return; |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
856 } |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
857 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
858 std::string publicId = call.GetUriComponent("id", ""); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
859 std::string dicomContent, png; |
233 | 860 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
861 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
862 try |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
863 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
864 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, mode); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
865 call.GetOutput().AnswerBuffer(png, "image/png"); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
866 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
867 catch (OrthancException& e) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
868 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
869 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange) |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
870 { |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
871 // The frame number is out of the range for this DICOM |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
872 // instance, the resource is not existent |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
873 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
874 else |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
875 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
876 std::string root = ""; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
877 for (size_t i = 1; i < call.GetFullUri().size(); i++) |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
878 { |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
879 root += "../"; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
880 } |
218 | 881 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
882 call.GetOutput().Redirect(root + "app/images/unsupported.png"); |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
883 } |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
884 } |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
885 } |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
886 |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
887 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
888 // Upload of DICOM files through HTTP --------------------------------------- |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
889 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
890 static void UploadDicomFile(RestApi::PostCall& call) |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
891 { |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
892 RETRIEVE_CONTEXT(call); |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
893 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
894 const std::string& postData = call.GetPostBody(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
895 if (postData.size() == 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
896 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
897 return; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
898 } |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
899 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
900 LOG(INFO) << "Receiving a DICOM file of " << postData.size() << " bytes through HTTP"; |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
901 |
304 | 902 std::string publicId; |
903 StoreStatus status = context.Store(publicId, postData); | |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
904 Json::Value result = Json::objectValue; |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
905 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
906 if (status != StoreStatus_Failure) |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
907 { |
304 | 908 result["ID"] = publicId; |
909 result["Path"] = GetBasePath(ResourceType_Instance, publicId); | |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
910 } |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
911 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
912 result["Status"] = EnumerationToString(status); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
913 call.GetOutput().AnswerJson(result); |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
914 } |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
915 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
916 |
304 | 917 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
918 // DICOM bridge ------------------------------------------------------------- |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
919 |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
920 static bool IsExistingModality(const OrthancRestApi::SetOfStrings& modalities, |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
921 const std::string& id) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
922 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
923 return modalities.find(id) != modalities.end(); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
924 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
925 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
926 static void ListModalities(RestApi::GetCall& call) |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
927 { |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
928 RETRIEVE_MODALITIES(call); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
929 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
930 Json::Value result = Json::arrayValue; |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
931 for (OrthancRestApi::SetOfStrings::const_iterator |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
932 it = modalities.begin(); it != modalities.end(); it++) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
933 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
934 result.append(*it); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
935 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
936 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
937 call.GetOutput().AnswerJson(result); |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
938 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
939 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
940 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
941 static void ListModalityOperations(RestApi::GetCall& call) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
942 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
943 RETRIEVE_MODALITIES(call); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
944 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
945 std::string id = call.GetUriComponent("id", ""); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
946 if (IsExistingModality(modalities, id)) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
947 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
948 Json::Value result = Json::arrayValue; |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
949 result.append("find-patient"); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
950 result.append("find-study"); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
951 result.append("find-series"); |
499
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
952 result.append("find-instance"); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
953 result.append("find"); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
954 result.append("store"); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
955 call.GetOutput().AnswerJson(result); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
956 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
957 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
958 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
959 |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
960 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
961 // Raw access to the DICOM tags of an instance ------------------------------ |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
962 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
963 static void GetRawContent(RestApi::GetCall& call) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
964 { |
315 | 965 boost::mutex::scoped_lock lock(cacheMutex_); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
966 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
967 RETRIEVE_CONTEXT(call); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
968 std::string id = call.GetUriComponent("id", ""); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
969 ParsedDicomFile& dicom = context.GetDicomFile(id); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
970 dicom.SendPathValue(call.GetOutput(), call.GetTrailingUri()); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
971 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
972 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
973 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
974 |
304 | 975 // Modification of DICOM instances ------------------------------------------ |
976 | |
311 | 977 namespace |
978 { | |
979 typedef std::set<DicomTag> Removals; | |
980 typedef std::map<DicomTag, std::string> Replacements; | |
350
8031f9cfe7fe
removal of old code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
349
diff
changeset
|
981 typedef std::map< std::pair<DicomRootLevel, std::string>, std::string> UidMap; |
311 | 982 } |
310 | 983 |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
984 static void ReplaceInstanceInternal(ParsedDicomFile& toModify, |
310 | 985 const Removals& removals, |
986 const Replacements& replacements, | |
312 | 987 DicomReplaceMode mode, |
988 bool removePrivateTags) | |
304 | 989 { |
312 | 990 if (removePrivateTags) |
991 { | |
992 toModify.RemovePrivateTags(); | |
993 } | |
994 | |
310 | 995 for (Removals::const_iterator it = removals.begin(); |
996 it != removals.end(); it++) | |
997 { | |
998 toModify.Remove(*it); | |
999 } | |
1000 | |
1001 for (Replacements::const_iterator it = replacements.begin(); | |
1002 it != replacements.end(); it++) | |
1003 { | |
1004 toModify.Replace(it->first, it->second, mode); | |
1005 } | |
1006 | |
1007 // A new SOP instance UID is automatically generated | |
1008 std::string instanceUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance); | |
1009 toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid, DicomReplaceMode_InsertIfAbsent); | |
1010 } | |
1011 | |
1012 | |
1013 static void ParseRemovals(Removals& target, | |
1014 const Json::Value& removals) | |
1015 { | |
1016 if (!removals.isArray()) | |
304 | 1017 { |
1018 throw OrthancException(ErrorCode_BadRequest); | |
1019 } | |
1020 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1021 for (Json::Value::ArrayIndex i = 0; i < removals.size(); i++) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1022 { |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1023 std::string name = removals[i].asString(); |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1024 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
310 | 1025 target.insert(tag); |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1026 |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1027 VLOG(1) << "Removal: " << name << " " << tag << std::endl; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1028 } |
310 | 1029 } |
1030 | |
1031 | |
1032 static void ParseReplacements(Replacements& target, | |
1033 const Json::Value& replacements) | |
1034 { | |
1035 if (!replacements.isObject()) | |
1036 { | |
1037 throw OrthancException(ErrorCode_BadRequest); | |
1038 } | |
1039 | |
304 | 1040 Json::Value::Members members = replacements.getMemberNames(); |
1041 for (size_t i = 0; i < members.size(); i++) | |
1042 { | |
1043 const std::string& name = members[i]; | |
1044 std::string value = replacements[name].asString(); | |
1045 | |
1046 DicomTag tag = FromDcmtkBridge::ParseTag(name); | |
310 | 1047 target[tag] = value; |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1048 |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
351
diff
changeset
|
1049 VLOG(1) << "Replacement: " << name << " " << tag << " == " << value << std::endl; |
304 | 1050 } |
1051 } | |
1052 | |
310 | 1053 |
311 | 1054 static std::string GeneratePatientName(ServerContext& context) |
1055 { | |
1056 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence); | |
1057 return "Anonymized" + boost::lexical_cast<std::string>(seq); | |
1058 } | |
1059 | |
1060 | |
310 | 1061 static void SetupAnonymization(Removals& removals, |
1062 Replacements& replacements) | |
1063 { | |
311 | 1064 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles |
310 | 1065 removals.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID |
311 | 1066 //removals.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set by ReplaceInstanceInternal() |
1067 removals.insert(DicomTag(0x0008, 0x0050)); // Accession Number | |
1068 removals.insert(DicomTag(0x0008, 0x0080)); // Institution Name | |
1069 removals.insert(DicomTag(0x0008, 0x0081)); // Institution Address | |
1070 removals.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name | |
1071 removals.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address | |
1072 removals.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers | |
1073 removals.insert(DicomTag(0x0008, 0x1010)); // Station Name | |
1074 removals.insert(DicomTag(0x0008, 0x1030)); // Study Description | |
1075 removals.insert(DicomTag(0x0008, 0x103e)); // Series Description | |
1076 removals.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name | |
1077 removals.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record | |
1078 removals.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name | |
1079 removals.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study | |
1080 removals.insert(DicomTag(0x0008, 0x1070)); // Operators' Name | |
1081 removals.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description | |
1082 removals.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID | |
1083 removals.insert(DicomTag(0x0008, 0x2111)); // Derivation Description | |
1084 removals.insert(DicomTag(0x0010, 0x0010)); // Patient's Name | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1085 //removals.insert(DicomTag(0x0010, 0x0020)); // Patient ID => cf. below (*) |
311 | 1086 removals.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date |
1087 removals.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time | |
1088 removals.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex | |
1089 removals.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids | |
1090 removals.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names | |
1091 removals.insert(DicomTag(0x0010, 0x1010)); // Patient's Age | |
1092 removals.insert(DicomTag(0x0010, 0x1020)); // Patient's Size | |
1093 removals.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight | |
1094 removals.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator | |
1095 removals.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group | |
1096 removals.insert(DicomTag(0x0010, 0x2180)); // Occupation | |
1097 removals.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History | |
1098 removals.insert(DicomTag(0x0010, 0x4000)); // Patient Comments | |
1099 removals.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number | |
1100 removals.insert(DicomTag(0x0018, 0x1030)); // Protocol Name | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1101 //removals.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => cf. below (*) |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1102 //removals.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => cf. below (*) |
311 | 1103 removals.insert(DicomTag(0x0020, 0x0010)); // Study ID |
1104 removals.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID | |
1105 removals.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID | |
1106 removals.insert(DicomTag(0x0020, 0x4000)); // Image Comments | |
1107 removals.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence | |
1108 removals.insert(DicomTag(0x0040, 0xa124)); // UID | |
1109 removals.insert(DicomTag(0x0040, 0xa730)); // Content Sequence | |
1110 removals.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID | |
1111 removals.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID | |
1112 removals.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID | |
1113 | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1114 /** |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1115 * (*) Patient ID, Study Instance UID and Series Instance UID |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1116 * are modified by "AnonymizeInstance()" if anonymizing a single |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1117 * instance, or by "RetrieveMappedUid()" if anonymizing a |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1118 * patient/study/series. |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1119 **/ |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1120 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1121 |
311 | 1122 // Some more removals (from the experience of DICOM files at the CHU of Liege) |
1123 removals.insert(DicomTag(0x0010, 0x1040)); // Patient's Address | |
1124 removals.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician | |
463
005aaeb63414
anonymization of PatientTelephoneNumbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
446
diff
changeset
|
1125 removals.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers |
527
d47ae896a754
anonymization of the medical alerts tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
519
diff
changeset
|
1126 removals.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts |
311 | 1127 |
1128 // Set the DeidentificationMethod tag | |
1129 replacements.insert(std::make_pair(DicomTag(0x0012, 0x0063), "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1")); | |
1130 | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1131 // Set the PatientIdentityRemoved tag |
311 | 1132 replacements.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES")); |
310 | 1133 } |
1134 | |
1135 | |
1136 static bool ParseModifyRequest(Removals& removals, | |
1137 Replacements& replacements, | |
312 | 1138 bool& removePrivateTags, |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1139 const RestApi::PostCall& call) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1140 { |
312 | 1141 removePrivateTags = false; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1142 Json::Value request; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1143 if (call.ParseJsonRequest(request) && |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1144 request.isObject()) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1145 { |
310 | 1146 Json::Value removalsPart = Json::arrayValue; |
1147 Json::Value replacementsPart = Json::objectValue; | |
304 | 1148 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1149 if (request.isMember("Remove")) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1150 { |
310 | 1151 removalsPart = request["Remove"]; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1152 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1153 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1154 if (request.isMember("Replace")) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1155 { |
310 | 1156 replacementsPart = request["Replace"]; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1157 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1158 |
312 | 1159 if (request.isMember("RemovePrivateTags")) |
1160 { | |
1161 removePrivateTags = true; | |
1162 } | |
1163 | |
310 | 1164 ParseRemovals(removals, removalsPart); |
1165 ParseReplacements(replacements, replacementsPart); | |
1166 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1167 return true; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1168 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1169 else |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1170 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1171 return false; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1172 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1173 } |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1174 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1175 |
311 | 1176 static bool ParseAnonymizationRequest(Removals& removals, |
1177 Replacements& replacements, | |
1178 bool& removePrivateTags, | |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1179 bool& keepPatientId, |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1180 RestApi::PostCall& call) |
311 | 1181 { |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1182 RETRIEVE_CONTEXT(call); |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1183 |
311 | 1184 removePrivateTags = true; |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1185 keepPatientId = false; |
311 | 1186 |
1187 Json::Value request; | |
1188 if (call.ParseJsonRequest(request) && | |
1189 request.isObject()) | |
1190 { | |
1191 Json::Value keepPart = Json::arrayValue; | |
312 | 1192 Json::Value removalsPart = Json::arrayValue; |
1193 Json::Value replacementsPart = Json::objectValue; | |
1194 | |
311 | 1195 if (request.isMember("Keep")) |
1196 { | |
1197 keepPart = request["Keep"]; | |
1198 } | |
1199 | |
1200 if (request.isMember("KeepPrivateTags")) | |
1201 { | |
1202 removePrivateTags = false; | |
1203 } | |
1204 | |
312 | 1205 if (request.isMember("Replace")) |
1206 { | |
1207 replacementsPart = request["Replace"]; | |
1208 } | |
1209 | |
311 | 1210 Removals toKeep; |
1211 ParseRemovals(toKeep, keepPart); | |
1212 | |
1213 SetupAnonymization(removals, replacements); | |
1214 | |
1215 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++) | |
1216 { | |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1217 if (*it == DICOM_TAG_PATIENT_ID) |
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1218 { |
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1219 keepPatientId = true; |
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1220 } |
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1221 |
311 | 1222 removals.erase(*it); |
1223 } | |
1224 | |
312 | 1225 Removals additionalRemovals; |
1226 ParseRemovals(additionalRemovals, removalsPart); | |
1227 | |
1228 for (Removals::iterator it = additionalRemovals.begin(); | |
1229 it != additionalRemovals.end(); it++) | |
1230 { | |
321 | 1231 removals.insert(*it); |
312 | 1232 } |
1233 | |
1234 ParseReplacements(replacements, replacementsPart); | |
1235 | |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1236 // Generate random Patient's Name if none is specified |
557 | 1237 if (toKeep.find(DICOM_TAG_PATIENT_NAME) == toKeep.end() && |
1238 replacements.find(DICOM_TAG_PATIENT_NAME) == replacements.end()) | |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1239 { |
557 | 1240 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_NAME, GeneratePatientName(context))); |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1241 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1242 |
311 | 1243 return true; |
1244 } | |
1245 else | |
1246 { | |
1247 return false; | |
1248 } | |
1249 } | |
1250 | |
1251 | |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1252 static void AnonymizeOrModifyInstance(Removals& removals, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1253 Replacements& replacements, |
314 | 1254 bool removePrivateTags, |
1255 RestApi::PostCall& call) | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1256 { |
315 | 1257 boost::mutex::scoped_lock lock(cacheMutex_); |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1258 RETRIEVE_CONTEXT(call); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1259 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1260 std::string id = call.GetUriComponent("id", ""); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1261 ParsedDicomFile& dicom = context.GetDicomFile(id); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
299
diff
changeset
|
1262 |
314 | 1263 std::auto_ptr<ParsedDicomFile> modified(dicom.Clone()); |
1264 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); | |
1265 modified->Answer(call.GetOutput()); | |
1266 } | |
1267 | |
1268 | |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1269 static bool RetrieveMappedUid(ParsedDicomFile& dicom, |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1270 DicomRootLevel level, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1271 Replacements& replacements, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1272 UidMap& uidMap) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1273 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1274 std::auto_ptr<DicomTag> tag; |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1275 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1276 switch (level) |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1277 { |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1278 case DicomRootLevel_Series: |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1279 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1280 break; |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1281 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1282 case DicomRootLevel_Study: |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1283 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1284 break; |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1285 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1286 case DicomRootLevel_Patient: |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1287 tag.reset(new DicomTag(DICOM_TAG_PATIENT_ID)); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1288 break; |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1289 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1290 default: |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1291 throw OrthancException(ErrorCode_InternalError); |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1292 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1293 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1294 std::string original; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1295 if (!dicom.GetTagValue(original, *tag)) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1296 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1297 throw OrthancException(ErrorCode_InternalError); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1298 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1299 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1300 std::string mapped; |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1301 bool isNew; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1302 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1303 UidMap::const_iterator previous = uidMap.find(std::make_pair(level, original)); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1304 if (previous == uidMap.end()) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1305 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1306 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1307 uidMap.insert(std::make_pair(std::make_pair(level, original), mapped)); |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1308 isNew = true; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1309 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1310 else |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1311 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1312 mapped = previous->second; |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1313 isNew = false; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1314 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1315 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1316 replacements[*tag] = mapped; |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1317 return isNew; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1318 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1319 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1320 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1321 static void AnonymizeOrModifyResource(Removals& removals, |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1322 Replacements& replacements, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1323 bool removePrivateTags, |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1324 bool keepPatientId, |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1325 MetadataType metadataType, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1326 ChangeType changeType, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1327 ResourceType resourceType, |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1328 RestApi::PostCall& call) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1329 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1330 typedef std::list<std::string> Instances; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1331 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1332 bool isFirst = true; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1333 Json::Value result(Json::objectValue); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1334 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1335 boost::mutex::scoped_lock lock(cacheMutex_); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1336 RETRIEVE_CONTEXT(call); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1337 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1338 Instances instances; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1339 std::string id = call.GetUriComponent("id", ""); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1340 context.GetIndex().GetChildInstances(instances, id); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1341 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1342 if (instances.size() == 0) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1343 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1344 return; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1345 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1346 |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1347 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1348 /** |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1349 * Loop over all the instances of the resource. |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1350 **/ |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1351 |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1352 UidMap uidMap; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1353 for (Instances::const_iterator it = instances.begin(); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1354 it != instances.end(); it++) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1355 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1356 LOG(INFO) << "Modifying instance " << *it; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1357 ParsedDicomFile& original = context.GetDicomFile(*it); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1358 |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1359 DicomInstanceHasher originalHasher = original.GetHasher(); |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1360 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1361 if (isFirst && keepPatientId) |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1362 { |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1363 std::string patientId = originalHasher.GetPatientId(); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1364 uidMap[std::make_pair(DicomRootLevel_Patient, patientId)] = patientId; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1365 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1366 |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1367 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1368 bool isNewStudy = RetrieveMappedUid(original, DicomRootLevel_Study, replacements, uidMap); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1369 bool isNewPatient = RetrieveMappedUid(original, DicomRootLevel_Patient, replacements, uidMap); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1370 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1371 |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1372 /** |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1373 * Compute the resulting DICOM instance and store it into the Orthanc store. |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1374 **/ |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1375 |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1376 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1377 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1378 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1379 std::string modifiedInstance; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1380 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1381 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1382 LOG(ERROR) << "Error while storing a modified instance " << *it; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1383 return; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1384 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1385 |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1386 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1387 /** |
443
be93b666ed79
link anonymized to original resource in OrthancExplorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
1388 * Record metadata information (AnonymizedFrom/ModifiedFrom). |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1389 **/ |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1390 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1391 DicomInstanceHasher modifiedHasher = modified->GetHasher(); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1392 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1393 if (isNewSeries) |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1394 { |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1395 context.GetIndex().SetMetadata(modifiedHasher.HashSeries(), |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1396 metadataType, originalHasher.HashSeries()); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1397 } |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1398 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1399 if (isNewStudy) |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1400 { |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1401 context.GetIndex().SetMetadata(modifiedHasher.HashStudy(), |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1402 metadataType, originalHasher.HashStudy()); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1403 } |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1404 |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1405 if (isNewPatient) |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1406 { |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1407 context.GetIndex().SetMetadata(modifiedHasher.HashPatient(), |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1408 metadataType, originalHasher.HashPatient()); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1409 } |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1410 |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1411 assert(*it == originalHasher.HashInstance()); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1412 assert(modifiedInstance == modifiedHasher.HashInstance()); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1413 context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it); |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1414 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1415 |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1416 /** |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1417 * Compute the JSON object that is returned by the REST call. |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1418 **/ |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1419 |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1420 if (isFirst) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1421 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1422 std::string newId; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1423 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1424 switch (resourceType) |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1425 { |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1426 case ResourceType_Series: |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1427 newId = modifiedHasher.HashSeries(); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1428 break; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1429 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1430 case ResourceType_Study: |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1431 newId = modifiedHasher.HashStudy(); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1432 break; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1433 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1434 case ResourceType_Patient: |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1435 newId = modifiedHasher.HashPatient(); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1436 break; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1437 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1438 default: |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1439 throw OrthancException(ErrorCode_InternalError); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1440 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1441 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
1442 result["Type"] = EnumerationToString(resourceType); |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1443 result["ID"] = newId; |
348
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1444 result["Path"] = GetBasePath(resourceType, newId); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1445 result["PatientID"] = modifiedHasher.HashPatient(); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1446 isFirst = false; |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1447 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1448 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1449 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1450 call.GetOutput().AnswerJson(result); |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1451 } |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1452 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1453 |
1082e8121d10
refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
344
diff
changeset
|
1454 |
314 | 1455 static void ModifyInstance(RestApi::PostCall& call) |
1456 { | |
310 | 1457 Removals removals; |
1458 Replacements replacements; | |
312 | 1459 bool removePrivateTags; |
310 | 1460 |
312 | 1461 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
304 | 1462 { |
314 | 1463 AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call); |
304 | 1464 } |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1465 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1466 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1467 |
311 | 1468 static void AnonymizeInstance(RestApi::PostCall& call) |
1469 { | |
1470 Removals removals; | |
1471 Replacements replacements; | |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1472 bool removePrivateTags, keepPatientId; |
311 | 1473 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1474 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
311 | 1475 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1476 // TODO Handle "keepPatientId" |
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1477 |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1478 // Generate random patient ID if not specified |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1479 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end()) |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1480 { |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1481 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1482 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1483 } |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1484 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1485 // Generate random study UID if not specified |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1486 if (replacements.find(DICOM_TAG_STUDY_INSTANCE_UID) == replacements.end()) |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1487 { |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1488 replacements.insert(std::make_pair(DICOM_TAG_STUDY_INSTANCE_UID, |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1489 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study))); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1490 } |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1491 |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1492 // Generate random series UID if not specified |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1493 if (replacements.find(DICOM_TAG_SERIES_INSTANCE_UID) == replacements.end()) |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1494 { |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1495 replacements.insert(std::make_pair(DICOM_TAG_SERIES_INSTANCE_UID, |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1496 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series))); |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1497 } |
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1498 |
314 | 1499 AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call); |
311 | 1500 } |
1501 } | |
1502 | |
1503 | |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1504 static void ModifySeriesInplace(RestApi::PostCall& call) |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
1505 { |
310 | 1506 Removals removals; |
1507 Replacements replacements; | |
312 | 1508 bool removePrivateTags; |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1509 |
312 | 1510 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1511 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1512 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/, |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1513 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries, |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1514 ResourceType_Series, call); |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1515 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1516 } |
315 | 1517 |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1518 |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1519 static void AnonymizeSeriesInplace(RestApi::PostCall& call) |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1520 { |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1521 Removals removals; |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1522 Replacements replacements; |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1523 bool removePrivateTags, keepPatientId; |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1524 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1525 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1526 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1527 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1528 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries, |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1529 ResourceType_Series, call); |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1530 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1531 } |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1532 |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1533 |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1534 static void ModifyStudyInplace(RestApi::PostCall& call) |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1535 { |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1536 Removals removals; |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1537 Replacements replacements; |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1538 bool removePrivateTags; |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1539 |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1540 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1541 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1542 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, true /*keepPatientId*/, |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1543 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy, |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1544 ResourceType_Study, call); |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1545 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1546 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1547 |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1548 |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1549 static void AnonymizeStudyInplace(RestApi::PostCall& call) |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1550 { |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1551 Removals removals; |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1552 Replacements replacements; |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1553 bool removePrivateTags, keepPatientId; |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1554 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1555 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1556 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1557 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, |
349
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1558 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy, |
c5edf0cc6e95
switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
348
diff
changeset
|
1559 ResourceType_Study, call); |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1560 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1561 } |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1562 |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1563 |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1564 /*static void ModifyPatientInplace(RestApi::PostCall& call) |
351 | 1565 { |
1566 Removals removals; | |
1567 Replacements replacements; | |
1568 bool removePrivateTags; | |
1569 | |
1570 if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) | |
1571 { | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1572 AnonymizeOrModifyResource(false, removals, replacements, removePrivateTags, |
351 | 1573 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient, |
1574 ResourceType_Patient, call); | |
1575 } | |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1576 }*/ |
351 | 1577 |
1578 | |
1579 static void AnonymizePatientInplace(RestApi::PostCall& call) | |
1580 { | |
1581 Removals removals; | |
1582 Replacements replacements; | |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1583 bool removePrivateTags, keepPatientId; |
351 | 1584 |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1585 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, keepPatientId, call)) |
351 | 1586 { |
602
d5043ff68d58
Possibility to keep the PatientID during an anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
557
diff
changeset
|
1587 AnonymizeOrModifyResource(removals, replacements, removePrivateTags, keepPatientId, |
351 | 1588 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient, |
1589 ResourceType_Patient, call); | |
1590 } | |
1591 } | |
1592 | |
1593 | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1594 // Handling of metadata ----------------------------------------------------- |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1595 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1596 static void ListMetadata(RestApi::GetCall& call) |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1597 { |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1598 RETRIEVE_CONTEXT(call); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1599 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1600 std::string publicId = call.GetUriComponent("id", ""); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1601 std::list<MetadataType> metadata; |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1602 if (context.GetIndex().ListAvailableMetadata(metadata, publicId)) |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1603 { |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1604 Json::Value result = Json::arrayValue; |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1605 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1606 for (std::list<MetadataType>::const_iterator |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1607 it = metadata.begin(); it != metadata.end(); it++) |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1608 { |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1609 result.append(EnumerationToString(*it)); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1610 } |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1611 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1612 call.GetOutput().AnswerJson(result); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1613 } |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1614 } |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1615 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1616 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1617 static void GetMetadata(RestApi::GetCall& call) |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1618 { |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1619 RETRIEVE_CONTEXT(call); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1620 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1621 std::string publicId = call.GetUriComponent("id", ""); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1622 std::string name = call.GetUriComponent("name", ""); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1623 MetadataType metadata = StringToMetadata(name); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1624 |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1625 std::string value; |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1626 if (context.GetIndex().LookupMetadata(value, publicId, metadata)) |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1627 { |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1628 call.GetOutput().AnswerBuffer(value, "text/plain"); |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1629 } |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1630 } |
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1631 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
1632 |
438 | 1633 static void DeleteMetadata(RestApi::DeleteCall& call) |
1634 { | |
1635 RETRIEVE_CONTEXT(call); | |
1636 | |
1637 std::string publicId = call.GetUriComponent("id", ""); | |
1638 std::string name = call.GetUriComponent("name", ""); | |
1639 MetadataType metadata = StringToMetadata(name); | |
1640 | |
1641 if (metadata >= MetadataType_StartUser && | |
1642 metadata <= MetadataType_EndUser) | |
1643 { | |
1644 // It is forbidden to modify internal metadata | |
1645 context.GetIndex().DeleteMetadata(publicId, metadata); | |
1646 call.GetOutput().AnswerBuffer("", "text/plain"); | |
1647 } | |
1648 } | |
1649 | |
1650 | |
437 | 1651 static void SetMetadata(RestApi::PutCall& call) |
1652 { | |
1653 RETRIEVE_CONTEXT(call); | |
1654 | |
1655 std::string publicId = call.GetUriComponent("id", ""); | |
1656 std::string name = call.GetUriComponent("name", ""); | |
1657 MetadataType metadata = StringToMetadata(name); | |
1658 std::string value = call.GetPutBody(); | |
1659 | |
1660 if (metadata >= MetadataType_StartUser && | |
1661 metadata <= MetadataType_EndUser) | |
1662 { | |
1663 // It is forbidden to modify internal metadata | |
1664 context.GetIndex().SetMetadata(publicId, metadata, value); | |
1665 call.GetOutput().AnswerBuffer("", "text/plain"); | |
1666 } | |
1667 } | |
1668 | |
1669 | |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1670 static void GetResourceStatistics(RestApi::GetCall& call) |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1671 { |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1672 RETRIEVE_CONTEXT(call); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1673 std::string publicId = call.GetUriComponent("id", ""); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1674 Json::Value result; |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1675 context.GetIndex().GetStatistics(result, publicId); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1676 call.GetOutput().AnswerJson(result); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1677 } |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1678 |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1679 |
437 | 1680 |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1681 // Orthanc Peers ------------------------------------------------------------ |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1682 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1683 static bool IsExistingPeer(const OrthancRestApi::SetOfStrings& peers, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1684 const std::string& id) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1685 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1686 return peers.find(id) != peers.end(); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1687 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1688 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1689 static void ListPeers(RestApi::GetCall& call) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1690 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1691 RETRIEVE_PEERS(call); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1692 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1693 Json::Value result = Json::arrayValue; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1694 for (OrthancRestApi::SetOfStrings::const_iterator |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1695 it = peers.begin(); it != peers.end(); it++) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1696 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1697 result.append(*it); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1698 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1699 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1700 call.GetOutput().AnswerJson(result); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1701 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1702 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1703 static void ListPeerOperations(RestApi::GetCall& call) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1704 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1705 RETRIEVE_PEERS(call); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1706 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1707 std::string id = call.GetUriComponent("id", ""); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1708 if (IsExistingPeer(peers, id)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1709 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1710 Json::Value result = Json::arrayValue; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1711 result.append("store"); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1712 call.GetOutput().AnswerJson(result); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1713 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1714 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1715 |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1716 static void PeerStore(RestApi::PostCall& call) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1717 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1718 RETRIEVE_CONTEXT(call); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1719 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1720 std::string remote = call.GetUriComponent("id", ""); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1721 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1722 std::list<std::string> instances; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1723 if (!GetInstancesToExport(instances, remote, call)) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1724 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1725 return; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1726 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1727 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1728 std::string url, username, password; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1729 GetOrthancPeer(remote, url, username, password); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1730 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1731 // Configure the HTTP client |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1732 HttpClient client; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1733 if (username.size() != 0 && password.size() != 0) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1734 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1735 client.SetCredentials(username.c_str(), password.c_str()); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1736 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1737 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1738 client.SetUrl(url + "instances"); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1739 client.SetMethod(HttpMethod_Post); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1740 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1741 // Loop over the instances that are to be sent |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1742 for (std::list<std::string>::const_iterator |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1743 it = instances.begin(); it != instances.end(); it++) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1744 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1745 LOG(INFO) << "Sending resource " << *it << " to peer \"" << remote << "\""; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1746 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1747 context.ReadFile(client.AccessPostData(), *it, FileContentType_Dicom); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1748 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1749 std::string answer; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1750 if (!client.Apply(answer)) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1751 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1752 LOG(ERROR) << "Unable to send resource " << *it << " to peer \"" << remote << "\""; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1753 return; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1754 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1755 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1756 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1757 call.GetOutput().AnswerBuffer("{}", "application/json"); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1758 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1759 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1760 |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1761 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1762 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1763 |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1764 // Registration of the various REST handlers -------------------------------- |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1765 |
230 | 1766 OrthancRestApi::OrthancRestApi(ServerContext& context) : |
224
4eb0c7ce86c9
refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
218
diff
changeset
|
1767 context_(context) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1768 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1769 GetListOfDicomModalities(modalities_); |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1770 GetListOfOrthancPeers(peers_); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1771 |
211 | 1772 Register("/", ServeRoot); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1773 Register("/system", GetSystemInformation); |
238 | 1774 Register("/statistics", GetStatistics); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1775 Register("/changes", GetChanges); |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
1776 Register("/changes", DeleteChanges); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
1777 Register("/exports", GetExports); |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
403
diff
changeset
|
1778 Register("/exports", DeleteExports); |
211 | 1779 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
1780 Register("/instances", UploadDicomFile); |
211 | 1781 Register("/instances", ListResources<ResourceType_Instance>); |
1782 Register("/patients", ListResources<ResourceType_Patient>); | |
1783 Register("/series", ListResources<ResourceType_Series>); | |
1784 Register("/studies", ListResources<ResourceType_Study>); | |
212 | 1785 |
1786 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>); | |
1787 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>); | |
1788 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>); | |
1789 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>); | |
1790 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>); | |
1791 Register("/series/{id}", GetSingleResource<ResourceType_Series>); | |
1792 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>); | |
1793 Register("/studies/{id}", GetSingleResource<ResourceType_Study>); | |
250
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
1794 |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
1795 Register("/patients/{id}/archive", GetArchive<ResourceType_Patient>); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
1796 Register("/studies/{id}/archive", GetArchive<ResourceType_Study>); |
f23318b11b39
creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
249
diff
changeset
|
1797 Register("/series/{id}/archive", GetArchive<ResourceType_Series>); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1798 |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1799 Register("/instances/{id}/statistics", GetResourceStatistics); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1800 Register("/patients/{id}/statistics", GetResourceStatistics); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1801 Register("/studies/{id}/statistics", GetResourceStatistics); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1802 Register("/series/{id}/statistics", GetResourceStatistics); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
1803 |
437 | 1804 Register("/instances/{id}/metadata", ListMetadata); |
438 | 1805 Register("/instances/{id}/metadata/{name}", DeleteMetadata); |
437 | 1806 Register("/instances/{id}/metadata/{name}", GetMetadata); |
1807 Register("/instances/{id}/metadata/{name}", SetMetadata); | |
1808 Register("/patients/{id}/metadata", ListMetadata); | |
438 | 1809 Register("/patients/{id}/metadata/{name}", DeleteMetadata); |
437 | 1810 Register("/patients/{id}/metadata/{name}", GetMetadata); |
1811 Register("/patients/{id}/metadata/{name}", SetMetadata); | |
1812 Register("/series/{id}/metadata", ListMetadata); | |
438 | 1813 Register("/series/{id}/metadata/{name}", DeleteMetadata); |
437 | 1814 Register("/series/{id}/metadata/{name}", GetMetadata); |
1815 Register("/series/{id}/metadata/{name}", SetMetadata); | |
1816 Register("/studies/{id}/metadata", ListMetadata); | |
438 | 1817 Register("/studies/{id}/metadata/{name}", DeleteMetadata); |
437 | 1818 Register("/studies/{id}/metadata/{name}", GetMetadata); |
1819 Register("/studies/{id}/metadata/{name}", SetMetadata); | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
1820 |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
1821 Register("/patients/{id}/protected", IsProtectedPatient); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
1822 Register("/patients/{id}/protected", SetPatientProtection); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1823 Register("/instances/{id}/file", GetInstanceFile); |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
465
diff
changeset
|
1824 Register("/instances/{id}/export", ExportInstanceFile); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1825 Register("/instances/{id}/tags", GetInstanceTags<false>); |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1826 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); |
214 | 1827 Register("/instances/{id}/frames", ListFrames); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
1828 Register("/instances/{id}/content/*", GetRawContent); |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
1829 |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1830 Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1831 Register("/instances/{id}/frames/{frame}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1832 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
465
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
463
diff
changeset
|
1833 Register("/instances/{id}/frames/{frame}/image-int16", GetImage<ImageExtractionMode_Int16>); |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1834 Register("/instances/{id}/preview", GetImage<ImageExtractionMode_Preview>); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1835 Register("/instances/{id}/image-uint8", GetImage<ImageExtractionMode_UInt8>); |
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1836 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>); |
465
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
463
diff
changeset
|
1837 Register("/instances/{id}/image-int16", GetImage<ImageExtractionMode_Int16>); |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
1838 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1839 Register("/modalities", ListModalities); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1840 Register("/modalities/{id}", ListModalityOperations); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1841 Register("/modalities/{id}/find-patient", DicomFindPatient); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1842 Register("/modalities/{id}/find-study", DicomFindStudy); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1843 Register("/modalities/{id}/find-series", DicomFindSeries); |
499
7db04aa5104f
instance-level find scu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
485
diff
changeset
|
1844 Register("/modalities/{id}/find-instance", DicomFindInstance); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1845 Register("/modalities/{id}/find", DicomFind); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1846 Register("/modalities/{id}/store", DicomStore); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
1847 |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1848 Register("/peers", ListPeers); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1849 Register("/peers/{id}", ListPeerOperations); |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
1850 Register("/peers/{id}/store", PeerStore); |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
1851 |
304 | 1852 Register("/instances/{id}/modify", ModifyInstance); |
308
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1853 Register("/series/{id}/modify", ModifySeriesInplace); |
fbf2b2282086
inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
1854 Register("/studies/{id}/modify", ModifyStudyInplace); |
515
a8be42bcf2bb
Link from modified to original resource in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
499
diff
changeset
|
1855 //Register("/patients/{id}/modify", ModifyPatientInplace); |
311 | 1856 |
1857 Register("/instances/{id}/anonymize", AnonymizeInstance); | |
316
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1858 Register("/series/{id}/anonymize", AnonymizeSeriesInplace); |
d526ac73c886
anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
1859 Register("/studies/{id}/anonymize", AnonymizeStudyInplace); |
351 | 1860 Register("/patients/{id}/anonymize", AnonymizePatientInplace); |
342
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
1861 |
a58a8be26aff
generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
321
diff
changeset
|
1862 Register("/tools/generate-uid", GenerateUid); |
418
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
1863 Register("/tools/execute-script", ExecuteScript); |
446 | 1864 Register("/tools/now", GetNowIsoString); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1865 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1866 } |