From 813b50f0c91805b22941bfb28758b49f8e00cb22 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 7 Sep 2012 11:08:01 +0200 Subject: Make client use luapraxisd.h from server folder. Add stub functions to luapraxisd in client. --- client/luapraxisd.cc | 169 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 152 insertions(+), 17 deletions(-) (limited to 'client/luapraxisd.cc') diff --git a/client/luapraxisd.cc b/client/luapraxisd.cc index 00ed961..3b8e430 100644 --- a/client/luapraxisd.cc +++ b/client/luapraxisd.cc @@ -25,7 +25,7 @@ * along with Pracro; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "luapraxisd.h" +#include "../server/src/luapraxisd.h" #include "praxisd.h" @@ -41,7 +41,28 @@ typedef struct px_userdata { PraxisdSync *px; } px_userdata; -static int px_getcave(lua_State *L) +int px_addcave(lua_State *L) +{ + lua_pushstring(L, "Add cave not implemented on client."); + lua_error(L); + return 0; +} + +int px_addbehandling(lua_State *L) +{ + lua_pushstring(L, "Add behandling not implemented on client."); + lua_error(L); + return 0; +} + +int px_adddiagnose(lua_State *L) +{ + lua_pushstring(L, "Add diagnose not implemented on client."); + lua_error(L); + return 0; +} + +int px_getcave(lua_State *L) { px_userdata *pxu; pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); @@ -81,7 +102,81 @@ static int px_getcave(lua_State *L) return 1; } -static int px_cavelist(lua_State *L) +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); + + QVector behandlinglist; + + Patient patient = pxu->px->patient_get_by_cpr(cpr); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } + QVector::iterator i = patient.sogeord.begin(); + while(i != patient.sogeord.end()) { + QString behandlingsogeord = i->sogenr;//.mid(1, i->sogenr.size() - 1); + QVector behandling = pxu->px->diverse_get_behandling(behandlingsogeord); + if(behandling.size() == 1) behandlinglist.push_back(i->sogetxt); + i++; + } + + lua_createtable(L, 0, behandlinglist.size()); + int top = lua_gettop(L); + + for(int i = 0; i < behandlinglist.size(); i++) { + QString c = behandlinglist[i]; + DEBUG(behandlinglist, "BEHANDLING '%s'\n", c.toStdString().c_str()); + lua_pushstring(L, c.toStdString().c_str()); + lua_rawseti(L, top, i); + } + + return 1; +} + +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); + + QVector diagnoselist; + + Patient patient = pxu->px->patient_get_by_cpr(cpr); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } + QVector::iterator i = patient.sogeord.begin(); + while(i != patient.sogeord.end()) { + QString diagnosesogeord = i->sogenr;//.mid(1, i->sogenr.size() - 1); + QVector diagnose = pxu->px->diverse_get_diagnose(diagnosesogeord); + if(diagnose.size() == 1) diagnoselist.push_back(i->sogetxt); + i++; + } + + lua_createtable(L, 0, diagnoselist.size()); + int top = lua_gettop(L); + + for(int i = 0; i < diagnoselist.size(); i++) { + QString c = diagnoselist[i]; + DEBUG(diagnoselist, "DIAGNOSE '%s'\n", c.toStdString().c_str()); + lua_pushstring(L, c.toStdString().c_str()); + lua_rawseti(L, top, i); + } + + return 1; +} + +int px_cavelist(lua_State *L) { px_userdata *pxu; pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); @@ -107,7 +202,59 @@ static int px_cavelist(lua_State *L) return 1; } -static int px_new(lua_State *L) +int px_behandlinglist(lua_State *L) +{ + px_userdata *pxu; + pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd"); + luaL_argcheck(L, pxu, 1, "Praxisd expected"); + + QVector behandlinglist = pxu->px->diverse_get_behandling("C"); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } + + lua_createtable(L, 0, behandlinglist.size()); + int top = lua_gettop(L); + + for(size_t i = 0; i < (size_t)behandlinglist.size(); i++) { + QString c = behandlinglist[i].behandling; + DEBUG(behandlinglist, "BEHANDLING '%s'\n", c.toStdString().c_str()); + lua_pushstring(L, c.toStdString().c_str()); + lua_rawseti(L, top, 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"); + + QVector diagnoselist = pxu->px->diverse_get_diagnose("C"); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } + + lua_createtable(L, 0, diagnoselist.size()); + int top = lua_gettop(L); + + for(size_t i = 0; i < (size_t)diagnoselist.size(); i++) { + QString c = diagnoselist[i].diagnose; + DEBUG(diagnoselist, "DIAGNOSE '%s'\n", c.toStdString().c_str()); + lua_pushstring(L, c.toStdString().c_str()); + lua_rawseti(L, top, i); + } + + return 1; +} + +int px_new(lua_State *L) { const char *host = luaL_checkstring(L, 1); int port = luaL_checknumber(L, 2); @@ -123,7 +270,7 @@ static int px_new(lua_State *L) return 1; } -static int px_gc(lua_State *L) +int px_gc(lua_State *L) { px_userdata *pxu; @@ -135,18 +282,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}, - {NULL, NULL} -}; - -static const struct luaL_reg px_funcs[] = { - {"new", px_new}, - {NULL, NULL} -}; - void register_praxisd(lua_State *L) { luaL_newmetatable(L, "Praxisd"); -- cgit v1.2.3