diff options
-rw-r--r-- | server/src/luapraxisd.cc | 323 | ||||
-rw-r--r-- | server/src/luapraxisd.h | 165 |
2 files changed, 427 insertions, 61 deletions
diff --git a/server/src/luapraxisd.cc b/server/src/luapraxisd.cc index bdaf372..da34d32 100644 --- a/server/src/luapraxisd.cc +++ b/server/src/luapraxisd.cc @@ -144,6 +144,11 @@ int px_adddiagnose(lua_State *L) return 0; } +class cavedata_t : public Praxisd::cave_t { +public: + std::string sogetxt; + std::string sogedato; +}; int px_getcave(lua_State *L) { px_userdata *pxu; @@ -152,7 +157,7 @@ int px_getcave(lua_State *L) const char *cpr = luaL_checkstring(L, 2); - std::vector<Praxisd::cave_t> cavelist; + std::vector<cavedata_t> cavelist; try { Praxisd::patient_t pat = pxu->px->patient_get_by_cpr(cpr); @@ -163,8 +168,14 @@ int px_getcave(lua_State *L) 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]); + cavedata_t cdata; + cdata.cave = cl[0].cave; + cdata.bemaerkning1 = cl[0].bemaerkning1; + cdata.bemaerkning2 = cl[0].bemaerkning2; + cdata.bemaerkning3 = cl[0].bemaerkning3; + cdata.sogetxt = s.sogetxt; + cdata.sogedato = s.sogedato; + cavelist.push_back(cdata); } } @@ -174,12 +185,159 @@ int px_getcave(lua_State *L) 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); + int num = cavelist.size(); + int sz = 6; // 4 fields in cave_t + 1 sogetxt and 1 sogedato + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, cavelist[i - 1].cave.c_str()); + if(j == 2) lua_pushstring(L, cavelist[i - 1].bemaerkning1.c_str()); + if(j == 3) lua_pushstring(L, cavelist[i - 1].bemaerkning2.c_str()); + if(j == 4) lua_pushstring(L, cavelist[i - 1].bemaerkning3.c_str()); + if(j == 5) lua_pushstring(L, cavelist[i - 1].sogetxt.c_str()); + if(j == 6) lua_pushstring(L, cavelist[i - 1].sogedato.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); + } + + return 1; +} + +class behandlingdata_t : public Praxisd::behandling_t { +public: + std::string sogetxt; + std::string sogedato; +}; +int px_getbehandling(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); + + std::vector<behandlingdata_t> behandlinglist; + + 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] == 'B') { + std::string csogenr = s.sogenr.substr(1, s.sogenr.length() - 1); + std::vector<Praxisd::behandling_t> cl = pxu->px->diverse_get_behandling(csogenr); + if(cl.size() == 1) { + behandlingdata_t cdata; + cdata.kode = cl[0].kode; + cdata.behandling = cl[0].behandling; + cdata.bemaerkning = cl[0].bemaerkning; + cdata.udregning = cl[0].udregning; + cdata.sogetxt = s.sogetxt; + cdata.sogedato = s.sogedato; + behandlinglist.push_back(cdata); + } + } + + i++; + } + } catch(const char *msg) { + error(L, msg); + } + + int num = behandlinglist.size(); + int sz = 6; // 4 fields in behandling_t + 1 sogetxt and 1 sogedato + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, behandlinglist[i - 1].kode.c_str()); + if(j == 2) lua_pushstring(L, behandlinglist[i - 1].behandling.c_str()); + if(j == 3) lua_pushstring(L, behandlinglist[i - 1].bemaerkning.c_str()); + if(j == 4) lua_pushstring(L, behandlinglist[i - 1].udregning.c_str()); + if(j == 5) lua_pushstring(L, behandlinglist[i - 1].sogetxt.c_str()); + if(j == 6) lua_pushstring(L, behandlinglist[i - 1].sogedato.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); + } + + return 1; +} + +class diagnosedata_t : public Praxisd::diagnose_t { +public: + std::string sogetxt; + std::string sogedato; +}; +int px_getdiagnose(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); + + std::vector<diagnosedata_t> diagnoselist; + + 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] == 'D') { + std::string csogenr = s.sogenr.substr(1, s.sogenr.length() - 1); + std::vector<Praxisd::diagnose_t> cl = pxu->px->diverse_get_diagnose(csogenr); + if(cl.size() == 1) { + diagnosedata_t cdata; + cdata.kode = cl[0].kode; + cdata.diagnose = cl[0].diagnose; + cdata.bemaerkning = cl[0].bemaerkning; + cdata.sogetxt = s.sogetxt; + cdata.sogedato = s.sogedato; + diagnoselist.push_back(cdata); + } + } + + i++; + } + } catch(const char *msg) { + error(L, msg); + } + + int num = diagnoselist.size(); + int sz = 5; // 3 fields in diagnose_t + 1 sogetxt and 1 sogedato + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, diagnoselist[i - 1].kode.c_str()); + if(j == 2) lua_pushstring(L, diagnoselist[i - 1].diagnose.c_str()); + if(j == 3) lua_pushstring(L, diagnoselist[i - 1].bemaerkning.c_str()); + if(j == 4) lua_pushstring(L, diagnoselist[i - 1].sogetxt.c_str()); + if(j == 5) lua_pushstring(L, diagnoselist[i - 1].sogedato.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); } return 1; @@ -200,12 +358,103 @@ int px_cavelist(lua_State *L) 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); + int num = cavelist.size(); + int sz = 4; // 4 fields in cave_t + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, cavelist[i - 1].cave.c_str()); + if(j == 2) lua_pushstring(L, cavelist[i - 1].bemaerkning1.c_str()); + if(j == 3) lua_pushstring(L, cavelist[i - 1].bemaerkning2.c_str()); + if(j == 4) lua_pushstring(L, cavelist[i - 1].bemaerkning3.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); + } + + return 1; +} + +int px_behandlinglist(lua_State *L) +{ + px_userdata *pxu; + pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); + luaL_argcheck(L, pxu, 1, "Praxisd expected"); + + const char *sogenr = luaL_checkstring(L, 2); + + std::vector<Praxisd::behandling_t> behandlinglist; + try { + behandlinglist = pxu->px->diverse_get_behandling(sogenr); + } catch(const char *msg) { + error(L, msg); + } + + int num = behandlinglist.size(); + int sz = 4; // 4 fields in behandling_t + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, behandlinglist[i - 1].kode.c_str()); + if(j == 2) lua_pushstring(L, behandlinglist[i - 1].behandling.c_str()); + if(j == 3) lua_pushstring(L, behandlinglist[i - 1].bemaerkning.c_str()); + if(j == 4) lua_pushstring(L, behandlinglist[i - 1].udregning.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); + } + + return 1; +} + +int px_diagnoselist(lua_State *L) +{ + px_userdata *pxu; + pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); + luaL_argcheck(L, pxu, 1, "Praxisd expected"); + + const char *sogenr = luaL_checkstring(L, 2); + + std::vector<Praxisd::diagnose_t> diagnoselist; + try { + diagnoselist = pxu->px->diverse_get_diagnose(sogenr); + } catch(const char *msg) { + error(L, msg); + } + + int num = diagnoselist.size(); + int sz = 3; // 3 fields in diagnose_t + + lua_createtable(L, num, 0); + int toptop = lua_gettop(L); + + for(int i = 1; i <= num; i++) { + lua_createtable(L, 0, sz); + int top = lua_gettop(L); + + for(int j = 1; j <= sz; j++) { + if(j == 1) lua_pushstring(L, diagnoselist[i - 1].kode.c_str()); + if(j == 2) lua_pushstring(L, diagnoselist[i - 1].diagnose.c_str()); + if(j == 3) lua_pushstring(L, diagnoselist[i - 1].bemaerkning.c_str()); + lua_rawseti(L, top, j); + } + + lua_rawseti(L, toptop, i); } return 1; @@ -231,7 +480,7 @@ int px_new(lua_State *L) return 1; } -static int px_gc(lua_State *L) +int px_gc(lua_State *L) { px_userdata *pxu; @@ -243,21 +492,6 @@ static int px_gc(lua_State *L) return 0; } -static const struct luaL_Reg px_meths[] = { - {"__gc", px_gc}, - {"cavelist", px_cavelist}, - {"getcave", px_getcave}, - {"addcave", px_addcave}, - {"adddiagnose", px_adddiagnose}, - {"addbehandling", px_addbehandling}, - {NULL, NULL} -}; - -static const struct luaL_reg px_funcs[] = { - {"new", px_new}, - {NULL, NULL} -}; - void register_praxisd(lua_State *L) { luaL_newmetatable(L, "Praxisd"); @@ -269,7 +503,7 @@ void register_praxisd(lua_State *L) } #ifdef TEST_LUAPRAXISD -//deps: praxisd.cc debug.cc saxparser.cc log.cc +//deps: praxisd.cc debug.cc saxparser.cc log.cc mutex.cc //cflags: -I.. $(LUA_CFLAGS) $(CURL_CFLAGS) $(EXPAT_CFLAGS) //libs: $(LUA_LIBS) $(CURL_LIBS) $(EXPAT_LIBS) #include "test.h" @@ -288,29 +522,36 @@ register_praxisd(L); ///// std::string program = "px = Praxisd.new('localhost', 10000)\n" - "cl = px:cavelist('')\n" - "for i=1,#cl do\n" - " print(cl[i])\n" - "end\n" + "--cl = px:cavelist('')\n" + "--for i=1,#cl do\n" + "-- print(cl[i])\n" + "--end\n" "\n" - "--pcl = px:addcave('1505050505', 'LUMIGAN')\n" + "pcl = px:addcave('1505050505', 'AZOPT', 'test')\n" "\n" - "pcl = px:addcave('1505050505', os.date('%H%M%S'))\n" + "--pcl = px:addcave('1505050505', os.date('%H%M%S'))\n" "\n" - "pcl = px:getcave('1505050505')\n" - "for i=1,#pcl do\n" - " print('p: ' .. pcl[i])\n" - "end\n" + "--pcl = px:getbehandling('1505050505')\n" + "--print('#pcl: ' .. #pcl)\n" + "--for i=1,#pcl do\n" + "-- pc = pcl[i]\n" + "-- print('#pc: ' .. #pc)\n" + "-- for j=1,#pc do\n" + "-- print(' pc: ' .. j .. ': ' .. pc[j])\n" + "-- end\n" + "--end\n" ; //int top = lua_gettop(L); if(luaL_loadbuffer(L, program.c_str(), program.size(), "luapraxisd test")) { ERR(luaresume, "loadbufer: %s\n", lua_tostring(L, lua_gettop(L))); + printf("loadbuffer error: %s", lua_tostring(L, lua_gettop(L))); } if(lua_pcall(L, 0, LUA_MULTRET, 0)) { ERR(luaresume, "pcall: %s\n" , lua_tostring(L, lua_gettop(L))); + printf("pcall error: %s", lua_tostring(L, lua_gettop(L))); } /* if(top != lua_gettop(L) - 1) { diff --git a/server/src/luapraxisd.h b/server/src/luapraxisd.h index 71225bf..82445e1 100644 --- a/server/src/luapraxisd.h +++ b/server/src/luapraxisd.h @@ -34,6 +34,7 @@ * Praxisd Class * @class Praxisd * @serverside + * @clientside * The praxisd class connects and handles communication with the praxisd * daemon process. */ @@ -50,65 +51,134 @@ int px_new(lua_State *L); /*** - * @method stringlist praxisd:cavelist() + * @method stringlist-list praxisd:cavelist() * Get server cave list. * To retrieve cavelist for a patient see @see praxisd:getcave(). * @return The complete list of known (possible) cave from the server. + * The returned stringlist are indexed as follows: 1: cave - 2: bemaerkning1 - + * 3: bemaerkning2 - 4: bemaerkning3 * @example Create a new praxisd object, get and print cavelist: * px = Praxisd.new('localhost', 10000) * lst = px:cavelist() * for i=0,#lst do - * print(lst[i]) + * print('cave: ' .. lst[i][1]) + * print('bemaerkning1: ' .. lst[i][2]) + * print('bemaerkning2: ' .. lst[i][3]) + * print('bemaerkning3: ' .. lst[i][4]) * end */ int px_cavelist(lua_State *L); /*** - * @method stringlist praxisd:getcave(string patientid) + * @method stringlist-list praxisd:behandlinglist() + * Get server behandling list. + * To retrieve behandlinglist for a patient see @see praxisd:getbehandling(). + * @return The complete list of known (possible) behandling from the server. + * The returned stringlist are indexed as follows: 1: kode - 2: behandling - + * 3: bemaerkning - 4: udregning. + * @example Create a new praxisd object, get and print behandlinglist: + * px = Praxisd.new('localhost', 10000) + * lst = px:behandlinglist() + * for i=0,#lst do + * print('kode: ' .. lst[i][1]) + * print('behandling: ' .. lst[i][2]) + * print('bemaerkning: ' .. lst[i][3]) + * print('udregning: ' .. lst[i][4]) + * end + */ +int px_behandlinglist(lua_State *L); + +/*** + * @method stringlist-list praxisd:diagnoselist() + * Get server diagnose list. + * To retrieve diagnoselist for a patient see @see praxisd:getdiagnose(). + * @return The complete list of known (possible) diagnose from the server. + * The returned stringlist are indexed as follows: 1: kode - 2: diagnose - + * 3: bemaerkning. + * @example Create a new praxisd object, get and print diagnoselist: + * px = Praxisd.new('localhost', 10000) + * lst = px:diagnoselist() + * for i=0,#lst do + * print('kode: ' .. lst[i][1]) + * print('diagnose: ' .. lst[i][2]) + * print('bemaerkning: ' .. lst[i][3]) + * end + */ +int px_diagnoselist(lua_State *L); + +/*** + * @method stringlist-list praxisd:getcave(string patientid) * Get cave list from a patient. * To retrieve cavelist from the server see @see praxisd:cavelist(). To add cave * to a patient see @see praxisd:addcave(). * @param patientid A string containing the patientid. * @return The list cave registered with the patient. + * The returned stringlist are indexed as follows: 1: cave - 2: bemaerkning1 - + * 3: bemaerkning2 - 4: bemaerkning3 - 5: sogetxt - 6: sogedato. * @example Create a new praxisd object, get and print cavelist: * px = Praxisd.new('localhost', 10000) * lst = px:getcave('1234567890') * for i=0,#lst do - * print(lst[i]) + * print('cave: ' .. lst[i][1]) + * print('bemaerkning1: ' .. lst[i][2]) + * print('bemaerkning2: ' .. lst[i][3]) + * print('bemaerkning3: ' .. lst[i][4]) + * print('sogetxt: ' .. lst[i][5]) + * print('sogedato: ' .. lst[i][6]) * end */ int px_getcave(lua_State *L); /*** - * @method nil praxisd:adddiagnose(string patientid, string diagnose, string text) - * Add a diagnose to a patient. + * @method stringlist-list praxisd:getbehandling(string patientid) + * Get behandling list from a patient. + * To retrieve behandlinglist from the server see @see praxisd:behandlinglist(). To add behandling + * to a patient see @see praxisd:addbehandling(). * @param patientid A string containing the patientid. - * @param diagnose The diagnose code. - * @param text A text to store with the diagnose code. The string mat be up to 6 - * characters long. If longer it will be trunkated. - * @example Create a new praxisd object and add a diagnose: + * @return The list behandling registered with the patient. + * The returned stringlist are indexed as follows: 1: kode - 2: behandling - + * 3: bemaerkning - 4: udregning - 5: sogetxt - 6: sogedato. + * @example Create a new praxisd object, get and print behandlinglist: * px = Praxisd.new('localhost', 10000) - * px:adddiagnose('1234567890', 'C0001', 'o.dxt') + * lst = px:getbehandling('1234567890') + * for i=0,#lst do + * print('kode: ' .. lst[i][1]) + * print('behandling: ' .. lst[i][2]) + * print('bemaerkning: ' .. lst[i][3]) + * print('udregning: ' .. lst[i][4]) + * print('sogetxt: ' .. lst[i][5]) + * print('sogedato: ' .. lst[i][6]) + * end */ -int px_adddiagnose(lua_State *L); +int px_getbehandling(lua_State *L); /*** - * @method nil praxisd:addbehandling(string patientid, string behandling, string text) - * Add a behandling to a patient. + * @method stringlist-list praxisd:getdiagnose(string patientid) + * Get diagnose list from a patient. + * To retrieve diagnoselist from the server see @see praxisd:diagnoselist(). To add diagnose + * to a patient see @see praxisd:adddiagnose(). * @param patientid A string containing the patientid. - * @param diagnose The behandling code. - * @param text A text to store with the behandling code. The string mat be up to 6 - * characters long. If longer it will be trunkated. - * @example Create a new praxisd object and add a behandling: + * @return The list diagnose registered with the patient. + * The returned stringlist are indexed as follows: 1: kode - 2: diagnose - + * 3: bemaerkning - 4: sogetxt - 5: sogedato. + * @example Create a new praxisd object, get and print diagnoselist: * px = Praxisd.new('localhost', 10000) - * px:addbehandling('1234567890', 'B0001', 'o.sin') + * lst = px:getdiagnose('1234567890') + * for i=0,#lst do + * print('kode: ' .. lst[i][1]) + * print('diagnose: ' .. lst[i][2]) + * print('bemaerkning: ' .. lst[i][3]) + * print('sogetxt: ' .. lst[i][4]) + * print('sogedato: ' .. lst[i][5]) + * end */ -int px_addbehandling(lua_State *L); +int px_getdiagnose(lua_State *L); /*** * @method nil praxisd:addcave(string patientid, string cave, string text) * Add a cave entry to a patient. To retrieve list of cave from a patient * see @see praxisd:getcave(). + * NOTE: This function is only available on the server. * @param patientid A string containing the patientid. * @param diagnose The cave string. * @param text A text to store with the cave entry. NOTE: This is not shown in @@ -120,6 +190,61 @@ int px_addbehandling(lua_State *L); */ int px_addcave(lua_State *L); +/*** + * @method nil praxisd:addbehandling(string patientid, string behandling, string text) + * Add a behandling to a patient. To retrieve list of behandling from a patient + * see @see praxisd:getbehandling(). + * NOTE: This function is only available on the server. + * @param patientid A string containing the patientid. + * @param diagnose The behandling code. + * @param text A text to store with the behandling code. The string mat be up to 6 + * characters long. If longer it will be trunkated. + * @example Create a new praxisd object and add a behandling: + * px = Praxisd.new('localhost', 10000) + * px:addbehandling('1234567890', 'B0001', 'o.sin') + */ +int px_addbehandling(lua_State *L); + +/*** + * @method nil praxisd:adddiagnose(string patientid, string diagnose, string text) + * Add a diagnose to a patient. To retrieve list of diagnose from a patient + * see @see praxisd:getdiagnose(). + * NOTE: This function is only available on the server. + * @param patientid A string containing the patientid. + * @param diagnose The diagnose code. + * @param text A text to store with the diagnose code. The string mat be up to 6 + * characters long. If longer it will be trunkated. + * @example Create a new praxisd object and add a diagnose: + * px = Praxisd.new('localhost', 10000) + * px:adddiagnose('1234567890', 'C0001', 'o.dxt') + */ +int px_adddiagnose(lua_State *L); + +/*** + * @method nil __gc() + * Garbage collector. Closes connection and frees all allocated memory. + */ +int px_gc(lua_State *L); + void register_praxisd(lua_State *L); +const struct luaL_Reg px_meths[] = { + {"__gc", px_gc}, + {"cavelist", px_cavelist}, + {"behandliglist", px_behandlinglist}, + {"diagnoselist", px_diagnoselist}, + {"getcave", px_getcave}, + {"getbehandling", px_getbehandling}, + {"getdiagnose", px_getdiagnose}, + {"addcave", px_addcave}, + {"addbehandling", px_addbehandling}, + {"adddiagnose", px_adddiagnose}, + {NULL, NULL} +}; + +const struct luaL_reg px_funcs[] = { + {"new", px_new}, + {NULL, NULL} +}; + #endif/*__PRACRO_LUAPRAXISD_H__*/ |