summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.pro14
-rw-r--r--client/luapraxisd.cc30
-rw-r--r--client/pcpviewer.cc4
-rw-r--r--client/pcpviewer.h2
-rw-r--r--client/praxisd.cc336
-rw-r--r--client/praxisd.h85
6 files changed, 417 insertions, 54 deletions
diff --git a/client/client.pro b/client/client.pro
index 445f29f..97d9d7d 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -31,18 +31,6 @@ win32 {
unix {
LIBS += -llua
- LIBS += -lcurl -lexpat
-
- HEADERS += \
- ../server/src/praxisd.h \
- ../server/src/saxparser.h \
- ../server/src/debug.h
-
- SOURCES += \
- ../server/src/praxisd.cc \
- ../server/src/saxparser.cc
-
- DEFINES += WITH_PRAXISD
}
HEADERS += \
@@ -62,6 +50,7 @@ HEADERS += \
messagebox.h \
netcom.h \
pcpviewer.h \
+ praxisd.h \
resumewidget.h \
template.h \
widgets.h \
@@ -102,6 +91,7 @@ SOURCES += \
messagebox.cc \
netcom.cc \
pcpviewer.cc \
+ praxisd.cc \
resumewidget.cc \
template.cc \
widgets/common.cc \
diff --git a/client/luapraxisd.cc b/client/luapraxisd.cc
index 1d9da4c..6fc4891 100644
--- a/client/luapraxisd.cc
+++ b/client/luapraxisd.cc
@@ -27,9 +27,7 @@
*/
#include "luapraxisd.h"
-#ifdef WITH_PRAXISD
-
-#include "../server/src/praxisd.h"
+#include "praxisd.h"
#include <lauxlib.h>
#include <strings.h>
@@ -40,7 +38,7 @@
(lua_isboolean(L,i) ? lua_toboolean(L,i) : luaL_checkint(L,i))
typedef struct px_userdata {
- Praxisd *px;
+ PraxisdSync *px;
} px_userdata;
static int px_getcave(lua_State *L)
@@ -54,13 +52,13 @@ static int px_getcave(lua_State *L)
QVector<QString> cavelist;
Praxisd::patient_t patient = pxu->px->patient_get_by_cpr(cpr);
- std::vector<Praxisd::sogeord_t>::iterator i = patient.sogeord.begin();
+ QVector<Praxisd::sogeord_t>::iterator i = patient.sogeord.begin();
while(i != patient.sogeord.end()) {
- std::string cavesogeord = i->sogenr.substr(1, i->sogenr.size() - 1);
- std::vector<Praxisd::cave_t> cave = pxu->px->diverse_get_cave(cavesogeord);
+ QString cavesogeord = i->sogenr.mid(1, i->sogenr.size() - 1);
+ QVector<Praxisd::cave_t> cave = pxu->px->diverse_get_cave(cavesogeord);
if(cave.size() == 1) {
- if(cave[0].cave != "ANDET") cavelist.push_back(cave[0].cave.c_str());
- else cavelist.push_back(i->sogetxt.c_str());
+ if(cave[0].cave != "ANDET") cavelist.push_back(cave[0].cave);
+ else cavelist.push_back(i->sogetxt);
}
i++;
}
@@ -82,13 +80,13 @@ static int px_cavelist(lua_State *L)
pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
luaL_argcheck(L, pxu, 1, "Praxisd expected");
- std::vector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave("");
+ QVector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave("");
lua_createtable(L, 0, cavelist.size());
int top = lua_gettop(L);
- for(size_t i = 0; i < cavelist.size(); i++) {
- lua_pushstring(L, QString::fromUtf8(cavelist[i].cave.c_str()).toStdString().c_str());
+ for(size_t i = 0; i < (size_t)cavelist.size(); i++) {
+ lua_pushstring(L, QString::fromUtf8(cavelist[i].cave.toStdString().c_str()).toStdString().c_str());
lua_rawseti(L, top, i);
}
@@ -106,7 +104,7 @@ static int px_new(lua_State *L)
luaL_getmetatable(L, "Praxisd");
lua_setmetatable(L, -2);
- pxu->px = new Praxisd(host, port);
+ pxu->px = new PraxisdSync(host, port);
return 1;
}
@@ -144,9 +142,3 @@ void register_praxisd(lua_State *L)
luaL_register(L, NULL, px_meths);
luaL_openlib (L, "Praxisd", px_funcs, 0);
}
-
-#else/*WITH_PRAXISD*/
-
-void register_praxisd(lua_State *L){}
-
-#endif/*WITH_PRAXISD*/
diff --git a/client/pcpviewer.cc b/client/pcpviewer.cc
index c665cf2..f0059f4 100644
--- a/client/pcpviewer.cc
+++ b/client/pcpviewer.cc
@@ -30,7 +30,7 @@
PCPViewer::PCPViewer(QString patientid) : praxisd("gargamel", 10000)
{
this->patientid = patientid;
-
+ /*
std::string j = praxisd.journal_get_by_cpr(patientid.toStdString());
printf("%s\n", j.c_str());
@@ -46,5 +46,5 @@ PCPViewer::PCPViewer(QString patientid) : praxisd("gargamel", 10000)
di->date.c_str());
di++;
}
-
+ */
}
diff --git a/client/pcpviewer.h b/client/pcpviewer.h
index dd86fea..5b57fd6 100644
--- a/client/pcpviewer.h
+++ b/client/pcpviewer.h
@@ -30,7 +30,7 @@
#include <QWidget>
-#include "../server/src/praxisd.h"
+#include "praxisd.h"
class PCPViewer : public QWidget {
Q_OBJECT
diff --git a/client/praxisd.cc b/client/praxisd.cc
index 2367eb1..d8b3444 100644
--- a/client/praxisd.cc
+++ b/client/praxisd.cc
@@ -27,20 +27,330 @@
*/
#include "praxisd.h"
-#ifdef TEST_PRAXISD
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
+#include <QDomDocument>
-TEST_BEGIN;
+#include <QNetworkReply>
-// TODO: Put some testcode here (see test.h for usable macros).
-TEST_TRUE(false, "No tests yet!");
+#define DOCAVE(x) if(element.tagName() == #x) cave.x = element.text()
+static QVector<Praxisd::cave_t> getCaveList(QByteArray data)
+{
+ QDomDocument doc;
+ doc.setContent(data);
-TEST_END;
+ QVector<Praxisd::cave_t> cavelist;
-#endif/*TEST_PRAXISD*/
+ QDomNode praxisd = doc.documentElement().firstChild();
+ 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_cave") {
+
+ Praxisd::cave_t cave;
+ cave.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();
+ DOCAVE(cave);
+ DOCAVE(bemaerkning1);
+ DOCAVE(bemaerkning2);
+ DOCAVE(bemaerkning3);
+ }
+
+ cavelist.push_back(cave);
+ }
+ }
+
+ return cavelist;
+}
+
+#define DOPATIENT(x) if(element.tagName() == #x) patient.x = element.text()
+static Praxisd::patient_t getPatient(QByteArray data)
+{
+ QDomDocument doc;
+ doc.setContent(data);
+
+ Praxisd::patient_t patient;
+
+ QDomNode praxisd = doc.documentElement().firstChild();
+ QDomNode patnode = praxisd.firstChild();
+
+ QDomElement patelement = patnode.toElement();
+ patient.cpr = patelement.attribute("cpr");
+
+ QDomNodeList nodes = patnode.childNodes();
+ for(int i = 0; i < nodes.count(); i++) {
+ QDomNode node = nodes.at(i);
+ QDomElement element = node.toElement();
+
+ DOPATIENT(fornavne);
+ DOPATIENT(efternavn);
+ DOPATIENT(stilling);
+ DOPATIENT(gade);
+ DOPATIENT(by);
+ DOPATIENT(telefonnumre);
+ DOPATIENT(sikringsgr);
+ DOPATIENT(amtsnr);
+ DOPATIENT(sygekontor);
+ DOPATIENT(henvnr);
+ DOPATIENT(frilinie1);
+ DOPATIENT(frilinie2);
+ DOPATIENT(frilinie3);
+ DOPATIENT(frilinie4);
+ DOPATIENT(frilinie5);
+
+ if(element.tagName() == "sogeords") {
+ Praxisd::sogeord_t sogeord;
+
+ QDomNodeList nodes = element.childNodes();
+ for(int j = 0; j < nodes.count(); j++) {
+ QDomNode node = nodes.at(j);
+ QDomElement element = node.toElement();
+ sogeord.sogenr = element.attribute("sogenr");
+ sogeord.sogedato = element.attribute("sogedato");
+ sogeord.sogetxt = element.text();
+ }
+
+ patient.sogeord.push_back(sogeord);
+ }
+
+ DOPATIENT(ydernr);
+ DOPATIENT(created);
+ DOPATIENT(donottouch);
+ DOPATIENT(visus);
+ DOPATIENT(labkort);
+ DOPATIENT(medkort);
+ DOPATIENT(jlock);
+ DOPATIENT(unknown1);
+ DOPATIENT(henvdato);
+ DOPATIENT(aarhund);
+ DOPATIENT(fakturadato);
+ DOPATIENT(fakturabelob);
+ DOPATIENT(betaldato);
+ DOPATIENT(betalbelob);
+ DOPATIENT(jdato);
+ DOPATIENT(unknown250);
+ DOPATIENT(unknown251);
+ DOPATIENT(jtime);
+ }
+
+ return patient;
+}
+
+#define DODOKMENU(x) if(element.tagName() == #x) dokmenu.x = element.text()
+QVector<Praxisd::dokmenu_t> getDokMenu(QByteArray data)
+{
+ QDomDocument doc;
+ doc.setContent(data);
+
+ QVector<Praxisd::dokmenu_t> dokmenus;
+
+ QDomNode praxisd = doc.documentElement().firstChild();
+ QDomNodeList nodes = praxisd.childNodes();
+ for(int i = 0; i < nodes.count(); i++) {
+ QDomNode node = nodes.at(i);
+ QDomElement element = node.toElement();
+ if(element.tagName() == "dokmenu") {
+
+ Praxisd::dokmenu_t dokmenu;
+ dokmenu.cpr = element.attribute("cpr");
+
+ QDomNodeList nodes = element.childNodes();
+ for(int j = 0; j < nodes.count(); j++) {
+ QDomNode node = nodes.at(j);
+ QDomElement element = node.toElement();
+ DODOKMENU(group);
+ DODOKMENU(subject);
+ if(element.tagName() == "filename") {
+ dokmenu.filename = element.text();
+ dokmenu.filesize = element.attribute("filesize").toUInt();
+ dokmenu.date = element.attribute("date");
+ }
+ }
+
+ dokmenus.push_back(dokmenu);
+ }
+ }
+
+ return dokmenus;
+}
+
+Praxisd::Praxisd(QString host, unsigned short int port)
+{
+ QUrl url;
+ url.setHost(host);
+ url.setPort(port);
+ url.setScheme("http");
+
+ request.setUrl(url);
+
+ manager = new QNetworkAccessManager(this);
+ connect(manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(replyFinished(QNetworkReply*)));
+}
+
+void Praxisd::replyFinished(QNetworkReply *reply)
+{
+ if(reply->error() == QNetworkReply::NoError) {
+
+ reply_t type = replytypes[reply];
+ switch(type) {
+ case journal:
+ emit gotJournal(reply->readAll());
+ break;
+
+ case cavelist:
+ emit gotCave(getCaveList(reply->readAll()));
+ break;
+
+ case patient:
+ emit gotPatient(getPatient(reply->readAll()));
+ break;
+
+ case dokmenu:
+ emit gotDokMenu(getDokMenu(reply->readAll()));
+ break;
+
+ case dokmenufile:
+ emit gotDokMenuFile(reply->readAll());
+ break;
+ }
+ } else {
+ emit networkError(reply->errorString());
+ }
+ replytypes.erase(replytypes.find(reply));
+}
+
+void Praxisd::makeTransfer(reply_t t, QString uri,
+ QMap<QString, QString> params)
+{
+ request.setRawHeader("User-Agent", "Pracro Client v"VERSION);
+
+ QUrl url;
+ url.setHost(request.url().host());
+ url.setPort(request.url().port());
+ url.setScheme(request.url().scheme());
+
+ url.setPath(uri);
+
+ QMap<QString, QString>::iterator i = params.begin();
+ while(i != params.end()) {
+ url.addQueryItem(i.key(), i.value());
+ i++;
+ }
+
+ request.setUrl(url);
+
+ QNetworkReply* r = manager->get(request);
+ replytypes[r] = t;
+}
+
+void Praxisd::journal_get_by_cpr(QString cpr)
+{
+ QMap<QString, QString> params;
+ params["cpr"] = cpr;
+ makeTransfer(journal, "/praxisd/1.0/journal/get_by_cpr", params);
+}
+
+void Praxisd::diverse_get_cave(QString sogenr)
+{
+ QMap<QString, QString> params;
+ params["sogenr"] = sogenr;
+ makeTransfer(cavelist, "/praxisd/1.0/diverse/get_all_by_sogenr", params);
+}
+
+void Praxisd::patient_get_by_cpr(QString cpr)
+{
+ QMap<QString, QString> params;
+ params["cpr"] = cpr;
+ makeTransfer(patient, "/praxisd/1.0/patient/get_by_cpr", params);
+}
+
+void Praxisd::dokmenu_get_all_by_cpr(QString cpr)
+{
+ QMap<QString, QString> params;
+ params["cpr"] = cpr;
+ makeTransfer(dokmenu, "/praxisd/1.0/dokmenu/get_all_by_cpr", params);
+}
+
+void Praxisd::dokmenu_get_by_cpr_and_name(QString cpr, QString name)
+{
+ cpr = cpr;
+ name = name;
+ // uri = host + "/praxisd/1.0/dokmenu/get_by_cpr_and_name?cpr=" + cpr + "&name=" + name;
+ QMap<QString, QString> params;
+ params["cpr"] = cpr;
+ params["name"] = name;
+ makeTransfer(dokmenufile, "/praxisd/1.0/dokmenu/get_by_cpr_and_name", params);
+}
+
+PraxisdSync::PraxisdSync(QString host, unsigned short int port)
+ : praxisd(host, port)
+{
+ connect(&praxisd, SIGNAL(gotCaveList(QVector<Praxisd::cave_t>)),
+ this, SLOT(gotCaveList(QVector<Praxisd::cave_t>)));
+
+ start();
+}
+
+void PraxisdSync::run()
+{
+ while(true) {
+ wsem.acquire();
+
+ switch(request_type) {
+ case Praxisd::journal:
+ break;
+ case Praxisd::cavelist:
+ praxisd.diverse_get_cave(request_sogenr);
+ break;
+ case Praxisd::patient:
+ break;
+ case Praxisd::dokmenu:
+ break;
+ case Praxisd::dokmenufile:
+ break;
+ }
+ }
+}
+
+void PraxisdSync::gotCaveList(QVector<Praxisd::cave_t> cl)
+{
+ cavelist = cl;
+ rsem.release();
+}
+
+QString PraxisdSync::journal_get_by_cpr(QString cpr)
+{
+ return cpr;
+}
+
+QVector<Praxisd::cave_t> PraxisdSync::diverse_get_cave(QString sogenr)
+{
+ request_type = Praxisd::cavelist;
+ request_sogenr = sogenr;
+
+ wsem.release();
+ rsem.acquire();
+
+ return cavelist;
+}
+
+Praxisd::patient_t PraxisdSync::patient_get_by_cpr(QString cpr)
+{
+ cpr = "";
+ return Praxisd::patient_t();
+}
+
+QVector<Praxisd::dokmenu_t> PraxisdSync::dokmenu_get_all_by_cpr(QString cpr)
+{
+ cpr = "";
+ return QVector<Praxisd::dokmenu_t>();
+}
+
+QString PraxisdSync::dokmenu_get_by_cpr_and_name(QString cpr, QString name)
+{
+ return cpr + name;
+}
diff --git a/client/praxisd.h b/client/praxisd.h
index dfaac59..c9ccaf3 100644
--- a/client/praxisd.h
+++ b/client/praxisd.h
@@ -28,12 +28,31 @@
#ifndef __PRACRO_PRAXISD_H__
#define __PRACRO_PRAXISD_H__
-class Praxisd {
+#include <QObject>
+#include <QString>
+#include <QVector>
+
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+
+#include <QByteArray>
+#include <QThread>
+#include <QSemaphore>
+
+class Praxisd : public QObject {
Q_OBJECT
-public;
- Praxisd();
+public:
+ typedef enum {
+ journal,
+ cavelist,
+ patient,
+ dokmenu,
+ dokmenufile
+ } reply_t;
- QString journal_get_by_cpr(QString patientid);
+ Praxisd(QString host, quint16 port);
+
+ void journal_get_by_cpr(QString patientid);
typedef struct {
QString sogenr;
@@ -42,7 +61,7 @@ public;
QString bemaerkning2;
QString bemaerkning3;
} cave_t;
- QVector<cave_t> diverse_get_cave(QString sogenr);
+ void diverse_get_cave(QString sogenr);
typedef struct {
QString sogenr;
@@ -87,18 +106,70 @@ public;
QString unknown251;
QString jtime;
} patient_t;
- patient_t patient_get_by_cpr(QString cpr);
+ void patient_get_by_cpr(QString cpr);
typedef struct {
+ QString cpr;
QString group;
QString subject;
QString filename;
size_t filesize;
QString date;
} dokmenu_t;
- QVector<dokmenu_t> dokmenu_get_all_by_cpr(QString cpr);
+ void dokmenu_get_all_by_cpr(QString cpr);
+
+ void dokmenu_get_by_cpr_and_name(QString cpr, QString name);
+
+signals:
+ void gotReply(QByteArray data);
+ void networkError(QString text);
+
+ void gotJournal(QString data);
+ void gotCave(QVector<cave_t> cave);
+ void gotPatient(patient_t patient);
+ void gotDokMenu(QVector<dokmenu_t> dokmenu);
+ void gotDokMenuFile(QString data);
+
+public slots:
+ void replyFinished(QNetworkReply*);
+
+private:
+ void makeTransfer(reply_t t, QString uri, QMap<QString, QString> params);
+
+ QNetworkAccessManager *manager;
+ QNetworkRequest request;
+ QString host;
+ unsigned short int port;
+
+ QMap<QNetworkReply*, reply_t> replytypes;
+};
+
+class PraxisdSync : public QThread {
+Q_OBJECT
+public:
+ PraxisdSync(QString host, unsigned short int port);
+
+ QString journal_get_by_cpr(QString patientid);
+ QVector<Praxisd::cave_t> diverse_get_cave(QString sogenr);
+ Praxisd::patient_t patient_get_by_cpr(QString cpr);
+ QVector<Praxisd::dokmenu_t> dokmenu_get_all_by_cpr(QString cpr);
QString dokmenu_get_by_cpr_and_name(QString cpr, QString name);
+
+ void run();
+
+public slots:
+ void gotCaveList(QVector<Praxisd::cave_t>);
+
+private:
+ Praxisd praxisd;
+ QSemaphore rsem;
+ QSemaphore wsem;
+
+ Praxisd::reply_t request_type;
+ QString request_sogenr;
+
+ QVector<Praxisd::cave_t> cavelist;
};
#endif/*__PRACRO_PRAXISD_H__*/