diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/praxisd.cc | 565 | ||||
-rw-r--r-- | server/src/praxisd.h | 138 |
2 files changed, 699 insertions, 4 deletions
diff --git a/server/src/praxisd.cc b/server/src/praxisd.cc index b4b0a88..4a9c2f1 100644 --- a/server/src/praxisd.cc +++ b/server/src/praxisd.cc @@ -191,6 +191,7 @@ void Praxisd::add_sogeord(std::string cpr, std::string sogeord, #define DOTAG(x) if(name == #x) str = &p.x; #include "saxparser.h" + class PatientParser : public SAXParser { public: PatientParser(Praxisd::patient_t &_p) : p(_p) { str = NULL; } @@ -278,6 +279,570 @@ Praxisd::patient_t Praxisd::patient_get_by_cpr(std::string cpr) return p; } +std::string Praxisd::get_sogenr(std::string sogenr) +{ + std::string xml; + + std::string uri = host + "/praxisd/1.0/diverse/get_all_by_sogenr?sogenr=" + + sogenr; + curl_easy_setopt(ch, CURLOPT_URL, uri.c_str()); + + curl_easy_setopt(ch, CURLOPT_POST, 0L); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, &xml); + + CURLcode errornum = curl_easy_perform(ch); + if(errornum != CURLE_OK) { + printf("Ouch %d\n", errornum); + } + + return xml; +} + +#define DODIVTAG(x) if(name == #x) str = &div[div.size() - 1].x; + +class AdresseParser : public SAXParser { +public: + AdresseParser(std::vector<Praxisd::adresse_t> &al) : div(al) { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_adresse") { + Praxisd::adresse_t a; + if(attr.find("sogenr") != attr.end()) a.sogenr = attr["sogenr"]; + div.push_back(a); + } + DODIVTAG(edi_adresse); + DODIVTAG(navn); + DODIVTAG(att); + DODIVTAG(gade); + DODIVTAG(by); + DODIVTAG(tlf); + DODIVTAG(fax); + } + +private: + std::string *str; + std::vector<Praxisd::adresse_t> ÷ +}; + +std::vector<Praxisd::adresse_t> Praxisd::diverse_get_adresse(std::string sogenr) +{ + std::vector<Praxisd::adresse_t> lst; + std::string xml = get_sogenr("A"+sogenr); + AdresseParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class BehandlingParser : public SAXParser { +public: + BehandlingParser(std::vector<Praxisd::behandling_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_behandling") { + Praxisd::behandling_t a; + if(attr.find("sogenr") != attr.end()) a.sogenr = attr["sogenr"]; + div.push_back(a); + } + DODIVTAG(kode); + DODIVTAG(behandling); + DODIVTAG(bemaerkning); + DODIVTAG(udregning); + } + +private: + std::string *str; + std::vector<Praxisd::behandling_t> ÷ +}; + +std::vector<Praxisd::behandling_t> +Praxisd::diverse_get_behandling(std::string sogenr) +{ + std::vector<Praxisd::behandling_t> lst; + std::string xml = get_sogenr("B"+sogenr); + BehandlingParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class CaveParser : public SAXParser { +public: + CaveParser(std::vector<Praxisd::cave_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_cave") { + Praxisd::cave_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(cave); + DODIVTAG(bemaerkning1); + DODIVTAG(bemaerkning2); + DODIVTAG(bemaerkning3); + } + +private: + std::string *str; + std::vector<Praxisd::cave_t> ÷ +}; + +std::vector<Praxisd::cave_t> Praxisd::diverse_get_cave(std::string sogenr) +{ + std::vector<Praxisd::cave_t> lst; + std::string xml = get_sogenr("C"+sogenr); + CaveParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class DiagnoseParser : public SAXParser { +public: + DiagnoseParser(std::vector<Praxisd::diagnose_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_diagnose") { + Praxisd::diagnose_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(kode); + DODIVTAG(diagnose); + DODIVTAG(bemaerkning); + } + +private: + std::string *str; + std::vector<Praxisd::diagnose_t> ÷ +}; + +std::vector<Praxisd::diagnose_t> +Praxisd::diverse_get_diagnose(std::string sogenr) +{ + std::vector<Praxisd::diagnose_t> lst; + std::string xml = get_sogenr("D"+sogenr); + DiagnoseParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class FraseParser : public SAXParser { +public: + FraseParser(std::vector<Praxisd::frase_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_frase") { + Praxisd::frase_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(frase1); + DODIVTAG(frase2); + DODIVTAG(frase3); + DODIVTAG(frase4); + } + +private: + std::string *str; + std::vector<Praxisd::frase_t> ÷ +}; + +std::vector<Praxisd::frase_t> Praxisd::diverse_get_frase(std::string sogenr) +{ + std::vector<Praxisd::frase_t> lst; + std::string xml = get_sogenr("F"+sogenr); + FraseParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class GrafikParser : public SAXParser { +public: + GrafikParser(std::vector<Praxisd::grafik_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_grafik") { + Praxisd::grafik_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(navn); + DODIVTAG(bemaerkning); + } + +private: + std::string *str; + std::vector<Praxisd::grafik_t> ÷ +}; + +std::vector<Praxisd::grafik_t> Praxisd::diverse_get_grafik(std::string sogenr) +{ + std::vector<Praxisd::grafik_t> lst; + std::string xml = get_sogenr("G"+sogenr); + GrafikParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class IndholdstofParser : public SAXParser { +public: + IndholdstofParser(std::vector<Praxisd::indholdstof_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_indholdstof") { + Praxisd::indholdstof_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(indholdstof); + DODIVTAG(form1); + DODIVTAG(form2); + DODIVTAG(form3); + DODIVTAG(form4); + } + +private: + std::string *str; + std::vector<Praxisd::indholdstof_t> ÷ +}; + +std::vector<Praxisd::indholdstof_t> +Praxisd::diverse_get_indholdstof(std::string sogenr) +{ + std::vector<Praxisd::indholdstof_t> lst; + std::string xml = get_sogenr("I"+sogenr); + IndholdstofParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class KlageParser : public SAXParser { +public: + KlageParser(std::vector<Praxisd::klage_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_klage") { + Praxisd::klage_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(kode); + DODIVTAG(klage); + DODIVTAG(bemaerkning); + } + +private: + std::string *str; + std::vector<Praxisd::klage_t> ÷ +}; + +std::vector<Praxisd::klage_t> +Praxisd::diverse_get_klage(std::string sogenr) +{ + std::vector<Praxisd::klage_t> lst; + std::string xml = get_sogenr("K"+sogenr); + KlageParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class OversigtParser : public SAXParser { +public: + OversigtParser(std::vector<Praxisd::oversigt_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_oversigt") { + Praxisd::oversigt_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(navn); + DODIVTAG(bemaerkning); + } + +private: + std::string *str; + std::vector<Praxisd::oversigt_t> ÷ +}; + +std::vector<Praxisd::oversigt_t> +Praxisd::diverse_get_oversigt(std::string sogenr) +{ + std::vector<Praxisd::oversigt_t> lst; + std::string xml = get_sogenr("O"+sogenr); + OversigtParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class PostnummerParser : public SAXParser { +public: + PostnummerParser(std::vector<Praxisd::postnummer_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_postnummer") { + Praxisd::postnummer_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(postnummer); + DODIVTAG(by_gade); + DODIVTAG(kbh); + DODIVTAG(amtsnr); + DODIVTAG(kommunenr); + DODIVTAG(regionnavn); + DODIVTAG(kommunenavn); + } + +private: + std::string *str; + std::vector<Praxisd::postnummer_t> ÷ +}; + +std::vector<Praxisd::postnummer_t> +Praxisd::diverse_get_postnummer(std::string sogenr) +{ + std::vector<Praxisd::postnummer_t> lst; + std::string xml = get_sogenr("P"+sogenr); + PostnummerParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class TypeParser : public SAXParser { +public: + TypeParser(std::vector<Praxisd::type_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_type") { + Praxisd::type_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(type); + DODIVTAG(bemaerkning1); + DODIVTAG(bemaerkning2); + DODIVTAG(bemaerkning3); + } + +private: + std::string *str; + std::vector<Praxisd::type_t> ÷ +}; + +std::vector<Praxisd::type_t> +Praxisd::diverse_get_type(std::string sogenr) +{ + std::vector<Praxisd::type_t> lst; + std::string xml = get_sogenr("T"+sogenr); + TypeParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class UndersoegelseParser : public SAXParser { +public: + UndersoegelseParser(std::vector<Praxisd::undersoegelse_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_undersoegelse") { + Praxisd::undersoegelse_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(kode); + DODIVTAG(undersoegelse); + DODIVTAG(udregning); + } + +private: + std::string *str; + std::vector<Praxisd::undersoegelse_t> ÷ +}; + +std::vector<Praxisd::undersoegelse_t> +Praxisd::diverse_get_undersoegelse(std::string sogenr) +{ + std::vector<Praxisd::undersoegelse_t> lst; + std::string xml = get_sogenr("U"+sogenr); + UndersoegelseParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + +class YdelseParser : public SAXParser { +public: + YdelseParser(std::vector<Praxisd::ydelse_t> &d) : div(d) + { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "div_ydelse") { + Praxisd::ydelse_t d; + if(attr.find("sogenr") != attr.end()) d.sogenr = attr["sogenr"]; + div.push_back(d); + } + DODIVTAG(nr); + DODIVTAG(gr1); + DODIVTAG(gr2); + DODIVTAG(privat); + DODIVTAG(journal1); + DODIVTAG(journal2); + DODIVTAG(moms); + } + +private: + std::string *str; + std::vector<Praxisd::ydelse_t> ÷ +}; + +std::vector<Praxisd::ydelse_t> +Praxisd::diverse_get_ydelse(std::string sogenr) +{ + std::vector<Praxisd::ydelse_t> lst; + std::string xml = get_sogenr("Y"+sogenr); + YdelseParser parser(lst); + parser.parse(xml.data(), xml.length()); + return lst; +} + + +class AftaleParser : public SAXParser { +public: + AftaleParser(std::vector<Praxisd::aftale_t> &a) : div(a) { str = NULL; } + void characterData(std::string &data) { if(str) *str += data; } + void endTag(std::string name) { str = NULL; } + void startTag(std::string name, std::map<std::string, std::string> attr) + { + if(name == "aftale") { + Praxisd::aftale_t a; + if(attr.find("date") != attr.end()) a.date = attr["date"]; + if(attr.find("calendar") != attr.end()) a.date = attr["calendar"]; + div.push_back(a); + } + DODIVTAG(cpr); + DODIVTAG(cref); + DODIVTAG(cmrk); + DODIVTAG(ctxt); + DODIVTAG(cres); + } + +private: + std::string *str; + std::vector<Praxisd::aftale_t> ÷ +}; +static std::string i2s(int i) { + char buf[32]; + snprintf(buf, sizeof(buf), "%d", i); + return buf; +} +std::vector<Praxisd::aftale_t> +Praxisd::aftale_get_all_by_date_and_calendar(int cal, int year, int month, + int day) +{ + std::vector<Praxisd::aftale_t> aft; + + std::string xml; + + std::string uri = host + "/praxisd/1.0/aftale/get_all_by_date_and_calendar?" + "calendar=" + i2s(cal) + "&year=" + i2s(year) + "&month=" + i2s(month) + + "&day=" + i2s(day); + curl_easy_setopt(ch, CURLOPT_URL, uri.c_str()); + + curl_easy_setopt(ch, CURLOPT_POST, 0L); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, &xml); + + CURLcode errornum = curl_easy_perform(ch); + if(errornum != CURLE_OK) { + printf("Ouch %d\n", errornum); + } + + AftaleParser parser(aft); + parser.parse(xml.data(), xml.length()); + + return aft; +} + +std::vector<Praxisd::aftale_t> Praxisd::aftale_get_all_by_cpr(std::string cpr) +{ + std::vector<Praxisd::aftale_t> aft; + + std::string xml; + + std::string uri = host + "/praxisd/1.0/aftale/get_all_by_cpr?cpr=" + cpr; + curl_easy_setopt(ch, CURLOPT_URL, uri.c_str()); + + curl_easy_setopt(ch, CURLOPT_POST, 0L); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, &xml); + + CURLcode errornum = curl_easy_perform(ch); + if(errornum != CURLE_OK) { + printf("Ouch %d\n", errornum); + } + + AftaleParser parser(aft); + parser.parse(xml.data(), xml.length()); + + return aft; +} + +bool Praxisd::authenticate(std::string user, std::string pass) +{ + std::string uri = host + "/praxisd/1.0/authenticate?user=" + user + "&pass=" + + pass; + curl_easy_setopt(ch, CURLOPT_URL, uri.c_str()); + + curl_easy_setopt(ch, CURLOPT_POST, 0L); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, NULL); + + CURLcode errornum = curl_easy_perform(ch); + if(errornum != CURLE_OK) { + return false; + } + + long code = 0; + errornum = curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &code); + if(code == 401) return false; + if(code == 200) return true; + + return false; // Don't interpret an error as successful login. +} + + #ifdef TEST_PRAXISD //deps: saxparser.cc debug.cc log.cc //cflags: $(CURL_CFLAGS) $(EXPAT_CFLAGS) -I.. diff --git a/server/src/praxisd.h b/server/src/praxisd.h index c0f6666..03029bb 100644 --- a/server/src/praxisd.h +++ b/server/src/praxisd.h @@ -91,13 +91,141 @@ public: } patient_t; patient_t patient_get_by_cpr(std::string cpr); -#if 0 // Get Diverse From Sogenr - typedef struct {} diverse_t; - std::vector<diverse_t> diverse_get_all_by_sogenr(std::string sogenr); + typedef struct { + std::string sogenr; + std::string edi_adresse; + std::string navn; + std::string att; + std::string gade; + std::string by; + std::string tlf; + std::string fax; + } adresse_t; + std::vector<adresse_t> diverse_get_adresse(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string kode; + std::string behandling; + std::string bemaerkning; + std::string udregning; + } behandling_t; + std::vector<behandling_t> diverse_get_behandling(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string cave; + std::string bemaerkning1; + std::string bemaerkning2; + std::string bemaerkning3; + } cave_t; + std::vector<cave_t> diverse_get_cave(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string kode; + std::string diagnose; + std::string bemaerkning; + } diagnose_t; + std::vector<diagnose_t> diverse_get_diagnose(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string frase1; + std::string frase2; + std::string frase3; + std::string frase4; + } frase_t; + std::vector<frase_t> diverse_get_frase(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string navn; + std::string bemaerkning; + } grafik_t; + std::vector<grafik_t> diverse_get_grafik(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string indholdstof; + std::string form1; + std::string form2; + std::string form3; + std::string form4; + } indholdstof_t; + std::vector<indholdstof_t> diverse_get_indholdstof(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string kode; + std::string klage; + std::string bemaerkning; + } klage_t; + std::vector<klage_t> diverse_get_klage(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string navn; + std::string bemaerkning; + } oversigt_t; + std::vector<oversigt_t> diverse_get_oversigt(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string postnummer; + std::string by_gade; + std::string kbh; + std::string amtsnr; + std::string kommunenr; + std::string regionnavn; + std::string kommunenavn; + } postnummer_t; + std::vector<postnummer_t> diverse_get_postnummer(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string type; + std::string bemaerkning1; + std::string bemaerkning2; + std::string bemaerkning3; + std::string recept; + } type_t; + std::vector<type_t> diverse_get_type(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string kode; + std::string undersoegelse; + std::string bemaerkning; + std::string udregning; + } undersoegelse_t; + std::vector<undersoegelse_t> diverse_get_undersoegelse(std::string sogenr); + + typedef struct { + std::string sogenr; + std::string nr; + std::string navn; + std::string gr1; + std::string gr2; + std::string privat; + std::string journal1; + std::string journal2; + std::string moms; + } ydelse_t; + std::vector<ydelse_t> diverse_get_ydelse(std::string sogenr); + // Get Aftale All by Date and Calendar - typedef struct {} aftale_t; + typedef struct { + std::string date; + std::string calendar; + std::string cpr; + std::string cref; + std::string cmrk; + std::string ctxt; + std::string cres; + } aftale_t; std::vector<aftale_t> aftale_get_all_by_date_and_calendar(int cal, int year, int month, int day); @@ -107,6 +235,7 @@ public: // Authenticate bool authenticate(std::string user, std::string pass); +#if 0 // Get Name by UserID std::string user_get_name_by_id(std::string user); @@ -134,6 +263,7 @@ public: // Delete File from Docmenu private: + std::string get_sogenr(std::string sogenr); CURL *ch; std::string host; }; |