annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1557:ad1e127b4ed5

fix in encodings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Aug 2015 17:29:42 +0200
parents d6a93e12b1c1
children 124de28b32ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
4 * Department, University Hospital of Liege, Belgium
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
5197fd35333c refactoring of OrthancRestApi
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
36 #include "../../Core/Logging.h"
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
37 #include "../../Core/Uuid.h"
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
38 #include "../FromDcmtkBridge.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
39 #include "../ServerContext.h"
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
40 #include "../OrthancInitialization.h"
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
41
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 // Modification of DICOM instances ------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
46 enum TagOperation
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
48 TagOperation_Keep,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
49 TagOperation_Remove
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
50 };
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
52 static void ParseListOfTags(DicomModification& target,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
53 const Json::Value& query,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
54 TagOperation operation)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
56 if (!query.isArray())
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 throw OrthancException(ErrorCode_BadRequest);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
61 for (Json::Value::ArrayIndex i = 0; i < query.size(); i++)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
63 std::string name = query[i].asString();
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
64
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 DicomTag tag = FromDcmtkBridge::ParseTag(name);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
66
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
67 switch (operation)
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
68 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
69 case TagOperation_Keep:
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
70 target.Keep(tag);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
71 VLOG(1) << "Keep: " << name << " " << tag << std::endl;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
72 break;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
74 case TagOperation_Remove:
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
75 target.Remove(tag);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
76 VLOG(1) << "Remove: " << name << " " << tag << std::endl;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
77 break;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
78
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
79 default:
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
80 throw OrthancException(ErrorCode_InternalError);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
81 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
86 static void ParseReplacements(DicomModification& target,
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 const Json::Value& replacements)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (!replacements.isObject())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 throw OrthancException(ErrorCode_BadRequest);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 Json::Value::Members members = replacements.getMemberNames();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 for (size_t i = 0; i < members.size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 const std::string& name = members[i];
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 std::string value = replacements[name].asString();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
100 DicomTag tag = FromDcmtkBridge::ParseTag(name);
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
101 target.Replace(tag, value);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
103 VLOG(1) << "Replace: " << name << " " << tag << " == " << value << std::endl;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 static std::string GeneratePatientName(ServerContext& context)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return "Anonymized" + boost::lexical_cast<std::string>(seq);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
115
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
116 bool OrthancRestApi::ParseModifyRequest(DicomModification& target,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
117 const Json::Value& request)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
119 if (request.isObject())
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
121 if (request.isMember("RemovePrivateTags"))
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
122 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
123 target.SetRemovePrivateTags(true);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
124 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (request.isMember("Remove"))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
128 ParseListOfTags(target, request["Remove"], TagOperation_Remove);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if (request.isMember("Replace"))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
133 ParseReplacements(target, request["Replace"]);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 else
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
145 static bool ParseModifyRequest(DicomModification& target,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
146 const RestApiPostCall& call)
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
147 {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
148 // curl http://localhost:8042/series/95a6e2bf-9296e2cc-bf614e2f-22b391ee-16e010e0/modify -X POST -d '{"Replace":{"InstitutionName":"My own clinic"}}'
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
149
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
150 Json::Value request;
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
151 if (call.ParseJsonRequest(request))
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
152 {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
153 return OrthancRestApi::ParseModifyRequest(target, request);
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
154 }
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
155 else
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
156 {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
157 return false;
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
158 }
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
159 }
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
160
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
161
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
162 static bool ParseAnonymizationRequest(DicomModification& target,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
163 RestApiPostCall& call)
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
164 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
165 // curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": null,"Remove":["Modality"]}' > Anonymized.dcm
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
166
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
167 target.SetupAnonymization();
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
168 std::string patientName = target.GetReplacement(DICOM_TAG_PATIENT_NAME);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
169
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
170 Json::Value request;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
171 if (call.ParseJsonRequest(request) && request.isObject())
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
172 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
173 if (request.isMember("KeepPrivateTags"))
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
174 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
175 target.SetRemovePrivateTags(false);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
176 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
177
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
178 if (request.isMember("Remove"))
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
179 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
180 ParseListOfTags(target, request["Remove"], TagOperation_Remove);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
181 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
182
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
183 if (request.isMember("Replace"))
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
184 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
185 ParseReplacements(target, request["Replace"]);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
186 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
187
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
188 if (request.isMember("Keep"))
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
189 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
190 ParseListOfTags(target, request["Keep"], TagOperation_Keep);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
191 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
192
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
193 if (target.IsReplaced(DICOM_TAG_PATIENT_NAME) &&
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
194 target.GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName)
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
195 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
196 // Overwrite the random Patient's Name by one that is more
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
197 // user-friendly (provided none was specified by the user)
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
198 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
199 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
200
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
201 return true;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
202 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
203 else
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
204 {
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
205 return false;
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
206 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
207 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
208
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
209
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
210 static void AnonymizeOrModifyInstance(DicomModification& modification,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
211 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
213 std::string id = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
215 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
216
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
217 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone());
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
218 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 modified->Answer(call.GetOutput());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
223 static void AnonymizeOrModifyResource(DicomModification& modification,
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 MetadataType metadataType,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 ChangeType changeType,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 ResourceType resourceType,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
227 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 bool isFirst = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 Json::Value result(Json::objectValue);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
234 typedef std::list<std::string> Instances;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 Instances instances;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 std::string id = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 context.GetIndex().GetChildInstances(instances, id);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 if (instances.empty())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
244
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 * Loop over all the instances of the resource.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 for (Instances::const_iterator it = instances.begin();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 it != instances.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 LOG(INFO) << "Modifying instance " << *it;
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
253
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
254 std::auto_ptr<ServerContext::DicomCacheLocker> locker;
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
255
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
256 try
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
257 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
258 locker.reset(new ServerContext::DicomCacheLocker(OrthancRestApi::GetContext(call), *it));
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
259 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
260 catch (OrthancException&)
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
261 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
262 // This child instance has been removed in between
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
263 continue;
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
264 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
265
1129
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1120
diff changeset
266
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
267 ParsedDicomFile& original = locker->GetDicom();
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 DicomInstanceHasher originalHasher = original.GetHasher();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 /**
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
272 * Compute the resulting DICOM instance.
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 std::auto_ptr<ParsedDicomFile> modified(original.Clone());
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
276 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
278 DicomInstanceToStore toStore;
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
279 toStore.SetParsedDicomFile(*modified);
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
280
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
281
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
282 /**
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
283 * Prepare the metadata information to associate with the
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
284 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom).
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
285 **/
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
286
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
287 DicomInstanceHasher modifiedHasher = modified->GetHasher();
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
288
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
289 if (originalHasher.HashSeries() != modifiedHasher.HashSeries())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
290 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
291 toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher.HashSeries());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
292 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
293
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
294 if (originalHasher.HashStudy() != modifiedHasher.HashStudy())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
295 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
296 toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher.HashStudy());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
297 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
298
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
299 if (originalHasher.HashPatient() != modifiedHasher.HashPatient())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
300 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
301 toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher.HashPatient());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
302 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
303
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
304 assert(*it == originalHasher.HashInstance());
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
305 toStore.AddMetadata(ResourceType_Instance, metadataType, *it);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
306
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
307
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
308 /**
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
309 * Store the resulting DICOM instance into the Orthanc store.
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
310 **/
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
311
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 std::string modifiedInstance;
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
313 if (context.Store(modifiedInstance, toStore) != StoreStatus_Success)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 LOG(ERROR) << "Error while storing a modified instance " << *it;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
319 // Sanity checks in debug mode
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 assert(modifiedInstance == modifiedHasher.HashInstance());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 * Compute the JSON object that is returned by the REST call.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 if (isFirst)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 std::string newId;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 switch (resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 case ResourceType_Series:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 newId = modifiedHasher.HashSeries();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 case ResourceType_Study:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 newId = modifiedHasher.HashStudy();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 case ResourceType_Patient:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 newId = modifiedHasher.HashPatient();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 default:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 throw OrthancException(ErrorCode_InternalError);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 result["Type"] = EnumerationToString(resourceType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 result["ID"] = newId;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 result["Path"] = GetBasePath(resourceType, newId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 result["PatientID"] = modifiedHasher.HashPatient();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 isFirst = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
362 static void ModifyInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
364 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
365 modification.SetAllowManualIdentifiers(true);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
366
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
367 if (ParseModifyRequest(modification, call))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
369 if (modification.IsReplaced(DICOM_TAG_PATIENT_ID))
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
370 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
371 modification.SetLevel(ResourceType_Patient);
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
372 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
373 else if (modification.IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
374 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
375 modification.SetLevel(ResourceType_Study);
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
376 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
377 else if (modification.IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
378 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
379 modification.SetLevel(ResourceType_Series);
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
380 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
381 else
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
382 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
383 modification.SetLevel(ResourceType_Instance);
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
384 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
385
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
386 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
391 static void AnonymizeInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
393 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
394 modification.SetAllowManualIdentifiers(true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
396 if (ParseAnonymizationRequest(modification, call))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
398 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
403 template <enum ChangeType changeType,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
404 enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
405 static void ModifyResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
407 DicomModification modification;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
409 if (ParseModifyRequest(modification, call))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
411 modification.SetLevel(resourceType);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
412 AnonymizeOrModifyResource(modification, MetadataType_ModifiedFrom,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
413 changeType, resourceType, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
418 template <enum ChangeType changeType,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
419 enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
420 static void AnonymizeResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
422 DicomModification modification;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
424 if (ParseAnonymizationRequest(modification, call))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
426 AnonymizeOrModifyResource(modification, MetadataType_AnonymizedFrom,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
427 changeType, resourceType, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
432 static bool CreateDicomV1(ParsedDicomFile& dicom,
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
433 const Json::Value& request)
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
434 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
435 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World"}'
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
436 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World","PixelData":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="}'
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
437
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
438 assert(request.isObject());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
439 LOG(WARNING) << "Using a deprecated call to /tools/create-dicom";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
440
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
441 Json::Value::Members members = request.getMemberNames();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
442 for (size_t i = 0; i < members.size(); i++)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
443 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
444 const std::string& name = members[i];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
445 if (request[name].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
446 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
447 LOG(ERROR) << "Only string values are supported when creating DICOM instances";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
448 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
449 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
450
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
451 std::string value = request[name].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
452
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
453 DicomTag tag = FromDcmtkBridge::ParseTag(name);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
454 if (tag == DICOM_TAG_PIXEL_DATA)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
455 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
456 dicom.EmbedImage(value);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
457 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
458 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
459 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
460 dicom.Replace(tag, value);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
461 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
462 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
463
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
464 return true;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
465 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
466
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
467
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
468 static bool CreateDicomV2(ParsedDicomFile& dicom,
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
469 ServerContext& context,
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
470 const Json::Value& request)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
471 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
472 assert(request.isObject());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
473
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
474 if (!request.isMember("Tags") ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
475 request["Tags"].type() != Json::objectValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
476 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
477 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
478 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
479
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
480 std::string tmp;
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
481 if (request["Tags"].isMember("SpecificCharacterSet"))
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
482 {
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
483 tmp = request["Tags"]["SpecificCharacterSet"].asString();
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
484 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
485 else
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
486 {
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
487 tmp = Configuration::GetGlobalStringParameter("DefaultEncoding", "Latin1");
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
488 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
489
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
490 Encoding encoding = StringToEncoding(tmp.c_str());
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
491 dicom.SetEncoding(encoding);
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
492
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
493 ResourceType parentType = ResourceType_Instance;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
494
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
495 if (request.isMember("Parent"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
496 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
497 // Locate the parent tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
498 std::string parent = request["Parent"].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
499 if (!context.GetIndex().LookupResourceType(parentType, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
500 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
501 LOG(ERROR) << "Trying to attach a new DICOM instance to an inexistent resource: " << parent;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
502 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
503 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
504
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
505 if (parentType == ResourceType_Instance)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
506 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
507 LOG(ERROR) << "Trying to attach a new DICOM instance to an instance (must be a series, study or patient): " << parent;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
508 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
509 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
510
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
511 // Select one existing child instance of the parent resource, to
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
512 // retrieve all its tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
513 Json::Value siblingTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
514
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
515 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
516 // Retrieve all the instances of the parent resource
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
517 std::list<std::string> siblingInstances;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
518 context.GetIndex().GetChildInstances(siblingInstances, parent);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
519
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
520 if (siblingInstances.empty())
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
521 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
522 return false; // Error: No instance (should never happen)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
523 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
524
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
525 context.ReadJson(siblingTags, siblingInstances.front());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
526 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
527
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
528 // Retrieve the tags for all the parent modules
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
529 typedef std::set<DicomTag> ModuleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
530 ModuleTags moduleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
531
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
532 ResourceType type = parentType;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
533 for (;;)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
534 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
535 DicomTag::AddTagsForModule(moduleTags, GetModule(type));
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
536
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
537 if (type == ResourceType_Patient)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
538 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
539 break; // We're done
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
540 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
541
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
542 // Go up
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
543 std::string tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
544 if (!context.GetIndex().LookupParent(tmp, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
545 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
546 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
547 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
548
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
549 parent = tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
550 type = GetParentResourceType(type);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
551 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
552
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
553 for (ModuleTags::const_iterator it = moduleTags.begin();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
554 it != moduleTags.end(); it++)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
555 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
556 std::string t = it->Format();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
557 if (siblingTags.isMember(t))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
558 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
559 const Json::Value& tag = siblingTags[t];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
560 if (tag["Type"] == "Null")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
561 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
562 dicom.Replace(*it, "");
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
563 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
564 else if (tag["Type"] == "String")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
565 {
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
566 std::string value = tag["Value"].asString();
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
567 dicom.Replace(*it, Toolbox::ConvertFromUtf8(value, encoding));
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
568 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
569 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
570 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
571 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
572
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
573
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
574 // Inject time-related information
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
575 std::string date, time;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
576 Toolbox::GetNowDicom(date, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
577 dicom.Replace(DICOM_TAG_ACQUISITION_DATE, date);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
578 dicom.Replace(DICOM_TAG_ACQUISITION_TIME, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
579 dicom.Replace(DICOM_TAG_CONTENT_DATE, date);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
580 dicom.Replace(DICOM_TAG_CONTENT_TIME, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
581 dicom.Replace(DICOM_TAG_INSTANCE_CREATION_DATE, date);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
582 dicom.Replace(DICOM_TAG_INSTANCE_CREATION_TIME, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
583
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
584 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
585 parentType == ResourceType_Study ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
586 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
587 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
588 dicom.Replace(DICOM_TAG_SERIES_DATE, date);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
589 dicom.Replace(DICOM_TAG_SERIES_TIME, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
590 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
591
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
592 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
593 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
594 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
595 dicom.Replace(DICOM_TAG_STUDY_DATE, date);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
596 dicom.Replace(DICOM_TAG_STUDY_TIME, time);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
597 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
598
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
599
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
600 // Inject the user-specified tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
601 Json::Value::Members members = request["Tags"].getMemberNames();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
602 for (size_t i = 0; i < members.size(); i++)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
603 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
604 const std::string& name = members[i];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
605 if (request["Tags"][name].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
606 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
607 LOG(ERROR) << "Only string values are supported when creating DICOM instances";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
608 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
609 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
610
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
611 std::string value = request["Tags"][name].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
612
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
613 DicomTag tag = FromDcmtkBridge::ParseTag(name);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
614 if (dicom.HasTag(tag))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
615 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
616 LOG(ERROR) << "Trying to override a value inherited from a parent module";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
617 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
618 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
619
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
620 if (tag == DICOM_TAG_PIXEL_DATA)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
621 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
622 LOG(ERROR) << "Use \"Content\" to inject an image into a new DICOM instance";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
623 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
624 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
625 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
626 {
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
627 dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, encoding));
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
628 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
629 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
630
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
631
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
632 // Inject the content (either an image, or a PDF file)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
633 if (request.isMember("Content"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
634 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
635 if (request["Content"].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
636 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
637 LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
638 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
639 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
640
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
641 std::string mime, base64;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
642 Toolbox::DecodeDataUriScheme(mime, base64, request["Content"].asString());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
643 Toolbox::ToLowerCase(mime);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
644
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
645 std::string content;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
646 Toolbox::DecodeBase64(content, base64);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
647
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
648 if (mime == "image/png")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
649 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
650 dicom.EmbedImage(mime, content);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
651 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
652 else if (mime == "application/pdf")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
653 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
654 dicom.EmbedPdf(content);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
655 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
656 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
657 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
658 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
659 return false;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
660 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
661 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
662
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
663
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
664 return true;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
665 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
666
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
667
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
668 static void CreateDicom(RestApiPostCall& call)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
669 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
670 ServerContext& context = OrthancRestApi::GetContext(call);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
671
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
672 Json::Value request;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
673 if (call.ParseJsonRequest(request) &&
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
674 request.isObject())
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
675 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
676 ParsedDicomFile dicom;
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
677
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
678 if (request.isMember("Tags") ?
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
679 CreateDicomV2(dicom, context, request) :
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
680 CreateDicomV1(dicom, request))
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
681 {
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
682 DicomInstanceToStore toStore;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
683 toStore.SetParsedDicomFile(dicom);
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1129
diff changeset
684
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
685 std::string id;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
686 StoreStatus status = OrthancRestApi::GetContext(call).Store(id, toStore);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
687
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
688 if (status == StoreStatus_Failure)
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1129
diff changeset
689 {
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
690 LOG(ERROR) << "Error while storing a manually-created instance";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
691 return;
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1129
diff changeset
692 }
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
693
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
694 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, id, status);
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
695 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
696 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
697 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
698
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
699
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 void OrthancRestApi::RegisterAnonymizeModify()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 Register("/instances/{id}/modify", ModifyInstance);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
703 Register("/series/{id}/modify", ModifyResource<ChangeType_ModifiedSeries, ResourceType_Series>);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
704 Register("/studies/{id}/modify", ModifyResource<ChangeType_ModifiedStudy, ResourceType_Study>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
705 Register("/patients/{id}/modify", ModifyResource<ChangeType_ModifiedPatient, ResourceType_Patient>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 Register("/instances/{id}/anonymize", AnonymizeInstance);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
708 Register("/series/{id}/anonymize", AnonymizeResource<ChangeType_ModifiedSeries, ResourceType_Series>);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
709 Register("/studies/{id}/anonymize", AnonymizeResource<ChangeType_ModifiedStudy, ResourceType_Study>);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
710 Register("/patients/{id}/anonymize", AnonymizeResource<ChangeType_ModifiedPatient, ResourceType_Patient>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
711
1120
009dce4ea2f6 /tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
712 Register("/tools/create-dicom", CreateDicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }