summaryrefslogtreecommitdiff
path: root/server/src/admin_export.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/admin_export.cc')
-rw-r--r--server/src/admin_export.cc48
1 files changed, 27 insertions, 21 deletions
diff --git a/server/src/admin_export.cc b/server/src/admin_export.cc
index 3ec77d1..0aa290c 100644
--- a/server/src/admin_export.cc
+++ b/server/src/admin_export.cc
@@ -47,8 +47,10 @@ static std::string escape(std::string &str)
std::string::iterator i = str.begin();
while(i != str.end()) {
if(*i == '\"') out += "''";
+ else if(*i == '\n') out += "\342\220\244"; // N/L controlcharacter pictogram
+ else if(*i == '\r') { }
else out += *i;
- i++;
+ i++;
}
out += "\"";
return out;
@@ -59,34 +61,22 @@ public:
File(fieldnames_t &f, pqxx::work &w)
: work(w), fieldnames(f)
{
- // name += ".csf";
- // fp = fopen(name.c_str(), "w");
-
pos["id"] = 0;
pos["patientid"] = 1;
pos["time"] = 2;
pos["template"] = 3;
- //printf("%s\n", n.c_str());
-
size_t idx = 4;
fieldnames_t::iterator i = f.begin();
while(i != f.end()) {
- //printf("%s ", i->c_str());
pos[*i] = idx;
idx++;
i++;
}
- // printf("\n");
output_header();
}
- ~File()
- {
- // if(fp) fclose(fp);
- }
-
void output_header()
{
beginrow();
@@ -144,7 +134,8 @@ private:
};
-static std::string do_export(std::string templ, bool *ok)
+static std::string do_export(Environment &env, std::string templ, bool *ok,
+ time_t from, time_t to)
{
if(Conf::database_backend != "pgsql") {
*ok = false;
@@ -182,7 +173,7 @@ static std::string do_export(std::string templ, bool *ok)
}
}
- templates_t t = scanfieldnames(filter);
+ templates_t t = scanfieldnames(env, filter);
/*
templates_t::iterator ti = t.begin();
while(ti != t.end()) {
@@ -198,10 +189,24 @@ static std::string do_export(std::string templ, bool *ok)
File file(t[templ], work);
+ std::string tostr;
+ std::string fromstr;
{
- pqxx::result result =
- work.exec("SELECT * FROM commits WHERE template='"+templ+"'"
- " AND status='committed' ORDER BY patientid, timestamp;");
+ char buf[32];
+ sprintf(buf, "%d", (int)from);
+ fromstr = buf;
+ sprintf(buf, "%d", (int)to);
+ tostr = buf;
+ }
+
+ {
+ std::string q = "SELECT * FROM commits WHERE template='"+templ+"'"
+ " AND status='committed' AND timestamp>=" +fromstr+
+ " AND timestamp<="+tostr+" ORDER BY patientid, timestamp;";
+
+ DEBUG(export, "QUERY: %s\n", q.c_str());
+
+ pqxx::result result = work.exec(q);
pqxx::result::const_iterator ri = result.begin();
for(unsigned int r = 0; r < result.size(); r++) {
pqxx::result::tuple tuple = result.at(r);
@@ -210,7 +215,7 @@ static std::string do_export(std::string templ, bool *ok)
std::string version = tuple.at(2).c_str();
std::string timestamp = tuple.at(3).c_str();
std::string uid = tuple.at(4).c_str();
- std::string status = tuple.at(5).c_str();
+ // std::string status = tuple.at(5).c_str();
file.beginrow();
file.addcell("id", uid);
@@ -253,10 +258,11 @@ static std::string do_export(std::string templ, bool *ok)
#endif/* WITHOUT_DB */
-std::string admin_export(Environment &env, std::string templ, bool *ok)
+std::string admin_export(Environment &env, std::string templ, bool *ok,
+ time_t from, time_t to)
{
#ifndef WITHOUT_DB
- return do_export(templ, ok);
+ return do_export(env, templ, ok, from, to);
#else
return "No database available";
#endif/* WITHOUT_DB */