From c6a870af7ee34c66e82202a67ce93dab45f74948 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 19 Feb 2009 15:21:48 +0000 Subject: Renamed cpr to patientid --- server/src/database.h | 24 ++++++++++++------------ server/src/pracrodao.h | 6 +++--- server/src/pracrodaopgsql.cc | 30 +++++++++++++++--------------- server/src/pracrodaopgsql.h | 6 +++--- 4 files changed, 33 insertions(+), 33 deletions(-) (limited to 'server/src') diff --git a/server/src/database.h b/server/src/database.h index a5bed81..5a82d67 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -41,32 +41,32 @@ public: ~Database(); // Make a commit to the db - void commitTransaction(std::string user, std::string cpr, Macro ¯o, Fields &fields, time_t now = time(NULL)) { - PRACRO_DEBUG(db, "%s, %s, %s,...\n", user.c_str(), cpr.c_str(), macro.attributes["name"].c_str()); - if(dao) dao->commitTransaction(user, cpr, macro, fields, now); + void commitTransaction(std::string user, std::string patientid, Macro ¯o, Fields &fields, time_t now = time(NULL)) { + PRACRO_DEBUG(db, "%s, %s, %s,...\n", user.c_str(), patientid.c_str(), macro.attributes["name"].c_str()); + if(dao) dao->commitTransaction(user, patientid, macro, fields, now); } // Get a list of values from the db - Values getValues(std::string cpr, Fieldnames &fieldnames, time_t oldest = 0) { - PRACRO_DEBUG(db, "%s, <%u fieldnames>, %ld\n", cpr.c_str(), fieldnames.size(), oldest); - if(dao) return dao->getLatestValues(cpr, NULL, fieldnames, oldest); + Values getValues(std::string patientid, Fieldnames &fieldnames, time_t oldest = 0) { + PRACRO_DEBUG(db, "%s, <%u fieldnames>, %ld\n", patientid.c_str(), fieldnames.size(), oldest); + if(dao) return dao->getLatestValues(patientid, NULL, fieldnames, oldest); else return Values(); } // Check if a macro has been committed. - bool checkMacro(std::string cpr, std::string macro, time_t oldest = 0) { - PRACRO_DEBUG(db, "%s, %s, %ld\n", cpr.c_str(), macro.c_str(), oldest); + bool checkMacro(std::string patientid, std::string macro, time_t oldest = 0) { + PRACRO_DEBUG(db, "%s, %s, %ld\n", patientid.c_str(), macro.c_str(), oldest); if(!dao) return false; - return dao->nrOfCommits(cpr, macro, oldest) > 0; + return dao->nrOfCommits(patientid, macro, oldest) > 0; } // Get latest resume of a given macro - std::string getResume(std::string cpr, Macro ¯o, time_t oldest) { - PRACRO_DEBUG(db, "%s, %s, %ld\n", cpr.c_str(), macro.attributes["name"].c_str(), oldest); + std::string getResume(std::string patientid, Macro ¯o, time_t oldest) { + PRACRO_DEBUG(db, "%s, %s, %ld\n", patientid.c_str(), macro.attributes["name"].c_str(), oldest); if(!dao) return ""; Fieldnames fn; fn.push_back("journal.resume"); - Values v = dao->getLatestValues(cpr, ¯o, fn, oldest); + Values v = dao->getLatestValues(patientid, ¯o, fn, oldest); Values::iterator i = v.find("journal.resume"); if(i != v.end()) return i->second.value; else return ""; diff --git a/server/src/pracrodao.h b/server/src/pracrodao.h index 580dfdd..7924d3d 100644 --- a/server/src/pracrodao.h +++ b/server/src/pracrodao.h @@ -40,9 +40,9 @@ public: PracroDAO(std::string _host, std::string _port, std::string _user, std::string _passwd, std::string _dbname); virtual ~PracroDAO(); - virtual void commitTransaction(std::string user, std::string cpr, Macro ¯o, Fields &fields, time_t now) = 0; - virtual Values getLatestValues(std::string cpr, Macro *macro, Fieldnames &fieldnames, time_t oldest) = 0; - virtual unsigned nrOfCommits(std::string cpr, std::string macroname, time_t oldest) = 0; + virtual void commitTransaction(std::string user, std::string patientid, Macro ¯o, Fields &fields, time_t now) = 0; + virtual Values getLatestValues(std::string patientid, Macro *macro, Fieldnames &fieldnames, time_t oldest) = 0; + virtual unsigned nrOfCommits(std::string patientid, std::string macroname, time_t oldest) = 0; protected: std::string host; diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc index c2e65bc..e48e549 100644 --- a/server/src/pracrodaopgsql.cc +++ b/server/src/pracrodaopgsql.cc @@ -63,9 +63,9 @@ PracroDAOPgsql::~PracroDAOPgsql() if(conn) delete conn; } -void PracroDAOPgsql::commitTransaction(std::string user, std::string cpr, Macro &_macro, Fields &fields, time_t now) +void PracroDAOPgsql::commitTransaction(std::string user, std::string patientid, Macro &_macro, Fields &fields, time_t now) { - PRACRO_DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n", user.c_str(), cpr.c_str(), _macro.attributes["name"].c_str(), fields.size(), now); + PRACRO_DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n", user.c_str(), patientid.c_str(), _macro.attributes["name"].c_str(), fields.size(), now); if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n"); if(fields.size() == 0) return; @@ -76,9 +76,9 @@ void PracroDAOPgsql::commitTransaction(std::string user, std::string cpr, Macro std::string ts; try { pqxx::work W(*conn); - ts = "INSERT INTO transactions (uid, cpr, macro, version, \"timestamp\", \"user\") VALUES (" + ts = "INSERT INTO transactions (uid, patientid, macro, version, \"timestamp\", \"user\") VALUES (" " nextval('trseq'), " - " '" + W.esc(cpr) + "', " + " '" + W.esc(patientid) + "', " " '" + W.esc(macro) + "', " " '" + W.esc(version) + "', " " '" + W.esc(timestamp.str()) + "', " @@ -139,20 +139,20 @@ void PracroDAOPgsql::commitTransaction(std::string user, std::string cpr, Macro * SELECT ff.name, ff.value, tt.timestamp FROM ( * SELECT f.name, max(t.timestamp) AS ts * FROM fields f, transactions t - * WHERE t.oid = f.transaction - * AND t.cpr = '1505050505' + * WHERE t.uid = f.transaction + * AND t.patientid = '1505050505' * AND t.timestamp >= 0 * AND f.name IN ('current_eye_disease') * GROUP BY f.name) xx, * transactions tt, fields ff * WHERE xx.ts = tt.timestamp * AND xx.name = ff.name - * AND tt.oid = ff.transaction - * AND tt.cpr = '1505050505' + * AND tt.uid = ff.transaction + * AND tt.patientid = '1505050505' */ -Values PracroDAOPgsql::getLatestValues(std::string cpr, Macro *macro, Fieldnames &fieldnames, time_t oldest) +Values PracroDAOPgsql::getLatestValues(std::string patientid, Macro *macro, Fieldnames &fieldnames, time_t oldest) { - PRACRO_DEBUG(db, "(%s, %s, <%u fieldnames>, %ld)\n", cpr.c_str(), macro ? macro->attributes["name"].c_str() : "(null)", fieldnames.size(), oldest); + PRACRO_DEBUG(db, "(%s, %s, <%u fieldnames>, %ld)\n", patientid.c_str(), macro ? macro->attributes["name"].c_str() : "(null)", fieldnames.size(), oldest); if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n"); Values values; @@ -176,7 +176,7 @@ Values PracroDAOPgsql::getLatestValues(std::string cpr, Macro *macro, Fieldnames // Begin inner query " (SELECT f.name, MAX(t.timestamp) AS ts FROM fields f, transactions t " " WHERE t.uid = f.transaction AND t.timestamp >= " + soldest.str() + - " AND t.cpr = '" + W.esc(cpr) + "' " + " AND t.patientid = '" + W.esc(patientid) + "' " + namecond; if(macro) { query += " AND t.macro = '" + macro->attributes["name"] + "'"; @@ -189,7 +189,7 @@ Values PracroDAOPgsql::getLatestValues(std::string cpr, Macro *macro, Fieldnames " WHERE xx.ts = tt.timestamp " " AND xx.name = ff.name " " AND tt.uid = ff.transaction " - " AND tt.cpr = '" + W.esc(cpr) + "' " + " AND tt.patientid = '" + W.esc(patientid) + "' " ; if(macro) { query += " AND tt.macro = '" + macro->attributes["name"] + "'"; @@ -215,14 +215,14 @@ Values PracroDAOPgsql::getLatestValues(std::string cpr, Macro *macro, Fieldnames } -unsigned PracroDAOPgsql::nrOfCommits(std::string cpr, std::string macroname, time_t oldest) +unsigned PracroDAOPgsql::nrOfCommits(std::string patientid, std::string macroname, time_t oldest) { std::string query; std::stringstream soldest; soldest << oldest; try { pqxx::work W(*conn); query = "SELECT count(*) FROM transactions " - " WHERE cpr = '" + W.esc(cpr) + "' " + " WHERE patientid = '" + W.esc(patientid) + "' " " AND macro = '" + W.esc(macroname) + "' " " AND timestamp >= " + soldest.str() ; @@ -233,7 +233,7 @@ unsigned PracroDAOPgsql::nrOfCommits(std::string cpr, std::string macroname, tim return 0; } unsigned n = (unsigned)atol((*R.begin())[0].c_str()); - PRACRO_DEBUG(db, "Found %u commits for %s(%s) from %ld\n", n, cpr.c_str(), macroname.c_str(), oldest); + PRACRO_DEBUG(db, "Found %u commits for %s(%s) from %ld\n", n, patientid.c_str(), macroname.c_str(), oldest); return n; } catch (std::exception &e) { PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str()); diff --git a/server/src/pracrodaopgsql.h b/server/src/pracrodaopgsql.h index 90498e9..303db28 100644 --- a/server/src/pracrodaopgsql.h +++ b/server/src/pracrodaopgsql.h @@ -41,9 +41,9 @@ public: PracroDAOPgsql(std::string _host, std::string _port, std::string _user, std::string _passwd, std::string _dbname); virtual ~PracroDAOPgsql(); - virtual void commitTransaction(std::string user, std::string cpr, Macro ¯o, Fields &fields, time_t now); - virtual Values getLatestValues(std::string cpr, Macro *macro, Fieldnames &fieldnames, time_t oldest); - virtual unsigned nrOfCommits(std::string cpr, std::string macroname, time_t oldest); + virtual void commitTransaction(std::string user, std::string patientid, Macro ¯o, Fields &fields, time_t now); + virtual Values getLatestValues(std::string patientid, Macro *macro, Fieldnames &fieldnames, time_t oldest); + virtual unsigned nrOfCommits(std::string patientid, std::string macroname, time_t oldest); private: pqxx::connection *conn; -- cgit v1.2.3