annotate OrthancServer/OrthancRestApi.cpp @ 602:d5043ff68d58

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