diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/src/admin_connection.cc | 7 | ||||
| -rw-r--r-- | server/src/admin_export.cc | 44 | ||||
| -rw-r--r-- | server/src/admin_export.h | 4 | ||||
| -rw-r--r-- | server/src/fieldnamescanner.cc | 6 | ||||
| -rw-r--r-- | server/src/fieldnamescanner.h | 4 | 
5 files changed, 39 insertions, 26 deletions
| diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc index 0fe5380..6ad7642 100644 --- a/server/src/admin_connection.cc +++ b/server/src/admin_connection.cc @@ -118,8 +118,13 @@ bool AdminConnection::handle(const char *data, size_t size)      }      if(uri == "/export" && args.find("template") != args.end()) { +      time_t from = 0; +      if(args.find("from") != args.end()) from = atoi(args["from"].c_str()); + +      time_t to = time(NULL); +      if(args.find("to") != args.end()) to = atoi(args["to"].c_str());        bool ok; -      std::string res = admin_export(env, args["template"], &ok); +      std::string res = admin_export(env, args["template"], &ok, from, to);        if(!ok) reply = admin_header(uri) + res + admin_rc("footer");        else {          reply = res; 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 */ diff --git a/server/src/admin_export.h b/server/src/admin_export.h index 69c7a36..804d373 100644 --- a/server/src/admin_export.h +++ b/server/src/admin_export.h @@ -29,9 +29,11 @@  #define __PRACRO_ADMIN_EXPORT_H__  #include <string> +#include <time.h>  #include "environment.h" -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);  #endif/*__PRACRO_ADMIN_EXPORT_H__*/ diff --git a/server/src/fieldnamescanner.cc b/server/src/fieldnamescanner.cc index 5418bb4..ba3b61f 100644 --- a/server/src/fieldnamescanner.cc +++ b/server/src/fieldnamescanner.cc @@ -58,12 +58,12 @@ fieldnames_t getFields(Widget &widget)    return fieldnames;  } -templates_t scanfieldnames(std::set<std::string> &filter) +templates_t scanfieldnames(Environment &env, std::set<std::string> &filter)  {    templates_t templates;    //  TemplateList templatelist(Conf::xml_basedir + "/templates"); -  MacroList macrolist(Conf::xml_basedir + "/macros"); +  //  MacroList macrolist(Conf::xml_basedir + "/macros");    // Iterate templates:    std::vector<std::string> templatefiles = getTemplates(); @@ -83,7 +83,7 @@ templates_t scanfieldnames(std::set<std::string> &filter)          if(ms->isHeader == false) {            std::string macro = ms->name;            DEBUG(scanner, "Name '%s'\n", macro.c_str()); -          std::string macrofile = macrolist.getLatestVersion(macro); +          std::string macrofile = env.macrolist.getLatestVersion(macro);            DEBUG(scanner, "File '%s'\n", macrofile.c_str());            // Iterate fields: diff --git a/server/src/fieldnamescanner.h b/server/src/fieldnamescanner.h index c766ba1..6201db7 100644 --- a/server/src/fieldnamescanner.h +++ b/server/src/fieldnamescanner.h @@ -33,12 +33,14 @@  #include <string>  #include <set> +#include "environment.h" +  typedef std::string fieldname_t;  typedef std::vector< fieldname_t > fieldnames_t;  typedef std::string template_name_t;  typedef std::map< template_name_t, fieldnames_t > templates_t; -templates_t scanfieldnames(std::set<std::string> &filter); +templates_t scanfieldnames(Environment &env, std::set<std::string> &filter);  #endif/*__PRACRO_FIELDNAMESCANNER_H__*/ | 
