diff options
-rw-r--r-- | server/src/journal.cc | 29 | ||||
-rw-r--r-- | server/src/journal.h | 8 | ||||
-rw-r--r-- | server/src/journal_uploadserver.cc | 14 | ||||
-rw-r--r-- | server/src/session.cc | 34 | ||||
-rw-r--r-- | server/src/session.h | 6 | ||||
-rw-r--r-- | server/src/sessionparser.cc | 3 | ||||
-rw-r--r-- | server/src/sessionparser.h | 1 | ||||
-rw-r--r-- | server/src/sessionserialiser.cc | 20 |
8 files changed, 76 insertions, 39 deletions
diff --git a/server/src/journal.cc b/server/src/journal.cc index b6638fd..b9f5c82 100644 --- a/server/src/journal.cc +++ b/server/src/journal.cc @@ -54,7 +54,7 @@ void Journal::addEntry(Transaction &transaction, Commit &commit, } if(entrylist.size() == 0) { - if(user() == "") setUser(transaction.user); + //if(user() == "") setUser(transaction.user); if(patientID() == "")setPatientID(transaction.cpr); } @@ -70,20 +70,19 @@ void Journal::addEntry(Transaction &transaction, Commit &commit, } #endif - addEntry(resume, commit.macro, index); + addEntry(resume, commit.macro, transaction.user, index); } -void Journal::addEntry(std::string resume, std::string macro, int index) +void Journal::addEntry(std::string resume, std::string macro, + std::string user, int index) { - // Strip trailing whitespace, and add newlines. - std::string r = resume; - std::string m = macro; - - DEBUG(journal, "Add: %p %s - %s\n", this, m.c_str(), r.c_str()); + DEBUG(journal, "Add: %p %s %s - %s\n", this, macro.c_str(), + user.c_str(), resume.c_str()); ResumeEntry re; - re.resume = r; - re.macro = m; + re.resume = resume; + re.macro = macro; + re.user = user; re.dirty = false; entrylist[index] = re; } @@ -138,16 +137,6 @@ bool Journal::dirty(std::string macro) } return false; } - -void Journal::setUser(std::string usr) -{ - _user = usr; -} - -std::string Journal::user() -{ - return _user; -} void Journal::setPatientID(std::string id) { diff --git a/server/src/journal.h b/server/src/journal.h index fe1a4bd..573f252 100644 --- a/server/src/journal.h +++ b/server/src/journal.h @@ -45,7 +45,8 @@ public: void addEntry(Transaction &transaction, Commit &commit, std::string resume, Template *templ); - void addEntry(std::string resume, std::string macro, int index); + void addEntry(std::string resume, std::string macro, + std::string user, int index); virtual void commit() = 0; @@ -54,9 +55,6 @@ public: void setDirty(std::string macro); bool dirty(std::string macro); - - void setUser(std::string user); - std::string user(); void setPatientID(std::string id); std::string patientID(); @@ -66,10 +64,10 @@ protected: public: std::string resume; std::string macro; + std::string user; bool dirty; }; - std::string _user; std::string _patientid; std::map< int, ResumeEntry > entrylist; diff --git a/server/src/journal_uploadserver.cc b/server/src/journal_uploadserver.cc index 5557d55..8bc6e2d 100644 --- a/server/src/journal_uploadserver.cc +++ b/server/src/journal_uploadserver.cc @@ -163,6 +163,7 @@ JournalUploadServer::JournalUploadServer(std::string host, void JournalUploadServer::commit() { std::string resume; + std::string olduser; // Iterate through all resumes, and create a string containing them all. std::map< int, ResumeEntry >::iterator i = entrylist.begin(); @@ -171,6 +172,17 @@ void JournalUploadServer::commit() i++; continue; } + + if(i->second.user != olduser && olduser != "" && resume != "") { + // Connect to praxisuploadserver and commit all resumes in one bulk. + journal_commit(patientID().c_str(), olduser.c_str(), + host.c_str(), port, + resume.c_str(), resume.size()); + resume = ""; + } + + olduser = i->second.user; + if(resume != "") resume += "\n\n"; // resume += i->macro + "\n"; resume += stripTrailingWhitepace(addNewlines(i->second.resume, 60)); @@ -180,7 +192,7 @@ void JournalUploadServer::commit() if(resume == "") return; // Connect to praxisuploadserver and commit all resumes in one bulk. - journal_commit(patientID().c_str(), user().c_str(), + journal_commit(patientID().c_str(), olduser.c_str(), host.c_str(), port, resume.c_str(), resume.size()); } diff --git a/server/src/session.cc b/server/src/session.cc index 6850e9b..31c9fe8 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -93,7 +93,6 @@ void Session::commitMacro(Transaction &transaction, Commit &commit, isreadonly = false; } - bool Session::idle() { if(isreadonly) return false; @@ -402,6 +401,39 @@ Session *s7 = env.sessions.newSession(PID, TMPL); TEST_NOTEQUAL(s7, NULL, "We did get one right?"); TEST_EQUAL_STR(s7->id(), id, "Did we get the stored session?"); +// Get an existing session and test locking. +Session *s8 = env.sessions.session(s7->id()); +s7->lock(); +TEST_FALSE(s8->mutex.trylock(), "Session should be locked.") +s7->unlock(); + +{ + Transaction transaction; + transaction.cpr = PID; + transaction.user = "me"; + + Commit commit; + commit.fields["field1"] = "hello"; + commit.fields["field2"] = "world"; + commit.templ = TMPL; + + Macro macro; + macro.attributes["version"] = "1.0"; + macro.attributes["name"] = "somemacro"; + + s7->commitMacro(transaction, commit, macro); +} +TEST_FALSE(s7->idle(), "Session is active."); +TEST_FALSE(s7->isReadonly(), "Not read only session."); +s7->setIdle(true); // Force idle +TEST_TRUE(s7->idle(), "Session is idle."); + +Session *s9 = env.sessions.newSession(PID, TMPL"empty"); +TEST_TRUE(s9->isReadonly(), "Read only session."); +TEST_FALSE(s9->idle(), "Readonly session is not idle."); +s9->setIdle(true); // Force idle (no effect) +TEST_FALSE(s9->idle(), "Readonly session still not idle."); + TEST_END; #endif/*TEST_SESSION*/ diff --git a/server/src/session.h b/server/src/session.h index e2751bd..b5c31d7 100644 --- a/server/src/session.h +++ b/server/src/session.h @@ -71,9 +71,13 @@ public: private: Environment *env; Journal *_journal; - Mutex mutex; std::string sessionid; bool isreadonly; +#ifdef TEST_SESSION +public: +#endif + Mutex mutex; + }; class Sessions { diff --git a/server/src/sessionparser.cc b/server/src/sessionparser.cc index 856ce36..17cc4fb 100644 --- a/server/src/sessionparser.cc +++ b/server/src/sessionparser.cc @@ -68,7 +68,7 @@ void SessionParser::startTag(std::string name, if(name == "journal") { // patientid = attributes["patientid"]; - userid = attributes["userid"]; + // userid = attributes["userid"]; } if(name == "database") { @@ -80,6 +80,7 @@ void SessionParser::startTag(std::string name, Entry e; e.index = atoi(attributes["index"].c_str()); e.macro = attributes["macro"]; + e.user = attributes["user"]; entries.push_back(e); } diff --git a/server/src/sessionparser.h b/server/src/sessionparser.h index 314f4ce..229ae10 100644 --- a/server/src/sessionparser.h +++ b/server/src/sessionparser.h @@ -57,6 +57,7 @@ public: int index; std::string macro; std::string resume; + std::string user; }; std::vector<Entry> entries; diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index b9e825a..36d0a0d 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -84,11 +84,11 @@ Session *SessionSerialiser::loadStr(const std::string &xml) XDEC(parser.templ)); session->isreadonly = parser.status == "readonly"; Journal *j = session->journal(); - j->setUser(XDEC(parser.userid)); + // j->setUser(XDEC(parser.userid)); j->setPatientID(XDEC(parser.patientid)); std::vector<SessionParser::Entry>::iterator i = parser.entries.begin(); while(i != parser.entries.end()) { - j->addEntry(XDEC(i->resume), xml_decode(i->macro), i->index); + j->addEntry(XDEC(i->resume), XDEC(i->macro), XDEC(i->user), i->index); i++; } @@ -104,23 +104,23 @@ std::string SessionSerialiser::saveStr(Session *session) std::string xml; xml += "<?xml version='1.0' encoding='UTF-8'?>\n"; - xml += "<session timestamp=\""+itostr(time(NULL))+"\" " - "status=\"" + XENC(session->isreadonly?"readonly":"") + "\" " - "id=\""+XENC(session->id())+"\" " - "template=\""+XENC(session->templ)+ "\" " - "patientid=\"" + XENC(session->patientid) + "\">\n"; + xml += "<session timestamp=\"" + itostr(time(NULL)) + "\"" + " status=\"" + XENC(session->isreadonly?"readonly":"") + "\"" + " id=\"" + XENC(session->id()) + "\"" + " template=\"" + XENC(session->templ) + "\"" + " patientid=\"" + XENC(session->patientid) + "\">\n"; Journal *journal = session->journal(); - xml += " <journal patientid=\"" + XENC(journal->patientID()) + - "\" userid=\"" + XENC(journal->user()) + "\">\n"; + xml += " <journal patientid=\"" + XENC(journal->patientID()) + "\">\n"; std::map< int, Journal::ResumeEntry >::iterator i = journal->entrylist.begin(); while(i != journal->entrylist.end()) { xml += " <entry index=\""+itostr(i->first) + "\"" - " macro=\"" + i->second.macro + "\">\n"; + " macro=\"" + XENC(i->second.macro) + "\"" + " user=\"" + XENC(i->second.user) + "\">\n"; xml += " <resume>" + XENC(i->second.resume) + "</resume>\n"; xml += " </entry>\n"; |