comparison OrthancServer/ServerIndex.cpp @ 2898:e5e3253a1164

DicomInstanceToStore::GetHasher()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Oct 2018 11:44:17 +0200
parents c277e0421200
children 4767d36679ed
comparison
equal deleted inserted replaced
2897:9ff17eb830ec 2898:e5e3253a1164
619 const DicomMap& dicomSummary = instanceToStore.GetSummary(); 619 const DicomMap& dicomSummary = instanceToStore.GetSummary();
620 const ServerIndex::MetadataMap& metadata = instanceToStore.GetMetadata(); 620 const ServerIndex::MetadataMap& metadata = instanceToStore.GetMetadata();
621 621
622 instanceMetadata.clear(); 622 instanceMetadata.clear();
623 623
624 DicomInstanceHasher hasher(instanceToStore.GetSummary());
625
626 try 624 try
627 { 625 {
628 Transaction t(*this); 626 Transaction t(*this);
629 627
630 // Check whether this instance is already stored 628 // Check whether this instance is already stored
631 { 629 {
632 ResourceType type; 630 ResourceType type;
633 int64_t tmp; 631 int64_t tmp;
634 if (db_.LookupResource(tmp, type, hasher.HashInstance())) 632 if (db_.LookupResource(tmp, type, instanceToStore.GetHasher().HashInstance()))
635 { 633 {
636 assert(type == ResourceType_Instance); 634 assert(type == ResourceType_Instance);
637 635
638 if (overwrite_) 636 if (overwrite_)
639 { 637 {
640 // Overwrite the old instance 638 // Overwrite the old instance
641 LOG(INFO) << "Overwriting instance: " << hasher.HashInstance(); 639 LOG(INFO) << "Overwriting instance: " << instanceToStore.GetHasher().HashInstance();
642 db_.DeleteResource(tmp); 640 db_.DeleteResource(tmp);
643 } 641 }
644 else 642 else
645 { 643 {
646 // Do nothing if the instance already exists 644 // Do nothing if the instance already exists
656 it != attachments.end(); ++it) 654 it != attachments.end(); ++it)
657 { 655 {
658 instanceSize += it->GetCompressedSize(); 656 instanceSize += it->GetCompressedSize();
659 } 657 }
660 658
661 Recycle(instanceSize, hasher.HashPatient()); 659 Recycle(instanceSize, instanceToStore.GetHasher().HashPatient());
662 660
663 // Create the instance 661 // Create the instance
664 int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance); 662 int64_t instance = CreateResource(instanceToStore.GetHasher().HashInstance(), ResourceType_Instance);
665 ServerToolbox::StoreMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary); 663 ServerToolbox::StoreMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary);
666 664
667 // Detect up to which level the patient/study/series/instance 665 // Detect up to which level the patient/study/series/instance
668 // hierarchy must be created 666 // hierarchy must be created
669 int64_t patient = -1, study = -1, series = -1; 667 int64_t patient = -1, study = -1, series = -1;
672 bool isNewSeries = false; 670 bool isNewSeries = false;
673 671
674 { 672 {
675 ResourceType dummy; 673 ResourceType dummy;
676 674
677 if (db_.LookupResource(series, dummy, hasher.HashSeries())) 675 if (db_.LookupResource(series, dummy, instanceToStore.GetHasher().HashSeries()))
678 { 676 {
679 assert(dummy == ResourceType_Series); 677 assert(dummy == ResourceType_Series);
680 // The patient, the study and the series already exist 678 // The patient, the study and the series already exist
681 679
682 bool ok = (db_.LookupResource(patient, dummy, hasher.HashPatient()) && 680 bool ok = (db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient()) &&
683 db_.LookupResource(study, dummy, hasher.HashStudy())); 681 db_.LookupResource(study, dummy, instanceToStore.GetHasher().HashStudy()));
684 assert(ok); 682 assert(ok);
685 } 683 }
686 else if (db_.LookupResource(study, dummy, hasher.HashStudy())) 684 else if (db_.LookupResource(study, dummy, instanceToStore.GetHasher().HashStudy()))
687 { 685 {
688 assert(dummy == ResourceType_Study); 686 assert(dummy == ResourceType_Study);
689 687
690 // New series: The patient and the study already exist 688 // New series: The patient and the study already exist
691 isNewSeries = true; 689 isNewSeries = true;
692 690
693 bool ok = db_.LookupResource(patient, dummy, hasher.HashPatient()); 691 bool ok = db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient());
694 assert(ok); 692 assert(ok);
695 } 693 }
696 else if (db_.LookupResource(patient, dummy, hasher.HashPatient())) 694 else if (db_.LookupResource(patient, dummy, instanceToStore.GetHasher().HashPatient()))
697 { 695 {
698 assert(dummy == ResourceType_Patient); 696 assert(dummy == ResourceType_Patient);
699 697
700 // New study and series: The patient already exist 698 // New study and series: The patient already exist
701 isNewStudy = true; 699 isNewStudy = true;
711 } 709 }
712 710
713 // Create the series if needed 711 // Create the series if needed
714 if (isNewSeries) 712 if (isNewSeries)
715 { 713 {
716 series = CreateResource(hasher.HashSeries(), ResourceType_Series); 714 series = CreateResource(instanceToStore.GetHasher().HashSeries(), ResourceType_Series);
717 ServerToolbox::StoreMainDicomTags(db_, series, ResourceType_Series, dicomSummary); 715 ServerToolbox::StoreMainDicomTags(db_, series, ResourceType_Series, dicomSummary);
718 } 716 }
719 717
720 // Create the study if needed 718 // Create the study if needed
721 if (isNewStudy) 719 if (isNewStudy)
722 { 720 {
723 study = CreateResource(hasher.HashStudy(), ResourceType_Study); 721 study = CreateResource(instanceToStore.GetHasher().HashStudy(), ResourceType_Study);
724 ServerToolbox::StoreMainDicomTags(db_, study, ResourceType_Study, dicomSummary); 722 ServerToolbox::StoreMainDicomTags(db_, study, ResourceType_Study, dicomSummary);
725 } 723 }
726 724
727 // Create the patient if needed 725 // Create the patient if needed
728 if (isNewPatient) 726 if (isNewPatient)
729 { 727 {
730 patient = CreateResource(hasher.HashPatient(), ResourceType_Patient); 728 patient = CreateResource(instanceToStore.GetHasher().HashPatient(), ResourceType_Patient);
731 ServerToolbox::StoreMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary); 729 ServerToolbox::StoreMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary);
732 } 730 }
733 731
734 // Create the parent-to-child links 732 // Create the parent-to-child links
735 db_.AttachChild(series, instance); 733 db_.AttachChild(series, instance);
851 } 849 }
852 850
853 SeriesStatus seriesStatus = GetSeriesStatus(series); 851 SeriesStatus seriesStatus = GetSeriesStatus(series);
854 if (seriesStatus == SeriesStatus_Complete) 852 if (seriesStatus == SeriesStatus_Complete)
855 { 853 {
856 LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries()); 854 LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, instanceToStore.GetHasher().HashSeries());
857 } 855 }
858 856
859 // Mark the parent resources of this instance as unstable 857 // Mark the parent resources of this instance as unstable
860 MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); 858 MarkAsUnstable(series, ResourceType_Series, instanceToStore.GetHasher().HashSeries());
861 MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); 859 MarkAsUnstable(study, ResourceType_Study, instanceToStore.GetHasher().HashStudy());
862 MarkAsUnstable(patient, ResourceType_Patient, hasher.HashPatient()); 860 MarkAsUnstable(patient, ResourceType_Patient, instanceToStore.GetHasher().HashPatient());
863 861
864 t.Commit(instanceSize); 862 t.Commit(instanceSize);
865 863
866 return StoreStatus_Success; 864 return StoreStatus_Success;
867 } 865 }