Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.cpp @ 262:2354560daf2f
primitives for recycling patients
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Dec 2012 12:56:27 +0100 |
parents | bd009f0b1931 |
children | 4bc02e2254ec |
comparison
equal
deleted
inserted
replaced
260:f1fb9d1aa444 | 262:2354560daf2f |
---|---|
741 try | 741 try |
742 { | 742 { |
743 LOG(INFO) << "Version of the Orthanc database: " << version; | 743 LOG(INFO) << "Version of the Orthanc database: " << version; |
744 unsigned int v = boost::lexical_cast<unsigned int>(version); | 744 unsigned int v = boost::lexical_cast<unsigned int>(version); |
745 | 745 |
746 // This version of Orthanc is only compatible with version 2 of | 746 // This version of Orthanc is only compatible with version 3 of |
747 // the DB schema (since Orthanc 0.3.1) | 747 // the DB schema (since Orthanc 0.3.2) |
748 ok = (v == 2); | 748 ok = (v == 3); |
749 } | 749 } |
750 catch (boost::bad_lexical_cast&) | 750 catch (boost::bad_lexical_cast&) |
751 { | 751 { |
752 } | 752 } |
753 | 753 |
775 int64_t c = s.ColumnInt(0); | 775 int64_t c = s.ColumnInt(0); |
776 assert(!s.Step()); | 776 assert(!s.Step()); |
777 | 777 |
778 return c; | 778 return c; |
779 } | 779 } |
780 | |
781 bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId) | |
782 { | |
783 SQLite::Statement s(db_, SQLITE_FROM_HERE, | |
784 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1"); | |
785 | |
786 if (!s.Step()) | |
787 { | |
788 // No patient remaining or all the patients are protected | |
789 return false; | |
790 } | |
791 else | |
792 { | |
793 internalId = s.ColumnInt(0); | |
794 return true; | |
795 } | |
796 } | |
797 | |
798 bool DatabaseWrapper::IsProtectedPatient(int64_t internalId) | |
799 { | |
800 SQLite::Statement s(db_, SQLITE_FROM_HERE, | |
801 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?"); | |
802 s.BindInt(0, internalId); | |
803 return !s.Step(); | |
804 } | |
805 | |
806 void DatabaseWrapper::SetProtectedPatient(int64_t internalId, | |
807 bool isProtected) | |
808 { | |
809 if (isProtected) | |
810 { | |
811 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM PatientRecyclingOrder WHERE patientId=?"); | |
812 s.BindInt(0, internalId); | |
813 s.Run(); | |
814 } | |
815 else if (IsProtectedPatient(internalId)) | |
816 { | |
817 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)"); | |
818 s.BindInt(0, internalId); | |
819 s.Run(); | |
820 } | |
821 else | |
822 { | |
823 // Nothing to do: The patient is already unprotected | |
824 } | |
825 } | |
780 } | 826 } |