summaryrefslogtreecommitdiff
path: root/server/src/praxisd.cc
diff options
context:
space:
mode:
authorLars Bisballe Jensen <larsbisballe@gmail.com>2011-10-14 10:42:27 +0200
committerLars Bisballe Jensen <larsbisballe@gmail.com>2011-10-14 10:42:27 +0200
commit2e574b6dfcb824239079a485527d420497b27b01 (patch)
treef49be56d98f0e952461b856d41eb54218b5f135b /server/src/praxisd.cc
parent2d5f72a787426b59658d1b66cfe0ea602ea66b61 (diff)
parentd602bdeb65d0e4007a8a02e5c6d4b9b271287aa9 (diff)
Merge branch 'master' of http://git.aasimon.org/public/pracro
Diffstat (limited to 'server/src/praxisd.cc')
-rw-r--r--server/src/praxisd.cc120
1 files changed, 102 insertions, 18 deletions
diff --git a/server/src/praxisd.cc b/server/src/praxisd.cc
index d814b54..a75ad9f 100644
--- a/server/src/praxisd.cc
+++ b/server/src/praxisd.cc
@@ -27,6 +27,8 @@
*/
#include "praxisd.h"
+#include "saxparser.h"
+
static std::string strtime(bool with_sec = true)
{
std::string ret;
@@ -190,7 +192,6 @@ void Praxisd::add_sogeord(std::string cpr, std::string sogeord,
}
#define DOTAG(x) if(name == #x) str = &p.x;
-#include "saxparser.h"
class PatientParser : public SAXParser {
public:
@@ -201,7 +202,7 @@ public:
if(str) *str += data;
}
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
DOTAG(fornavne);
DOTAG(efternavn);
@@ -236,11 +237,12 @@ public:
DOTAG(unknown250);
DOTAG(unknown251);
DOTAG(jtime);
+
if(name == "sogeords") {} // do nothing
if(name == "sogeord") {
Praxisd::sogeord_t s;
if(attr.find("sogenr") != attr.end()) s.sogenr = attr["sogenr"];
- if(attr.find("sogedatpo") != attr.end()) s.sogedato = attr["sogedato"];
+ if(attr.find("sogedato") != attr.end()) s.sogedato = attr["sogedato"];
p.sogeord.push_back(s);
str = &p.sogeord[p.sogeord.size() - 1].sogetxt;
}
@@ -273,6 +275,8 @@ Praxisd::patient_t Praxisd::patient_get_by_cpr(std::string cpr)
printf("Ouch %d\n", errornum);
}
+ // printf("Get Patient: %d %s\n", xml.length(), xml.c_str()); fflush(stdout);
+
PatientParser parser(p);
parser.parse(xml.data(), xml.length());
@@ -305,7 +309,7 @@ public:
AdresseParser(std::vector<Praxisd::adresse_t> &al) : div(al) { str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_adresse") {
Praxisd::adresse_t a;
@@ -341,7 +345,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_behandling") {
Praxisd::behandling_t a;
@@ -375,7 +379,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_cave") {
Praxisd::cave_t d;
@@ -408,7 +412,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_diagnose") {
Praxisd::diagnose_t d;
@@ -441,7 +445,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_frase") {
Praxisd::frase_t d;
@@ -474,7 +478,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_grafik") {
Praxisd::grafik_t d;
@@ -505,7 +509,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_indholdstof") {
Praxisd::indholdstof_t d;
@@ -540,7 +544,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_klage") {
Praxisd::klage_t d;
@@ -573,7 +577,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_oversigt") {
Praxisd::oversigt_t d;
@@ -605,7 +609,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_postnummer") {
Praxisd::postnummer_t d;
@@ -642,7 +646,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_type") {
Praxisd::type_t d;
@@ -676,7 +680,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_undersoegelse") {
Praxisd::undersoegelse_t d;
@@ -709,7 +713,7 @@ public:
{ str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "div_ydelse") {
Praxisd::ydelse_t d;
@@ -746,7 +750,7 @@ public:
AftaleParser(std::vector<Praxisd::aftale_t> &a) : div(a) { str = NULL; }
void characterData(std::string &data) { if(str) *str += data; }
void endTag(std::string) { str = NULL; }
- void startTag(std::string name, std::map<std::string, std::string> attr)
+ void startTag(std::string name, attributes_t &attr)
{
if(name == "aftale") {
Praxisd::aftale_t a;
@@ -842,6 +846,77 @@ bool Praxisd::authenticate(std::string user, std::string pass)
return false; // Don't interpret an error as successful login.
}
+class DokMenuParser : public SAXParser {
+public:
+ DokMenuParser(std::vector<Praxisd::dokmenu_t> &a) : div(a) { str = NULL; }
+ void characterData(std::string &data) { if(str) *str += data; }
+ void endTag(std::string) { str = NULL; }
+ void startTag(std::string name, attributes_t &attr)
+ {
+ if(name == "dokmenu") {
+ Praxisd::dokmenu_t a;
+ if(attr.find("date") != attr.end()) a.date = attr["date"];
+ if(attr.find("calendar") != attr.end()) a.date = attr["calendar"];
+ div.push_back(a);
+ }
+
+ DODIVTAG(group);
+ DODIVTAG(subject);
+
+ DODIVTAG(filename);
+ if(name == "filename") {
+ div[div.size() - 1].filesize = atoi(attr["filesize"].c_str());
+ div[div.size() - 1].date = attr["date"];
+ }
+ }
+
+private:
+ std::string *str;
+ std::vector<Praxisd::dokmenu_t> &div;
+};
+
+std::vector<Praxisd::dokmenu_t> Praxisd::dokmenu_get_all_by_cpr(std::string cpr)
+{
+ std::vector<Praxisd::dokmenu_t> dokmenu;
+ std::string xml;
+
+ std::string uri = host + "/praxisd/1.0/dokmenu/get_all_by_cpr?cpr=" + cpr;
+ curl_easy_setopt(ch, CURLOPT_URL, uri.c_str());
+
+ curl_easy_setopt(ch, CURLOPT_POST, 0L);
+ curl_easy_setopt(ch, CURLOPT_WRITEDATA, &xml);
+
+ CURLcode errornum = curl_easy_perform(ch);
+ if(errornum != CURLE_OK) {
+ printf("Ouch %d\n", errornum);
+ }
+
+ DokMenuParser parser(dokmenu);
+ parser.parse(xml.data(), xml.length());
+
+ return dokmenu;
+}
+
+// Get Dokmenu by Name and CPR
+std::string Praxisd::dokmenu_get_by_cpr_and_name(std::string cpr,
+ std::string name)
+{
+ std::string data;
+
+ std::string uri = host + "/praxisd/1.0/dokmenu/get_by_cpr_and_name?cpr=" +
+ cpr + "&name=" + name;
+ curl_easy_setopt(ch, CURLOPT_URL, uri.c_str());
+
+ curl_easy_setopt(ch, CURLOPT_POST, 0L);
+ curl_easy_setopt(ch, CURLOPT_WRITEDATA, &data);
+
+ CURLcode errornum = curl_easy_perform(ch);
+ if(errornum != CURLE_OK) {
+ printf("Ouch %d\n", errornum);
+ }
+
+ return data;
+}
#ifdef TEST_PRAXISD
//deps: saxparser.cc debug.cc log.cc
@@ -875,7 +950,8 @@ TEST_EQUAL_INT(exp.length(), j2.length(), "Compare lengths");
TEST_EQUAL_STR(exp, j2, "Did we correctly append to the journal?");
*/
-p.add_sogeord(CPR, "CA0003", "Nolder");
+
+//p.add_sogeord(CPR, "CA0003", "Nolder");
{
std::vector<Praxisd::cave_t> cave = p.diverse_get_cave("A0001");
@@ -888,6 +964,14 @@ p.add_sogeord(CPR, "CA0003", "Nolder");
TEST_EQUAL_INT(cave.size(), 25, "Get them all.");
}
+{
+ std::vector<Praxisd::dokmenu_t> dm = p.dokmenu_get_all_by_cpr(CPR);
+ TEST_NOTEQUAL_INT(dm.size(), 0, "Empty result?");
+
+ std::string file = p.dokmenu_get_by_cpr_and_name(CPR, dm[0].filename);
+ TEST_EQUAL_INT(file.size(), dm[0].filesize, "Size matters?");
+}
+
TEST_END;
#endif/*TEST_PRAXISD*/