diff options
author | deva <deva> | 2011-04-27 06:50:36 +0000 |
---|---|---|
committer | deva <deva> | 2011-04-27 06:50:36 +0000 |
commit | 21a45e2102d973a13a8c35da16abb50a28480f4b (patch) | |
tree | 2b4a5b62ef26fec38aa520049c1492b14358be57 /server/src/praxisd.cc | |
parent | eb91a2967ed18aa24166f13a635091e2193aecc0 (diff) |
Expand praxisd birdge.
Diffstat (limited to 'server/src/praxisd.cc')
-rw-r--r-- | server/src/praxisd.cc | 565 |
1 files changed, 565 insertions, 0 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.. |