summaryrefslogtreecommitdiff
path: root/server/src/pracrodaopgsql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/pracrodaopgsql.cc')
-rw-r--r--server/src/pracrodaopgsql.cc30
1 files changed, 15 insertions, 15 deletions
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());