diff options
-rw-r--r-- | server/src/luapraxisd.cc | 138 | ||||
-rw-r--r-- | server/src/praxisd.cc | 62 | ||||
-rw-r--r-- | server/src/praxisd.h | 78 |
3 files changed, 210 insertions, 68 deletions
diff --git a/server/src/luapraxisd.cc b/server/src/luapraxisd.cc index 04a83db..b50446c 100644 --- a/server/src/luapraxisd.cc +++ b/server/src/luapraxisd.cc @@ -37,6 +37,9 @@ #define luaL_checkbool(L, i) \ (lua_isboolean(L,i) ? lua_toboolean(L,i) : luaL_checkint(L,i)) +#define error(L, m) \ + ERR(luapraxisd, "%s\n", m); lua_pushstring(L, m); lua_error(L); + typedef struct px_userdata { Praxisd *px; } px_userdata; @@ -49,23 +52,95 @@ static int px_addcave(lua_State *L) const char *cpr = luaL_checkstring(L, 2); const char *cave = luaL_checkstring(L, 3); + const char *txt = luaL_checkstring(L, 4); + + std::string sogeord; + std::string sogetxt; + + try { + std::vector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave(""); + std::vector<Praxisd::cave_t>::iterator i = cavelist.begin(); + while(i != cavelist.end()) { + Praxisd::cave_t &c = *i; + if(strcasecmp(cave, c.cave.c_str()) == 0) { + pxu->px->add_sogeord(cpr, c.sogenr, txt); + return 0; + } + i++; + } + + std::string text = cave; + text += " "; + text += txt; + pxu->px->add_sogeord(cpr, "CA0003", text.c_str()); // CA0003 == 'ANDET' + } catch(const char *msg) { + error(L, msg); + } + + return 0; +} + +static int px_addbehandling(lua_State *L) +{ + px_userdata *pxu; + pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); + luaL_argcheck(L, pxu, 1, "Praxisd expected"); + + const char *cpr = luaL_checkstring(L, 2); + const char *behandling = luaL_checkstring(L, 3); + const char *text = luaL_checkstring(L, 4); std::string sogeord; std::string sogetxt; - std::vector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave(""); - std::vector<Praxisd::cave_t>::iterator i = cavelist.begin(); - while(i != cavelist.end()) { - Praxisd::cave_t &c = *i; - if(strcasecmp(cave, c.cave.c_str()) == 0) { - pxu->px->add_sogeord(cpr, c.sogenr, ""); - return 0; + try { + std::vector<Praxisd::behandling_t> bhlst = + pxu->px->diverse_get_behandling(""); + std::vector<Praxisd::behandling_t>::iterator i = bhlst.begin(); + while(i != bhlst.end()) { + Praxisd::behandling_t &b = *i; + if(strcasecmp(behandling, b.kode.c_str()) == 0) { + pxu->px->add_sogeord(cpr, b.sogenr, text); + return 0; + } + i++; } - i++; + } catch(const char *msg) { + error(L, msg); } - pxu->px->add_sogeord(cpr, "CA0003", cave); // CA0003 == 'ANDET' + return 0; +} + +static int px_adddiagnose(lua_State *L) +{ + px_userdata *pxu; + pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); + luaL_argcheck(L, pxu, 1, "Praxisd expected"); + + const char *cpr = luaL_checkstring(L, 2); + const char *diagnose = luaL_checkstring(L, 3); + const char *text = luaL_checkstring(L, 4); + + std::string sogeord; + std::string sogetxt; + try { + std::vector<Praxisd::diagnose_t> dialst = + pxu->px->diverse_get_diagnose(""); + std::vector<Praxisd::diagnose_t>::iterator i = dialst.begin(); + while(i != dialst.end()) { + Praxisd::diagnose_t &d = *i; + if(strcasecmp(diagnose, d.kode.c_str()) == 0) { + pxu->px->add_sogeord(cpr, d.sogenr, text); + return 0; + } + i++; + } + } catch(const char *msg) { + error(L, msg); + } + return 0; } @@ -79,25 +154,29 @@ static int px_getcave(lua_State *L) std::vector<Praxisd::cave_t> cavelist; - Praxisd::patient_t pat = pxu->px->patient_get_by_cpr(cpr); - std::vector<Praxisd::sogeord_t>::iterator i = pat.sogeord.begin(); - while(i != pat.sogeord.end()) { - Praxisd::sogeord_t &s = *i; - if(s.sogenr[0] == 'C') { - std::string csogenr = s.sogenr.substr(1, s.sogenr.length() - 1); - std::vector<Praxisd::cave_t> cl = pxu->px->diverse_get_cave(csogenr); - if(cl.size() == 1) { - if(cl[0].cave == "ANDET") cl[0].cave = s.sogetxt; - cavelist.push_back(cl[0]); + try { + Praxisd::patient_t pat = pxu->px->patient_get_by_cpr(cpr); + std::vector<Praxisd::sogeord_t>::iterator i = pat.sogeord.begin(); + while(i != pat.sogeord.end()) { + Praxisd::sogeord_t &s = *i; + if(s.sogenr[0] == 'C') { + std::string csogenr = s.sogenr.substr(1, s.sogenr.length() - 1); + std::vector<Praxisd::cave_t> cl = pxu->px->diverse_get_cave(csogenr); + if(cl.size() == 1) { + if(cl[0].cave == "ANDET") cl[0].cave = s.sogetxt; + cavelist.push_back(cl[0]); + } } + + i++; } - - i++; + } catch(const char *msg) { + error(L, msg); } lua_createtable(L, 0, cavelist.size()); int top = lua_gettop(L); - + for(size_t i = 0; i < cavelist.size(); i++) { lua_pushstring(L, cavelist[i].cave.c_str()); lua_rawseti(L, top, i); @@ -114,7 +193,12 @@ static int px_cavelist(lua_State *L) const char *sogenr = luaL_checkstring(L, 2); - std::vector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave(sogenr); + std::vector<Praxisd::cave_t> cavelist; + try { + cavelist = pxu->px->diverse_get_cave(sogenr); + } catch(const char *msg) { + error(L, msg); + } lua_createtable(L, 0, cavelist.size()); int top = lua_gettop(L); @@ -138,7 +222,11 @@ static int px_new(lua_State *L) luaL_getmetatable(L, "Praxisd"); lua_setmetatable(L, -2); - pxu->px = new Praxisd(host, port); + try { + pxu->px = new Praxisd(host, port); + } catch(const char *msg) { + error(L, msg); + } return 1; } @@ -160,6 +248,8 @@ static const struct luaL_Reg px_meths[] = { {"cavelist", px_cavelist}, {"getcave", px_getcave}, {"addcave", px_addcave}, + {"adddiagnose", px_adddiagnose}, + {"addbehandling", px_addbehandling}, {NULL, NULL} }; diff --git a/server/src/praxisd.cc b/server/src/praxisd.cc index 3ccdf0d..8a5b6d6 100644 --- a/server/src/praxisd.cc +++ b/server/src/praxisd.cc @@ -59,6 +59,7 @@ static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) } Praxisd::Praxisd(std::string h, int port) + throw(const char*) { ch = curl_easy_init(); host = h; @@ -82,6 +83,7 @@ Praxisd::~Praxisd() // Get Journal By CPR std::string Praxisd::journal_get_by_cpr(std::string cpr) + throw(const char*) { std::string journal; @@ -93,16 +95,14 @@ std::string Praxisd::journal_get_by_cpr(std::string cpr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } - time_t time; - errornum = curl_easy_getinfo(ch, CURLINFO_FILETIME, &time); - return journal; } time_t Praxisd::journal_last_changed(std::string cpr) + throw(const char*) { std::string journal; @@ -114,17 +114,21 @@ time_t Praxisd::journal_last_changed(std::string cpr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } time_t time; errornum = curl_easy_getinfo(ch, CURLINFO_FILETIME, &time); + if(errornum != CURLE_OK) { + throw curl_easy_strerror(errornum); + } return time; } void Praxisd::journal_add(std::string cpr, std::string entry) + throw(const char*) { std::string xml; xml += "<praxisd version=\"1.0\">\n"; @@ -150,12 +154,13 @@ void Praxisd::journal_add(std::string cpr, std::string entry) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch: %d %s\n", errornum, reply.c_str()); + throw curl_easy_strerror(errornum); } } void Praxisd::add_sogeord(std::string cpr, std::string sogeord, std::string sogetxt) + throw(const char*) { std::string datestr = strtime(false); @@ -187,7 +192,7 @@ void Praxisd::add_sogeord(std::string cpr, std::string sogeord, CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch: %d %s\n", errornum, reply.c_str()); + throw curl_easy_strerror(errornum); } } @@ -259,6 +264,7 @@ private: }; Praxisd::patient_t Praxisd::patient_get_by_cpr(std::string cpr) + throw(const char*) { patient_t p; @@ -272,11 +278,9 @@ Praxisd::patient_t Praxisd::patient_get_by_cpr(std::string cpr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } - // printf("Get Patient: %d %s\n", xml.length(), xml.c_str()); fflush(stdout); - PatientParser parser(p); parser.parse(xml.data(), xml.length()); @@ -284,6 +288,7 @@ Praxisd::patient_t Praxisd::patient_get_by_cpr(std::string cpr) } std::string Praxisd::get_sogenr(std::string sogenr) + throw(const char*) { std::string xml; @@ -296,7 +301,7 @@ std::string Praxisd::get_sogenr(std::string sogenr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } return xml; @@ -331,6 +336,7 @@ private: }; std::vector<Praxisd::adresse_t> Praxisd::diverse_get_adresse(std::string sogenr) + throw(const char*) { std::vector<Praxisd::adresse_t> lst; std::string xml = get_sogenr("A"+sogenr); @@ -365,6 +371,7 @@ private: std::vector<Praxisd::behandling_t> Praxisd::diverse_get_behandling(std::string sogenr) + throw(const char*) { std::vector<Praxisd::behandling_t> lst; std::string xml = get_sogenr("B"+sogenr); @@ -398,6 +405,7 @@ private: }; std::vector<Praxisd::cave_t> Praxisd::diverse_get_cave(std::string sogenr) + throw(const char*) { std::vector<Praxisd::cave_t> lst; std::string xml = get_sogenr("C"+sogenr); @@ -431,6 +439,7 @@ private: std::vector<Praxisd::diagnose_t> Praxisd::diverse_get_diagnose(std::string sogenr) + throw(const char*) { std::vector<Praxisd::diagnose_t> lst; std::string xml = get_sogenr("D"+sogenr); @@ -464,6 +473,7 @@ private: }; std::vector<Praxisd::frase_t> Praxisd::diverse_get_frase(std::string sogenr) + throw(const char*) { std::vector<Praxisd::frase_t> lst; std::string xml = get_sogenr("F"+sogenr); @@ -495,6 +505,7 @@ private: }; std::vector<Praxisd::grafik_t> Praxisd::diverse_get_grafik(std::string sogenr) + throw(const char*) { std::vector<Praxisd::grafik_t> lst; std::string xml = get_sogenr("G"+sogenr); @@ -530,6 +541,7 @@ private: std::vector<Praxisd::indholdstof_t> Praxisd::diverse_get_indholdstof(std::string sogenr) + throw(const char*) { std::vector<Praxisd::indholdstof_t> lst; std::string xml = get_sogenr("I"+sogenr); @@ -563,6 +575,7 @@ private: std::vector<Praxisd::klage_t> Praxisd::diverse_get_klage(std::string sogenr) + throw(const char*) { std::vector<Praxisd::klage_t> lst; std::string xml = get_sogenr("K"+sogenr); @@ -595,6 +608,7 @@ private: std::vector<Praxisd::oversigt_t> Praxisd::diverse_get_oversigt(std::string sogenr) + throw(const char*) { std::vector<Praxisd::oversigt_t> lst; std::string xml = get_sogenr("O"+sogenr); @@ -632,6 +646,7 @@ private: std::vector<Praxisd::postnummer_t> Praxisd::diverse_get_postnummer(std::string sogenr) + throw(const char*) { std::vector<Praxisd::postnummer_t> lst; std::string xml = get_sogenr("P"+sogenr); @@ -666,6 +681,7 @@ private: std::vector<Praxisd::type_t> Praxisd::diverse_get_type(std::string sogenr) + throw(const char*) { std::vector<Praxisd::type_t> lst; std::string xml = get_sogenr("T"+sogenr); @@ -699,6 +715,7 @@ private: std::vector<Praxisd::undersoegelse_t> Praxisd::diverse_get_undersoegelse(std::string sogenr) + throw(const char*) { std::vector<Praxisd::undersoegelse_t> lst; std::string xml = get_sogenr("U"+sogenr); @@ -736,6 +753,7 @@ private: std::vector<Praxisd::ydelse_t> Praxisd::diverse_get_ydelse(std::string sogenr) + throw(const char*) { std::vector<Praxisd::ydelse_t> lst; std::string xml = get_sogenr("Y"+sogenr); @@ -775,8 +793,9 @@ static std::string i2s(int i) { return buf; } std::vector<Praxisd::aftale_t> -Praxisd::aftale_get_all_by_date_and_calendar(int cal, int year, int month, - int day) +Praxisd::aftale_get_all_by_date_and_calendar(int cal, + int year, int month, int day) + throw(const char*) { std::vector<Praxisd::aftale_t> aft; @@ -792,7 +811,7 @@ Praxisd::aftale_get_all_by_date_and_calendar(int cal, int year, int month, CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } AftaleParser parser(aft); @@ -802,6 +821,7 @@ Praxisd::aftale_get_all_by_date_and_calendar(int cal, int year, int month, } std::vector<Praxisd::aftale_t> Praxisd::aftale_get_all_by_cpr(std::string cpr) + throw(const char*) { std::vector<Praxisd::aftale_t> aft; @@ -815,7 +835,7 @@ std::vector<Praxisd::aftale_t> Praxisd::aftale_get_all_by_cpr(std::string cpr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } AftaleParser parser(aft); @@ -825,6 +845,7 @@ std::vector<Praxisd::aftale_t> Praxisd::aftale_get_all_by_cpr(std::string cpr) } bool Praxisd::authenticate(std::string user, std::string pass) + throw(const char*) { std::string uri = host + "/praxisd/1.0/authenticate?user=" + user + "&pass=" + pass; @@ -835,11 +856,14 @@ bool Praxisd::authenticate(std::string user, std::string pass) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - return false; + throw curl_easy_strerror(errornum); } long code = 0; errornum = curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &code); + if(errornum != CURLE_OK) { + throw curl_easy_strerror(errornum); + } if(code == 401) return false; if(code == 200) return true; @@ -876,6 +900,7 @@ private: }; std::vector<Praxisd::dokmenu_t> Praxisd::dokmenu_get_all_by_cpr(std::string cpr) + throw(const char*) { std::vector<Praxisd::dokmenu_t> dokmenu; std::string xml; @@ -888,7 +913,7 @@ std::vector<Praxisd::dokmenu_t> Praxisd::dokmenu_get_all_by_cpr(std::string cpr) CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } DokMenuParser parser(dokmenu); @@ -900,6 +925,7 @@ std::vector<Praxisd::dokmenu_t> Praxisd::dokmenu_get_all_by_cpr(std::string cpr) // Get Dokmenu by Name and CPR std::string Praxisd::dokmenu_get_by_cpr_and_name(std::string cpr, std::string name) + throw(const char*) { std::string data; @@ -912,7 +938,7 @@ std::string Praxisd::dokmenu_get_by_cpr_and_name(std::string cpr, CURLcode errornum = curl_easy_perform(ch); if(errornum != CURLE_OK) { - printf("Ouch %d\n", errornum); + throw curl_easy_strerror(errornum); } return data; diff --git a/server/src/praxisd.h b/server/src/praxisd.h index 84848b8..785cba1 100644 --- a/server/src/praxisd.h +++ b/server/src/praxisd.h @@ -37,13 +37,16 @@ class Praxisd { public: - Praxisd(std::string host, int port); + Praxisd(std::string host, int port) + throw(const char*); ~Praxisd(); - time_t journal_last_changed(std::string cpr); + time_t journal_last_changed(std::string cpr) + throw(const char*); // Get Journal By CPR - std::string journal_get_by_cpr(std::string cpr); + std::string journal_get_by_cpr(std::string cpr) + throw(const char*); // Get Patient By CPR typedef struct { @@ -89,7 +92,8 @@ public: std::string unknown251; std::string jtime; } patient_t; - patient_t patient_get_by_cpr(std::string cpr); + patient_t patient_get_by_cpr(std::string cpr) + throw(const char*); // Get Diverse From Sogenr typedef struct { @@ -102,7 +106,8 @@ public: std::string tlf; std::string fax; } adresse_t; - std::vector<adresse_t> diverse_get_adresse(std::string sogenr); + std::vector<adresse_t> diverse_get_adresse(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -111,7 +116,8 @@ public: std::string bemaerkning; std::string udregning; } behandling_t; - std::vector<behandling_t> diverse_get_behandling(std::string sogenr); + std::vector<behandling_t> diverse_get_behandling(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -120,7 +126,8 @@ public: std::string bemaerkning2; std::string bemaerkning3; } cave_t; - std::vector<cave_t> diverse_get_cave(std::string sogenr); + std::vector<cave_t> diverse_get_cave(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -128,7 +135,8 @@ public: std::string diagnose; std::string bemaerkning; } diagnose_t; - std::vector<diagnose_t> diverse_get_diagnose(std::string sogenr); + std::vector<diagnose_t> diverse_get_diagnose(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -137,14 +145,16 @@ public: std::string frase3; std::string frase4; } frase_t; - std::vector<frase_t> diverse_get_frase(std::string sogenr); + std::vector<frase_t> diverse_get_frase(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; std::string navn; std::string bemaerkning; } grafik_t; - std::vector<grafik_t> diverse_get_grafik(std::string sogenr); + std::vector<grafik_t> diverse_get_grafik(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -154,7 +164,8 @@ public: std::string form3; std::string form4; } indholdstof_t; - std::vector<indholdstof_t> diverse_get_indholdstof(std::string sogenr); + std::vector<indholdstof_t> diverse_get_indholdstof(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -162,14 +173,16 @@ public: std::string klage; std::string bemaerkning; } klage_t; - std::vector<klage_t> diverse_get_klage(std::string sogenr); + std::vector<klage_t> diverse_get_klage(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; std::string navn; std::string bemaerkning; } oversigt_t; - std::vector<oversigt_t> diverse_get_oversigt(std::string sogenr); + std::vector<oversigt_t> diverse_get_oversigt(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -181,7 +194,8 @@ public: std::string regionnavn; std::string kommunenavn; } postnummer_t; - std::vector<postnummer_t> diverse_get_postnummer(std::string sogenr); + std::vector<postnummer_t> diverse_get_postnummer(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -191,7 +205,8 @@ public: std::string bemaerkning3; std::string recept; } type_t; - std::vector<type_t> diverse_get_type(std::string sogenr); + std::vector<type_t> diverse_get_type(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -200,7 +215,8 @@ public: std::string bemaerkning; std::string udregning; } undersoegelse_t; - std::vector<undersoegelse_t> diverse_get_undersoegelse(std::string sogenr); + std::vector<undersoegelse_t> diverse_get_undersoegelse(std::string sogenr) + throw(const char*); typedef struct { std::string sogenr; @@ -213,7 +229,8 @@ public: std::string journal2; std::string moms; } ydelse_t; - std::vector<ydelse_t> diverse_get_ydelse(std::string sogenr); + std::vector<ydelse_t> diverse_get_ydelse(std::string sogenr) + throw(const char*); // Get Aftale All by Date and Calendar @@ -227,17 +244,21 @@ public: std::string cres; } aftale_t; std::vector<aftale_t> aftale_get_all_by_date_and_calendar(int cal, int year, - int month, int day); + int month, int day) + throw(const char*); // Get Aftale All by CPR - std::vector<aftale_t> aftale_get_all_by_cpr(std::string cpr); + std::vector<aftale_t> aftale_get_all_by_cpr(std::string cpr) + throw(const char*); // Authenticate - bool authenticate(std::string user, std::string pass); + bool authenticate(std::string user, std::string pass) + throw(const char*); #if 0 // Get Name by UserID - std::string user_get_name_by_id(std::string user); + std::string user_get_name_by_id(std::string user) + throw(const char*); #endif // Get All Dokmenu by CPR @@ -248,19 +269,23 @@ public: size_t filesize; std::string date; } dokmenu_t; - std::vector<dokmenu_t> dokmenu_get_all_by_cpr(std::string cpr); + std::vector<dokmenu_t> dokmenu_get_all_by_cpr(std::string cpr) + throw(const char*); // Get Dokmenu by Name and CPR - std::string dokmenu_get_by_cpr_and_name(std::string cpr, std::string name); + std::string dokmenu_get_by_cpr_and_name(std::string cpr, std::string name) + throw(const char*); // POST: // Add To Journal - void journal_add(std::string cpr, std::string entry); + void journal_add(std::string cpr, std::string entry) + throw(const char*); // Update Patient // Add Sogeord to Patient - void add_sogeord(std::string cpr, std::string sogeord, std::string sogetxt); + void add_sogeord(std::string cpr, std::string sogeord, std::string sogetxt) + throw(const char*); // Update Aftale // Add Aftale @@ -269,7 +294,8 @@ public: // Delete File from Dokmenu private: - std::string get_sogenr(std::string sogenr); + std::string get_sogenr(std::string sogenr) + throw(const char*); CURL *ch; std::string host; }; |