From c41c204f421c4c1bc453932d2d5552227d794201 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 25 Nov 2011 09:28:31 +0100 Subject: Replace newline with symbol to avoid new row generation in office import. --- server/src/admin_export.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'server/src/admin_export.cc') diff --git a/server/src/admin_export.cc b/server/src/admin_export.cc index 3ec77d1..e125699 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; -- cgit v1.2.3 From dd1fb6e16ff777d3e098076d1015c6c565b51bb7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 25 Nov 2011 11:59:37 +0100 Subject: Reuse environment (macrolist) instead of creating a new one. Add 'to' and 'from' times to export, both unixtimestamps. --- server/src/admin_export.cc | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'server/src/admin_export.cc') diff --git a/server/src/admin_export.cc b/server/src/admin_export.cc index e125699..0aa290c 100644 --- a/server/src/admin_export.cc +++ b/server/src/admin_export.cc @@ -61,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(); @@ -146,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; @@ -184,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()) { @@ -200,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); @@ -212,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); @@ -255,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 */ -- cgit v1.2.3