Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1668:de1413733c97 db-changes
reconstructing main dicom tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2015 17:18:39 +0200 |
parents | d7039be97eeb |
children | a412ad57f0f9 |
comparison
equal
deleted
inserted
replaced
1667:9e875db36aef | 1668:de1413733c97 |
---|---|
611 | 611 |
612 return StartDicomServer(context, restApi, plugins); | 612 return StartDicomServer(context, restApi, plugins); |
613 } | 613 } |
614 | 614 |
615 | 615 |
616 | |
617 | |
618 static bool ReconstructLevel(IDatabaseWrapper& database, | |
619 IStorageArea& storageArea, | |
620 bool allowDatabaseUpgrade, | |
621 ResourceType level) | |
622 { | |
623 GlobalProperty property; | |
624 const char* plural = NULL; | |
625 | |
626 switch (level) | |
627 { | |
628 case ResourceType_Patient: | |
629 plural = "patients"; | |
630 property = GlobalProperty_ReconstructPatientsTags; | |
631 break; | |
632 | |
633 case ResourceType_Study: | |
634 plural = "studies"; | |
635 property = GlobalProperty_ReconstructStudiesTags; | |
636 break; | |
637 | |
638 case ResourceType_Series: | |
639 plural = "series"; | |
640 property = GlobalProperty_ReconstructSeriesTags; | |
641 break; | |
642 | |
643 case ResourceType_Instance: | |
644 plural = "instances"; | |
645 property = GlobalProperty_ReconstructInstancesTags; | |
646 break; | |
647 | |
648 default: | |
649 throw OrthancException(ErrorCode_InternalError); | |
650 } | |
651 | |
652 std::string tmp; | |
653 if (database.LookupGlobalProperty(tmp, property) && tmp != "0") | |
654 { | |
655 if (!allowDatabaseUpgrade) | |
656 { | |
657 LOG(ERROR) << "The main DICOM tags of all the " << plural | |
658 << " must be reconstructed: " | |
659 << "Please run Orthanc with the \"--upgrade\" command-line option"; | |
660 return false; | |
661 } | |
662 | |
663 std::auto_ptr<SQLite::ITransaction> transaction(database.StartTransaction()); | |
664 transaction->Begin(); | |
665 | |
666 LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "..."; | |
667 Toolbox::ReconstructMainDicomTags(database, storageArea, level); | |
668 | |
669 database.SetGlobalProperty(property, "0"); | |
670 | |
671 transaction->Commit(); | |
672 } | |
673 | |
674 return true; | |
675 } | |
676 | |
677 | |
616 static bool UpgradeDatabase(IDatabaseWrapper& database, | 678 static bool UpgradeDatabase(IDatabaseWrapper& database, |
617 IStorageArea& storageArea, | 679 IStorageArea& storageArea, |
618 bool allowDatabaseUpgrade) | 680 bool allowDatabaseUpgrade) |
619 { | 681 { |
620 // Upgrade the database, if needed | 682 // Upgrade the schema of the database, if needed |
621 unsigned int currentVersion = database.GetDatabaseVersion(); | 683 unsigned int currentVersion = database.GetDatabaseVersion(); |
622 if (currentVersion == ORTHANC_DATABASE_VERSION) | 684 if (currentVersion != ORTHANC_DATABASE_VERSION) |
623 { | 685 { |
624 return true; | 686 if (currentVersion > ORTHANC_DATABASE_VERSION) |
625 } | 687 { |
626 | 688 LOG(ERROR) << "The version of the database schema (" << currentVersion |
627 if (currentVersion > ORTHANC_DATABASE_VERSION) | 689 << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; |
628 { | 690 return false; |
629 LOG(ERROR) << "The version of the database (" << currentVersion | 691 } |
630 << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; | 692 |
693 if (!allowDatabaseUpgrade) | |
694 { | |
695 LOG(ERROR) << "The database schema must be upgraded from version " | |
696 << currentVersion << " to " << ORTHANC_DATABASE_VERSION | |
697 << ": Please run Orthanc with the \"--upgrade\" command-line option"; | |
698 return false; | |
699 } | |
700 | |
701 LOG(WARNING) << "Upgrading the database from schema version " | |
702 << currentVersion << " to " << ORTHANC_DATABASE_VERSION; | |
703 database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); | |
704 | |
705 // Sanity check | |
706 currentVersion = database.GetDatabaseVersion(); | |
707 if (ORTHANC_DATABASE_VERSION != currentVersion) | |
708 { | |
709 LOG(ERROR) << "The database schema was not properly upgraded, it is still at version " << currentVersion; | |
710 throw OrthancException(ErrorCode_InternalError); | |
711 } | |
712 } | |
713 | |
714 | |
715 // Reconstruct the main DICOM tags at each level, if needed | |
716 if (!ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Patient) || | |
717 !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Study) || | |
718 !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Series) || | |
719 !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Instance)) | |
720 { | |
631 return false; | 721 return false; |
632 } | 722 } |
633 | 723 |
634 if (!allowDatabaseUpgrade) | |
635 { | |
636 LOG(ERROR) << "The database must be upgraded from version " | |
637 << currentVersion << " to " << ORTHANC_DATABASE_VERSION | |
638 << ": Please run Orthanc with the \"--upgrade\" command-line option"; | |
639 return false; | |
640 } | |
641 | |
642 LOG(WARNING) << "Upgrading the database from version " | |
643 << currentVersion << " to " << ORTHANC_DATABASE_VERSION; | |
644 database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); | |
645 | |
646 // Sanity check | |
647 currentVersion = database.GetDatabaseVersion(); | |
648 if (ORTHANC_DATABASE_VERSION != currentVersion) | |
649 { | |
650 LOG(ERROR) << "The database was not properly updated, it is still at version " << currentVersion; | |
651 throw OrthancException(ErrorCode_InternalError); | |
652 } | |
653 | 724 |
654 return true; | 725 return true; |
655 } | 726 } |
656 | 727 |
657 | 728 |