summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2007-10-01 15:18:21 +0000
committerdeva <deva>2007-10-01 15:18:21 +0000
commitc09b06d5e765955ea41c6b02891390ed6a714e55 (patch)
treeb90a1a919fd086146256a4ef5ecc44faa2dd5c51
parent1890cff193f6e5c10c7581b0767bbb5ac91f8cc7 (diff)
Now the resume is generated using a format string.
-rw-r--r--server/src/Makefile.am2
-rw-r--r--server/src/database.cc62
-rw-r--r--server/src/database.h2
-rw-r--r--server/src/macro.h1
-rw-r--r--server/src/resumeparser.cc97
-rw-r--r--server/src/resumeparser.h35
-rw-r--r--server/src/server.cc42
-rw-r--r--server/src/transaction.h7
-rw-r--r--server/src/xmlparser.cc10
-rw-r--r--server/xml/example.xml28
-rw-r--r--server/xml/patient.xml2
11 files changed, 222 insertions, 66 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index 43fa560..4cee6cf 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -12,6 +12,7 @@ pracrod_SOURCES = \
exception.cc \
log.cc \
macro_parser.cc \
+ resumeparser.cc \
server.cc \
tcpsocket.cc \
tostring.cc \
@@ -26,6 +27,7 @@ EXTRA_DIST = \
log.h \
macro.h \
macro_parser.h \
+ resumeparser.h \
server.h \
tcpsocket.h \
tostring.h \
diff --git a/server/src/database.cc b/server/src/database.cc
index 1a48925..ad6bbe0 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -26,9 +26,8 @@
*/
#include "database.h"
-#include "tostring.h"
+//#include "tostring.h"
#include "uid.h"
-#include <time.h>
Database::Database(std::string hostname, std::string user, std::string password)
: c("host=" + hostname +
@@ -42,47 +41,44 @@ Database::~Database()
{
}
-int Database::post(Transaction &transaction)
+int Database::post(std::string &user, std::string &cpr, std::string &time, Commit &commit)
{
UID uid;
- std::string now = toString((unsigned int)time(NULL));
try {
pqxx::work W(c);
- Commits::iterator i = transaction.commits.begin();
- while(i != transaction.commits.end()) {
- Commit &commit = *i;
- // std::string transid = transidbase + toString(idx);
-
- // Insert transaction entry
- std::string sql = "INSERT INTO transactions VALUES('" +
- transaction.cpr + "', '" +
+ // std::string transid = transidbase + toString(idx);
+
+ // Insert transaction entry
+ std::string sql = "INSERT INTO transactions VALUES('" +
+ cpr + "', '" +
+ uid.toString() + "', '" +
+ commit.macro + "', '" +
+ commit.version + "', '" +
+ time + "', '" +
+ user + "')";
+ W.exec(sql);
+
+ // Insert field entries
+ Fields::iterator j = commit.fields.begin();
+ while(j != commit.fields.end()) {
+ // std::string name = j->first;
+ // std::string value = j->second;
+
+ sql = "INSERT INTO fields VALUES('" +
uid.toString() + "', '" +
- commit.macro + "', '" +
- commit.version + "', '" +
- now + "', '" +
- transaction.user + "')";
+ j->first + "', '" +
+ j->second + "')";
+ // name + "', '" +
+ // value + "')";
W.exec(sql);
-
- // Insert field entries
- Fields::iterator j = commit.fields.begin();
- while(j != commit.fields.end()) {
- Field &field = *j;
-
- sql = "INSERT INTO fields VALUES('" +
- uid.toString() + "', '" +
- field.name + "', '" +
- field.value + "')";
- W.exec(sql);
-
- j++;
- }
-
- uid++;
- i++;
+
+ j++;
}
+ uid++;
+
W.commit();
} catch(const std::exception &e) {
// throw PostgreSQLException(e.what());
diff --git a/server/src/database.h b/server/src/database.h
index 9659eda..a841188 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -38,7 +38,7 @@ public:
std::string password = "pracro");
~Database();
- int post(Transaction &transaction);
+ int post(std::string &user, std::string &cpr, std::string &time, Commit &commit);
private:
pqxx::connection c;
diff --git a/server/src/macro.h b/server/src/macro.h
index af9749d..2252d90 100644
--- a/server/src/macro.h
+++ b/server/src/macro.h
@@ -51,6 +51,7 @@ class Macro {
public:
std::string name;
std::string version;
+ std::string format;
WidgetList widgets;
};
diff --git a/server/src/resumeparser.cc b/server/src/resumeparser.cc
new file mode 100644
index 0000000..769bb25
--- /dev/null
+++ b/server/src/resumeparser.cc
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * resumeparser.cc
+ *
+ * Mon Oct 1 11:17:35 CEST 2007
+ * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup
+ * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk
+ ****************************************************************************/
+
+/*
+ * 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 "resumeparser.h"
+
+#include <string.h>
+
+std::string resume_parser(const char *format, Commit &commit)
+{
+ std::string resume;
+ std::string var;
+
+ const char *p = format;
+ const char *theend = p + strlen(format);
+ while(p < theend) {
+ switch(*p) {
+ case '$':
+ p++;
+ switch(*p) {
+ case '$':
+ resume.append(1, *p);
+ break;
+
+ case '{':
+ p++;
+ var = "";
+ // Parser
+ while(p < theend && *p != '}') {
+ var.append(1, *p);
+ p++;
+ }
+ // p++;
+ printf("[%s]\n", var.c_str());
+ // resume += "var(" + var + ")";
+ resume += commit.fields[var];
+ break;
+
+ default:
+ resume.append(1, *p);
+ // printf("Illigal $ command\n");
+ break;
+ }
+ p++;
+ break;
+
+ case '\\':
+ p++;
+ switch(*p) {
+ case 't':
+ resume.append(1, '\t');
+ break;
+ case 'n':
+ resume.append(1, '\n');
+ break;
+ case 'r':
+ resume.append(1, '\r');
+ break;
+ case '\\':
+ default:
+ resume.append(1, *p);
+ break;
+ }
+ p++;
+ break;
+
+ default:
+ resume.append(1, *p);
+ p++;
+ break;
+ }
+ }
+
+ return resume;
+}
diff --git a/server/src/resumeparser.h b/server/src/resumeparser.h
new file mode 100644
index 0000000..991f106
--- /dev/null
+++ b/server/src/resumeparser.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * resumeparser.h
+ *
+ * Mon Oct 1 11:17:35 CEST 2007
+ * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup
+ * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk
+ ****************************************************************************/
+
+/*
+ * 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_RESUMEPARSER_H__
+#define __PRACRO_RESUMEPARSER_H__
+
+#include <string>
+#include "transaction.h"
+
+std::string resume_parser(const char *format, Commit &commit);
+
+#endif/*__PRACRO_RESUMEPARSER_H__*/
diff --git a/server/src/server.cc b/server/src/server.cc
index 064d8b9..815f0db 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -45,6 +45,11 @@
#include "macro.h"
#include "macro_parser.h"
+#include "resumeparser.h"
+
+#include "tostring.h"
+#include <time.h>
+
static void send_macro_widget(Widget &widget, TCPSocket &socket, std::string tabs)
{
socket.write(tabs + "<" + widget.type);
@@ -97,26 +102,29 @@ static void connection(TCPSocket &socket)
// Handle commits
if(transaction.commits.size() > 0) {
- Database db;
- db.post(transaction);
- }
+ std::string now = toString((unsigned int)time(NULL));
- /*
- Commits::iterator j = transaction.commits.begin();
- while(j != transaction.commits.end()) {
- Commit &commit = *j;
- printf("Commit %s\n", commit.macro.c_str());
-
- Fields::iterator k = commit.fields.begin();
- while(k != commit.fields.end()) {
- Field &val = *k;
- printf("\t%s=%s\n", val.name.c_str(), val.value.c_str());
- k++;
- }
+ Commits::iterator i = transaction.commits.begin();
+ while(i != transaction.commits.end()) {
+ Commit &commit = *i;
+
+ Database db;
+ db.post(transaction.user, transaction.cpr, now, commit);
- j++;
+ Macro macro;
+ parse_macro(commit.macro, macro);
+ //parse_macro("example", macro);
+
+ macro.format = "Det koster 50$$\\n\\tLinse: ${linse}D\\n"
+ "\\y${combo}\\\\\\nHćvelse: ${radio}\\n\\n${spl_note}";
+
+ std::string resume = resume_parser(macro.format.c_str(), commit);
+
+ printf("%s\n", resume.c_str());
+
+ i++;
+ }
}
- */
socket.write("</pracro>\n");
diff --git a/server/src/transaction.h b/server/src/transaction.h
index 97bb556..daf0de3 100644
--- a/server/src/transaction.h
+++ b/server/src/transaction.h
@@ -29,7 +29,7 @@
#include <string>
#include <vector>
-
+#include <map>
class Request {
public:
@@ -38,12 +38,15 @@ public:
typedef std::vector< Request > Requests;
+/*
class Field {
public:
std::string name;
std::string value;
};
-typedef std::vector< Field > Fields;
+*/
+//typedef std::vector< Field > Fields;
+typedef std::map< std::string, std::string > Fields;
class Commit {
diff --git a/server/src/xmlparser.cc b/server/src/xmlparser.cc
index 31ffbed..6ef7338 100644
--- a/server/src/xmlparser.cc
+++ b/server/src/xmlparser.cc
@@ -82,10 +82,12 @@ static void start_hndl(void *p, const char *el, const char **attr)
}
if(name == "field") {
- Field f;
- f.name = attributes["name"];
- f.value = attributes["value"];
- transaction->commits.back().fields.push_back(f);
+ // Field f;
+ // f.name = attributes["name"];
+ // f.value = attributes["value"];
+ // transaction->commits.back().fields.push_back(f);
+ transaction->commits.back().fields[attributes["name"]] = attributes["value"];
+ // printf("[%s]=[%s]\n", f.name.c_str(), f.value.c_str());
}
}
diff --git a/server/xml/example.xml b/server/xml/example.xml
index ebef918..57f9587 100644
--- a/server/xml/example.xml
+++ b/server/xml/example.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<macro name="fundus" version="1.0">
+<macro name="example" version="1.0"
+ resume="Det koster 50$$\nLinse: ${linse}D\n${linse_note}\nHævelse: ${radio}\n\n${spl_note}">
<window name="mainwindow"
caption="Fundus"
width="500"
@@ -7,26 +8,37 @@
layout="vbox">
<include name="patient"/>
<frame name="spl_frame" caption="Spl:" layout="vbox">
- <textedit name="spl_note" regexp=".*" value="På begge sider alderssvarende forhold. Der er let katarakt, som dog ikke er operationskrævende."/>
+ <lineedit name="spl_note" regexp=".*" value="På begge sider alderssvarende forhold. Der er let katarakt, som dog ikke er operationskrævende."/>
</frame>
- <frame name="linse_frame" caption="Linse:" layout="vbox">
- <lineedit name="linse" regexp="[0-9]{1,3}D" value="90D"/>
- <textedit name="linse_note" regexp=".*" value="Der findes centrale atrofiske forandringer."/>
+ <frame name="linse_frame" caption="Linser:" layout="vbox">
+ <frame name="linse_framea" layout="hbox">
+ <label name="a" width="300" caption="Linse1 er en lidt længere streng end de to andre:"/>
+ <lineedit name="linse1" regexp="[0-9]{1,3}D" value="90K"/>
+ </frame>
+ <frame name="linse_frameb" layout="hbox">
+ <label name="b" width="300" caption="Linse2:"/>
+ <lineedit name="linse2" regexp="[0-9]{1,3}D" value="90D"/>
+ </frame>
+ <frame name="linse_framec" layout="hbox">
+ <label name="c" width="300" caption="Linse3:"/>
+ <lineedit name="linse3" regexp="[0-9]{1,3}D" value="90D"/>
+ </frame>
</frame>
<frame name="swelling_frame" layout="hbox">
<label name="swelling" caption="Der findes central hævelse med:"/>
<frame name="swelling_radios" layout="hbox">
- <radiobuttons name="radio" value="exsudater" layout="vbox">
+ <radiobuttons name="radio" value="" layout="vbox">
<item caption="Radio Randblødning" value="rand"/>
<item caption="Radio Exsudater" value="exsudater"/>
<item caption="Radio Blahblah" value="blabla"/>
</radiobuttons>
- <combobox name="combo" value="exsudater">
+ <combobox name="combo" value="fiskesuppe">
<item caption="Combo Randblødning" value="rand"/>
<item caption="Combo Exsudater" value="exsudater"/>
<item caption="Combo Blahblah" value="blabla"/>
+ <item caption="Combo Blahblah" value="fisk"/>
</combobox>
- <listbox name="list" value="exsudater">
+ <listbox name="list" value="exsudate">
<item caption="List Randblødning" value="rand"/>
<item caption="List Exsudater" value="exsudater"/>
<item caption="List Blahblah" value="blabla"/>
diff --git a/server/xml/patient.xml b/server/xml/patient.xml
index 3debfb4..8be7e7f 100644
--- a/server/xml/patient.xml
+++ b/server/xml/patient.xml
@@ -5,6 +5,6 @@
<lineedit name="patient_navn" regexp=".+" value="Birger Fiskenolder"/>
</frame>
<frame name="name_frame" caption="Noter" layout="vbox">
- <textedit name="patient_note" regexp=".*" value="Noget note om et eller andet"/>
+ <lineedit name="patient_note" regexp=".*" value="Noget note om et eller andet"/>
</frame>
</macro>