Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1669:a412ad57f0f9 db-changes
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Oct 2015 11:55:25 +0200 |
parents | de1413733c97 |
children | 4c5a85c3ff43 |
comparison
equal
deleted
inserted
replaced
1668:de1413733c97 | 1669:a412ad57f0f9 |
---|---|
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 | |
678 static bool UpgradeDatabase(IDatabaseWrapper& database, | 616 static bool UpgradeDatabase(IDatabaseWrapper& database, |
679 IStorageArea& storageArea, | 617 IStorageArea& storageArea, |
680 bool allowDatabaseUpgrade) | 618 bool allowDatabaseUpgrade) |
681 { | 619 { |
682 // Upgrade the schema of the database, if needed | 620 // Upgrade the schema of the database, if needed |
683 unsigned int currentVersion = database.GetDatabaseVersion(); | 621 unsigned int currentVersion = database.GetDatabaseVersion(); |
684 if (currentVersion != ORTHANC_DATABASE_VERSION) | 622 if (currentVersion == ORTHANC_DATABASE_VERSION) |
685 { | 623 { |
686 if (currentVersion > ORTHANC_DATABASE_VERSION) | 624 return true; |
687 { | 625 } |
688 LOG(ERROR) << "The version of the database schema (" << currentVersion | 626 |
689 << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; | 627 if (currentVersion > ORTHANC_DATABASE_VERSION) |
690 return false; | 628 { |
691 } | 629 LOG(ERROR) << "The version of the database schema (" << currentVersion |
692 | 630 << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; |
693 if (!allowDatabaseUpgrade) | 631 return false; |
694 { | 632 } |
695 LOG(ERROR) << "The database schema must be upgraded from version " | 633 |
696 << currentVersion << " to " << ORTHANC_DATABASE_VERSION | 634 if (!allowDatabaseUpgrade) |
697 << ": Please run Orthanc with the \"--upgrade\" command-line option"; | 635 { |
698 return false; | 636 LOG(ERROR) << "The database schema must be upgraded from version " |
699 } | 637 << currentVersion << " to " << ORTHANC_DATABASE_VERSION |
700 | 638 << ": Please run Orthanc with the \"--upgrade\" command-line option"; |
701 LOG(WARNING) << "Upgrading the database from schema version " | 639 return false; |
702 << currentVersion << " to " << ORTHANC_DATABASE_VERSION; | 640 } |
703 database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); | 641 |
642 LOG(WARNING) << "Upgrading the database from schema version " | |
643 << currentVersion << " to " << ORTHANC_DATABASE_VERSION; | |
644 database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); | |
704 | 645 |
705 // Sanity check | 646 // Sanity check |
706 currentVersion = database.GetDatabaseVersion(); | 647 currentVersion = database.GetDatabaseVersion(); |
707 if (ORTHANC_DATABASE_VERSION != currentVersion) | 648 if (ORTHANC_DATABASE_VERSION != currentVersion) |
708 { | 649 { |
709 LOG(ERROR) << "The database schema was not properly upgraded, it is still at version " << currentVersion; | 650 LOG(ERROR) << "The database schema was not properly upgraded, it is still at version " << currentVersion; |
710 throw OrthancException(ErrorCode_InternalError); | 651 throw OrthancException(ErrorCode_InternalError); |
711 } | 652 } |
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 { | |
721 return false; | |
722 } | |
723 | |
724 | 653 |
725 return true; | 654 return true; |
726 } | 655 } |
727 | 656 |
728 | 657 |