Backend Service

This commit is contained in:
2019-03-17 21:05:52 +00:00
parent aea9090510
commit be67ec3729
5 changed files with 100 additions and 11 deletions
+1
View File
@@ -82,6 +82,7 @@ enum {
#define MERMS_USER_LOADPROFILE 120035
#define MERMS_USER_UPDATEPROFILE 120040
#define MERMS_USER_REMINDERS 120045
#define MERMS_USER_PRACTICES 120050
// //#define 120001
// //#define 120001
// //--
@@ -545,7 +545,62 @@ long getMemberReminders(CVars in, CVars &out) {
return ret;
}
/*
mermsemr_dev=> select p.id AS partient_id,p.added AS patient_added,p.long_id AS long_id, pra.* from patients p LEFT JOIN practice pra ON pra.id=p.practice_id WHERE p.member_id=3;
partient_id | patient_added | long_id | id | name | firstname | lastname | email | phone | username | password | added | loc | last_login | status
-------------+----------------------------+-------------+----+---------------------------+-----------+----------+--------------------------+------------+----------+----------------------------------+---------------------------+----------+------------+--------
3 | 2019-03-11 14:31:54.207198 | INT00000003 | 1 | University Hospital Space | Sanya | Ameye | ses66181+merms@gmail.com | 6784564356 | sameye | d0fbea2563b377ea7074bced45c88dcb | 2019-03-03 21:35:51.48451 | 10.0.0.1 | | 1
(1 row)
*/
long getMemberPractice(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM;
char vname[20];
try {
// REQ_LONG(in, "status", 0, -1);
REQ_LONG(in, "member_id", 0, -1);
out["total_record"] = "0";
const PGresult *res = pgsql_query("SELECT p.id AS patient_id,p.status AS patient_status, pra.* FROM patients p LEFT JOIN practice pra ON pra.id=p.practice_id WHERE p.member_id = %lu", in["member_id"].Long());
if (res != NULL && pgsql_num_rows(res) > 0) {
out["total_record"] = pgsql_num_rows(res);
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
if (f.empty()) continue;
CVars rec;
map_to_cvars(f, rec);
snprintf(vname, sizeof (vname), "id_%05d", i);
out[vname] = rec["id"];
snprintf(vname, sizeof (vname), "patient_id_%05d", i);
out[vname] = rec["patient_id"];
snprintf(vname, sizeof (vname), "name_%05d", i);
out[vname] = rec["name"];
snprintf(vname, sizeof (vname), "long_id_%05d", i);
out[vname] = rec["long_id"];
snprintf(vname, sizeof (vname), "patient_added_%05d", i);
out[vname] = rec["patient_added"];
snprintf(vname, sizeof (vname), "patient_status_%05d", i);
out[vname] = rec["patient_status"];
}
}
ret = PHP_API_OK;
out["status"] = "OK";
} catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL long getMemberPractice(CVars in, CVars &out)");
}
return ret;
}
//------------------------------------------------------
+6 -2
View File
@@ -25,7 +25,7 @@ Other Headers
long MemberReminders(CVars in, CVars &out);
long MemberProfile(CVars in, CVars &out);
long getMemberPractice(CVars in, CVars &out);
long members_call(CVars in, CVars &out) {
@@ -53,7 +53,11 @@ long members_call(CVars in, CVars &out) {
case MERMS_USER_UPDATEPROFILE:
return MemberProfile(in, out);
break;
case MERMS_USER_PRACTICES:
return getMemberPractice(in, out);
break;
}
logfmt(logINFO, "/members_call()");
return ret;
+2
View File
@@ -16,6 +16,8 @@ define('MERMS_USER_DASHLOAD', 120030);
define('MERMS_USER_LOADPROFILE', 120035);
define('MERMS_USER_UPDATEPROFILE', 120040);
define('MERMS_USER_REMINDERS', 120045);
define('MERMS_USER_PRACTICES', 120050);
//define('', 120001);
//define('', 120001);
+36 -9
View File
@@ -20,17 +20,18 @@ header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
$endpoints = array(
'createuser' => array('POST'),
'login' => array('POST'),
'userlogin' => array('POST'),
'getprofile' => array('POST'),
'createuser' => array('POST'),
'login' => array('POST'),
'userlogin' => array('POST'),
'getprofile' => array('POST'),
'setprofile' => array('POST'),
'userstask' => array('POST'),
'createtask' => array('POST'),
'deletetask' => array('POST')
'deletetask' => array('POST'),
'getpractice' => array('POST')
);
/*
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
@@ -101,7 +102,12 @@ switch ($endpoint) {
case 'deletetask':
$in["action"] = MERMS_USER_REMINDERS;
$in["task_mode"] = USER_DELETETASK;
break;
break;
case 'getpractice':
$in["action"] = MERMS_USER_PRACTICES;
$in["task_mode"] = MODE_GETVALUE;
break;
}
@@ -177,8 +183,29 @@ function processOutJson($in, $out) {
switch ($in["action"]) {
case 1000:
case MERMS_USER_PRACTICES:
if ( $in["task_mode"] == MODE_GETVALUE )
{
$total = $out["total_record"];
$res = array(
"status" => $out["status"],
"total_record" => ($total),
"internal_return" => $out["internal_return"],
"result_list" => array(),
);
for ($i = 0; $i < $total; $i++) {
$key = sprintf("%05d", $i);
$res["result_list"][] = array(
"id" => $out["id_${key}"],
"patient_id" => $out["patient_id_${key}"],
"name" => $out["name_${key}"],
"long_id" => $out["long_id_${key}"],
"patient_added" => $out["patient_added_${key}"],
"patient_status" => $out["patient_status_${key}"]
);
} // "request_id"
}
break;
case MERMS_USER_REMINDERS: