annotate OrthancServer/OrthancRestApi.cpp @ 399:4d5f0857ec9c

copyright update
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Apr 2013 10:54:46 +0200
parents 8d3a0db39967
children d2c69150a979
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
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
35 #include "../Core/HttpServer/FilesystemHttpSender.h"
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
36 #include "../Core/Uuid.h"
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
37 #include "../Core/Compression/HierarchicalZipWriter.h"
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
38 #include "DicomProtocol/DicomUserConnection.h"
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "FromDcmtkBridge.h"
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
40 #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
41 #include "ServerToolbox.h"
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <dcmtk/dcmdata/dcistrmb.h>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include <dcmtk/dcmdata/dcfilefo.h>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <boost/lexical_cast.hpp>
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
46 #include <glog/logging.h>
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
49 #define RETRIEVE_CONTEXT(call) \
230
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
50 OrthancRestApi& contextApi = \
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
51 dynamic_cast<OrthancRestApi&>(call.GetContext()); \
225
03aa59ecf6d8 fix for mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
52 ServerContext& context = contextApi.GetContext()
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
54 #define RETRIEVE_MODALITIES(call) \
230
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
55 const OrthancRestApi::Modalities& modalities = \
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
56 dynamic_cast<OrthancRestApi&>(call.GetContext()).GetModalities();
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
57
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
58
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 namespace Orthanc
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
62 // TODO IMPROVE MULTITHREADING
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
63 // Every call to "ParsedDicomFile" must lock this mutex!!!
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
64 static boost::mutex cacheMutex_;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
65
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
66
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
67 // DICOM SCU ----------------------------------------------------------------
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
68
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
69 static void ConnectToModality(DicomUserConnection& connection,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
70 const std::string& name)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
71 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
72 std::string aet, address;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
73 int port;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
74 GetDicomModality(name, aet, address, port);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
75 connection.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
76 connection.SetDistantApplicationEntityTitle(aet);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
77 connection.SetDistantHost(address);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
78 connection.SetDistantPort(port);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
79 connection.Open();
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
80 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
81
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
82 static bool MergeQueryAndTemplate(DicomMap& result,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
83 const std::string& postData)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
84 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
85 Json::Value query;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
86 Json::Reader reader;
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 if (!reader.parse(postData, query) ||
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
89 query.type() != Json::objectValue)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
90 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
91 return false;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
92 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
93
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
94 Json::Value::Members members = query.getMemberNames();
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
95 for (size_t i = 0; i < members.size(); i++)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
96 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
97 DicomTag t = FromDcmtkBridge::ParseTag(members[i]);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
98 result.SetValue(t, query[members[i]].asString());
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 return true;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
102 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
103
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
104 static void DicomFindPatient(RestApi::PostCall& call)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
105 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
106 DicomMap m;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
107 DicomMap::SetupFindPatientTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
108 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
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 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
111 }
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 DicomUserConnection connection;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
114 ConnectToModality(connection, call.GetUriComponent("id", ""));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
115
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
116 DicomFindAnswers answers;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
117 connection.FindPatient(answers, m);
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 Json::Value result;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
120 answers.ToJson(result);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
121 call.GetOutput().AnswerJson(result);
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
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
124 static void DicomFindStudy(RestApi::PostCall& call)
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 DicomMap m;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
127 DicomMap::SetupFindStudyTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
128 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
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 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
131 }
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 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
134 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
135 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
136 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
137 }
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 DicomUserConnection connection;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
140 ConnectToModality(connection, call.GetUriComponent("id", ""));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
141
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
142 DicomFindAnswers answers;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
143 connection.FindStudy(answers, m);
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 Json::Value result;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
146 answers.ToJson(result);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
147 call.GetOutput().AnswerJson(result);
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
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
150 static void DicomFindSeries(RestApi::PostCall& call)
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 DicomMap m;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
153 DicomMap::SetupFindSeriesTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
154 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
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 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
157 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
158
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
159 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
160 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) ||
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
161 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
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 DicomUserConnection connection;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
167 ConnectToModality(connection, call.GetUriComponent("id", ""));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
168
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
169 DicomFindAnswers answers;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
170 connection.FindSeries(answers, m);
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 Json::Value result;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
173 answers.ToJson(result);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
174 call.GetOutput().AnswerJson(result);
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
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
177 static void DicomFind(RestApi::PostCall& call)
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 DicomMap m;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
180 DicomMap::SetupFindPatientTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
181 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
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 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
184 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
185
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
186 DicomUserConnection connection;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
187 ConnectToModality(connection, call.GetUriComponent("id", ""));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
188
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
189 DicomFindAnswers patients;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
190 connection.FindPatient(patients, m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
191
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
192 // Loop over the found patients
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
193 Json::Value result = Json::arrayValue;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
194 for (size_t i = 0; i < patients.GetSize(); i++)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
195 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
196 Json::Value patient(Json::objectValue);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
197 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
198
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
199 DicomMap::SetupFindStudyTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
200 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
201 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
202 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
203 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
204 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
205
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
206 DicomFindAnswers studies;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
207 connection.FindStudy(studies, m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
208
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
209 patient["Studies"] = Json::arrayValue;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
210
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
211 // Loop over the found studies
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
212 for (size_t j = 0; j < studies.GetSize(); j++)
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 Json::Value study(Json::objectValue);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
215 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
216
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
217 DicomMap::SetupFindSeriesTemplate(m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
218 if (!MergeQueryAndTemplate(m, call.GetPostBody()))
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 return;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
221 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
222 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
223 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
224
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
225 DicomFindAnswers series;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
226 connection.FindSeries(series, m);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
228 // Loop over the found series
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
229 study["Series"] = Json::arrayValue;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
230 for (size_t k = 0; k < series.GetSize(); k++)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
231 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
232 Json::Value series2(Json::objectValue);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
233 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k));
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
234 study["Series"].append(series2);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
235 }
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 patient["Studies"].append(study);
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
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
240 result.append(patient);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
241 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
242
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
243 call.GetOutput().AnswerJson(result);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
244 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
245
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
246
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
247 static void DicomStore(RestApi::PostCall& call)
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 RETRIEVE_CONTEXT(call);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
250
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
251 std::string remote = call.GetUriComponent("id", "");
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
252 DicomUserConnection connection;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
253 ConnectToModality(connection, remote);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
254
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
255 const std::string& resourceId = call.GetPostBody();
227
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 Json::Value found;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
258 if (context.GetIndex().LookupResource(found, resourceId, ResourceType_Series))
227
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 // The UUID corresponds to a series
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
261 context.GetIndex().LogExportedResource(resourceId, remote);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
262
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
263 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
264 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
265 std::string instanceId = found["Instances"][i].asString();
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
266 std::string dicom;
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
267 context.ReadFile(dicom, instanceId, FileContentType_Dicom);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
268 connection.Store(dicom);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
269 }
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 call.GetOutput().AnswerBuffer("{}", "application/json");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
272 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
273 else if (context.GetIndex().LookupResource(found, resourceId, ResourceType_Instance))
227
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 // The UUID corresponds to an instance
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
276 context.GetIndex().LogExportedResource(resourceId, remote);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
277
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
278 std::string dicom;
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
279 context.ReadFile(dicom, resourceId, FileContentType_Dicom);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
280 connection.Store(dicom);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
281
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
282 call.GetOutput().AnswerBuffer("{}", "application/json");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
283 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
284 else
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 // The POST body is not a known resource, assume that it
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
287 // contains a raw DICOM instance
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
288 connection.Store(resourceId);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
289 call.GetOutput().AnswerBuffer("{}", "application/json");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
290 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
291 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
292
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
293
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
294
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 // System information -------------------------------------------------------
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
296
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
297 static void ServeRoot(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
298 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
299 call.GetOutput().Redirect("app/explorer.html");
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
300 }
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 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
303 {
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
304 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
305
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 result["Version"] = ORTHANC_VERSION;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 result["Name"] = GetGlobalStringParameter("Name", "");
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
308
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
309 call.GetOutput().AnswerJson(result);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
310 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
311
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
312 static void GetStatistics(RestApi::GetCall& call)
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
313 {
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
314 RETRIEVE_CONTEXT(call);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
315 Json::Value result = Json::objectValue;
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
316 context.GetIndex().ComputeStatistics(result);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
342
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
320 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
321 {
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
322 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
323 if (level == "patient")
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
324 {
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
325 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
326 }
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
327 else if (level == "study")
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
328 {
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
329 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
330 }
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
331 else if (level == "series")
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
332 {
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
333 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
334 }
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
335 else if (level == "instance")
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
336 {
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
337 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
338 }
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
339 }
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
340
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
342 // List all the patients, studies, series or instances ----------------------
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
343
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
344 template <enum ResourceType resourceType>
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
345 static void ListResources(RestApi::GetCall& call)
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
346 {
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
347 RETRIEVE_CONTEXT(call);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
348
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
349 Json::Value result;
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
350 context.GetIndex().GetAllUuids(result, resourceType);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
351 call.GetOutput().AnswerJson(result);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
352 }
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
353
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
354 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
355 static void GetSingleResource(RestApi::GetCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
356 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
357 RETRIEVE_CONTEXT(call);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
358
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
359 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
360 if (context.GetIndex().LookupResource(result, call.GetUriComponent("id", ""), resourceType))
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
361 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
362 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
363 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
364 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
365
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
366 template <enum ResourceType resourceType>
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
367 static void DeleteSingleResource(RestApi::DeleteCall& call)
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
368 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
369 RETRIEVE_CONTEXT(call);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
370
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
371 Json::Value result;
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
372 if (context.GetIndex().DeleteResource(result, call.GetUriComponent("id", ""), resourceType))
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
373 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
374 call.GetOutput().AnswerJson(result);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
375 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
376 }
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
377
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
378
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
379 // Download of ZIP files ----------------------------------------------------
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
380
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
381
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
382 static std::string GetDirectoryNameInArchive(const Json::Value& resource,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
383 ResourceType resourceType)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
384 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
385 switch (resourceType)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
386 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
387 case ResourceType_Patient:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
388 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
389 std::string p = resource["MainDicomTags"]["PatientID"].asString();
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
390 std::string n = resource["MainDicomTags"]["PatientName"].asString();
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
391 return p + " " + n;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
392 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
393
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
394 case ResourceType_Study:
253
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
395 {
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
396 return resource["MainDicomTags"]["StudyDescription"].asString();
253
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
397 }
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
398
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
399 case ResourceType_Series:
253
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
400 {
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
401 std::string d = resource["MainDicomTags"]["SeriesDescription"].asString();
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
402 std::string m = resource["MainDicomTags"]["Modality"].asString();
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
403 return m + " " + d;
15fcd925b05b improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 250
diff changeset
404 }
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
405
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
406 default:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
407 throw OrthancException(ErrorCode_InternalError);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
408 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
409 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
410
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
411 static bool CreateRootDirectoryInArchive(HierarchicalZipWriter& writer,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
412 ServerContext& context,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
413 const Json::Value& resource,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
414 ResourceType resourceType)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
415 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
416 if (resourceType == ResourceType_Patient)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
417 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
418 return true;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
419 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
420
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
421 ResourceType parentType = GetParentResourceType(resourceType);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
422 Json::Value parent;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
423
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
424 switch (resourceType)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
425 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
426 case ResourceType_Study:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
427 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
428 if (!context.GetIndex().LookupResource(parent, resource["ParentPatient"].asString(), parentType))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
429 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
430 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
431 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
432
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
433 break;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
434 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
435
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
436 case ResourceType_Series:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
437 if (!context.GetIndex().LookupResource(parent, resource["ParentStudy"].asString(), parentType) ||
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
438 !CreateRootDirectoryInArchive(writer, context, parent, parentType))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
439 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
440 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
441 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
442 break;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
443
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
444 default:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
445 throw OrthancException(ErrorCode_NotImplemented);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
446 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
447
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
448 writer.OpenDirectory(GetDirectoryNameInArchive(parent, parentType).c_str());
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
449 return true;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
450 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
451
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
452 static bool ArchiveInstance(HierarchicalZipWriter& writer,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
453 ServerContext& context,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
454 const std::string& instancePublicId)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
455 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
456 Json::Value instance;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
457 if (!context.GetIndex().LookupResource(instance, instancePublicId, ResourceType_Instance))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
458 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
459 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
460 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
461
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
462 std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm";
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
463 writer.OpenFile(filename.c_str());
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
464
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
465 std::string dicom;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
466 context.ReadFile(dicom, instancePublicId, FileContentType_Dicom);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
467 writer.Write(dicom);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
468
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
469 return true;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
470 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
471
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
472 static bool ArchiveInternal(HierarchicalZipWriter& writer,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
473 ServerContext& context,
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
474 const std::string& publicId,
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 bool isFirstLevel)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
477 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
478 Json::Value resource;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
479 if (!context.GetIndex().LookupResource(resource, publicId, resourceType))
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 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
482 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
483
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
484 if (isFirstLevel &&
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
485 !CreateRootDirectoryInArchive(writer, context, resource, resourceType))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
486 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
487 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
488 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
489
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
490 writer.OpenDirectory(GetDirectoryNameInArchive(resource, resourceType).c_str());
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
491
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
492 switch (resourceType)
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
493 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
494 case ResourceType_Patient:
299
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
495 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
496 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
497 std::string studyId = resource["Studies"][i].asString();
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
498 if (!ArchiveInternal(writer, context, studyId, ResourceType_Study, false))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
499 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
500 return false;
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 break;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
504
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
505 case ResourceType_Study:
299
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
506 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
507 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
508 std::string seriesId = resource["Series"][i].asString();
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
509 if (!ArchiveInternal(writer, context, seriesId, ResourceType_Series, false))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
510 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
511 return false;
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 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
514 break;
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 case ResourceType_Series:
299
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
517 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
518 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
519 if (!ArchiveInstance(writer, context, resource["Instances"][i].asString()))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
520 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
521 return false;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
522 }
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 break;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
525
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
526 default:
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
527 throw OrthancException(ErrorCode_InternalError);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
528 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
529
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
530 writer.CloseDirectory();
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
531 return true;
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
532 }
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
533
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
534 template <enum ResourceType resourceType>
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
535 static void GetArchive(RestApi::GetCall& call)
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
536 {
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
537 RETRIEVE_CONTEXT(call);
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
538
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
539 // 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
540 Toolbox::TemporaryFile tmp;
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
541 std::string id = call.GetUriComponent("id", "");
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
542
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
543 {
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
544 // Create a ZIP writer
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
545 HierarchicalZipWriter writer(tmp.GetPath().c_str());
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
546
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
547 // Store the requested resource into the ZIP
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
548 if (!ArchiveInternal(writer, context, id, resourceType, true))
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
549 {
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
550 return;
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
551 }
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
552 }
250
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 // Prepare the sending of the ZIP file
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
555 FilesystemHttpSender sender(tmp.GetPath().c_str());
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
556 sender.SetContentType("application/zip");
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
557 sender.SetDownloadFilename(id + ".zip");
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
558
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
559 // Send the ZIP
248
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
560 call.GetOutput().AnswerFile(sender);
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
561
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
562 // 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
563 }
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
564
2442033911d6 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
565
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 // Changes API --------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
568 static void GetSinceAndLimit(int64_t& since,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
569 unsigned int& limit,
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
570 bool& last,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
571 const RestApi::GetCall& call)
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 static const unsigned int MAX_RESULTS = 100;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
574
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
575 if (call.HasArgument("last"))
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
576 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
577 last = true;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
578 return;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
579 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
580
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
581 last = false;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
582
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 try
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 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
586 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
587 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 catch (boost::bad_lexical_cast)
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 return;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 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
594 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 limit = MAX_RESULTS;
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
597 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
598
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
599 static void GetChanges(RestApi::GetCall& call)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
600 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
601 RETRIEVE_CONTEXT(call);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
602
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
603 //std::string filter = GetArgument(getArguments, "filter", "");
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
604 int64_t since;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
605 unsigned int limit;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
606 bool last;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
607 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
608
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 Json::Value result;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
610 if ((!last && context.GetIndex().GetChanges(result, since, limit)) ||
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
611 ( 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
612 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
618 static void GetExports(RestApi::GetCall& call)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
619 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
620 RETRIEVE_CONTEXT(call);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
621
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
622 int64_t since;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
623 unsigned int limit;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
624 bool last;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
625 GetSinceAndLimit(since, limit, last, call);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
626
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
627 Json::Value result;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
628 if ((!last && context.GetIndex().GetExportedResources(result, since, limit)) ||
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
629 ( last && context.GetIndex().GetLastExportedResource(result)))
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
630 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
631 call.GetOutput().AnswerJson(result);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
632 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
633 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
634
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
636 // Get information about a single patient -----------------------------------
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
637
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
638 static void IsProtectedPatient(RestApi::GetCall& call)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
639 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
640 RETRIEVE_CONTEXT(call);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
641 std::string publicId = call.GetUriComponent("id", "");
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
642 bool isProtected = context.GetIndex().IsProtectedPatient(publicId);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
643 call.GetOutput().AnswerBuffer(isProtected ? "1" : "0", "text/plain");
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
644 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
645
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
646
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
647 static void SetPatientProtection(RestApi::PutCall& call)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
648 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
649 RETRIEVE_CONTEXT(call);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
650 std::string publicId = call.GetUriComponent("id", "");
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
651 std::string s = Toolbox::StripSpaces(call.GetPutBody());
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
652
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
653 if (s == "0")
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
654 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
655 context.GetIndex().SetProtectedPatient(publicId, false);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
656 call.GetOutput().AnswerBuffer("", "text/plain");
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
657 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
658 else if (s == "1")
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
659 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
660 context.GetIndex().SetProtectedPatient(publicId, true);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
661 call.GetOutput().AnswerBuffer("", "text/plain");
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
662 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
663 else
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
664 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
665 // Bad request
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
666 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
667 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
668
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
669
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
670 // 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
671
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
672 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
673 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
674 RETRIEVE_CONTEXT(call);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
675
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
676 std::string publicId = call.GetUriComponent("id", "");
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
677 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
678 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
679
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
680
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
681 template <bool simplify>
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
682 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
683 {
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
684 RETRIEVE_CONTEXT(call);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
685
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
686 std::string publicId = call.GetUriComponent("id", "");
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
687
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
688 Json::Value full;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
689 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
690
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
691 if (simplify)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
692 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
693 Json::Value simplified;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
694 SimplifyTags(simplified, full);
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
695 call.GetOutput().AnswerJson(simplified);
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
696 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
697 else
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
698 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
699 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
700 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
701 }
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
702
214
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
703
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
704 static void ListFrames(RestApi::GetCall& call)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
705 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
706 RETRIEVE_CONTEXT(call);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
707
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
708 Json::Value instance;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
709 if (context.GetIndex().LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance))
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
710 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
711 unsigned int numberOfFrames = 1;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
712
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
713 try
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
714 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
715 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"];
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
716 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString());
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
717 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
718 catch (...)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
719 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
720 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
721
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
722 Json::Value result = Json::arrayValue;
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
723 for (unsigned int i = 0; i < numberOfFrames; i++)
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
724 {
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
725 result.append(i);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
726 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
727
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
728 call.GetOutput().AnswerJson(result);
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
729 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
730 }
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
731
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
732
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
733 template <enum ImageExtractionMode mode>
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
734 static void GetImage(RestApi::GetCall& call)
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
735 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
736 RETRIEVE_CONTEXT(call);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
737
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
738 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
739
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
740 unsigned int frame;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
741 try
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
742 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
743 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
744 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
745 catch (boost::bad_lexical_cast)
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
746 {
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
747 return;
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
748 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
749
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
750 std::string publicId = call.GetUriComponent("id", "");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
751 std::string dicomContent, png;
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
752 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
753
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
754 try
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
755 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
756 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, mode);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
757 call.GetOutput().AnswerBuffer(png, "image/png");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
758 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
759 catch (OrthancException& e)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
760 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
761 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange)
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
762 {
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
763 // 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
764 // instance, the resource is not existent
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
765 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
766 else
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
767 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
768 std::string root = "";
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
769 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
770 {
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
771 root += "../";
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
772 }
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
773
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
774 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
775 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
776 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
777 }
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
778
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
779
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
780 // Upload of DICOM files through HTTP ---------------------------------------
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
781
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
782 static void UploadDicomFile(RestApi::PostCall& call)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
783 {
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
784 RETRIEVE_CONTEXT(call);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
785
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
786 const std::string& postData = call.GetPostBody();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
787 if (postData.size() == 0)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
788 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
789 return;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
790 }
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
791
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
792 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
793
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
794 std::string publicId;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
795 StoreStatus status = context.Store(publicId, postData);
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
796 Json::Value result = Json::objectValue;
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
797
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
798 if (status != StoreStatus_Failure)
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
799 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
800 result["ID"] = publicId;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
801 result["Path"] = GetBasePath(ResourceType_Instance, publicId);
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
802 }
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
803
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
804 result["Status"] = ToString(status);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
805 call.GetOutput().AnswerJson(result);
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
806 }
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
807
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
809
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 // DICOM bridge -------------------------------------------------------------
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
230
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
812 static bool IsExistingModality(const OrthancRestApi::Modalities& modalities,
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
813 const std::string& id)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
814 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
815 return modalities.find(id) != modalities.end();
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
816 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
817
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 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
819 {
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
820 RETRIEVE_MODALITIES(call);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 Json::Value result = Json::arrayValue;
230
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
823 for (OrthancRestApi::Modalities::const_iterator
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
824 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
825 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 result.append(*it);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 call.GetOutput().AnswerJson(result);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
833 static void ListModalityOperations(RestApi::GetCall& call)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
834 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
835 RETRIEVE_MODALITIES(call);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
836
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
837 std::string id = call.GetUriComponent("id", "");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
838 if (IsExistingModality(modalities, id))
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
839 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
840 Json::Value result = Json::arrayValue;
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
841 result.append("find-patient");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
842 result.append("find-study");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
843 result.append("find-series");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
844 result.append("find");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
845 result.append("store");
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
846 call.GetOutput().AnswerJson(result);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
847 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
848 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
849
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
850
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
851
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
852 // 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
853
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
854 static void GetRawContent(RestApi::GetCall& call)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
855 {
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
856 boost::mutex::scoped_lock lock(cacheMutex_);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
857
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
858 RETRIEVE_CONTEXT(call);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
859 std::string id = call.GetUriComponent("id", "");
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
860 ParsedDicomFile& dicom = context.GetDicomFile(id);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
861 dicom.SendPathValue(call.GetOutput(), call.GetTrailingUri());
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
862 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
863
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
864
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
865
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
866 // Modification of DICOM instances ------------------------------------------
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
867
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
868 namespace
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
869 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
870 typedef std::set<DicomTag> Removals;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
871 typedef std::map<DicomTag, std::string> Replacements;
350
8031f9cfe7fe removal of old code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 349
diff changeset
872 typedef std::map< std::pair<DicomRootLevel, std::string>, std::string> UidMap;
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
873 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
874
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
875 static void ReplaceInstanceInternal(ParsedDicomFile& toModify,
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
876 const Removals& removals,
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
877 const Replacements& replacements,
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
878 DicomReplaceMode mode,
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
879 bool removePrivateTags)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
880 {
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
881 if (removePrivateTags)
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
882 {
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
883 toModify.RemovePrivateTags();
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
884 }
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
885
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
886 for (Removals::const_iterator it = removals.begin();
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
887 it != removals.end(); it++)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
888 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
889 toModify.Remove(*it);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
890 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
891
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
892 for (Replacements::const_iterator it = replacements.begin();
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
893 it != replacements.end(); it++)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
894 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
895 toModify.Replace(it->first, it->second, mode);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
896 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
897
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
898 // A new SOP instance UID is automatically generated
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
899 std::string instanceUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
900 toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid, DicomReplaceMode_InsertIfAbsent);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
901 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
902
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
903
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
904 static void ParseRemovals(Removals& target,
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
905 const Json::Value& removals)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
906 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
907 if (!removals.isArray())
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
908 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
909 throw OrthancException(ErrorCode_BadRequest);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
910 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
911
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
912 target.clear();
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
913
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
914 for (Json::Value::ArrayIndex i = 0; i < removals.size(); i++)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
915 {
357
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
916 std::string name = removals[i].asString();
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
917 DicomTag tag = FromDcmtkBridge::ParseTag(name);
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
918 target.insert(tag);
357
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
919
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
920 VLOG(1) << "Removal: " << name << " " << tag << std::endl;
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
921 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
922 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
923
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
924
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
925 static void ParseReplacements(Replacements& target,
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
926 const Json::Value& replacements)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
927 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
928 if (!replacements.isObject())
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
929 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
930 throw OrthancException(ErrorCode_BadRequest);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
931 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
932
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
933 target.clear();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
934
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
935 Json::Value::Members members = replacements.getMemberNames();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
936 for (size_t i = 0; i < members.size(); i++)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
937 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
938 const std::string& name = members[i];
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
939 std::string value = replacements[name].asString();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
940
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
941 DicomTag tag = FromDcmtkBridge::ParseTag(name);
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
942 target[tag] = value;
357
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
943
8d3a0db39967 fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 351
diff changeset
944 VLOG(1) << "Replacement: " << name << " " << tag << " == " << value << std::endl;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
945 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
946 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
947
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
948
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
949 static std::string GeneratePatientName(ServerContext& context)
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
950 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
951 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
952 return "Anonymized" + boost::lexical_cast<std::string>(seq);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
953 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
954
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
955
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
956 static void SetupAnonymization(Removals& removals,
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
957 Replacements& replacements)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
958 {
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
959 // 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
960 removals.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
961 //removals.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set by ReplaceInstanceInternal()
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
962 removals.insert(DicomTag(0x0008, 0x0050)); // Accession Number
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
963 removals.insert(DicomTag(0x0008, 0x0080)); // Institution Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
964 removals.insert(DicomTag(0x0008, 0x0081)); // Institution Address
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
965 removals.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
966 removals.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
967 removals.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
968 removals.insert(DicomTag(0x0008, 0x1010)); // Station Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
969 removals.insert(DicomTag(0x0008, 0x1030)); // Study Description
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
970 removals.insert(DicomTag(0x0008, 0x103e)); // Series Description
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
971 removals.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
972 removals.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
973 removals.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
974 removals.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
975 removals.insert(DicomTag(0x0008, 0x1070)); // Operators' Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
976 removals.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
977 removals.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
978 removals.insert(DicomTag(0x0008, 0x2111)); // Derivation Description
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
979 removals.insert(DicomTag(0x0010, 0x0010)); // Patient's Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
980 removals.insert(DicomTag(0x0010, 0x0020)); // Patient ID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
981 removals.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
982 removals.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
983 removals.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
984 removals.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
985 removals.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
986 removals.insert(DicomTag(0x0010, 0x1010)); // Patient's Age
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
987 removals.insert(DicomTag(0x0010, 0x1020)); // Patient's Size
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
988 removals.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
989 removals.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
990 removals.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
991 removals.insert(DicomTag(0x0010, 0x2180)); // Occupation
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
992 removals.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
993 removals.insert(DicomTag(0x0010, 0x4000)); // Patient Comments
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
994 removals.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
995 removals.insert(DicomTag(0x0018, 0x1030)); // Protocol Name
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
996 //removals.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => generated below
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
997 //removals.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => generated below
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
998 removals.insert(DicomTag(0x0020, 0x0010)); // Study ID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
999 removals.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1000 removals.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1001 removals.insert(DicomTag(0x0020, 0x4000)); // Image Comments
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1002 removals.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1003 removals.insert(DicomTag(0x0040, 0xa124)); // UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1004 removals.insert(DicomTag(0x0040, 0xa730)); // Content Sequence
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1005 removals.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1006 removals.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1007 removals.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1008
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1009 // 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
1010 removals.insert(DicomTag(0x0010, 0x1040)); // Patient's Address
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1011 removals.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1012
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1013 // Set the DeidentificationMethod tag
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1014 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
1015
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1016 // Set the PatientIdentityRemoved
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1017 replacements.insert(std::make_pair(DicomTag(0x0012, 0x0062), "YES"));
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1018
321
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1019 // Generate random study UID if not specified
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1020 if (replacements.find(DICOM_TAG_STUDY_INSTANCE_UID) == replacements.end())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1021 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1022 replacements.insert(std::make_pair(DICOM_TAG_STUDY_INSTANCE_UID,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1023 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study)));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1024 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1025
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1026 // Generate random series UID if not specified
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1027 if (replacements.find(DICOM_TAG_SERIES_INSTANCE_UID) == replacements.end())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1028 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1029 replacements.insert(std::make_pair(DICOM_TAG_SERIES_INSTANCE_UID,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1030 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series)));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1031 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1032 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1033
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1034
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1035 static bool ParseModifyRequest(Removals& removals,
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1036 Replacements& replacements,
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1037 bool& removePrivateTags,
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1038 const RestApi::PostCall& call)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1039 {
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1040 removePrivateTags = false;
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1041 Json::Value request;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1042 if (call.ParseJsonRequest(request) &&
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1043 request.isObject())
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1044 {
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1045 Json::Value removalsPart = Json::arrayValue;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1046 Json::Value replacementsPart = Json::objectValue;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1047
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1048 if (request.isMember("Remove"))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1049 {
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1050 removalsPart = request["Remove"];
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1051 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1052
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1053 if (request.isMember("Replace"))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1054 {
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1055 replacementsPart = request["Replace"];
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1056 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1057
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1058 if (request.isMember("RemovePrivateTags"))
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1059 {
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1060 removePrivateTags = true;
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1061 }
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1062
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1063 ParseRemovals(removals, removalsPart);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1064 ParseReplacements(replacements, replacementsPart);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1065
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1066 return true;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1067 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1068 else
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1069 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1070 return false;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1071 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1072 }
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1073
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1074
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1075 static bool ParseAnonymizationRequest(Removals& removals,
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1076 Replacements& replacements,
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1077 bool& removePrivateTags,
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1078 RestApi::PostCall& call)
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1079 {
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1080 RETRIEVE_CONTEXT(call);
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1081
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1082 removePrivateTags = true;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1083
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1084 Json::Value request;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1085 if (call.ParseJsonRequest(request) &&
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1086 request.isObject())
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1087 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1088 Json::Value keepPart = Json::arrayValue;
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1089 Json::Value removalsPart = Json::arrayValue;
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1090 Json::Value replacementsPart = Json::objectValue;
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1091
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1092 if (request.isMember("Keep"))
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1093 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1094 keepPart = request["Keep"];
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1095 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1096
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1097 if (request.isMember("KeepPrivateTags"))
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1098 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1099 removePrivateTags = false;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1100 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1101
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1102 if (request.isMember("Replace"))
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1103 {
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1104 replacementsPart = request["Replace"];
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1105 }
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1106
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1107 Removals toKeep;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1108 ParseRemovals(toKeep, keepPart);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1109
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1110 SetupAnonymization(removals, replacements);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1111
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1112 for (Removals::iterator it = toKeep.begin(); it != toKeep.end(); it++)
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1113 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1114 removals.erase(*it);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1115 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1116
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1117 Removals additionalRemovals;
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1118 ParseRemovals(additionalRemovals, removalsPart);
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1119
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1120 for (Removals::iterator it = additionalRemovals.begin();
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1121 it != additionalRemovals.end(); it++)
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1122 {
321
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
1123 removals.insert(*it);
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1124 }
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1125
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1126 ParseReplacements(replacements, replacementsPart);
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1127
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1128 // Generate random Patient's Name if none is specified
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1129 if (replacements.find(DicomTag(0x0010, 0x0010)) == replacements.end())
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1130 {
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1131 replacements.insert(std::make_pair(DicomTag(0x0010, 0x0010), GeneratePatientName(context)));
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1132 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1133
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1134 // Generate random Patient's ID if none is specified
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1135 if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end())
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1136 {
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1137 replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID,
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1138 FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient)));
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1139 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1140
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1141 return true;
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 else
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1144 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1145 return false;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1146 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1147 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1148
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1149
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1150 static void AnonymizeOrModifyInstance(Removals& removals,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1151 Replacements& replacements,
314
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1152 bool removePrivateTags,
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1153 RestApi::PostCall& call)
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1154 {
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
1155 boost::mutex::scoped_lock lock(cacheMutex_);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1156 RETRIEVE_CONTEXT(call);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1157
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1158 std::string id = call.GetUriComponent("id", "");
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1159 ParsedDicomFile& dicom = context.GetDicomFile(id);
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 299
diff changeset
1160
314
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1161 std::auto_ptr<ParsedDicomFile> modified(dicom.Clone());
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1162 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags);
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1163 modified->Answer(call.GetOutput());
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1164 }
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1165
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1166
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1167 static bool RetrieveMappedUid(ParsedDicomFile& dicom,
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1168 DicomRootLevel level,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1169 Replacements& replacements,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1170 UidMap& uidMap)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1171 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1172 std::auto_ptr<DicomTag> tag;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1173 if (level == DicomRootLevel_Series)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1174 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1175 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID));
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1176 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1177 else
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1178 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1179 assert(level == DicomRootLevel_Study);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1180 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID));
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1181 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1182
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1183 std::string original;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1184 if (!dicom.GetTagValue(original, *tag))
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1185 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1186 throw OrthancException(ErrorCode_InternalError);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1187 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1188
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1189 std::string mapped;
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1190 bool isNew;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1191
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1192 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
1193 if (previous == uidMap.end())
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1194 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1195 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1196 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
1197 isNew = true;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1198 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1199 else
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1200 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1201 mapped = previous->second;
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1202 isNew = false;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1203 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1204
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1205 replacements[*tag] = mapped;
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1206 return isNew;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1207 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1208
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1209
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1210 static void AnonymizeOrModifyResource(Removals& removals,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1211 Replacements& replacements,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1212 bool removePrivateTags,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1213 MetadataType metadataType,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1214 ChangeType changeType,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1215 ResourceType resourceType,
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1216 RestApi::PostCall& call)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1217 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1218 typedef std::list<std::string> Instances;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1219
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1220 bool isFirst = true;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1221 Json::Value result(Json::objectValue);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1222
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1223 boost::mutex::scoped_lock lock(cacheMutex_);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1224 RETRIEVE_CONTEXT(call);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1225
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1226 Instances instances;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1227 std::string id = call.GetUriComponent("id", "");
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1228 context.GetIndex().GetChildInstances(instances, id);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1229
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1230 if (instances.size() == 0)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1231 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1232 return;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1233 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1234
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1235
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1236 /**
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1237 * Loop over all the instances of the resource.
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1238 **/
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1239
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1240 UidMap uidMap;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1241 for (Instances::const_iterator it = instances.begin();
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1242 it != instances.end(); it++)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1243 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1244 LOG(INFO) << "Modifying instance " << *it;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1245 ParsedDicomFile& original = context.GetDicomFile(*it);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1246
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1247 bool isNewSeries = RetrieveMappedUid(original, DicomRootLevel_Series, replacements, uidMap);
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1248
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1249 bool isNewStudy = false;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1250 if (resourceType == ResourceType_Study ||
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1251 resourceType == ResourceType_Patient)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1252 {
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1253 isNewStudy = RetrieveMappedUid(original, DicomRootLevel_Study, replacements, uidMap);
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1254 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1255
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1256 /**
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1257 * 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
1258 **/
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1259
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1260 std::auto_ptr<ParsedDicomFile> modified(original.Clone());
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1261 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1262
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1263 std::string modifiedInstance;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1264 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1265 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1266 LOG(ERROR) << "Error while storing a modified instance " << *it;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1267 return;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1268 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1269
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1270
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1271 /**
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1272 * Record metadata information (AnonimizedFrom/ModifiedFrom).
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1273 **/
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1274
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1275 DicomInstanceHasher modifiedHasher = modified->GetHasher();
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1276 DicomInstanceHasher originalHasher = original.GetHasher();
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1277
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1278 if (isNewSeries)
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1279 {
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1280 context.GetIndex().SetMetadata(modifiedHasher.HashSeries(),
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1281 metadataType, originalHasher.HashSeries());
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1282 }
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1283
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1284 if (isNewStudy)
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1285 {
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1286 context.GetIndex().SetMetadata(modifiedHasher.HashStudy(),
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1287 metadataType, originalHasher.HashStudy());
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1288 }
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1289
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1290 assert(*it == originalHasher.HashInstance());
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1291 assert(modifiedInstance == modifiedHasher.HashInstance());
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1292 context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it);
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1293
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1294
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1295 /**
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1296 * 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
1297 **/
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1298
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1299 if (isFirst)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1300 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1301 std::string newId;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1302
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1303 switch (resourceType)
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1304 {
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1305 case ResourceType_Series:
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1306 newId = modifiedHasher.HashSeries();
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1307 break;
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 case ResourceType_Study:
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1310 newId = modifiedHasher.HashStudy();
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1311 break;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1312
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1313 case ResourceType_Patient:
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1314 newId = modifiedHasher.HashPatient();
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1315 break;
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1316
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1317 default:
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1318 throw OrthancException(ErrorCode_InternalError);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1319 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1320
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1321 result["Type"] = ToString(resourceType);
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1322 result["ID"] = newId;
348
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1323 result["Path"] = GetBasePath(resourceType, newId);
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1324 result["PatientID"] = modifiedHasher.HashPatient();
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1325 isFirst = false;
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 }
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1328
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1329 call.GetOutput().AnswerJson(result);
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
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1332
1082e8121d10 refactoring anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 344
diff changeset
1333
314
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1334 static void ModifyInstance(RestApi::PostCall& call)
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1335 {
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1336 Removals removals;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1337 Replacements replacements;
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1338 bool removePrivateTags;
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1339
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1340 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1341 {
314
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1342 AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1343 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1344 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1345
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1346
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1347 static void AnonymizeInstance(RestApi::PostCall& call)
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1348 {
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1349 Removals removals;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1350 Replacements replacements;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1351 bool removePrivateTags;
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1352
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1353 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1354 {
314
4f17834a50b6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
1355 AnonymizeOrModifyInstance(removals, replacements, removePrivateTags, call);
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1356 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1357 }
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1358
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1359
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1360 static void ModifySeriesInplace(RestApi::PostCall& call)
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1361 {
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1362 Removals removals;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1363 Replacements replacements;
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1364 bool removePrivateTags;
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1365
312
1642a354fec8 flexible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1366 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1367 {
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1368 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1369 MetadataType_ModifiedFrom, ChangeType_ModifiedSeries,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1370 ResourceType_Series, call);
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1371 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1372 }
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
1373
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1374
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1375 static void AnonymizeSeriesInplace(RestApi::PostCall& call)
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1376 {
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1377 Removals removals;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1378 Replacements replacements;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1379 bool removePrivateTags;
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1380
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1381 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1382 {
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1383 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1384 MetadataType_AnonymizedFrom, ChangeType_AnonymizedSeries,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1385 ResourceType_Series, call);
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1386 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1387 }
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1388
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1389
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1390 static void ModifyStudyInplace(RestApi::PostCall& call)
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1391 {
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1392 Removals removals;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1393 Replacements replacements;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1394 bool removePrivateTags;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1395
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1396 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1397 {
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1398 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1399 MetadataType_ModifiedFrom, ChangeType_ModifiedStudy,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1400 ResourceType_Study, call);
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1401 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1402 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1403
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1404
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1405 static void AnonymizeStudyInplace(RestApi::PostCall& call)
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1406 {
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1407 Removals removals;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1408 Replacements replacements;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1409 bool removePrivateTags;
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1410
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1411 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1412 {
349
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1413 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1414 MetadataType_AnonymizedFrom, ChangeType_AnonymizedStudy,
c5edf0cc6e95 switch to refactored version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 348
diff changeset
1415 ResourceType_Study, call);
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1416 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1417 }
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1418
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1419
351
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1420 static void ModifyPatientInplace(RestApi::PostCall& call)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1421 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1422 Removals removals;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1423 Replacements replacements;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1424 bool removePrivateTags;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1425
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1426 if (ParseModifyRequest(removals, replacements, removePrivateTags, call))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1427 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1428 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1429 MetadataType_ModifiedFrom, ChangeType_ModifiedPatient,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1430 ResourceType_Patient, call);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1431 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1432 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1433
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1435 static void AnonymizePatientInplace(RestApi::PostCall& call)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1436 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1437 Removals removals;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1438 Replacements replacements;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1439 bool removePrivateTags;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1440
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1441 if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1442 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1443 AnonymizeOrModifyResource(removals, replacements, removePrivateTags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1444 MetadataType_AnonymizedFrom, ChangeType_AnonymizedPatient,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1445 ResourceType_Patient, call);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1446 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1447 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1448
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1449
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
1450
213
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
1451 // 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
1452
230
ae2367145b49 renames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 229
diff changeset
1453 OrthancRestApi::OrthancRestApi(ServerContext& context) :
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
1454 context_(context)
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 {
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 GetListOfDicomModalities(modalities_);
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1458 Register("/", ServeRoot);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 Register("/system", GetSystemInformation);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1460 Register("/statistics", GetStatistics);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 Register("/changes", GetChanges);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
1462 Register("/exports", GetExports);
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1463
216
e5d5d4a9a326 refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
1464 Register("/instances", UploadDicomFile);
211
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1465 Register("/instances", ListResources<ResourceType_Instance>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1466 Register("/patients", ListResources<ResourceType_Patient>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1467 Register("/series", ListResources<ResourceType_Series>);
b7aea293b965 list of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
1468 Register("/studies", ListResources<ResourceType_Study>);
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1469
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1470 Register("/instances/{id}", DeleteSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1471 Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1472 Register("/patients/{id}", DeleteSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1473 Register("/patients/{id}", GetSingleResource<ResourceType_Patient>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1474 Register("/series/{id}", DeleteSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1475 Register("/series/{id}", GetSingleResource<ResourceType_Series>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1476 Register("/studies/{id}", DeleteSingleResource<ResourceType_Study>);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 211
diff changeset
1477 Register("/studies/{id}", GetSingleResource<ResourceType_Study>);
250
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
1478
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
1479 Register("/patients/{id}/archive", GetArchive<ResourceType_Patient>);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
1480 Register("/studies/{id}/archive", GetArchive<ResourceType_Study>);
f23318b11b39 creation of zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
1481 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
1482
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
1483 Register("/patients/{id}/protected", IsProtectedPatient);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
1484 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
1485 Register("/instances/{id}/file", GetInstanceFile);
4ce7fdcc8879 access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
1486 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
1487 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);
214
03817919169b list of frames
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
1488 Register("/instances/{id}/frames", ListFrames);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
1489 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
1490
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
1491 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
1492 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
1493 Register("/instances/{id}/frames/{frame}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
1494 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
1495 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
1496 Register("/instances/{id}/image-uint16", GetImage<ImageExtractionMode_UInt16>);
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
1497
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1498 Register("/modalities", ListModalities);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1499 Register("/modalities/{id}", ListModalityOperations);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1500 Register("/modalities/{id}/find-patient", DicomFindPatient);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1501 Register("/modalities/{id}/find-study", DicomFindStudy);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1502 Register("/modalities/{id}/find-series", DicomFindSeries);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1503 Register("/modalities/{id}/find", DicomFind);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1504 Register("/modalities/{id}/store", DicomStore);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
1505
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
1506 Register("/instances/{id}/modify", ModifyInstance);
308
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1507 Register("/series/{id}/modify", ModifySeriesInplace);
fbf2b2282086 inplace modification of series and studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
1508 Register("/studies/{id}/modify", ModifyStudyInplace);
351
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1509 Register("/patients/{id}/modify", ModifyPatientInplace);
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1510
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1511 Register("/instances/{id}/anonymize", AnonymizeInstance);
316
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1512 Register("/series/{id}/anonymize", AnonymizeSeriesInplace);
d526ac73c886 anonymization of studies and series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
1513 Register("/studies/{id}/anonymize", AnonymizeStudyInplace);
351
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 350
diff changeset
1514 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
1515
a58a8be26aff generation of random uid in the rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
1516 Register("/tools/generate-uid", GenerateUid);
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 }
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 }