432 lines
13 KiB
PHP
432 lines
13 KiB
PHP
<?php
|
|
/*
|
|
### Register API
|
|
- Functions
|
|
- login x
|
|
- logout
|
|
- search_patient x
|
|
- search_doctor x
|
|
- search_px x
|
|
- last_px x
|
|
- search_patient_type x
|
|
- search_delivery_type x
|
|
- do_register
|
|
- get_barcode
|
|
- update_barcode
|
|
|
|
template function {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
*/
|
|
|
|
class Register extends MY_Controller {
|
|
function index() {
|
|
echo "isLogin : {$this->isLogin} \n";
|
|
print_r($this->sys_input);
|
|
print_r($this->sys_user);
|
|
}
|
|
function last_test() {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$patientID = $prm["M_PatientID"];
|
|
$orderHeaderID = 0;
|
|
$sql = "select T_OrderHeaderID
|
|
from
|
|
t_orderheader
|
|
where
|
|
T_OrderHeaderM_PatientID = ? and T_OrderHeaderIsActive = 'Y'
|
|
order by T_OrderHeaderID desc
|
|
limit 0,1";
|
|
$query = $this->db->query($sql,array($patientID));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if (count($rows) > 0 ) $orderHeaderID = $rows[0]["T_OrderHeaderID"];
|
|
} else {
|
|
$this->sys_error_db("find last order");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($orderHeaderID > 0 ) {
|
|
$sql = "select T_TestID,T_TestName
|
|
from
|
|
t_orderdetail
|
|
join t_test on T_OrderDetailT_OrderHeaderID =? and
|
|
T_TestIsActive ='Y' and T_OrderDetailT_TestID = T_TestID
|
|
and T_TestIsPrice = 'Y' and T_OrderDetailIsActive='Y'";
|
|
$query = $this->db->query($sql,array($orderHeaderID));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("find last test");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array ("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_delivery_type() {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$s_query = "%" . $prm["query"] . "%";
|
|
$max = 25;
|
|
if (isset($prm["max_row"]) && $prm["max_row"] < $max ) $max = $prm["max_row"];
|
|
$tot_count = 0;
|
|
$sql_param = array($s_query);
|
|
$sql = "select count(*) as tot
|
|
from m_deliveryservice
|
|
where M_DeliveryServiceName like ? and M_DeliveryServiceIsActive='Y'";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["tot"];
|
|
} else {
|
|
$this->sys_error_db("delivery type count");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($tot_count > 0) {
|
|
$sql = "select *
|
|
from m_deliveryservice
|
|
where M_DeliveryServiceName like ? and M_DeliveryServiceIsActive='Y'
|
|
limit 0,$max";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("delivery type count");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array ("total" => $tot_count, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_patient_type() {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$s_query = "%" . $prm["query"] . "%";
|
|
$max = 25;
|
|
if (isset($prm["max_row"]) && $prm["max_row"] < $max ) $max = $prm["max_row"];
|
|
$tot_count = 0;
|
|
$sql_param = array($s_query);
|
|
$sql = "select count(*) as tot
|
|
from m_patienttype
|
|
where M_PatientTypeName like ? and M_PatientTypeIsActive='Y'";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["tot"];
|
|
} else {
|
|
$this->sys_error_db("test/panel count");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($tot_count > 0) {
|
|
$sql = "select *
|
|
from m_patienttype
|
|
where M_PatientTypeName like ? and M_PatientTypeIsActive='Y'
|
|
limit 0,$max";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("test/panel count");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array ("total" => $tot_count, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_test() {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$s_query = "%" . $prm["query"] . "%";
|
|
$max = 25;
|
|
if (isset($prm["max_row"]) && $prm["max_row"] < $max ) $max = $prm["max_row"];
|
|
//name
|
|
$sql = "select count(*) as tot
|
|
from
|
|
(
|
|
select T_TestID
|
|
from
|
|
t_test
|
|
where T_TestName like ? and T_TestIsActive = 'Y'
|
|
union
|
|
select T_TestPanelID
|
|
from
|
|
t_testpanel
|
|
where
|
|
T_TestPanelName like ? and T_TestPanelIsActive = 'Y'
|
|
) x
|
|
";
|
|
$tot_count = 0;
|
|
$sql_param = array($s_query, $s_query);
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["tot"];
|
|
} else {
|
|
$this->sys_error_db("test/panel count");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($tot_count > 0) {
|
|
$sql = "select *
|
|
from
|
|
(
|
|
select T_TestID X_ID, T_TestName X_Name, 'N' IsPanel , concat('\'',T_TestID,'\'') as A_Test
|
|
from
|
|
t_test
|
|
where T_TestName like ? and T_TestIsActive = 'Y'
|
|
union
|
|
select T_TestPanelID X_ID, T_TestPanelName X_Name, 'Y' IsPanel,
|
|
group_concat(T_TestPanelDetailT_TestID) as A_Test
|
|
from
|
|
t_testpanel
|
|
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
|
|
and T_TestPanelDetailIsActive = 'Y'
|
|
where
|
|
T_TestPanelName like ? and T_TestPanelIsActive = 'Y'
|
|
group by T_TestPanelID
|
|
) x
|
|
limit 0, $max
|
|
";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
foreach($rows as $idx => $r) {
|
|
$a_test = explode(",",$r["A_Test"]);
|
|
$rows[$idx]["A_Test"] = $a_test;
|
|
}
|
|
} else {
|
|
$this->sys_error_db("test/panel data");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array ("total" => $tot_count, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_doctor() {
|
|
$this->sys_debug();
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
//name+address+phone
|
|
$a_param = explode("+",$prm["query"]);
|
|
$sql_where = " M_DoctorIsActive='Y' ";
|
|
$sql_param = array();
|
|
foreach($a_param as $idx => $inp) {
|
|
if (trim($inp) == "") continue;
|
|
if ($sql_where != "") $sql_where .= " and ";
|
|
switch($idx) {
|
|
case 0 :
|
|
$sql_where .= " M_DoctorName like ? ";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
case 1 :
|
|
$sql_where .= " ( M_DoctorHomeAddress like ? or M_DoctorPracticeAddress like ? ) ";
|
|
$sql_param[] = "%$inp%";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
case 2 :
|
|
$sql_where .= " M_DoctorPhone like ? ";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
}
|
|
}
|
|
if ($sql_where != "" ) $sql_where = " where $sql_where";
|
|
$max = 25;
|
|
if (isset($prm["max_row"]) && $prm["max_row"] < $max ) $max = $prm["max_row"];
|
|
|
|
$sql = "select count(*) as tot from m_doctor $sql_where";
|
|
$tot_count = 0;
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["tot"];
|
|
} else {
|
|
$this->sys_error_db("search_doctor count");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($tot_count > 0) {
|
|
$sql = "select * from m_doctor $sql_where limit 0,$max";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("search_doctor data");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array ("total" => $tot_count, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_patient() {
|
|
// $this->sys_debug();
|
|
try {
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
//name+address+phone+dob(ddmmyy)
|
|
|
|
$a_param = explode("+",$prm["query"]);
|
|
$sql_where = " M_PatientIsActive='Y' ";
|
|
$sql_param = array();
|
|
foreach($a_param as $idx => $inp) {
|
|
if (trim($inp) == "") continue;
|
|
if ($sql_where != "") $sql_where .= " and ";
|
|
switch($idx) {
|
|
case 0 :
|
|
$sql_where .= " M_PatientName like ? ";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
case 1 :
|
|
$sql_where .= " M_PatientAddress like ? ";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
case 2 :
|
|
$sql_where .= " M_PatientPhone like ? ";
|
|
$sql_param[] = "%$inp%";
|
|
break;
|
|
case 3 :
|
|
$sql_where .= " M_PatientDOB like ? ";
|
|
//ddmmyy
|
|
if (strlen($inp) == 6) {
|
|
$year = substr($inp,4,2);
|
|
if ($year > 20) {
|
|
$year = "19$year";
|
|
} else {
|
|
$year = "20$year";
|
|
}
|
|
$dob = "$year-" . substr($inp,2,2) . "-" . substr($inp,0,2);
|
|
}
|
|
$sql_param[] = $dob;
|
|
break;
|
|
}
|
|
}
|
|
if ($sql_where != "" ) $sql_where = " where $sql_where";
|
|
$max = 25;
|
|
if (isset($prm["max_row"]) && $prm["max_row"] < $max ) $max = $prm["max_row"];
|
|
|
|
$sql = "select count(*) as tot from m_patient $sql_where";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
$tot_count = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["tot"];
|
|
} else {
|
|
$this->sys_error_db("search patient count");
|
|
exit;
|
|
}
|
|
$rows = array();
|
|
if ($tot_count > 0 ) {
|
|
$sql = "select * from m_patient $sql_where limit 0,$max";
|
|
$query = $this->db->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("search patient data");
|
|
exit;
|
|
}
|
|
}
|
|
$result = array("total" => $tot_count , "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function login() {
|
|
$prm = $this->sys_input;
|
|
try {
|
|
//existing password enc
|
|
$sm_password = md5($this->smartlab_salt . $prm["userPassword"] .
|
|
$this->smartlab_salt);
|
|
$query = $this->db->query("select M_UserID,M_UserUserName
|
|
from m_user
|
|
where M_UserUserName=? and M_UserPassword=?
|
|
and M_UserIsActive = 'Y'
|
|
",array($prm["userName"], $sm_password));
|
|
if (!$query) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$user = $rows[0];
|
|
$token = JWT::encode($user,$this->SECRET_KEY);
|
|
$data = array(
|
|
"user" => $user,
|
|
"token" => $token
|
|
);
|
|
$this->sys_ok($data);
|
|
exit;
|
|
}
|
|
$this->sys_error_db("Invalid UserName / Password");
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function logout() {
|
|
$this->sys_error("ok");
|
|
}
|
|
}
|
|
?>
|