1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
* praxisd.cc
*
* Tue Oct 11 15:20:18 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.
*/
#include "praxisd.h"
#include <stdio.h>
#include <QDomDocument>
#include <QNetworkReply>
#define DOCAVE(x) if(element.tagName() == #x) cave.x = element.text()
static CaveVector getCaveList(QByteArray data)
{
QDomDocument doc;
doc.setContent(data);
CaveVector cavelist;
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_cave") {
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 Patient getPatient(QByteArray data)
{
QDomDocument doc;
doc.setContent(data);
Patient patient;
QDomNode praxisd = doc.documentElement();
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") {
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()
static DokMenuVector getDokMenu(QByteArray data)
{
QDomDocument doc;
doc.setContent(data);
DokMenuVector dokmenus;
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() == "dokmenu") {
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)
{
qRegisterMetaType<CaveVector>("CaveVector");
qRegisterMetaType<Patient>("Patient");
qRegisterMetaType<DokMenuVector>("DokMenuVector");
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 gotCaveList(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(), reply->rawHeader("Content-Type"));
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)
{
this->host = host;
this->port = port;
this->running = true;
start();
}
PraxisdSync::~PraxisdSync()
{
this->running = false;
wsem.release();
wait();
}
void PraxisdSync::run()
{
Praxisd praxisd(host, port);
connect(&praxisd, SIGNAL(networkError(QString)),
this, SLOT(networkError(QString)), Qt::DirectConnection);
connect(&praxisd, SIGNAL(gotCaveList(CaveVector)),
this, SLOT(gotCaveList(CaveVector)), Qt::DirectConnection);
connect(&praxisd, SIGNAL(gotPatient(Patient)),
this, SLOT(gotPatient(Patient)), Qt::DirectConnection);
connect(&praxisd, SIGNAL(gotDokMenu(DokMenuVector)),
this, SLOT(gotDokMenu(DokMenuVector)), Qt::DirectConnection);
while(true) {
wsem.acquire();
// Reset error state
error = false;
errorStr = "";
if(this->running == false) break;
switch(request_type) {
case Praxisd::journal:
break;
case Praxisd::cavelist:
praxisd.diverse_get_cave(request_sogenr);
break;
case Praxisd::patient:
praxisd.patient_get_by_cpr(request_cpr);
break;
case Praxisd::dokmenu:
praxisd.dokmenu_get_all_by_cpr(request_cpr);
break;
case Praxisd::dokmenufile:
break;
}
exec();
}
rsem.release();
}
bool PraxisdSync::hasError()
{
return error;
}
QString PraxisdSync::errorString()
{
return errorStr;
}
void PraxisdSync::networkError(QString err)
{
error = true;
errorStr = err;
rsem.release();
quit();
}
void PraxisdSync::gotCaveList(CaveVector cl)
{
cavelist = cl;
rsem.release();
quit();
}
void PraxisdSync::gotPatient(Patient p)
{
patient = p;
rsem.release();
quit();
}
void PraxisdSync::gotDokMenu(DokMenuVector d)
{
dokmenu = d;
rsem.release();
quit();
}
QString PraxisdSync::journal_get_by_cpr(QString cpr)
{
return cpr;
}
CaveVector PraxisdSync::diverse_get_cave(QString sogenr)
{
request_type = Praxisd::cavelist;
request_sogenr = sogenr;
wsem.release();
rsem.acquire();
return cavelist;
}
Patient PraxisdSync::patient_get_by_cpr(QString cpr)
{
cpr = "";
return Patient();
}
DokMenuVector PraxisdSync::dokmenu_get_all_by_cpr(QString cpr)
{
request_type = Praxisd::dokmenu;
request_cpr = cpr;
wsem.release();
rsem.acquire();
return dokmenu;
}
QString PraxisdSync::dokmenu_get_by_cpr_and_name(QString cpr, QString name)
{
return cpr + name;
}
|