comparison OrthancServer/ServerContext.cpp @ 1004:a226e0959d8b lua-scripting

DicomInstanceToStore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jul 2014 14:06:05 +0200
parents b067017a8a5b
children 84b6d7bca6db
comparison
equal deleted inserted replaced
1003:1d35281d967c 1004:a226e0959d8b
157 } 157 }
158 #endif 158 #endif
159 } 159 }
160 160
161 161
162 StoreStatus ServerContext::Store(std::string& resultPublicId,
163 DicomInstanceToStore& dicom)
164 {
165 try
166 {
167 DicomInstanceHasher hasher(dicom.GetSummary());
168 resultPublicId = hasher.HashInstance();
169
170 Json::Value simplified;
171 SimplifyTags(simplified, dicom.GetJson());
172
173 // Test if the instance must be filtered out
174 if (!ApplyReceivedInstanceFilter(simplified, dicom.GetRemoteAet()))
175 {
176 LOG(INFO) << "An incoming instance has been discarded by the filter";
177 return StoreStatus_FilteredOut;
178 }
179
180 if (compressionEnabled_)
181 {
182 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
183 }
184 else
185 {
186 accessor_.SetCompressionForNextOperations(CompressionType_None);
187 }
188
189 FileInfo dicomInfo = accessor_.Write(dicom.GetBufferData(), dicom.GetBufferSize(), FileContentType_Dicom);
190 FileInfo jsonInfo = accessor_.Write(dicom.GetJson().toStyledString(), FileContentType_DicomAsJson);
191
192 ServerIndex::Attachments attachments;
193 attachments.push_back(dicomInfo);
194 attachments.push_back(jsonInfo);
195
196 StoreStatus status = index_.Store(dicom.GetSummary(), attachments, dicom.GetRemoteAet(), dicom.GetMetadata());
197
198 if (status != StoreStatus_Success)
199 {
200 storage_.Remove(dicomInfo.GetUuid());
201 storage_.Remove(jsonInfo.GetUuid());
202 }
203
204 switch (status)
205 {
206 case StoreStatus_Success:
207 LOG(INFO) << "New instance stored";
208 break;
209
210 case StoreStatus_AlreadyStored:
211 LOG(INFO) << "Already stored";
212 break;
213
214 case StoreStatus_Failure:
215 LOG(ERROR) << "Store failure";
216 break;
217
218 default:
219 // This should never happen
220 break;
221 }
222
223 if (status == StoreStatus_Success ||
224 status == StoreStatus_AlreadyStored)
225 {
226 try
227 {
228 Json::Value metadata = Json::objectValue;
229 for (ServerIndex::MetadataMap::const_iterator
230 it = dicom.GetMetadata().begin();
231 it != dicom.GetMetadata().end(); ++it)
232 {
233 if (it->first.first == ResourceType_Instance)
234 {
235 metadata[EnumerationToString(it->first.second)] = it->second;
236 }
237 }
238
239 ApplyOnStoredInstance(resultPublicId, simplified, metadata);
240 }
241 catch (OrthancException&)
242 {
243 LOG(ERROR) << "Error when dealing with OnStoredInstance";
244 }
245 }
246
247 return status;
248 }
249 catch (OrthancException& e)
250 {
251 if (e.GetErrorCode() == ErrorCode_InexistentTag)
252 {
253 LogMissingRequiredTag(dicom.GetSummary());
254 }
255
256 throw;
257 }
258 }
259
260
261
162 StoreStatus ServerContext::Store(const char* dicomInstance, 262 StoreStatus ServerContext::Store(const char* dicomInstance,
163 size_t dicomSize, 263 size_t dicomSize,
164 const DicomMap& dicomSummary, 264 const DicomMap& dicomSummary,
165 const Json::Value& dicomJson, 265 const Json::Value& dicomJson,
166 const std::string& remoteAet, 266 const std::string& remoteAet,
190 290
191 ServerIndex::Attachments attachments; 291 ServerIndex::Attachments attachments;
192 attachments.push_back(dicomInfo); 292 attachments.push_back(dicomInfo);
193 attachments.push_back(jsonInfo); 293 attachments.push_back(jsonInfo);
194 294
195 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet, metadata); 295 // TODO REMOVE CONST_CAST !!!!
296 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet, const_cast<ServerIndex::MetadataMap&>(metadata));
196 297
197 if (status != StoreStatus_Success) 298 if (status != StoreStatus_Success)
198 { 299 {
199 storage_.Remove(dicomInfo.GetUuid()); 300 storage_.Remove(dicomInfo.GetUuid());
200 storage_.Remove(jsonInfo.GetUuid()); 301 storage_.Remove(jsonInfo.GetUuid());
377 StoreStatus ServerContext::Store(std::string& resultPublicId, 478 StoreStatus ServerContext::Store(std::string& resultPublicId,
378 ParsedDicomFile& dicomInstance, 479 ParsedDicomFile& dicomInstance,
379 const ServerIndex::MetadataMap& metadata) 480 const ServerIndex::MetadataMap& metadata)
380 { 481 {
381 std::string buffer; 482 std::string buffer;
382 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, GetDicom(dicomInstance).getDataset())) 483 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, *GetDicom(dicomInstance).getDataset()))
383 { 484 {
384 throw OrthancException(ErrorCode_InternalError); 485 throw OrthancException(ErrorCode_InternalError);
385 } 486 }
386 487
387 if (buffer.size() == 0) 488 if (buffer.size() == 0)