Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1006:649d47854314 lua-scripting
proper handling of metadata in Store
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jul 2014 15:11:00 +0200 |
parents | a226e0959d8b |
children | ce6386b37afd |
comparison
equal
deleted
inserted
replaced
1005:84b6d7bca6db | 1006:649d47854314 |
---|---|
380 unstableResourcesMonitorThread_.join(); | 380 unstableResourcesMonitorThread_.join(); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 | 384 |
385 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, | 385 StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata, |
386 const DicomMap& dicomSummary, | |
386 const Attachments& attachments, | 387 const Attachments& attachments, |
387 const std::string& remoteAet, | 388 const std::string& remoteAet, |
388 MetadataMap* metadata) | 389 const MetadataMap& metadata) |
389 { | 390 { |
390 boost::mutex::scoped_lock lock(mutex_); | 391 boost::mutex::scoped_lock lock(mutex_); |
391 listener_->Reset(); | 392 listener_->Reset(); |
393 | |
394 instanceMetadata.clear(); | |
392 | 395 |
393 DicomInstanceHasher hasher(dicomSummary); | 396 DicomInstanceHasher hasher(dicomSummary); |
394 | 397 |
395 try | 398 try |
396 { | 399 { |
401 ResourceType type; | 404 ResourceType type; |
402 int64_t tmp; | 405 int64_t tmp; |
403 if (db_->LookupResource(hasher.HashInstance(), tmp, type)) | 406 if (db_->LookupResource(hasher.HashInstance(), tmp, type)) |
404 { | 407 { |
405 assert(type == ResourceType_Instance); | 408 assert(type == ResourceType_Instance); |
409 db_->GetAllMetadata(instanceMetadata, tmp); | |
406 return StoreStatus_AlreadyStored; | 410 return StoreStatus_AlreadyStored; |
407 } | 411 } |
408 } | 412 } |
409 | 413 |
410 // Ensure there is enough room in the storage for the new instance | 414 // Ensure there is enough room in the storage for the new instance |
519 { | 523 { |
520 db_->AddAttachment(instance, *it); | 524 db_->AddAttachment(instance, *it); |
521 } | 525 } |
522 | 526 |
523 // Attach the user-specified metadata | 527 // Attach the user-specified metadata |
524 if (metadata) | 528 for (MetadataMap::const_iterator |
525 { | 529 it = metadata.begin(); it != metadata.end(); ++it) |
526 for (MetadataMap::const_iterator | 530 { |
527 it = metadata->begin(); it != metadata->end(); ++it) | 531 switch (it->first.first) |
528 { | 532 { |
529 switch (it->first.first) | 533 case ResourceType_Patient: |
530 { | 534 db_->SetMetadata(patient, it->first.second, it->second); |
531 case ResourceType_Patient: | 535 break; |
532 db_->SetMetadata(patient, it->first.second, it->second); | 536 |
533 break; | 537 case ResourceType_Study: |
534 | 538 db_->SetMetadata(study, it->first.second, it->second); |
535 case ResourceType_Study: | 539 break; |
536 db_->SetMetadata(study, it->first.second, it->second); | 540 |
537 break; | 541 case ResourceType_Series: |
538 | 542 db_->SetMetadata(series, it->first.second, it->second); |
539 case ResourceType_Series: | 543 break; |
540 db_->SetMetadata(series, it->first.second, it->second); | 544 |
541 break; | 545 case ResourceType_Instance: |
542 | 546 db_->SetMetadata(instance, it->first.second, it->second); |
543 case ResourceType_Instance: | 547 instanceMetadata[it->first.second] = it->second; |
544 db_->SetMetadata(instance, it->first.second, it->second); | 548 break; |
545 break; | 549 |
546 | 550 default: |
547 default: | 551 throw OrthancException(ErrorCode_ParameterOutOfRange); |
548 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
549 } | |
550 } | 552 } |
551 } | 553 } |
552 | 554 |
553 // Attach the auto-computed metadata for the patient/study/series levels | 555 // Attach the auto-computed metadata for the patient/study/series levels |
554 std::string now = Toolbox::GetNowIsoString(); | 556 std::string now = Toolbox::GetNowIsoString(); |
557 db_->SetMetadata(patient, MetadataType_LastUpdate, now); | 559 db_->SetMetadata(patient, MetadataType_LastUpdate, now); |
558 | 560 |
559 // Attach the auto-computed metadata for the instance level, | 561 // Attach the auto-computed metadata for the instance level, |
560 // reflecting these additions into the input metadata map | 562 // reflecting these additions into the input metadata map |
561 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, now); | 563 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, now); |
564 instanceMetadata[MetadataType_Instance_ReceptionDate] = now; | |
565 | |
562 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); | 566 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); |
563 | 567 instanceMetadata[MetadataType_Instance_RemoteAet] = remoteAet; |
564 if (metadata) | |
565 { | |
566 (*metadata) [std::make_pair(ResourceType_Instance, MetadataType_Instance_ReceptionDate)] = now; | |
567 (*metadata) [std::make_pair(ResourceType_Instance, MetadataType_Instance_RemoteAet)] = remoteAet; | |
568 } | |
569 | 568 |
570 const DicomValue* value; | 569 const DicomValue* value; |
571 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || | 570 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || |
572 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) | 571 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) |
573 { | 572 { |
574 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString()); | 573 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString()); |
575 | 574 instanceMetadata[MetadataType_Instance_IndexInSeries] = value->AsString(); |
576 if (metadata) | |
577 { | |
578 (*metadata) [std::make_pair(ResourceType_Instance, MetadataType_Instance_IndexInSeries)] = value->AsString(); | |
579 } | |
580 } | 575 } |
581 | 576 |
582 // Check whether the series of this new instance is now completed | 577 // Check whether the series of this new instance is now completed |
583 if (isNewSeries) | 578 if (isNewSeries) |
584 { | 579 { |