diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/praxisd.cc | 120 | ||||
-rw-r--r-- | server/src/praxisd.h | 22 |
2 files changed, 116 insertions, 26 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> ÷ +}; + +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*/ diff --git a/server/src/praxisd.h b/server/src/praxisd.h index 03029bb..84848b8 100644 --- a/server/src/praxisd.h +++ b/server/src/praxisd.h @@ -238,14 +238,20 @@ public: #if 0 // Get Name by UserID std::string user_get_name_by_id(std::string user); +#endif - // Get All Docmenu by CPR - typedef struct {} docmenu_t; - std::vector<docmenu_t> docmenu_get_all_by_cpr(std::string cpr); + // Get All Dokmenu by CPR + typedef struct { + std::string group; + std::string subject; + std::string filename; + size_t filesize; + std::string date; + } dokmenu_t; + std::vector<dokmenu_t> dokmenu_get_all_by_cpr(std::string cpr); - // Get Docmenu by Name and CPR - std::string docmenu_get_by_cpr_and_name(std::string cpr, std::string name); -#endif + // Get Dokmenu by Name and CPR + std::string dokmenu_get_by_cpr_and_name(std::string cpr, std::string name); // POST: // Add To Journal @@ -259,8 +265,8 @@ public: // Update Aftale // Add Aftale // Delete Aftale - // Add File to Docmenu - // Delete File from Docmenu + // Add File to Dokmenu + // Delete File from Dokmenu private: std::string get_sogenr(std::string sogenr); |