Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5692:7c11a71927a9 find-refactoring
improved handling of limits
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Jul 2024 20:20:50 +0200 |
parents | f7adfb22e20e |
children | 8db85be7a445 |
rev | line source |
---|---|
2642 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5558
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5558
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5344
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2642 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "../PrecompiledHeadersServer.h" | |
25 #include "ResourceModificationJob.h" | |
26 | |
4045 | 27 #include "../../../OrthancFramework/Sources/Logging.h" |
28 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
29 #include "../ServerContext.h" |
2642 | 30 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
31 #include <dcmtk/dcmdata/dcfilefo.h> |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
32 #include <dcmtk/dcmdata/dcdeftag.h> |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
33 #include <cassert> |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
34 |
2642 | 35 namespace Orthanc |
36 { | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
37 static void FormatResource(Json::Value& target, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
38 ResourceType level, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
39 const std::string& id) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
40 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
41 target["Type"] = EnumerationToString(level); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
42 target["ID"] = id; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
43 target["Path"] = GetBasePath(level, id); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
44 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
45 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
46 class ResourceModificationJob::SingleOutput : public IOutput |
2642 | 47 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
48 private: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
49 ResourceType level_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
50 bool isFirst_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
51 std::string id_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
52 std::string patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
53 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
54 public: |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
55 explicit SingleOutput(ResourceType level) : |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
56 level_(level), |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
57 isFirst_(true) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
58 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
59 if (level_ != ResourceType_Patient && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
60 level_ != ResourceType_Study && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
61 level_ != ResourceType_Series) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
62 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
63 throw OrthancException(ErrorCode_ParameterOutOfRange); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
64 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
65 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
66 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
67 virtual void Update(DicomInstanceHasher& hasher) ORTHANC_OVERRIDE |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
68 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
69 if (isFirst_) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
70 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
71 switch (level_) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
72 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
73 case ResourceType_Series: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
74 id_ = hasher.HashSeries(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
75 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
76 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
77 case ResourceType_Study: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
78 id_ = hasher.HashStudy(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
79 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
80 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
81 case ResourceType_Patient: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
82 id_ = hasher.HashPatient(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
83 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
84 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
85 default: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
86 throw OrthancException(ErrorCode_InternalError); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
87 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
88 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
89 patientId_ = hasher.HashPatient(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
90 isFirst_ = false; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
91 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
92 } |
2642 | 93 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
94 virtual void Format(Json::Value& target) const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
95 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
96 assert(target.type() == Json::objectValue); |
2642 | 97 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
98 if (!isFirst_) |
2642 | 99 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
100 FormatResource(target, level_, id_); |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
101 target["PatientID"] = patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
102 } |
2642 | 103 } |
104 | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
105 virtual bool IsSingleResource() const ORTHANC_OVERRIDE |
2642 | 106 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
107 return true; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
108 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
109 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
110 ResourceType GetLevel() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
111 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
112 return level_; |
2642 | 113 } |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
114 }; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
115 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
116 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
117 class ResourceModificationJob::MultipleOutputs : public IOutput |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
118 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
119 private: |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
120 static void FormatResources(Json::Value& target, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
121 ResourceType level, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
122 const std::set<std::string>& resources) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
123 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
124 assert(target.type() == Json::arrayValue); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
125 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
126 for (std::set<std::string>::const_iterator |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
127 it = resources.begin(); it != resources.end(); ++it) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
128 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
129 Json::Value item = Json::objectValue; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
130 FormatResource(item, level, *it); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
131 target.append(item); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
132 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
133 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
134 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
135 std::set<std::string> instances_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
136 std::set<std::string> series_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
137 std::set<std::string> studies_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
138 std::set<std::string> patients_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
139 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
140 public: |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
141 virtual void Update(DicomInstanceHasher& hasher) ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
142 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
143 instances_.insert(hasher.HashInstance()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
144 series_.insert(hasher.HashSeries()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
145 studies_.insert(hasher.HashStudy()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
146 patients_.insert(hasher.HashPatient()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
147 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
148 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
149 virtual void Format(Json::Value& target) const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
150 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
151 assert(target.type() == Json::objectValue); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
152 Json::Value resources = Json::arrayValue; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
153 FormatResources(resources, ResourceType_Instance, instances_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
154 FormatResources(resources, ResourceType_Series, series_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
155 FormatResources(resources, ResourceType_Study, studies_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
156 FormatResources(resources, ResourceType_Patient, patients_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
157 target["Resources"] = resources; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
158 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
159 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
160 virtual bool IsSingleResource() const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
161 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
162 return false; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
163 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
164 }; |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
165 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
166 // Reset is called when resubmitting a failed job |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
167 void ResourceModificationJob::Reset() |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
168 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
169 boost::recursive_mutex::scoped_lock lock(mutex_); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
170 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
171 // TODO: cleanup the instances that have been generated during the previous run |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
172 modifiedSeries_.clear(); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
173 instancesToReconstruct_.clear(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
174 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
175 ThreadedSetOfInstancesJob::Reset(); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
176 } |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
177 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
178 void ResourceModificationJob::PostProcessInstances() |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
179 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
180 boost::recursive_mutex::scoped_lock lock(mutex_); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
181 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
182 // reconstruct the parents MainDicomTags in case one of them has changed |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
183 if (instancesToReconstruct_.size() > 0) |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
184 { |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
185 for (std::set<std::string>::const_iterator it = instancesToReconstruct_.begin(); it != instancesToReconstruct_.end(); ++it) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
186 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
187 ServerContext::DicomCacheLocker locker(GetContext(), *it); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
188 ParsedDicomFile& modifiedDicom = locker.GetDicom(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
189 |
5558
c1ed59a5bdc2
new LimitToThisLevelMainDicomTags reconstruct mode + * Housekeeper plugin: Added an option LimitMainDicomTagsReconstructLevel
Alain Mazy <am@orthanc.team>
parents:
5495
diff
changeset
|
190 GetContext().GetIndex().ReconstructInstance(modifiedDicom, false, ResourceType_Instance /* dummy */); |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
191 } |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
192 } |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
193 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
194 } |
2642 | 195 |
196 bool ResourceModificationJob::HandleInstance(const std::string& instance) | |
197 { | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
198 if (modification_.get() == NULL || |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
199 output_.get() == NULL) |
2642 | 200 { |
2955 | 201 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
202 "No modification was provided for this job"); | |
2642 | 203 } |
204 | |
205 | |
206 LOG(INFO) << "Modifying instance in a job: " << instance; | |
207 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
208 /** |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
209 * Retrieve the original instance from the DICOM cache. |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
210 **/ |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
211 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
212 std::unique_ptr<DicomInstanceHasher> originalHasher; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
213 std::unique_ptr<ParsedDicomFile> modified; |
5495
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
214 std::set<std::string> instanceLabels; |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
215 std::set<std::string> seriesLabels; |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
216 std::set<std::string> studyLabels; |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
217 std::set<std::string> patientLabels; |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
218 |
2642 | 219 try |
220 { | |
3942
5b882ad2ffd0
"/{patients|studies|series}/.../modify": New option "KeepSource"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
221 ServerContext::DicomCacheLocker locker(GetContext(), instance); |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
222 ParsedDicomFile& original = locker.GetDicom(); |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
223 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
224 originalHasher.reset(new DicomInstanceHasher(original.GetHasher())); |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
225 modified.reset(original.Clone(true)); |
2642 | 226 } |
3430 | 227 catch (OrthancException& e) |
2642 | 228 { |
3430 | 229 LOG(WARNING) << "An error occurred while executing a Modification job on instance " << instance << ": " << e.GetDetails(); |
5344 | 230 throw; |
2642 | 231 } |
232 | |
233 | |
234 /** | |
235 * Compute the resulting DICOM instance. | |
236 **/ | |
237 | |
5141
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
238 { |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
239 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
240 |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
241 modification_->Apply(*modified); |
5495
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
242 |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
243 if (modification_->AreLabelsKept()) |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
244 { |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
245 GetContext().GetIndex().ListLabels(instanceLabels, instance, ResourceType_Instance); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
246 // we must also save the parent labels. This instance might currently be the only one in the hierarchy and therefore it might be in charge of restoring all labels of the hierarchy |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
247 GetContext().GetIndex().ListLabels(seriesLabels, originalHasher->HashSeries(), ResourceType_Series); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
248 GetContext().GetIndex().ListLabels(studyLabels, originalHasher->HashStudy(), ResourceType_Study); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
249 GetContext().GetIndex().ListLabels(patientLabels, originalHasher->HashPatient(), ResourceType_Patient); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
250 } |
5141
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
251 } |
2642 | 252 |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
253 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
254 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
255 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
256 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
257 std::set<DicomTransferSyntax> syntaxes; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
258 syntaxes.insert(transferSyntax_); |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
259 |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
260 IDicomTranscoder::DicomImage source; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
261 source.AcquireParsed(*modified); // "modified" is invalid below this point |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
262 |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
263 IDicomTranscoder::DicomImage transcoded; |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3948
diff
changeset
|
264 if (GetContext().Transcode(transcoded, source, syntaxes, true)) |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
265 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
266 modified.reset(transcoded.ReleaseAsParsedDicomFile()); |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
267 |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
268 // Fix the SOP instance UID in order the preserve the |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
269 // references between instance UIDs in the DICOM hierarchy |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
270 // (the UID might have changed in the case of lossy transcoding) |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
271 if (modified.get() == NULL || |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
272 modified->GetDcmtkObject().getDataset() == NULL || |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
273 !modified->GetDcmtkObject().getDataset()->putAndInsertString( |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
274 DCM_SOPInstanceUID, modifiedUid.c_str(), OFTrue /* replace */).good()) |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
275 { |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
276 throw OrthancException(ErrorCode_InternalError); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
277 } |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
278 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
279 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
280 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
281 LOG(WARNING) << "Cannot transcode instance, keeping original transfer syntax: " << instance; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
282 modified.reset(source.ReleaseAsParsedDicomFile()); |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
283 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
284 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
285 |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
286 assert(modifiedUid == IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject())); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
287 |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
288 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*modified)); |
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
289 toStore->SetOrigin(origin_); |
5148
2df546a76e17
If specifying 'Transcode' option to /modify or /anonymize, this value will take over the 'IngestTranscoding' global configuration
Alain Mazy <am@osimis.io>
parents:
5142
diff
changeset
|
290 toStore->SetSkipIngestTranscoding(transcode_); // do not apply IngestTranscoding if you have forced the transfer syntax during the modification/anonymization |
2642 | 291 |
292 | |
293 /** | |
294 * Prepare the metadata information to associate with the | |
295 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom). | |
296 **/ | |
297 | |
298 DicomInstanceHasher modifiedHasher = modified->GetHasher(); | |
299 | |
300 MetadataType metadataType = (isAnonymization_ ? | |
301 MetadataType_AnonymizedFrom : | |
302 MetadataType_ModifiedFrom); | |
303 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
304 if (originalHasher->HashSeries() != modifiedHasher.HashSeries()) |
2642 | 305 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
306 toStore->AddMetadata(ResourceType_Series, metadataType, originalHasher->HashSeries()); |
2642 | 307 } |
308 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
309 if (originalHasher->HashStudy() != modifiedHasher.HashStudy()) |
2642 | 310 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
311 toStore->AddMetadata(ResourceType_Study, metadataType, originalHasher->HashStudy()); |
2642 | 312 } |
313 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
314 if (originalHasher->HashPatient() != modifiedHasher.HashPatient()) |
2642 | 315 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
316 toStore->AddMetadata(ResourceType_Patient, metadataType, originalHasher->HashPatient()); |
2642 | 317 } |
318 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
319 assert(instance == originalHasher->HashInstance()); |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
320 toStore->AddMetadata(ResourceType_Instance, metadataType, instance); |
2642 | 321 |
322 | |
323 /** | |
324 * Store the resulting DICOM instance into the Orthanc store. | |
325 **/ | |
326 | |
327 std::string modifiedInstance; | |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4693
diff
changeset
|
328 ServerContext::StoreResult result = GetContext().Store(modifiedInstance, *toStore, StoreInstanceMode_Default); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
329 if (result.GetStatus() != StoreStatus_Success && result.GetStatus() != StoreStatus_AlreadyStored) // when retrying a job, we might save the same data again |
2642 | 330 { |
2955 | 331 throw OrthancException(ErrorCode_CannotStoreInstance, |
332 "Error while storing a modified instance " + instance); | |
2642 | 333 } |
334 | |
5495
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
335 { |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
336 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
337 |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
338 if (modification_->AreLabelsKept()) |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
339 { |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
340 GetContext().GetIndex().AddLabels(instance, ResourceType_Instance, instanceLabels); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
341 GetContext().GetIndex().AddLabels(modifiedHasher.HashSeries(), ResourceType_Series, seriesLabels); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
342 GetContext().GetIndex().AddLabels(modifiedHasher.HashStudy(), ResourceType_Study, studyLabels); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
343 GetContext().GetIndex().AddLabels(modifiedHasher.HashPatient(), ResourceType_Patient, patientLabels); |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
344 } |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
345 } |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
346 |
4b3f5986eca1
Added a 'KeepLabels' option in /modify routes (default = false)
Alain Mazy <am@osimis.io>
parents:
5485
diff
changeset
|
347 |
3938 | 348 /** |
349 * The assertion below will fail if automated transcoding to a | |
350 * lossy transfer syntax is enabled in the Orthanc core, and if | |
351 * the source instance is not in this transfer syntax. | |
352 **/ | |
353 // assert(modifiedInstance == modifiedHasher.HashInstance()); | |
2642 | 354 |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
355 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
356 boost::recursive_mutex::scoped_lock lock(outputMutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
357 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
358 output_->Update(modifiedHasher); |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
359 if (modifiedSeries_.find(modifiedHasher.HashSeries()) == modifiedSeries_.end()) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
360 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
361 modifiedSeries_.insert(modifiedHasher.HashSeries()); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
362 // add an instance to reconstruct for each series |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
363 instancesToReconstruct_.insert(modifiedHasher.HashInstance()); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
364 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
365 |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
366 } |
2642 | 367 |
368 return true; | |
369 } | |
370 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
371 |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
372 ResourceModificationJob::ResourceModificationJob(ServerContext& context, unsigned int workersCount) : |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5134
diff
changeset
|
373 ThreadedSetOfInstancesJob(context, true /* post processing step */, true /* by default, keep source */, workersCount), |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
374 isAnonymization_(false), |
4206 | 375 transcode_(false), |
376 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization | |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
377 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
378 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
379 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
380 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
381 void ResourceModificationJob::SetSingleResourceModification(DicomModification* modification, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
382 ResourceType outputLevel, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
383 bool isAnonymization) |
2642 | 384 { |
385 if (modification == NULL) | |
386 { | |
387 throw OrthancException(ErrorCode_NullPointer); | |
388 } | |
389 else if (IsStarted()) | |
390 { | |
391 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
392 } | |
393 else | |
394 { | |
395 modification_.reset(modification); | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
396 output_.reset(new SingleOutput(outputLevel)); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
397 isAnonymization_ = isAnonymization; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
398 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
399 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
400 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
401 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
402 void ResourceModificationJob::SetMultipleResourcesModification(DicomModification* modification, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
403 bool isAnonymization) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
404 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
405 if (modification == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
406 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
407 throw OrthancException(ErrorCode_NullPointer); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
408 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
409 else if (IsStarted()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
410 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
411 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
412 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
413 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
414 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
415 modification_.reset(modification); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
416 output_.reset(new MultipleOutputs); |
2642 | 417 isAnonymization_ = isAnonymization; |
418 } | |
419 } | |
420 | |
421 | |
422 void ResourceModificationJob::SetOrigin(const DicomInstanceOrigin& origin) | |
423 { | |
424 if (IsStarted()) | |
425 { | |
426 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
427 } | |
428 else | |
429 { | |
430 origin_ = origin; | |
431 } | |
432 } | |
433 | |
434 | |
435 void ResourceModificationJob::SetOrigin(const RestApiCall& call) | |
436 { | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
437 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
438 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
439 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
440 |
5141
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
441 #if ORTHANC_BUILD_UNIT_TESTS == 1 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
442 const DicomModification& ResourceModificationJob::GetModification() const |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
443 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
444 if (modification_.get() == NULL) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
445 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
446 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
447 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
448 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
449 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
450 return *modification_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
451 } |
2642 | 452 } |
5141
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
453 #endif |
2642 | 454 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
455 DicomTransferSyntax ResourceModificationJob::GetTransferSyntax() const |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
456 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
457 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
458 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
459 return transferSyntax_; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
460 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
461 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
462 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
463 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
464 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
465 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
466 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
467 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
468 void ResourceModificationJob::SetTranscode(DicomTransferSyntax syntax) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
469 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
470 if (IsStarted()) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
471 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
472 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
473 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
474 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
475 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
476 transcode_ = true; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
477 transferSyntax_ = syntax; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
478 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
479 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
480 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
481 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
482 void ResourceModificationJob::SetTranscode(const std::string& transferSyntaxUid) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
483 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
484 DicomTransferSyntax s; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
485 if (LookupTransferSyntax(s, transferSyntaxUid)) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
486 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
487 SetTranscode(s); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
488 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
489 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
490 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
491 throw OrthancException(ErrorCode_BadFileFormat, |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
492 "Unknown transfer syntax UID: " + transferSyntaxUid); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
493 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
494 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
495 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
496 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
497 void ResourceModificationJob::ClearTranscode() |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
498 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
499 if (IsStarted()) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
500 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
501 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
502 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
503 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
504 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
505 transcode_ = false; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
506 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
507 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
508 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
509 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
510 bool ResourceModificationJob::IsSingleResourceModification() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
511 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
512 if (modification_.get() == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
513 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
514 assert(output_.get() == NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
515 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
516 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
517 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
518 { |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
519 boost::recursive_mutex::scoped_lock lock(outputMutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
520 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
521 assert(output_.get() != NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
522 return output_->IsSingleResource(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
523 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
524 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
525 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
526 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
527 ResourceType ResourceModificationJob::GetOutputLevel() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
528 { |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
529 boost::recursive_mutex::scoped_lock lock(outputMutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
530 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
531 if (IsSingleResourceModification()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
532 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
533 assert(modification_.get() != NULL && |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
534 output_.get() != NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
535 return dynamic_cast<const SingleOutput&>(*output_).GetLevel(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
536 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
537 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
538 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
539 // Not applicable if multiple resources |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
540 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
541 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
542 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
543 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
544 |
2642 | 545 void ResourceModificationJob::GetPublicContent(Json::Value& value) |
546 { | |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
547 boost::recursive_mutex::scoped_lock lock(outputMutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
548 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
549 ThreadedSetOfInstancesJob::GetPublicContent(value); |
2642 | 550 |
551 value["IsAnonymization"] = isAnonymization_; | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
552 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
553 if (output_.get() != NULL) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
554 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
555 output_->Format(value); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
556 } |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
557 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
558 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
559 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
560 value["Transcode"] = GetTransferSyntaxUid(transferSyntax_); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
561 } |
2642 | 562 } |
563 | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
564 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
565 static const char* MODIFICATION = "Modification"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
566 static const char* ORIGIN = "Origin"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
567 static const char* IS_ANONYMIZATION = "IsAnonymization"; |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
568 static const char* TRANSCODE = "Transcode"; |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
569 static const char* OUTPUT_LEVEL = "OutputLevel"; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
570 static const char* IS_SINGLE_RESOURCE = "IsSingleResource"; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
571 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
572 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
573 ResourceModificationJob::ResourceModificationJob(ServerContext& context, |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
574 const Json::Value& serialized) : |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
575 ThreadedSetOfInstancesJob(context, serialized, false /* no post processing step */, true /* by default, keep source */), |
4223 | 576 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
577 { |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
578 assert(serialized.type() == Json::objectValue); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
579 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
580 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
581 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
582 if (serialized.isMember(TRANSCODE)) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
583 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
584 SetTranscode(SerializationToolbox::ReadString(serialized, TRANSCODE)); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
585 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
586 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
587 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
588 transcode_ = false; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
589 } |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
590 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
591 bool isSingleResource; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
592 if (serialized.isMember(IS_SINGLE_RESOURCE)) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
593 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
594 isSingleResource = SerializationToolbox::ReadBoolean(serialized, IS_SINGLE_RESOURCE); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
595 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
596 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
597 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
598 isSingleResource = true; // Backward compatibility with Orthanc <= 1.9.3 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
599 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
600 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
601 bool isAnonymization = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
602 std::unique_ptr<DicomModification> modification(new DicomModification(serialized[MODIFICATION])); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
603 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
604 if (isSingleResource) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
605 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
606 ResourceType outputLevel; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
607 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
608 if (serialized.isMember(OUTPUT_LEVEL)) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
609 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
610 // New in Orthanc 1.9.4. This fixes an *incorrect* behavior in |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
611 // Orthanc <= 1.9.3, in which "outputLevel" would be set to |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
612 // "modification->GetLevel()" |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
613 outputLevel = StringToResourceType(SerializationToolbox::ReadString(serialized, OUTPUT_LEVEL).c_str()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
614 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
615 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
616 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
617 // Use the buggy convention from Orthanc <= 1.9.3 (which is |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
618 // the only thing we have at hand) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
619 outputLevel = modification->GetLevel(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
620 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
621 if (outputLevel == ResourceType_Instance) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
622 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
623 // This should never happen, but as "SingleOutput" doesn't |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
624 // support instance-level anonymization, don't take any risk |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
625 // and choose an arbitrary output level |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
626 outputLevel = ResourceType_Patient; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
627 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
628 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
629 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
630 SetSingleResourceModification(modification.release(), outputLevel, isAnonymization); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
631 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
632 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
633 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
634 // New in Orthanc 1.9.4 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
635 SetMultipleResourcesModification(modification.release(), isAnonymization); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
636 } |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
637 } |
2642 | 638 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
639 bool ResourceModificationJob::Serialize(Json::Value& value) |
2642 | 640 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
641 if (modification_.get() == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
642 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
643 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
644 } |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
645 else if (!ThreadedSetOfInstancesJob::Serialize(value)) |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
646 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
647 return false; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
648 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
649 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
650 { |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
651 assert(value.type() == Json::objectValue); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
652 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
653 value[IS_ANONYMIZATION] = isAnonymization_; |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
654 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
655 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
656 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
657 value[TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
658 } |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
659 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
660 origin_.Serialize(value[ORIGIN]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
661 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
662 Json::Value tmp; |
5141
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
663 |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
664 { |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
665 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
666 |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
667 modification_->Serialize(tmp); |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
668 } |
023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
Alain Mazy <am@osimis.io>
parents:
5139
diff
changeset
|
669 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
670 value[MODIFICATION] = tmp; |
2642 | 671 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
672 // New in Orthanc 1.9.4 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
673 value[IS_SINGLE_RESOURCE] = IsSingleResourceModification(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
674 if (IsSingleResourceModification()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
675 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
676 value[OUTPUT_LEVEL] = EnumerationToString(GetOutputLevel()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
677 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
678 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
679 return true; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
680 } |
2642 | 681 } |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
682 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
683 void ResourceModificationJob::PerformSanityChecks() |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
684 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
685 boost::recursive_mutex::scoped_lock lock(mutex_); // because we access the parentResources_ |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
686 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
687 std::set<DicomTag> emptyRequestedTags; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
688 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
689 if (modification_.get() == NULL) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
690 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
691 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
692 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
693 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
694 bool replacePatientMainDicomTags = false; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
695 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
696 ResourceType modificationLevel = modification_->GetLevel(); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
697 std::set<DicomTag> replacedTags; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
698 modification_->GetReplacedTags(replacedTags); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
699 |
5158 | 700 for (std::set<DicomTag>::const_iterator it = replacedTags.begin(); it != replacedTags.end(); ++it) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
701 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
702 replacePatientMainDicomTags |= DicomMap::IsMainDicomTag(*it, ResourceType_Patient); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
703 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
704 |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
705 if ((modificationLevel == ResourceType_Study || |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
706 modificationLevel == ResourceType_Patient) && |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
707 !modification_->IsReplaced(DICOM_TAG_PATIENT_ID) && |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
708 modification_->IsKept(DICOM_TAG_STUDY_INSTANCE_UID) && |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
709 modification_->IsKept(DICOM_TAG_SERIES_INSTANCE_UID) && |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
710 modification_->IsKept(DICOM_TAG_SOP_INSTANCE_UID)) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
711 { |
5139
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
712 // if we keep the SOPInstanceUID, it very likely means that we are modifying existing resources 'in place' |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
713 |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
714 // we must make sure we do not delete them at the end of the job |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
715 if (!IsKeepSource()) // note: we can refine this criteria -> this is valid only if all DicomUIDs are kept identical (but this can happen through Keep or Replace options) |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
716 { |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
717 throw OrthancException(ErrorCode_BadRequest, |
5142
45ce9dfa42e0
DicomModification: sanity checks
Alain Mazy <am@osimis.io>
parents:
5141
diff
changeset
|
718 "When keeping StudyInstanceUID, SeriesInstanceUID and SOPInstanceUID tag, you must set KeepSource to true to avoid deleting the modified files at the end of the process"); |
5139
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
719 } |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
720 |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
721 // and we must make sure that we overwite them with the modified resources |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
722 if (IsKeepSource() && !GetContext().IsOverwriteInstances()) |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
723 { |
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
724 throw OrthancException(ErrorCode_BadRequest, |
5142
45ce9dfa42e0
DicomModification: sanity checks
Alain Mazy <am@osimis.io>
parents:
5141
diff
changeset
|
725 "When keeping StudyInstanceUID, SeriesInstanceUID and SOPInstanceUID tag, you must have the 'OverwriteInstances' Orthanc configuration set to true in order to replace the modified resources"); |
5139
021d7fdcb659
more sanity checks for modifications
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
726 } |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
727 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
728 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
729 if (modificationLevel == ResourceType_Study && replacePatientMainDicomTags) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
730 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
731 for (std::set<std::string>::const_iterator studyId = parentResources_.begin(); studyId != parentResources_.end(); ++studyId) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
732 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
733 // When modifying a study, you may not modify patient tags as you wish. |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
734 // - If this is the patient's only study, you may modify all patient tags. This could be performed in 2 steps (modify the patient and then, the study) but, |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
735 // for many use cases, it's helpful to be able to do it one step (e.g, to modify a name in a study that has just been acquired) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
736 // - If the patient already has other studies, you may only 'attach' the study to an existing patient by modifying |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
737 // all patient tags from the study to match those of the target patient. |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
738 // - Otherwise, you can't modify the patient tags |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
739 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
740 std::string targetPatientId; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
741 if (modification_->IsReplaced(DICOM_TAG_PATIENT_ID)) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
742 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
743 targetPatientId = modification_->GetReplacementAsString(DICOM_TAG_PATIENT_ID); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
744 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
745 else |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
746 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
747 ExpandedResource originalStudy; |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
748 if (GetContext().GetIndex().ExpandResource(originalStudy, *studyId, ResourceType_Study, emptyRequestedTags, ExpandResourceFlags_IncludeMainDicomTags)) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
749 { |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
750 targetPatientId = originalStudy.GetMainDicomTags().GetStringValue(DICOM_TAG_PATIENT_ID, "", false); |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
751 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
752 else |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
753 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
754 throw OrthancException(ErrorCode_UnknownResource, "Study not found"); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
755 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
756 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
757 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
758 // try to find the targetPatient |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
759 std::vector<std::string> lookupPatientResult; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
760 GetContext().GetIndex().LookupIdentifierExact(lookupPatientResult, ResourceType_Patient, DICOM_TAG_PATIENT_ID, targetPatientId); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
761 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
762 // if the patient exists, check how many child studies it has. |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
763 if (lookupPatientResult.size() >= 1) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
764 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
765 ExpandedResource targetPatient; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
766 |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
767 if (GetContext().GetIndex().ExpandResource(targetPatient, lookupPatientResult[0], ResourceType_Patient, emptyRequestedTags, static_cast<ExpandResourceFlags>(ExpandResourceFlags_IncludeMainDicomTags | ExpandResourceFlags_IncludeChildren))) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
768 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
769 const std::list<std::string> childrenIds = targetPatient.childrenIds_; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
770 bool targetPatientHasOtherStudies = childrenIds.size() > 1; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
771 if (childrenIds.size() == 1) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
772 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
773 targetPatientHasOtherStudies = std::find(childrenIds.begin(), childrenIds.end(), *studyId) == childrenIds.end(); // if the patient has one study that is not the one being modified |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
774 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
775 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
776 if (targetPatientHasOtherStudies) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
777 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
778 // this is allowed if all patient replacedTags do match the target patient tags |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
779 DicomMap targetPatientTags; |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
780 targetPatient.GetMainDicomTags().ExtractPatientInformation(targetPatientTags); |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
781 |
5175
48005e522bd6
start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5158
diff
changeset
|
782 std::set<DicomTag> mainPatientTags; |
48005e522bd6
start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5158
diff
changeset
|
783 DicomMap::GetMainDicomTags(mainPatientTags, ResourceType_Patient); |
48005e522bd6
start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5158
diff
changeset
|
784 |
48005e522bd6
start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5158
diff
changeset
|
785 for (std::set<DicomTag>::const_iterator mainPatientTag = mainPatientTags.begin(); |
48005e522bd6
start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5158
diff
changeset
|
786 mainPatientTag != mainPatientTags.end(); ++mainPatientTag) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
787 { |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
788 if (targetPatientTags.HasTag(*mainPatientTag) && |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
789 (!modification_->IsReplaced(*mainPatientTag) || |
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
790 modification_->GetReplacementAsString(*mainPatientTag) != targetPatientTags.GetStringValue(*mainPatientTag, "", false))) |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
791 { |
5342 | 792 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. " |
793 "The Patient already exists and has other studies. All the 'Replace' tags should match the existing patient main dicom tags " | |
794 "and you should specify all Patient MainDicomTags in your query. Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format()); | |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
795 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
796 else if (!targetPatientTags.HasTag(*mainPatientTag) && modification_->IsReplaced(*mainPatientTag) ) |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
797 { |
5342 | 798 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. " |
799 "The Patient already exists and has other studies. You are trying to replace a tag that is not defined yet in this patient. " | |
800 "Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format()); | |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
801 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
802 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
803 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
804 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
805 } |
5222
3a61fd50f804
starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
806 } |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
807 } |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
808 } |
2642 | 809 } |