summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authordeva <deva>2009-07-10 09:59:41 +0000
committerdeva <deva>2009-07-10 09:59:41 +0000
commita619ccc300a00947207600e11fac848b7d37b26b (patch)
tree1fcfef3cdde2f176368b7a15f795a0ad5508687b /server/src
parentca32aba4df1b021b1acaa8f0650fa6a0cd7b9d80 (diff)
Fieldname queries added macrotool.
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Makefile.am2
-rw-r--r--server/src/database.h21
-rw-r--r--server/src/dbtypes.h7
-rw-r--r--server/src/macrotool_dump.cc48
-rw-r--r--server/src/macrotool_fieldnames.cc119
-rw-r--r--server/src/macrotool_util.cc77
-rw-r--r--server/src/macrotool_util.h40
-rw-r--r--server/src/pracrodao.h5
-rw-r--r--server/src/pracrodaopgsql.cc35
-rw-r--r--server/src/pracrodaopgsql.h12
10 files changed, 312 insertions, 54 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index c1ba9e4..f8f6e21 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -48,6 +48,7 @@ macrotool_SOURCES = \
macroparser.cc \
macrotool_dump.cc \
macrotool_fieldnames.cc \
+ macrotool_util.cc \
pracrodao.cc \
pracrodaopgsql.cc \
saxparser.cc \
@@ -72,6 +73,7 @@ EXTRA_DIST = \
macroparser.h \
macrotool_dump.h \
macrotool_fieldnames.h \
+ macrotool_util.h \
pracrodao.h \
pracrodaopgsql.h \
resumeparser.h \
diff --git a/server/src/database.h b/server/src/database.h
index 5a82d67..396dda4 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -72,6 +72,27 @@ public:
else return "";
}
+ void addFieldname(std::string name, std::string description)
+ {
+ if(!dao) return;
+ dao->addFieldname(name, description);
+ }
+
+ void delFieldname(std::string name)
+ {
+ if(!dao) return;
+ dao->delFieldname(name);
+ }
+
+ std::vector<Fieldname> getFieldnames()
+ {
+ if(!dao) {
+ std::vector<Fieldname> fieldnames;
+ return fieldnames;
+ }
+ return dao->getFieldnames();
+ }
+
private:
PracroDAO *dao;
};
diff --git a/server/src/dbtypes.h b/server/src/dbtypes.h
index 79ac629..04db0bd 100644
--- a/server/src/dbtypes.h
+++ b/server/src/dbtypes.h
@@ -38,4 +38,11 @@ typedef std::map< std::string, Value > Values;
typedef std::vector< std::string > Fieldnames;
+class Fieldname {
+public:
+ std::string name;
+ std::string description;
+ time_t timestamp;
+};
+
#endif
diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc
index 9248d03..370397a 100644
--- a/server/src/macrotool_dump.cc
+++ b/server/src/macrotool_dump.cc
@@ -27,6 +27,8 @@
*/
#include "macrotool_dump.h"
+#include "macrotool_util.h"
+
#include "debug.h"
#include "macroparser.h"
@@ -36,9 +38,6 @@
#include <map>
#include <set>
-#include <sys/types.h>
-#include <dirent.h>
-
#include <config.h>
#include "configuration.h"
@@ -65,49 +64,6 @@ static const char usage_str[] =
" templates Writes template names, versions, filenames, titles and macro references to stdout.\n"
;
-
-static std::vector<std::string> listdir(std::string path)
-{
- std::vector<std::string> files;
-
- DIR* dir = opendir(path.c_str());
- if(!dir) {
- PRACRO_ERR(dump, "Could not open directory: %s\n", path.c_str());
- return files;
- }
-
- struct dirent *d;
- while((d = readdir(dir)) != 0) {
- //if(d->d_type == DT_DIR) {
- std::string name = d->d_name;
- if(name.length() >= 4 && name.substr(name.length() - 4) == ".xml")
- files.push_back(name);
- //}
- }
- closedir(dir);
-
- return files;
-}
-
-static std::vector<std::string> getMacros()
-{
- std::vector<std::string> macros = listdir(Conf::xml_basedir + "/macros");
- return macros;
-}
-
-static std::vector<std::string> getTemplates()
-{
- std::vector<std::string> templates = listdir(Conf::xml_basedir + "/templates");
- return templates;
-}
-
-static void printcolumn(std::string text, size_t width)
-{
- printf(text.c_str());
- for(size_t i = text.length(); i < width; i++) printf(" ");
- printf("\t");
-}
-
static std::map<std::string, struct _macro> macroList()
{
std::map<std::string, struct _macro> macros;
diff --git a/server/src/macrotool_fieldnames.cc b/server/src/macrotool_fieldnames.cc
index f2475f2..eeed648 100644
--- a/server/src/macrotool_fieldnames.cc
+++ b/server/src/macrotool_fieldnames.cc
@@ -27,9 +27,12 @@
*/
#include "macrotool_fieldnames.h"
+#include "macrotool_util.h"
+#include "macroparser.h"
+
#include "debug.h"
-#include "pracrodaopgsql.h"
+#include "database.h"
#include "configuration.h"
static const char usage_str[] =
@@ -41,15 +44,113 @@ static void add(std::string name, std::string desc)
{
#ifndef WITHOUT_DB
PRACRO_DEBUG("SET (name: %s - desc: %s)\n", name.c_str(), desc.c_str());
- PracroDAOPgsql sql(Conf::database_addr, "",
- Conf::database_user,
- Conf::database_passwd, "");
#else /*WITHOUT_DB*/
printf("Project not compiled with db spport.")
#endif/*WITHOUT_DB*/
}
+static std::vector<std::string> getWidgetNames(Widget &w)
+{
+ std::vector<std::string> v;
+ if(w.attributes.find("name") != w.attributes.end()) v.push_back(w.attributes["name"]);
+
+ std::vector< Widget >::iterator i = w.widgets.begin();
+ while(i != w.widgets.end()) {
+ std::vector<std::string> _v = getWidgetNames(*i);
+ v.insert(v.end(), _v.begin(), _v.end());
+ i++;
+ }
+
+ return v;
+}
+
+static std::map<std::string, std::vector<std::string> > getMacroRefsList()
+{
+ std::map<std::string, std::vector<std::string> > reflist;
+
+ std::vector<std::string> macrofiles = getMacros();
+ std::vector<std::string>::iterator mfs = macrofiles.begin();
+ while(mfs != macrofiles.end()) {
+ std::string name = mfs->substr(0, mfs->length() - 4);
+
+ MacroParser parser(name);
+ parser.parse();
+ Macro *macro = parser.getMacro();
+
+ std::string key = name;
+ reflist[key] = getWidgetNames(macro->window);
+
+ mfs++;
+ }
+
+ return reflist;
+}
+
+static std::vector<std::string> getMacroRefs(std::map<std::string, std::vector<std::string> > reflist, std::string name)
+{
+ std::vector<std::string> macros;
+ std::map<std::string, std::vector<std::string> >::iterator macro = reflist.begin();
+ while(macro != reflist.end()) {
+ std::vector<std::string>::iterator field = macro->second.begin();
+ while(field != macro->second.end()) {
+ if(*field == name) macros.push_back(macro->first);
+ field++;
+ }
+ macro++;
+ }
+ return macros;
+}
+
+static void list()
+{
+ Database db("pgsql", Conf::database_addr, "", Conf::database_user, Conf::database_passwd, "");
+
+ std::vector<Fieldname> fieldnames = db.getFieldnames();
+
+ std::map<std::string, std::vector<std::string> > reflist = getMacroRefsList();
+
+ size_t name_sz = 0;
+ size_t desc_sz = 0;
+ size_t time_sz = 0;
+
+ std::vector<Fieldname>::iterator i = fieldnames.begin();
+ while(i != fieldnames.end()) {
+ if(i->name.length() > name_sz) name_sz = i->name.length();
+ if(i->description.length() > desc_sz) desc_sz = i->description.length();
+ char ts[32];
+ sprintf(ts, "%u", (unsigned int)i->timestamp);
+ if(strlen(ts) > time_sz) time_sz = strlen(ts);
+ i++;
+ }
+
+ printcolumn("Name:", name_sz);
+ printcolumn("Description:", desc_sz);
+ printcolumn("Timestamp:", time_sz);
+ printf("Macros:");
+ printf("\n");
+
+ i = fieldnames.begin();
+ while(i != fieldnames.end()) {
+ printcolumn(i->name, name_sz);
+ printcolumn(i->description, desc_sz);
+ char ts[32];
+ sprintf(ts, "%u", (unsigned int)i->timestamp);
+ printcolumn(ts, time_sz);
+
+ std::vector<std::string> macros = getMacroRefs(reflist, i->name);
+ std::vector<std::string>::iterator j = macros.begin();
+ while(j != macros.end()) {
+ if(j != macros.begin()) printf(", ");
+ printf("%s", j->c_str());
+ j++;
+ }
+
+ printf("\n");
+ i++;
+ }
+}
+
void macrotool_fieldnames(std::vector<std::string> params)
{
if(params.size() < 1) {
@@ -59,6 +160,16 @@ void macrotool_fieldnames(std::vector<std::string> params)
PRACRO_DEBUG(fieldnames, "fieldnames: %s\n", params[0].c_str());
+ if(params[0] == "list") {
+ if(params.size() != 1) {
+ printf("The command 'list' does not need any parameters.\n");
+ printf(usage_str);
+ return;
+ }
+ list();
+ return;
+ }
+
if(params[0] == "set") {
if(params.size() != 3) {
printf("The command 'set' needs 2 parameters.\n");
diff --git a/server/src/macrotool_util.cc b/server/src/macrotool_util.cc
new file mode 100644
index 0000000..fa066aa
--- /dev/null
+++ b/server/src/macrotool_util.cc
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macrotool_util.cc
+ *
+ * Fri Jul 10 09:11:28 CEST 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "macrotool_util.h"
+
+#include "debug.h"
+
+#include <sys/types.h>
+#include <dirent.h>
+
+#include "configuration.h"
+
+std::vector<std::string> listdir(std::string path)
+{
+ std::vector<std::string> files;
+
+ DIR* dir = opendir(path.c_str());
+ if(!dir) {
+ PRACRO_ERR(dump, "Could not open directory: %s\n", path.c_str());
+ return files;
+ }
+
+ struct dirent *d;
+ while((d = readdir(dir)) != 0) {
+ //if(d->d_type == DT_DIR) {
+ std::string name = d->d_name;
+ if(name.length() >= 4 && name.substr(name.length() - 4) == ".xml")
+ files.push_back(name);
+ //}
+ }
+ closedir(dir);
+
+ return files;
+}
+
+std::vector<std::string> getMacros()
+{
+ std::vector<std::string> macros = listdir(Conf::xml_basedir + "/macros");
+ return macros;
+}
+
+std::vector<std::string> getTemplates()
+{
+ std::vector<std::string> templates = listdir(Conf::xml_basedir + "/templates");
+ return templates;
+}
+
+void printcolumn(std::string text, size_t width)
+{
+ printf(text.c_str());
+ for(size_t i = text.length(); i < width; i++) printf(" ");
+ printf("\t");
+}
diff --git a/server/src/macrotool_util.h b/server/src/macrotool_util.h
new file mode 100644
index 0000000..1725f23
--- /dev/null
+++ b/server/src/macrotool_util.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * macrotool_util.h
+ *
+ * Fri Jul 10 09:11:28 CEST 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_MACROTOOL_UTIL_H__
+#define __PRACRO_MACROTOOL_UTIL_H__
+
+#include <vector>
+#include <string>
+
+std::vector<std::string> listdir(std::string path);
+std::vector<std::string> getMacros();
+std::vector<std::string> getTemplates();
+
+void printcolumn(std::string text, size_t width);
+
+#endif/*__PRACRO_MACROTOOL_UTIL_H__*/
diff --git a/server/src/pracrodao.h b/server/src/pracrodao.h
index 7924d3d..1ef9686 100644
--- a/server/src/pracrodao.h
+++ b/server/src/pracrodao.h
@@ -29,6 +29,7 @@
#define __PRACRO_PRACRODAO_H__
#include <string>
+#include <vector>
#include "dbtypes.h"
#include "template.h"
@@ -44,6 +45,10 @@ public:
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;
+ virtual void addFieldname(std::string name, std::string description) = 0;
+ virtual void delFieldname(std::string name) = 0;
+ virtual std::vector<Fieldname> getFieldnames() = 0;
+
protected:
std::string host;
std::string port;
diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc
index e48e549..683fe85 100644
--- a/server/src/pracrodaopgsql.cc
+++ b/server/src/pracrodaopgsql.cc
@@ -242,4 +242,39 @@ unsigned PracroDAOPgsql::nrOfCommits(std::string patientid, std::string macronam
return 0;
}
+void PracroDAOPgsql::addFieldname(std::string name, std::string description)
+{
+}
+
+void PracroDAOPgsql::delFieldname(std::string name)
+{
+}
+
+std::vector<Fieldname> PracroDAOPgsql::getFieldnames()
+{
+ if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n");
+ std::vector<Fieldname> fieldnames;
+
+ std::string query;
+ try {
+ pqxx::work W(*conn);
+ query = "SELECT * FROM fieldnames";
+ PRACRO_DEBUG(sql, "Query: %s\n", query.c_str());
+ pqxx::result R = W.exec(query);
+ pqxx::result::const_iterator ri = R.begin();
+ while(ri != R.end()) {
+ Fieldname f;
+ f.name = (*ri)[0].c_str();
+ f.description = (*ri)[1].c_str();
+ f.timestamp = atol((*ri)[2].c_str());
+ fieldnames.push_back(f);
+ ri++;
+ }
+ } catch (std::exception &e) {
+ PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
+ }
+
+ return fieldnames;
+}
+
#endif/*WITHOUT_DB*/
diff --git a/server/src/pracrodaopgsql.h b/server/src/pracrodaopgsql.h
index 303db28..b226cfd 100644
--- a/server/src/pracrodaopgsql.h
+++ b/server/src/pracrodaopgsql.h
@@ -39,11 +39,15 @@ class PracroDAOPgsql : public PracroDAO
{
public:
PracroDAOPgsql(std::string _host, std::string _port, std::string _user, std::string _passwd, std::string _dbname);
- virtual ~PracroDAOPgsql();
+ ~PracroDAOPgsql();
- virtual void commitTransaction(std::string user, std::string patientid, Macro &macro, 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);
+ void commitTransaction(std::string user, std::string patientid, Macro &macro, Fields &fields, time_t now);
+ Values getLatestValues(std::string patientid, Macro *macro, Fieldnames &fieldnames, time_t oldest);
+ unsigned nrOfCommits(std::string patientid, std::string macroname, time_t oldest);
+
+ void addFieldname(std::string name, std::string description);
+ void delFieldname(std::string name);
+ std::vector<Fieldname> getFieldnames();
private:
pqxx::connection *conn;