comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 3920:82e88ff003d7 c-get

merge default -> c-get
author Alain Mazy <alain@mazy.be>
date Tue, 12 May 2020 14:58:24 +0200
parents 6ddad3e0b569
children 7dc5e7e0045d
comparison
equal deleted inserted replaced
3918:dba48c162b7b 3920:82e88ff003d7
110 } 110 }
111 } 111 }
112 112
113 113
114 static void AnonymizeOrModifyInstance(DicomModification& modification, 114 static void AnonymizeOrModifyInstance(DicomModification& modification,
115 RestApiPostCall& call) 115 RestApiPostCall& call,
116 { 116 bool transcode,
117 DicomTransferSyntax targetSyntax)
118 {
119 ServerContext& context = OrthancRestApi::GetContext(call);
117 std::string id = call.GetUriComponent("id", ""); 120 std::string id = call.GetUriComponent("id", "");
118 121
119 std::unique_ptr<ParsedDicomFile> modified; 122 std::unique_ptr<ParsedDicomFile> modified;
120 123
121 { 124 {
122 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); 125 ServerContext::DicomCacheLocker locker(context, id);
123 modified.reset(locker.GetDicom().Clone(true)); 126 modified.reset(locker.GetDicom().Clone(true));
124 } 127 }
125 128
126 modification.Apply(*modified); 129 modification.Apply(*modified);
127 modified->Answer(call.GetOutput()); 130
131 if (transcode)
132 {
133 std::string transcoded;
134 DicomTransferSyntax sourceSyntax;
135 bool hasSopInstanceUidChanged;
136
137 if (context.GetTranscoder().TranscodeParsedToBuffer(
138 transcoded, sourceSyntax, hasSopInstanceUidChanged,
139 modified->GetDcmtkObject(), targetSyntax, true))
140 {
141 call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom);
142 }
143 else
144 {
145 throw OrthancException(ErrorCode_InternalError,
146 "Cannot transcode to transfer syntax: " +
147 std::string(GetTransferSyntaxUid(targetSyntax)));
148 }
149 }
150 else
151 {
152 modified->Answer(call.GetOutput());
153 }
128 } 154 }
129 155
130 156
131 static void ModifyInstance(RestApiPostCall& call) 157 static void ModifyInstance(RestApiPostCall& call)
132 { 158 {
151 else 177 else
152 { 178 {
153 modification.SetLevel(ResourceType_Instance); 179 modification.SetLevel(ResourceType_Instance);
154 } 180 }
155 181
156 AnonymizeOrModifyInstance(modification, call); 182 if (request.isMember("Transcode"))
183 {
184 std::string s = SerializationToolbox::ReadString(request, "Transcode");
185
186 DicomTransferSyntax syntax;
187 if (LookupTransferSyntax(syntax, s))
188 {
189 AnonymizeOrModifyInstance(modification, call, true, syntax);
190 }
191 else
192 {
193 throw OrthancException(ErrorCode_ParameterOutOfRange, "Unknown transfer syntax: " + s);
194 }
195 }
196 else
197 {
198 AnonymizeOrModifyInstance(modification, call, false /* no transcoding */,
199 DicomTransferSyntax_LittleEndianImplicit /* unused */);
200 }
157 } 201 }
158 202
159 203
160 static void AnonymizeInstance(RestApiPostCall& call) 204 static void AnonymizeInstance(RestApiPostCall& call)
161 { 205 {
163 modification.SetAllowManualIdentifiers(true); 207 modification.SetAllowManualIdentifiers(true);
164 208
165 Json::Value request; 209 Json::Value request;
166 ParseAnonymizationRequest(request, modification, call); 210 ParseAnonymizationRequest(request, modification, call);
167 211
168 AnonymizeOrModifyInstance(modification, call); 212 AnonymizeOrModifyInstance(modification, call, false /* no transcoding */,
213 DicomTransferSyntax_LittleEndianImplicit /* unused */);
169 } 214 }
170 215
171 216
172 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification, 217 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification,
173 bool isAnonymization, 218 bool isAnonymization,
225 DicomInstanceToStore toStore; 270 DicomInstanceToStore toStore;
226 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call)); 271 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
227 toStore.SetParsedDicomFile(dicom); 272 toStore.SetParsedDicomFile(dicom);
228 273
229 ServerContext& context = OrthancRestApi::GetContext(call); 274 ServerContext& context = OrthancRestApi::GetContext(call);
230 StoreStatus status = context.Store(id, toStore); 275 StoreStatus status = context.Store(id, toStore, StoreInstanceMode_Default);
231 276
232 if (status == StoreStatus_Failure) 277 if (status == StoreStatus_Failure)
233 { 278 {
234 throw OrthancException(ErrorCode_CannotStoreInstance); 279 throw OrthancException(ErrorCode_CannotStoreInstance);
235 } 280 }
236 281
237 if (sendAnswer) 282 if (sendAnswer)
238 { 283 {
239 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status); 284 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status, id);
240 } 285 }
241 } 286 }
242 287
243 288
244 static void CreateDicomV1(ParsedDicomFile& dicom, 289 static void CreateDicomV1(ParsedDicomFile& dicom,