comparison OrthancServer/Sources/Database/FindResponse.cpp @ 5595:a87f2a56257d find-refactoring

implemented FindRequest::retrieveChildrenMetadata_
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 May 2024 12:53:12 +0200
parents a906dc19264c
children 81a29ad7fb4b
comparison
equal deleted inserted replaced
5594:a906dc19264c 5595:a87f2a56257d
22 22
23 #include "FindResponse.h" 23 #include "FindResponse.h"
24 24
25 #include "../../../OrthancFramework/Sources/DicomFormat/DicomInstanceHasher.h" 25 #include "../../../OrthancFramework/Sources/DicomFormat/DicomInstanceHasher.h"
26 #include "../../../OrthancFramework/Sources/OrthancException.h" 26 #include "../../../OrthancFramework/Sources/OrthancException.h"
27 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
27 28
28 #include <cassert> 29 #include <cassert>
29 30
30 31
31 namespace Orthanc 32 namespace Orthanc
248 for (MainDicomTags::iterator it = mainDicomTags_.begin(); it != mainDicomTags_.end(); ++it) 249 for (MainDicomTags::iterator it = mainDicomTags_.begin(); it != mainDicomTags_.end(); ++it)
249 { 250 {
250 assert(it->second != NULL); 251 assert(it->second != NULL);
251 delete it->second; 252 delete it->second;
252 } 253 }
254
255 for (ChildrenMetadata::iterator it = childrenMetadata_.begin(); it != childrenMetadata_.end(); ++it)
256 {
257 assert(it->second != NULL);
258 delete it->second;
259 }
253 } 260 }
254 261
255 262
256 void FindResponse::Resource::SetParentIdentifier(const std::string& id) 263 void FindResponse::Resource::SetParentIdentifier(const std::string& id)
257 { 264 {
322 return false; 329 return false;
323 } 330 }
324 } 331 }
325 332
326 333
327 void FindResponse::Resource::Format(Json::Value& target, 334 void FindResponse::Resource::AddChildrenMetadata(MetadataType metadata,
335 const std::list<std::string>& values)
336 {
337 if (childrenMetadata_.find(metadata) == childrenMetadata_.end())
338 {
339 childrenMetadata_[metadata] = new std::list<std::string>(values);
340 }
341 else
342 {
343 throw OrthancException(ErrorCode_BadSequenceOfCalls);
344 }
345 }
346
347
348 bool FindResponse::Resource::LookupChildrenMetadata(std::list<std::string>& values,
349 MetadataType metadata) const
350 {
351 ChildrenMetadata::const_iterator found = childrenMetadata_.find(metadata);
352 if (found == childrenMetadata_.end())
353 {
354 return false;
355 }
356 else
357 {
358 assert(found->second != NULL);
359 values = *found->second;
360 return true;
361 }
362 }
363
364
365 SeriesStatus FindResponse::Resource::GetSeriesStatus(uint32_t& expectedNumberOfInstances) const
366 {
367 if (level_ != ResourceType_Series)
368 {
369 throw OrthancException(ErrorCode_BadParameterType);
370 }
371
372 std::string s;
373 if (!LookupMetadata(s, MetadataType_Series_ExpectedNumberOfInstances) ||
374 !SerializationToolbox::ParseUnsignedInteger32(expectedNumberOfInstances, s))
375 {
376 return SeriesStatus_Unknown;
377 }
378
379 std::list<std::string> values;
380 if (!LookupChildrenMetadata(values, MetadataType_Instance_IndexInSeries))
381 {
382 throw OrthancException(ErrorCode_BadSequenceOfCalls);
383 }
384
385 std::set<int64_t> instances;
386
387 for (std::list<std::string>::const_iterator
388 it = values.begin(); it != values.end(); ++it)
389 {
390 int64_t index;
391
392 if (!SerializationToolbox::ParseInteger64(index, *it))
393 {
394 return SeriesStatus_Unknown;
395 }
396
397 if (index <= 0 ||
398 index > static_cast<int64_t>(expectedNumberOfInstances))
399 {
400 // Out-of-range instance index
401 return SeriesStatus_Inconsistent;
402 }
403
404 if (instances.find(index) != instances.end())
405 {
406 // Twice the same instance index
407 return SeriesStatus_Inconsistent;
408 }
409
410 instances.insert(index);
411 }
412
413 if (instances.size() == static_cast<size_t>(expectedNumberOfInstances))
414 {
415 return SeriesStatus_Complete;
416 }
417 else
418 {
419 return SeriesStatus_Missing;
420 }
421 }
422
423
424 void FindResponse::Resource::Expand(Json::Value& target,
328 const FindRequest& request) const 425 const FindRequest& request) const
329 { 426 {
330 /** 427 /**
331 428
332 TODO-FIND: 429 TODO-FIND: