summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/connection.cc10
-rw-r--r--server/src/connection.h3
-rw-r--r--server/src/server.cc7
-rw-r--r--server/src/session.cc19
-rw-r--r--server/src/session.h7
-rw-r--r--server/src/sessionserialiser.cc2
6 files changed, 38 insertions, 10 deletions
diff --git a/server/src/connection.cc b/server/src/connection.cc
index dd76f97..e4ec7f4 100644
--- a/server/src/connection.cc
+++ b/server/src/connection.cc
@@ -44,11 +44,15 @@ static std::string error_box(std::string message)
static bool did_commit = false;
#endif
-Connection::Connection(Environment &e, std::string sid, bool c, bool d, bool nc)
+Connection::Connection(Environment &e, std::string sid,
+ std::string pid, std::string t,
+ bool c, bool d, bool nc)
: env(e), parser(&transaction)
{
DEBUG(connection, "[%p] CREATE\n", this);
+ patientid = pid;
+ templ = t;
sessionid = sid;
docommit = c;
dodiscard = d;
@@ -104,13 +108,13 @@ bool Connection::handle(const char *data, size_t size)
Session *session = NULL;
if(sessionid == "") {
// Create new session
- session = env.sessions.newSession();
+ session = env.sessions.newSession(patientid, templ);
} else {
// Attach to old session
session = env.sessions.session(sessionid);
// Session didn't exist - create a new one anyway.
- if(session == NULL) session = env.sessions.newSession();
+ if(session == NULL) session = env.sessions.newSession(patientid, templ);
}
if(session == NULL) {
diff --git a/server/src/connection.h b/server/src/connection.h
index 010034e..e9a4e50 100644
--- a/server/src/connection.h
+++ b/server/src/connection.h
@@ -38,6 +38,7 @@ class Session;
class Connection {
public:
Connection(Environment &e, std::string sessionid,
+ std::string patientid, std::string templ,
bool commit, bool discard, bool nocommit);
~Connection();
@@ -51,6 +52,8 @@ private:
void nocommit(Session *session);
void discard(Session *session);
+ std::string patientid;
+ std::string templ;
std::string sessionid;
bool docommit;
bool donocommit;
diff --git a/server/src/server.cc b/server/src/server.cc
index 3973756..6474fb5 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -54,13 +54,18 @@ public:
headers_t &headers)
{
std::string sessionid;
+ std::string patientid;
+ std::string templ;
if(headers.contains("SessionID")) sessionid = headers["SessionID"];
+ if(headers.contains("SessionPatientID"))
+ patientid = headers["SessionPatientID"];
+ if(headers.contains("SessionTemplate")) templ = headers["SessionTemplate"];
bool commit = headers.contains("SessionCommit");
bool nocommit = headers.contains("SessionNoCommit");
bool discard = headers.contains("SessionDiscard");
- Connection *connection = new Connection(env, sessionid,
+ Connection *connection = new Connection(env, sessionid, patientid, templ,
commit, discard, nocommit);
return connection;
diff --git a/server/src/session.cc b/server/src/session.cc
index 612f264..58249af 100644
--- a/server/src/session.cc
+++ b/server/src/session.cc
@@ -44,10 +44,14 @@
#include "connectionpool.h"
#include "sessionserialiser.h"
-Session::Session(std::string sessionid)
+Session::Session(std::string sessionid, std::string pid, std::string t)
{
_journal = NULL;
_database = NULL;
+
+ patientid = pid;
+ templ = t;
+
database()->setSessionId(sessionid);
}
@@ -141,9 +145,18 @@ static bool fexists(const std::string &f)
return ret;
}
-Session *Sessions::newSession()
+Session *Sessions::newSession(std::string patientid, std::string templ)
{
- Session *session = new Session();
+ std::map<std::string, Session *>::iterator i = sessions.begin();
+ while(i != sessions.end()) {
+ if(i->second->patientid == patientid &&
+ i->second->templ == templ) {
+ return i->second;
+ }
+ i++;
+ }
+
+ Session *session = new Session("", patientid, templ);
sessions[session->id()] = session;
return session;
}
diff --git a/server/src/session.h b/server/src/session.h
index c0f6dfc..5b9b0bb 100644
--- a/server/src/session.h
+++ b/server/src/session.h
@@ -38,7 +38,7 @@ class Journal;
class Session {
public:
- Session(std::string sessionid = "");
+ Session(std::string sessionid, std::string patientid, std::string templ);
~Session();
std::string id();
@@ -53,6 +53,9 @@ public:
Journal *journal();
Database *database();
+ std::string patientid;
+ std::string templ;
+
private:
Journal *_journal;
Database *_database;
@@ -67,7 +70,7 @@ public:
* Create a new session, with a unique id. Insert it into the session list,
* and return its pointer.
*/
- Session *newSession();
+ Session *newSession(std::string patientid, std::string templ);
/**
* Lookup session in session list. Returns the session or NULL if no session
diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc
index b816331..4065214 100644
--- a/server/src/sessionserialiser.cc
+++ b/server/src/sessionserialiser.cc
@@ -70,7 +70,7 @@ Session *SessionSerialiser::loadStr(const std::string &xml,
SessionParser parser;
parser.parse(xml.data(), xml.length());
- Session *session = new Session(sessionid);
+ Session *session = new Session(sessionid, parser.patientid, "");
Journal *j = session->journal();
j->setUser(XDEC(parser.userid));
j->setPatientID(XDEC(parser.patientid));