summaryrefslogtreecommitdiff
path: root/server/src/luapraxisd.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/luapraxisd.cc')
-rw-r--r--server/src/luapraxisd.cc323
1 files changed, 282 insertions, 41 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) {