diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/client.pro | 2 | ||||
-rw-r--r-- | client/lua.cc | 2 | ||||
-rw-r--r-- | client/luapraxisd.cc | 169 | ||||
-rw-r--r-- | client/luapraxisd.h | 35 | ||||
-rw-r--r-- | client/praxisd.cc | 137 | ||||
-rw-r--r-- | client/praxisd.h | 39 |
6 files changed, 330 insertions, 54 deletions
diff --git a/client/client.pro b/client/client.pro index 5e16942..375818f 100644 --- a/client/client.pro +++ b/client/client.pro @@ -40,7 +40,7 @@ HEADERS += \ launcherwindow.h \ lua.h \ luadb.h \ - luapraxisd.h \ + ../server/src/luapraxisd.h \ luawidget.h \ macro.h \ macrowindow.h \ diff --git a/client/lua.cc b/client/lua.cc index 48840ce..f017986 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -32,7 +32,7 @@ #include "luawidget.h" #include "luadb.h" -#include "luapraxisd.h" +#include "../server/src/luapraxisd.h" #include "debug.h" 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<QString> 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<sogeord_t>::iterator i = patient.sogeord.begin(); + while(i != patient.sogeord.end()) { + QString behandlingsogeord = i->sogenr;//.mid(1, i->sogenr.size() - 1); + QVector<behandling_t> 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<QString> 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<sogeord_t>::iterator i = patient.sogeord.begin(); + while(i != patient.sogeord.end()) { + QString diagnosesogeord = i->sogenr;//.mid(1, i->sogenr.size() - 1); + QVector<diagnose_t> 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<behandling_t> 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<diagnose_t> 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"); diff --git a/client/luapraxisd.h b/client/luapraxisd.h deleted file mode 100644 index 86be31f..0000000 --- a/client/luapraxisd.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * luapraxisd.h - * - * Thu May 5 11:16:20 CEST 2011 - * Copyright 2011 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of Pracro. - * - * Pracro is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Pracro is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Pracro; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#ifndef __PRACRO_LUAPRAXISD_H__ -#define __PRACRO_LUAPRAXISD_H__ - -#include <lua.hpp> - -void register_praxisd(lua_State *L); - -#endif/*__PRACRO_LUAPRAXISD_H__*/ diff --git a/client/praxisd.cc b/client/praxisd.cc index 2fbaddc..42fdd0c 100644 --- a/client/praxisd.cc +++ b/client/praxisd.cc @@ -68,6 +68,75 @@ static CaveVector getCaveList(QByteArray data) return cavelist; } +#define DOBEHANDLING(x) if(element.tagName() == #x) behandling.x = element.text() +static BehandlingVector getBehandlingList(QByteArray data) +{ + QDomDocument doc; + doc.setContent(data); + + BehandlingVector behandlinglist; + + QDomNode praxisd = doc.documentElement(); + QDomNodeList nodes = praxisd.childNodes(); + for(int i = 0; i < nodes.count(); i++) { + QDomNode node = nodes.at(i); + QDomElement element = node.toElement(); + if(element.tagName() == "div_behandling") { + + behandling_t behandling; + behandling.sogenr = element.attribute("sogenr"); + + QDomNodeList nodes = element.childNodes(); + for(int j = 0; j < nodes.count(); j++) { + QDomNode node = nodes.at(j); + QDomElement element = node.toElement(); + DOBEHANDLING(kode); + DOBEHANDLING(behandling); + DOBEHANDLING(bemaerkning); + DOBEHANDLING(udregning); + } + + behandlinglist.push_back(behandling); + } + } + + return behandlinglist; +} + +#define DODIAGNOSE(x) if(element.tagName() == #x) diagnose.x = element.text() +static DiagnoseVector getDiagnoseList(QByteArray data) +{ + QDomDocument doc; + doc.setContent(data); + + DiagnoseVector diagnoselist; + + QDomNode praxisd = doc.documentElement(); + QDomNodeList nodes = praxisd.childNodes(); + for(int i = 0; i < nodes.count(); i++) { + QDomNode node = nodes.at(i); + QDomElement element = node.toElement(); + if(element.tagName() == "div_diagnose") { + + diagnose_t diagnose; + diagnose.sogenr = element.attribute("sogenr"); + + QDomNodeList nodes = element.childNodes(); + for(int j = 0; j < nodes.count(); j++) { + QDomNode node = nodes.at(j); + QDomElement element = node.toElement(); + DODIAGNOSE(kode); + DODIAGNOSE(diagnose); + DODIAGNOSE(bemaerkning); + } + + diagnoselist.push_back(diagnose); + } + } + + return diagnoselist; +} + #define DOPATIENT(x) if(element.tagName() == #x) patient.x = element.text() static Patient getPatient(QByteArray data) { @@ -208,6 +277,14 @@ void Praxisd::replyFinished(QNetworkReply *reply) emit gotCaveList(getCaveList(reply->readAll())); break; + case behandlinglist: + emit gotBehandlingList(getBehandlingList(reply->readAll())); + break; + + case diagnoselist: + emit gotDiagnoseList(getDiagnoseList(reply->readAll())); + break; + case patient: emit gotPatient(getPatient(reply->readAll())); break; @@ -264,6 +341,20 @@ void Praxisd::diverse_get_cave(QString sogenr) makeTransfer(cavelist, "/praxisd/1.0/diverse/get_all_by_sogenr", params); } +void Praxisd::diverse_get_behandling(QString sogenr) +{ + QMap<QString, QString> params; + params["sogenr"] = sogenr; + makeTransfer(behandlinglist, "/praxisd/1.0/diverse/get_all_by_sogenr", params); +} + +void Praxisd::diverse_get_diagnose(QString sogenr) +{ + QMap<QString, QString> params; + params["sogenr"] = sogenr; + makeTransfer(diagnoselist, "/praxisd/1.0/diverse/get_all_by_sogenr", params); +} + void Praxisd::patient_get_by_cpr(QString cpr) { QMap<QString, QString> params; @@ -317,6 +408,10 @@ void PraxisdSync::run() connect(&praxisd, SIGNAL(gotCaveList(CaveVector)), this, SLOT(gotCaveList(CaveVector)), Qt::DirectConnection); + connect(&praxisd, SIGNAL(gotBehandlingList(BehandlingVector)), + this, SLOT(gotBehandlingList(BehandlingVector)), Qt::DirectConnection); + connect(&praxisd, SIGNAL(gotDiagnoseList(DiagnoseVector)), + this, SLOT(gotDiagnoseList(DiagnoseVector)), Qt::DirectConnection); connect(&praxisd, SIGNAL(gotPatient(Patient)), this, SLOT(gotPatient(Patient)), Qt::DirectConnection); @@ -339,6 +434,12 @@ void PraxisdSync::run() case Praxisd::cavelist: praxisd.diverse_get_cave(request_sogenr); break; + case Praxisd::behandlinglist: + praxisd.diverse_get_behandling(request_sogenr); + break; + case Praxisd::diagnoselist: + praxisd.diverse_get_diagnose(request_sogenr); + break; case Praxisd::patient: praxisd.patient_get_by_cpr(request_cpr); break; @@ -380,6 +481,20 @@ void PraxisdSync::gotCaveList(CaveVector cl) quit(); } +void PraxisdSync::gotBehandlingList(BehandlingVector bl) +{ + behandlinglist = bl; + rsem.release(); + quit(); +} + +void PraxisdSync::gotDiagnoseList(DiagnoseVector dl) +{ + diagnoselist = dl; + rsem.release(); + quit(); +} + void PraxisdSync::gotPatient(Patient p) { patient = p; @@ -410,6 +525,28 @@ CaveVector PraxisdSync::diverse_get_cave(QString sogenr) return cavelist; } +BehandlingVector PraxisdSync::diverse_get_behandling(QString sogenr) +{ + request_type = Praxisd::behandlinglist; + request_sogenr = sogenr; + + wsem.release(); + rsem.acquire(); + + return behandlinglist; +} + +DiagnoseVector PraxisdSync::diverse_get_diagnose(QString sogenr) +{ + request_type = Praxisd::diagnoselist; + request_sogenr = sogenr; + + wsem.release(); + rsem.acquire(); + + return diagnoselist; +} + Patient PraxisdSync::patient_get_by_cpr(QString cpr) { request_type = Praxisd::patient; diff --git a/client/praxisd.h b/client/praxisd.h index 507e63e..38404da 100644 --- a/client/praxisd.h +++ b/client/praxisd.h @@ -49,6 +49,23 @@ typedef struct { typedef struct { QString sogenr; + QString kode; + QString behandling; + QString bemaerkning; + QString udregning; +} behandling_t; +//std::vector<behandling_t> diverse_get_behandling(std::string sogenr) + +typedef struct { + QString sogenr; + QString kode; + QString diagnose; + QString bemaerkning; +} diagnose_t; +// std::vector<diagnose_t> diverse_get_diagnose(std::string sogenr) + +typedef struct { + QString sogenr; QString sogedato; QString sogetxt; } sogeord_t; @@ -101,6 +118,9 @@ typedef struct { } dokmenu_t; typedef QVector<cave_t> CaveVector; +typedef QVector<behandling_t> BehandlingVector; +typedef QVector<diagnose_t> DiagnoseVector; + typedef patient_t Patient; typedef QVector<dokmenu_t> DokMenuVector; @@ -110,6 +130,8 @@ public: typedef enum { journal, cavelist, + behandlinglist, + diagnoselist, patient, dokmenu, dokmenufile @@ -120,6 +142,8 @@ public: void journal_get_by_cpr(QString patientid); void diverse_get_cave(QString sogenr); + void diverse_get_behandling(QString sogenr); + void diverse_get_diagnose(QString sogenr); void patient_get_by_cpr(QString cpr); @@ -132,7 +156,11 @@ signals: void networkError(QString text); void gotJournal(QString data); + void gotCaveList(CaveVector cave); + void gotBehandlingList(BehandlingVector cave); + void gotDiagnoseList(DiagnoseVector cave); + void gotPatient(Patient patient); void gotDokMenu(DokMenuVector dokmenu); void gotDokMenuFile(QByteArray data, QString mimetype); @@ -159,7 +187,11 @@ public: ~PraxisdSync(); QString journal_get_by_cpr(QString patientid); + CaveVector diverse_get_cave(QString sogenr); + BehandlingVector diverse_get_behandling(QString sogenr); + DiagnoseVector diverse_get_diagnose(QString sogenr); + Patient patient_get_by_cpr(QString cpr); DokMenuVector dokmenu_get_all_by_cpr(QString cpr); QString dokmenu_get_by_cpr_and_name(QString cpr, QString name); @@ -171,7 +203,11 @@ public: private slots: void networkError(QString); + void gotCaveList(CaveVector); + void gotBehandlingList(BehandlingVector); + void gotDiagnoseList(DiagnoseVector); + void gotPatient(Patient); void gotDokMenu(DokMenuVector); @@ -187,6 +223,9 @@ private: QString request_cpr; CaveVector cavelist; + BehandlingVector behandlinglist; + DiagnoseVector diagnoselist; + Patient patient; DokMenuVector dokmenu; |