annotate OrthancServer/ServerJobs/ResourceModificationJob.cpp @ 2663:228e2783ce83 jobs

some jobs might not be serializable
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Jun 2018 18:18:02 +0200
parents e1893d31652a
children a21b244efb37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
ccc470091ea6 reorganization
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
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeadersServer.h"
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ResourceModificationJob.h"
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/Logging.h"
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 ResourceModificationJob::Output::Output(ResourceType level) :
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 level_(level),
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 isFirst_(true)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 if (level_ != ResourceType_Patient &&
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 level_ != ResourceType_Study &&
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 level_ != ResourceType_Series)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 throw OrthancException(ErrorCode_ParameterOutOfRange);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 void ResourceModificationJob::Output::Update(DicomInstanceHasher& hasher)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 boost::mutex::scoped_lock lock(mutex_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 if (isFirst_)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 switch (level_)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 case ResourceType_Series:
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 id_ = hasher.HashSeries();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 break;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 case ResourceType_Study:
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 id_ = hasher.HashStudy();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 break;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 case ResourceType_Patient:
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 id_ = hasher.HashPatient();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 break;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 default:
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 throw OrthancException(ErrorCode_InternalError);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 patientId_ = hasher.HashPatient();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 isFirst_ = false;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 bool ResourceModificationJob::Output::Format(Json::Value& target)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 boost::mutex::scoped_lock lock(mutex_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 if (isFirst_)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return false;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 else
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 target = Json::objectValue;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 target["Type"] = EnumerationToString(level_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 target["ID"] = id_;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 target["Path"] = GetBasePath(level_, id_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 target["PatientID"] = patientId_;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return true;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 bool ResourceModificationJob::Output::GetIdentifier(std::string& id)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 boost::mutex::scoped_lock lock(mutex_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (isFirst_)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 return false;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 else
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 id = id_;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return true;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 bool ResourceModificationJob::HandleInstance(const std::string& instance)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (modification_.get() == NULL)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 LOG(ERROR) << "No modification was provided for this job";
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 LOG(INFO) << "Modifying instance in a job: " << instance;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 std::auto_ptr<ServerContext::DicomCacheLocker> locker;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 try
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 locker.reset(new ServerContext::DicomCacheLocker(context_, instance));
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 catch (OrthancException&)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 LOG(WARNING) << "An instance was removed after the job was issued: " << instance;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return false;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ParsedDicomFile& original = locker->GetDicom();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 DicomInstanceHasher originalHasher = original.GetHasher();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 /**
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 * Compute the resulting DICOM instance.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 **/
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 std::auto_ptr<ParsedDicomFile> modified(original.Clone(true));
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 modification_->Apply(*modified);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 DicomInstanceToStore toStore;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 toStore.SetOrigin(origin_);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 toStore.SetParsedDicomFile(*modified);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 /**
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 * Prepare the metadata information to associate with the
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom).
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 **/
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 DicomInstanceHasher modifiedHasher = modified->GetHasher();
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 MetadataType metadataType = (isAnonymization_ ?
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 MetadataType_AnonymizedFrom :
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 MetadataType_ModifiedFrom);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (originalHasher.HashSeries() != modifiedHasher.HashSeries())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher.HashSeries());
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (originalHasher.HashStudy() != modifiedHasher.HashStudy())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher.HashStudy());
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 if (originalHasher.HashPatient() != modifiedHasher.HashPatient())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher.HashPatient());
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 assert(instance == originalHasher.HashInstance());
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 toStore.AddMetadata(ResourceType_Instance, metadataType, instance);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 /**
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 * Store the resulting DICOM instance into the Orthanc store.
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 **/
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 std::string modifiedInstance;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 LOG(ERROR) << "Error while storing a modified instance " << instance;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 throw OrthancException(ErrorCode_CannotStoreInstance);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 // Sanity checks in debug mode
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 assert(modifiedInstance == modifiedHasher.HashInstance());
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (output_.get() != NULL)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 output_->Update(modifiedHasher);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 return true;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 void ResourceModificationJob::SetModification(DicomModification* modification,
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 bool isAnonymization)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 if (modification == NULL)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 throw OrthancException(ErrorCode_NullPointer);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 else if (IsStarted())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 else
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 modification_.reset(modification);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 isAnonymization_ = isAnonymization;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 void ResourceModificationJob::SetOutput(boost::shared_ptr<Output>& output)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (IsStarted())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 else
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 output_ = output;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 void ResourceModificationJob::SetOrigin(const DicomInstanceOrigin& origin)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 if (IsStarted())
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 else
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 origin_ = origin;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 void ResourceModificationJob::SetOrigin(const RestApiCall& call)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 DicomInstanceOrigin tmp;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 tmp.SetRestOrigin(call);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 SetOrigin(tmp);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 void ResourceModificationJob::GetPublicContent(Json::Value& value)
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 SetOfInstancesJob::GetPublicContent(value);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 value["IsAnonymization"] = isAnonymization_;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
276 bool ResourceModificationJob::Serialize(Json::Value& value)
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
2648
e1893d31652a serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2642
diff changeset
278 SetOfInstancesJob::Serialize(value);
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 Json::Value tmp;
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 modification_->Serialize(tmp);
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 value["Modification"] = tmp;
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
283
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
284 return true;
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }