Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2310:b7fba68747f6 issue-46-anonymization
DicomModification::Clear()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2017 14:00:00 +0200 |
parents | 4dc313b9a20a |
children | 78dcb3ddea9f |
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 |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2194
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * 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
|
9 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * 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
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * version. If you delete this exception statement from all source files |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * 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
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * 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
|
30 * 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
|
31 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
37 #include "../../Core/Logging.h" |
795 | 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 | 40 #include "../OrthancInitialization.h" |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
41 |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
42 #include <boost/lexical_cast.hpp> |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
43 #include <boost/algorithm/string/predicate.hpp> |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
44 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 // Modification of DICOM instances ------------------------------------------ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
49 enum TagOperation |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
51 TagOperation_Keep, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
52 TagOperation_Remove |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
53 }; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
55 static void ParseListOfTags(DicomModification& target, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
56 const Json::Value& query, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
57 TagOperation operation) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
59 if (!query.isArray()) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 throw OrthancException(ErrorCode_BadRequest); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
64 for (Json::Value::ArrayIndex i = 0; i < query.size(); i++) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
66 std::string name = query[i].asString(); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
67 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
69 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
70 switch (operation) |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
71 { |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
72 case TagOperation_Keep: |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
73 target.Keep(tag); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
74 VLOG(1) << "Keep: " << name << " " << tag << std::endl; |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
75 break; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
77 case TagOperation_Remove: |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
78 target.Remove(tag); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
79 VLOG(1) << "Remove: " << name << " " << tag << std::endl; |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
80 break; |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
81 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
82 default: |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
83 throw OrthancException(ErrorCode_InternalError); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
84 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
89 static void ParseReplacements(DicomModification& target, |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 const Json::Value& replacements) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 if (!replacements.isObject()) |
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 throw OrthancException(ErrorCode_BadRequest); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
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 Json::Value::Members members = replacements.getMemberNames(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 for (size_t i = 0; i < members.size(); i++) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 const std::string& name = members[i]; |
1699
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1698
diff
changeset
|
101 const Json::Value& value = replacements[name]; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
103 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
2310
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
104 target.Replace(tag, value, false); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
1699
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1698
diff
changeset
|
106 VLOG(1) << "Replace: " << name << " " << tag |
8ca0e89798b2
"/modify" can insert/modify sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1698
diff
changeset
|
107 << " == " << value.toStyledString() << std::endl; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 } |
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 static std::string GeneratePatientName(ServerContext& context) |
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 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 return "Anonymized" + boost::lexical_cast<std::string>(seq); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 |
1010 | 119 |
120 bool OrthancRestApi::ParseModifyRequest(DicomModification& target, | |
121 const Json::Value& request) | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 { |
1010 | 123 if (request.isObject()) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
125 if (request.isMember("RemovePrivateTags")) |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
126 { |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
127 target.SetRemovePrivateTags(true); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
128 } |
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 if (request.isMember("Remove")) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
132 ParseListOfTags(target, request["Remove"], TagOperation_Remove); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 } |
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 if (request.isMember("Replace")) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
137 ParseReplacements(target, request["Replace"]); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
2194
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
140 // The "Keep" operation only makes sense for the tags |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
141 // StudyInstanceUID, SeriesInstanceUID and SOPInstanceUID. Avoid |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
142 // this feature as much as possible, as this breaks the DICOM |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
143 // model of the real world, except if you know exactly what |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
144 // you're doing! |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
145 if (request.isMember("Keep")) |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
146 { |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
147 ParseListOfTags(target, request["Keep"], TagOperation_Keep); |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
148 } |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2142
diff
changeset
|
149 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 return true; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 else |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 return false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
1010 | 159 static bool ParseModifyRequest(DicomModification& target, |
160 const RestApiPostCall& call) | |
161 { | |
162 // curl http://localhost:8042/series/95a6e2bf-9296e2cc-bf614e2f-22b391ee-16e010e0/modify -X POST -d '{"Replace":{"InstitutionName":"My own clinic"}}' | |
163 | |
164 Json::Value request; | |
165 if (call.ParseJsonRequest(request)) | |
166 { | |
167 return OrthancRestApi::ParseModifyRequest(target, request); | |
168 } | |
169 else | |
170 { | |
171 return false; | |
172 } | |
173 } | |
174 | |
175 | |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
176 static bool ParseAnonymizationRequest(DicomModification& target, |
974 | 177 RestApiPostCall& call) |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
178 { |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
179 // 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
|
180 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
181 Json::Value request; |
2309
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
182 if (!call.ParseJsonRequest(request) || |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
183 !request.isObject()) |
787
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 return false; |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
186 } |
2309
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
187 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
188 DicomVersion version = DicomVersion_2008; // TODO Switch to 2017c |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
189 if (request.isMember("DicomVersion")) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
190 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
191 if (request["DicomVersion"].type() != Json::stringValue) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
192 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
193 throw OrthancException(ErrorCode_BadFileFormat); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
194 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
195 else |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
196 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
197 version = StringToDicomVersion(request["DicomVersion"].asString()); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
198 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
199 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
200 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
201 target.SetupAnonymization(version); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
202 std::string patientName = target.GetReplacementAsString(DICOM_TAG_PATIENT_NAME); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
203 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
204 if (request.isMember("KeepPrivateTags")) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
205 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
206 target.SetRemovePrivateTags(false); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
207 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
208 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
209 if (request.isMember("Remove")) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
210 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
211 ParseListOfTags(target, request["Remove"], TagOperation_Remove); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
212 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
213 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
214 if (request.isMember("Replace")) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
215 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
216 ParseReplacements(target, request["Replace"]); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
217 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
218 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
219 if (request.isMember("Keep")) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
220 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
221 ParseListOfTags(target, request["Keep"], TagOperation_Keep); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
222 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
223 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
224 if (target.IsReplaced(DICOM_TAG_PATIENT_NAME) && |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
225 target.GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
226 { |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
227 // Overwrite the random Patient's Name by one that is more |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
228 // user-friendly (provided none was specified by the user) |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
229 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
230 } |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
231 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2250
diff
changeset
|
232 return true; |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
233 } |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
234 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
235 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
236 static void AnonymizeOrModifyInstance(DicomModification& modification, |
974 | 237 RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 { |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
239 std::string id = call.GetUriComponent("id", ""); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
241 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
|
242 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
243 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone()); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
244 modification.Apply(*modified); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 modified->Answer(call.GetOutput()); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 } |
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 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
249 static void AnonymizeOrModifyResource(DicomModification& modification, |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 MetadataType metadataType, |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 ChangeType changeType, |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 ResourceType resourceType, |
974 | 253 RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 bool isFirst = true; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 Json::Value result(Json::objectValue); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
260 typedef std::list<std::string> Instances; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 Instances instances; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 std::string id = call.GetUriComponent("id", ""); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 context.GetIndex().GetChildInstances(instances, id); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 if (instances.empty()) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
270 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 * Loop over all the instances of the resource. |
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 for (Instances::const_iterator it = instances.begin(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 it != instances.end(); ++it) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 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
|
279 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
280 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
|
281 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
282 try |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
283 { |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
284 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
|
285 } |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
286 catch (OrthancException&) |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
287 { |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
288 // 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
|
289 continue; |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
290 } |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
291 |
1129
8dabdc0d3007
fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1120
diff
changeset
|
292 |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
293 ParsedDicomFile& original = locker->GetDicom(); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 DicomInstanceHasher originalHasher = original.GetHasher(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 /** |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
298 * Compute the resulting DICOM instance. |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
302 modification.Apply(*modified); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
304 DicomInstanceToStore toStore; |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
305 toStore.SetRestOrigin(call); |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
306 toStore.SetParsedDicomFile(*modified); |
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
307 |
1002
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 /** |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
310 * Prepare the metadata information to associate with the |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
311 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom). |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
312 **/ |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
313 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
314 DicomInstanceHasher modifiedHasher = modified->GetHasher(); |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
315 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
316 if (originalHasher.HashSeries() != modifiedHasher.HashSeries()) |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
317 { |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
318 toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher.HashSeries()); |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
319 } |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
320 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
321 if (originalHasher.HashStudy() != modifiedHasher.HashStudy()) |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
322 { |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
323 toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher.HashStudy()); |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
324 } |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
325 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
326 if (originalHasher.HashPatient() != modifiedHasher.HashPatient()) |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
327 { |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
328 toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher.HashPatient()); |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
329 } |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
330 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
331 assert(*it == originalHasher.HashInstance()); |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
332 toStore.AddMetadata(ResourceType_Instance, metadataType, *it); |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
333 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
334 |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
335 /** |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
336 * Store the resulting DICOM instance into the Orthanc store. |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
337 **/ |
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
338 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 std::string modifiedInstance; |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1002
diff
changeset
|
340 if (context.Store(modifiedInstance, toStore) != StoreStatus_Success) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
342 LOG(ERROR) << "Error while storing a modified instance " << *it; |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
343 throw OrthancException(ErrorCode_CannotStoreInstance); |
751
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 |
1002
b067017a8a5b
anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
346 // Sanity checks in debug mode |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 assert(modifiedInstance == modifiedHasher.HashInstance()); |
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 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 * Compute the JSON object that is returned by the REST call. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 if (isFirst) |
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 std::string newId; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 switch (resourceType) |
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 case ResourceType_Series: |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 newId = modifiedHasher.HashSeries(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 break; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 case ResourceType_Study: |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 newId = modifiedHasher.HashStudy(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 break; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 case ResourceType_Patient: |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 newId = modifiedHasher.HashPatient(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 break; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 default: |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 throw OrthancException(ErrorCode_InternalError); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 result["Type"] = EnumerationToString(resourceType); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 result["ID"] = newId; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 result["Path"] = GetBasePath(resourceType, newId); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 result["PatientID"] = modifiedHasher.HashPatient(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 isFirst = false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 call.GetOutput().AnswerJson(result); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 |
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 |
974 | 389 static void ModifyInstance(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
391 DicomModification modification; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
392 modification.SetAllowManualIdentifiers(true); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
393 |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
394 if (ParseModifyRequest(modification, call)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 { |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
396 if (modification.IsReplaced(DICOM_TAG_PATIENT_ID)) |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
397 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
398 modification.SetLevel(ResourceType_Patient); |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
399 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
400 else if (modification.IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
401 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
402 modification.SetLevel(ResourceType_Study); |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
403 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
404 else if (modification.IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
405 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
406 modification.SetLevel(ResourceType_Series); |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
407 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
408 else |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
409 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
410 modification.SetLevel(ResourceType_Instance); |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
411 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
412 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
413 AnonymizeOrModifyInstance(modification, 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 |
974 | 418 static void AnonymizeInstance(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
420 DicomModification modification; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1160
diff
changeset
|
421 modification.SetAllowManualIdentifiers(true); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
423 if (ParseAnonymizationRequest(modification, call)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
425 AnonymizeOrModifyInstance(modification, call); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 } |
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 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
430 template <enum ChangeType changeType, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
431 enum ResourceType resourceType> |
974 | 432 static void ModifyResource(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
434 DicomModification modification; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
436 if (ParseModifyRequest(modification, call)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 { |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
438 modification.SetLevel(resourceType); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
439 AnonymizeOrModifyResource(modification, MetadataType_ModifiedFrom, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
440 changeType, resourceType, call); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
445 template <enum ChangeType changeType, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
446 enum ResourceType resourceType> |
974 | 447 static void AnonymizeResource(RestApiPostCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
448 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
449 DicomModification modification; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
451 if (ParseAnonymizationRequest(modification, call)) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 { |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
453 AnonymizeOrModifyResource(modification, MetadataType_AnonymizedFrom, |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
454 changeType, resourceType, call); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
456 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
457 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 |
1569 | 459 static void StoreCreatedInstance(std::string& id /* out */, |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
460 RestApiPostCall& call, |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
461 ParsedDicomFile& dicom) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
462 { |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
463 DicomInstanceToStore toStore; |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
464 toStore.SetRestOrigin(call); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
465 toStore.SetParsedDicomFile(dicom); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
466 |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
467 ServerContext& context = OrthancRestApi::GetContext(call); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
468 StoreStatus status = context.Store(id, toStore); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
469 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
470 if (status == StoreStatus_Failure) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
471 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
472 throw OrthancException(ErrorCode_CannotStoreInstance); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
473 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
474 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
475 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
476 |
1569 | 477 static void CreateDicomV1(ParsedDicomFile& dicom, |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
478 RestApiPostCall& call, |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
479 const Json::Value& request) |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
480 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
481 // 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
|
482 // 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
|
483 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
484 assert(request.isObject()); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
485 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
|
486 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
487 Json::Value::Members members = request.getMemberNames(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
488 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
|
489 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
490 const std::string& name = members[i]; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
491 if (request[name].type() != Json::stringValue) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
492 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
493 throw OrthancException(ErrorCode_CreateDicomNotString); |
1555
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 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
496 std::string value = request[name].asString(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
497 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
498 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
499 if (tag == DICOM_TAG_PIXEL_DATA) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
500 { |
1562 | 501 dicom.EmbedContent(value); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
502 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
503 else |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
504 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
505 // This is V1, don't try and decode data URI scheme |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
506 dicom.ReplacePlainString(tag, value); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
507 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
508 } |
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 |
1569 | 512 static void InjectTags(ParsedDicomFile& dicom, |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
513 const Json::Value& tags, |
1689 | 514 bool decodeBinaryTags) |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
515 { |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
516 if (tags.type() != Json::objectValue) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
517 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
518 throw OrthancException(ErrorCode_BadRequest); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
519 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
520 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
521 // Inject the user-specified tags |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
522 Json::Value::Members members = tags.getMemberNames(); |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
523 for (size_t i = 0; i < members.size(); i++) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
524 { |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
525 const std::string& name = members[i]; |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
526 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
527 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
528 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
529 { |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
530 if (tag != DICOM_TAG_PATIENT_ID && |
1640
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
531 tag != DICOM_TAG_ACQUISITION_DATE && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
532 tag != DICOM_TAG_ACQUISITION_TIME && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
533 tag != DICOM_TAG_CONTENT_DATE && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
534 tag != DICOM_TAG_CONTENT_TIME && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
535 tag != DICOM_TAG_INSTANCE_CREATION_DATE && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
536 tag != DICOM_TAG_INSTANCE_CREATION_TIME && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
537 tag != DICOM_TAG_SERIES_DATE && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
538 tag != DICOM_TAG_SERIES_TIME && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
539 tag != DICOM_TAG_STUDY_DATE && |
48224db51ee7
allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
540 tag != DICOM_TAG_STUDY_TIME && |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
541 dicom.HasTag(tag)) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
542 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
543 throw OrthancException(ErrorCode_CreateDicomOverrideTag); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
544 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
545 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
546 if (tag == DICOM_TAG_PIXEL_DATA) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
547 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
548 throw OrthancException(ErrorCode_CreateDicomUseContent); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
549 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
550 else |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
551 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
552 dicom.Replace(tag, tags[name], decodeBinaryTags, DicomReplaceMode_InsertIfAbsent); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
553 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
554 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
555 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
556 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
557 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
558 |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
559 static void CreateSeries(RestApiPostCall& call, |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
560 ParsedDicomFile& base /* in */, |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
561 const Json::Value& content, |
1689 | 562 bool decodeBinaryTags) |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
563 { |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
564 assert(content.isArray()); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
565 assert(content.size() > 0); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
566 ServerContext& context = OrthancRestApi::GetContext(call); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
567 |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
568 base.ReplacePlainString(DICOM_TAG_IMAGES_IN_ACQUISITION, boost::lexical_cast<std::string>(content.size())); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
569 base.ReplacePlainString(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "1"); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
570 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
571 std::string someInstance; |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
572 |
1566 | 573 try |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
574 { |
1569 | 575 for (Json::ArrayIndex i = 0; i < content.size(); i++) |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
576 { |
1566 | 577 std::auto_ptr<ParsedDicomFile> dicom(base.Clone()); |
578 const Json::Value* payload = NULL; | |
579 | |
580 if (content[i].type() == Json::stringValue) | |
581 { | |
582 payload = &content[i]; | |
583 } | |
584 else if (content[i].type() == Json::objectValue) | |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
585 { |
1566 | 586 if (!content[i].isMember("Content")) |
587 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
588 throw OrthancException(ErrorCode_CreateDicomNoPayload); |
1566 | 589 } |
590 | |
591 payload = &content[i]["Content"]; | |
592 | |
1569 | 593 if (content[i].isMember("Tags")) |
1570 | 594 { |
1689 | 595 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags); |
1570 | 596 } |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
597 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
598 |
1566 | 599 if (payload == NULL || |
600 payload->type() != Json::stringValue) | |
601 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
602 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme); |
1566 | 603 } |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
604 |
1566 | 605 dicom->EmbedContent(payload->asString()); |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
606 dicom->ReplacePlainString(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
607 dicom->ReplacePlainString(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); |
1566 | 608 |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
609 StoreCreatedInstance(someInstance, call, *dicom); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
610 } |
1566 | 611 } |
1616 | 612 catch (OrthancException&) |
1566 | 613 { |
1569 | 614 // Error: Remove the newly-created series |
615 | |
616 std::string series; | |
617 if (context.GetIndex().LookupParent(series, someInstance)) | |
1570 | 618 { |
1569 | 619 Json::Value dummy; |
620 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series); | |
1570 | 621 } |
1569 | 622 |
1616 | 623 throw; |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
624 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
625 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
626 std::string series; |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
627 if (context.GetIndex().LookupParent(series, someInstance)) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
628 { |
1569 | 629 OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
630 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
631 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
632 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
633 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
634 static void CreateDicomV2(RestApiPostCall& call, |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
635 const Json::Value& request) |
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 assert(request.isObject()); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
638 ServerContext& context = OrthancRestApi::GetContext(call); |
1555
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 if (!request.isMember("Tags") || |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
641 request["Tags"].type() != Json::objectValue) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
642 { |
1569 | 643 throw OrthancException(ErrorCode_BadRequest); |
1555
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 |
1805
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1699
diff
changeset
|
646 ParsedDicomFile dicom(true); |
1558
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
647 |
1557 | 648 { |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
649 Encoding encoding; |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
650 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
651 if (request["Tags"].isMember("SpecificCharacterSet")) |
1558
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
652 { |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
653 const char* tmp = request["Tags"]["SpecificCharacterSet"].asCString(); |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
654 if (!GetDicomEncoding(encoding, tmp)) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
655 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
656 LOG(ERROR) << "Unknown specific character set: " << std::string(tmp); |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
657 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
658 } |
1558
124de28b32ed
fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
659 } |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
660 else |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
661 { |
1934
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
662 encoding = Configuration::GetDefaultEncoding(); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
663 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
664 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
665 dicom.SetEncoding(encoding); |
1557 | 666 } |
667 | |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
668 ResourceType parentType = ResourceType_Instance; |
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 if (request.isMember("Parent")) |
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 // Locate the parent tags |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
673 std::string parent = request["Parent"].asString(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
674 if (!context.GetIndex().LookupResourceType(parentType, parent)) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
675 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
676 throw OrthancException(ErrorCode_CreateDicomBadParent); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
677 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
678 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
679 if (parentType == ResourceType_Instance) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
680 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
681 throw OrthancException(ErrorCode_CreateDicomParentIsInstance); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
682 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
683 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
684 // 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
|
685 // retrieve all its tags |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
686 Json::Value siblingTags; |
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 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
689 // 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
|
690 std::list<std::string> siblingInstances; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
691 context.GetIndex().GetChildInstances(siblingInstances, parent); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
692 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
693 if (siblingInstances.empty()) |
1569 | 694 { |
695 // Error: No instance (should never happen) | |
696 throw OrthancException(ErrorCode_InternalError); | |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
697 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
698 |
2124 | 699 context.ReadDicomAsJson(siblingTags, siblingInstances.front()); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
700 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
701 |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
702 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
703 // Choose the same encoding as the parent resource |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
704 { |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
705 static const char* SPECIFIC_CHARACTER_SET = "0008,0005"; |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
706 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
707 if (siblingTags.isMember(SPECIFIC_CHARACTER_SET)) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
708 { |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
709 Encoding encoding; |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
710 if (!siblingTags[SPECIFIC_CHARACTER_SET].isMember("Value") || |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
711 siblingTags[SPECIFIC_CHARACTER_SET]["Value"].type() != Json::stringValue || |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
712 !GetDicomEncoding(encoding, siblingTags[SPECIFIC_CHARACTER_SET]["Value"].asCString())) |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
713 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
714 throw OrthancException(ErrorCode_CreateDicomParentEncoding); |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
715 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
716 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
717 dicom.SetEncoding(encoding); |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
718 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
719 } |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
720 |
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
721 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
722 // 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
|
723 typedef std::set<DicomTag> ModuleTags; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
724 ModuleTags moduleTags; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
725 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
726 ResourceType type = parentType; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
727 for (;;) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
728 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
729 DicomTag::AddTagsForModule(moduleTags, GetModule(type)); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
730 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
731 if (type == ResourceType_Patient) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
732 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
733 break; // We're done |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
734 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
735 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
736 // Go up |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
737 std::string tmp; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
738 if (!context.GetIndex().LookupParent(tmp, parent)) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
739 { |
1569 | 740 throw OrthancException(ErrorCode_InternalError); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
741 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
742 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
743 parent = tmp; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
744 type = GetParentResourceType(type); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
745 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
746 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
747 for (ModuleTags::const_iterator it = moduleTags.begin(); |
1616 | 748 it != moduleTags.end(); ++it) |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
749 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
750 std::string t = it->Format(); |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
751 if (siblingTags.isMember(t)) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
752 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
753 const Json::Value& tag = siblingTags[t]; |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
754 if (tag["Type"] == "Null") |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
755 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
756 dicom.ReplacePlainString(*it, ""); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
757 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
758 else if (tag["Type"] == "String") |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
759 { |
1557 | 760 std::string value = tag["Value"].asString(); |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
761 dicom.ReplacePlainString(*it, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding())); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
762 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
763 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
764 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
765 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
766 |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
767 |
1689 | 768 bool decodeBinaryTags = true; |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
769 if (request.isMember("InterpretBinaryTags")) |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
770 { |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
771 const Json::Value& v = request["InterpretBinaryTags"]; |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
772 if (v.type() != Json::booleanValue) |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
773 { |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
774 throw OrthancException(ErrorCode_BadRequest); |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
775 } |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
776 |
1689 | 777 decodeBinaryTags = v.asBool(); |
1641
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
778 } |
4e56b5a206b7
Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
779 |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
780 |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
781 // Inject time-related information |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
782 std::string date, time; |
2140 | 783 SystemToolbox::GetNowDicom(date, time); |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
784 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
785 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_TIME, time); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
786 dicom.ReplacePlainString(DICOM_TAG_CONTENT_DATE, date); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
787 dicom.ReplacePlainString(DICOM_TAG_CONTENT_TIME, time); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
788 dicom.ReplacePlainString(DICOM_TAG_INSTANCE_CREATION_DATE, date); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
789 dicom.ReplacePlainString(DICOM_TAG_INSTANCE_CREATION_TIME, time); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
790 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
791 if (parentType == ResourceType_Patient || |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
792 parentType == ResourceType_Study || |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
793 parentType == ResourceType_Instance /* no parent */) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
794 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
795 dicom.ReplacePlainString(DICOM_TAG_SERIES_DATE, date); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
796 dicom.ReplacePlainString(DICOM_TAG_SERIES_TIME, time); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
797 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
798 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
799 if (parentType == ResourceType_Patient || |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
800 parentType == ResourceType_Instance /* no parent */) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
801 { |
1982
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
802 dicom.ReplacePlainString(DICOM_TAG_STUDY_DATE, date); |
b5d4f9c156ad
Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
803 dicom.ReplacePlainString(DICOM_TAG_STUDY_TIME, time); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
804 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
805 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
806 |
1689 | 807 InjectTags(dicom, request["Tags"], decodeBinaryTags); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
808 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
809 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
810 // 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
|
811 if (request.isMember("Content")) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
812 { |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
813 const Json::Value& content = request["Content"]; |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
814 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
815 if (content.type() == Json::stringValue) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
816 { |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
817 dicom.EmbedContent(request["Content"].asString()); |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
818 |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
819 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
820 else if (content.type() == Json::arrayValue) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
821 { |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
822 if (content.size() > 0) |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
823 { |
1565
4b23310eb7e8
add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
824 // Let's create a series instead of a single instance |
1689 | 825 CreateSeries(call, dicom, content, decodeBinaryTags); |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
826 return; |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
827 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
828 } |
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
829 else |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
830 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
831 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
832 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
833 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
834 |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
835 std::string id; |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
836 StoreCreatedInstance(id, call, dicom); |
1569 | 837 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
838 |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1562
diff
changeset
|
839 return; |
1555
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
840 } |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
841 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
842 |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
843 static void CreateDicom(RestApiPostCall& call) |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
844 { |
d6a93e12b1c1
Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
845 Json::Value request; |
1569 | 846 if (!call.ParseJsonRequest(request) || |
847 !request.isObject()) | |
1570 | 848 { |
849 throw OrthancException(ErrorCode_BadRequest); | |
850 } | |
1569 | 851 |
852 if (request.isMember("Tags")) | |
1570 | 853 { |
854 CreateDicomV2(call, request); | |
855 } | |
1569 | 856 else |
1570 | 857 { |
858 // Compatibility with Orthanc <= 0.9.3 | |
1805
f08978b1f45b
c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1699
diff
changeset
|
859 ParsedDicomFile dicom(true); |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
860 CreateDicomV1(dicom, call, request); |
1569 | 861 |
1570 | 862 std::string id; |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
863 StoreCreatedInstance(id, call, dicom); |
1570 | 864 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); |
865 } | |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
866 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
867 |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
868 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
869 void OrthancRestApi::RegisterAnonymizeModify() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
870 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
871 Register("/instances/{id}/modify", ModifyInstance); |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
872 Register("/series/{id}/modify", ModifyResource<ChangeType_ModifiedSeries, ResourceType_Series>); |
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
782
diff
changeset
|
873 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
|
874 Register("/patients/{id}/modify", ModifyResource<ChangeType_ModifiedPatient, ResourceType_Patient>); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
875 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
876 Register("/instances/{id}/anonymize", AnonymizeInstance); |
2250 | 877 Register("/series/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedSeries, ResourceType_Series>); |
878 Register("/studies/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedStudy, ResourceType_Study>); | |
879 Register("/patients/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedPatient, ResourceType_Patient>); | |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
795
diff
changeset
|
880 |
1120
009dce4ea2f6
/tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1010
diff
changeset
|
881 Register("/tools/create-dicom", CreateDicom); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
882 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
883 } |