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.cc455
1 files changed, 393 insertions, 62 deletions
diff --git a/server/src/luapraxisd.cc b/server/src/luapraxisd.cc
index 04a83db..da34d32 100644
--- a/server/src/luapraxisd.cc
+++ b/server/src/luapraxisd.cc
@@ -37,11 +37,14 @@
#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;
-static int px_addcave(lua_State *L)
+int px_addcave(lua_State *L)
{
px_userdata *pxu;
pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
@@ -49,64 +52,377 @@ 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;
- 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::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++;
}
- 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);
}
- pxu->px->add_sogeord(cpr, "CA0003", cave); // CA0003 == 'ANDET'
+ return 0;
+}
+
+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;
+
+ 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++;
+ }
+ } catch(const char *msg) {
+ error(L, msg);
+ }
return 0;
}
-static int px_getcave(lua_State *L)
+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::vector<Praxisd::cave_t> cavelist;
+ 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;
+}
+
+class cavedata_t : public Praxisd::cave_t {
+public:
+ std::string sogetxt;
+ std::string sogedato;
+};
+int px_getcave(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<cavedata_t> cavelist;
+
+ 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) {
+ 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);
+ }
+ }
+
+ i++;
+ }
+ } catch(const char *msg) {
+ error(L, msg);
+ }
+
+ 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");
- 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]);
+ 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;
+}
+
+int px_cavelist(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::cave_t> cavelist;
+ try {
+ cavelist = pxu->px->diverse_get_cave(sogenr);
+ } catch(const char *msg) {
+ error(L, msg);
+ }
+
+
+ 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);
}
- i++;
+ 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);
}
- lua_createtable(L, 0, cavelist.size());
- int top = lua_gettop(L);
+ 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);
+ }
- for(size_t i = 0; i < cavelist.size(); i++) {
- lua_pushstring(L, cavelist[i].cave.c_str());
- lua_rawseti(L, top, i);
+ lua_rawseti(L, toptop, i);
}
return 1;
}
-static int px_cavelist(lua_State *L)
+int px_diagnoselist(lua_State *L)
{
px_userdata *pxu;
pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
@@ -114,20 +430,37 @@ 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::diagnose_t> diagnoselist;
+ try {
+ diagnoselist = pxu->px->diverse_get_diagnose(sogenr);
+ } catch(const char *msg) {
+ error(L, msg);
+ }
- lua_createtable(L, 0, cavelist.size());
- int top = lua_gettop(L);
+ 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);
+ }
- for(size_t i = 0; i < cavelist.size(); i++) {
- lua_pushstring(L, cavelist[i].cave.c_str());
- lua_rawseti(L, top, i);
+ lua_rawseti(L, toptop, i);
}
return 1;
}
-static int px_new(lua_State *L)
+int px_new(lua_State *L)
{
const char *host = luaL_checkstring(L, 1);
int port = (int)luaL_checknumber(L, 2);
@@ -138,12 +471,16 @@ 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;
}
-static int px_gc(lua_State *L)
+int px_gc(lua_State *L)
{
px_userdata *pxu;
@@ -155,19 +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},
- {NULL, NULL}
-};
-
-static const struct luaL_reg px_funcs[] = {
- {"new", px_new},
- {NULL, NULL}
-};
-
void register_praxisd(lua_State *L)
{
luaL_newmetatable(L, "Praxisd");
@@ -179,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"
@@ -198,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) {