You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
5.9 KiB
209 lines
5.9 KiB
<?php |
|
ini_set("display_errors", 1); |
|
ini_set("display_startup_errors", 1); |
|
error_reporting(E_ALL); |
|
class Md extends MY_Controller |
|
{ |
|
function __construct() |
|
{ |
|
parent::__construct(); |
|
} |
|
function index() |
|
{ |
|
echo "Mitra:MD:API"; |
|
} |
|
function add() |
|
{ |
|
$param = $this->sys_input; |
|
print_r($param); |
|
} |
|
|
|
function corss() |
|
{ |
|
global $_SERVER; |
|
if (isset($_SERVER["HTTP_ORIGIN"])) { |
|
header("Access-Control-Allow-Origin:" . $_SERVER["HTTP_ORIGIN"]); |
|
} else { |
|
header("Access-Control-Allow-Origin: */*"); |
|
} |
|
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS"); |
|
header( |
|
"Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization" |
|
); |
|
if ( |
|
isset($_SERVER["REQUEST_METHOD"]) && |
|
$_SERVER["REQUEST_METHOD"] == "OPTIONS" |
|
) { |
|
http_response_code(200); |
|
echo json_encode("OK"); |
|
exit(); |
|
} |
|
} |
|
function search() |
|
{ |
|
$this->corss(); |
|
$sql = "select mitra.*, |
|
M_CompanyName, M_CompanyAddress, |
|
group_concat(concat(M_MouName,' [', date_format(M_MouEndDate,'%d/%m/%Y'),'] ') separator '^') aggrement |
|
from mitra |
|
join m_company |
|
on MitraM_CompanyID = M_CompanyID |
|
and MitraIsActive = 'Y' |
|
and ( |
|
MitraUsername like ? |
|
or M_CompanyName like ?) |
|
join mitra_mou |
|
on MitraID = MitraMouMitraID |
|
and MitraMouIsActive ='Y' |
|
join m_mou on MitraMouM_MouID = M_MouID |
|
group by MitraID "; |
|
$query = "%" . $this->sys_input["query"] . "%"; |
|
$qry = $this->db->query($sql, [$query, $query]); |
|
if (!$qry) { |
|
echo json_encode([ |
|
"status" => "ERR", |
|
"message" => $this->db->error()["message"], |
|
]); |
|
exit(); |
|
} |
|
echo json_encode(["status" => "OK", "data" => $qry->result_array()]); |
|
} |
|
function lookup_doctor() |
|
{ |
|
$param = $this->sys_input; |
|
$sql = "select M_DoctorID, fn_get_doctor_fullname(M_DoctorID) FullName |
|
from m_doctor |
|
where M_DoctorName like ? |
|
and M_DoctorIsActive = 'Y' |
|
limit 0,50"; |
|
$qry = $this->db->query($sql, ["%" . $param["query"] . "%"]); |
|
if (!$qry) { |
|
echo json_encode([ |
|
"status" => "ERR", |
|
"message" => $this->db->error()["message"], |
|
]); |
|
exit(); |
|
} |
|
echo json_encode(["status" => "OK", "data" => $qry->result_array()]); |
|
} |
|
|
|
function lookup_doctoraddress($doctorID) |
|
{ |
|
$param = $this->sys_input; |
|
$sql = "select M_DoctorAddressID,M_DoctorAddressDescription |
|
from m_doctoraddress |
|
where M_DoctorAddressM_DoctorID = ? |
|
and M_DoctorAddressIsActive = 'Y' |
|
limit 0,50"; |
|
$qry = $this->db->query($sql, [$doctorID]); |
|
if (!$qry) { |
|
echo json_encode([ |
|
"status" => "ERR", |
|
"message" => $this->db->error()["message"], |
|
]); |
|
exit(); |
|
} |
|
echo json_encode(["status" => "OK", "data" => $qry->result_array()]); |
|
} |
|
function lookup_company() |
|
{ |
|
$param = $this->sys_input; |
|
$sql = "select * from m_company |
|
where M_CompanyName like ? |
|
and M_CompanyIsActive = 'Y' |
|
limit 0,50"; |
|
$qry = $this->db->query($sql, ["%" . $param["query"] . "%"]); |
|
if (!$qry) { |
|
echo json_encode([ |
|
"status" => "ERR", |
|
"message" => $this->db->error()["message"], |
|
]); |
|
exit(); |
|
} |
|
echo json_encode(["status" => "OK", "data" => $qry->result_array()]); |
|
} |
|
function lookup_mou($companyID) |
|
{ |
|
$sql = "select |
|
* from m_mou |
|
where M_MouM_CompanyID = ? |
|
and M_MouIsReleased = 'Y' |
|
and M_MouIsActive ='Y'"; |
|
$qry = $this->db->query($sql, [$companyID]); |
|
if (!$qry) { |
|
echo json_encode([ |
|
"status" => "ERR", |
|
"message" => $this->db->error()["message"], |
|
]); |
|
exit(); |
|
} |
|
echo json_encode(["status" => "OK", "data" => $qry->result_array()]); |
|
} |
|
} |
|
/* |
|
drop table if exists mitra; |
|
create table mitra( |
|
MitraID int not null auto_increment primary key, |
|
MitraIDNo varchar(6), |
|
MitraUsername varchar(20), |
|
MitraPassword varchar(32), |
|
MitraM_CompanyID int, |
|
MitraIsActive varchar(1) default 'Y', |
|
MitraCommitment text, |
|
MitraCreated datetime default current_timestamp(), |
|
MitraLastUpdated datetime default current_timestamp() on update current_timestamp(), |
|
MitraM_UserID int, |
|
MitraIsHold varchar(1) default 'N', |
|
MitraHoldDate datetime default current_timestamp(), |
|
MitraHoldM_UserID int, |
|
unique(MitraIDNo,MitraUsername), |
|
key(MitraIsActive), |
|
key(MitraIsHold), |
|
key(MitraM_CompanyID) |
|
); |
|
create table mitra_mou( |
|
MitraMouID int not null auto_increment primary key, |
|
MitraMouMitraID int, |
|
MitraMouM_MouID int, |
|
MitraMouIsActive varchar(1) default 'Y', |
|
MitraMouCreated datetime default current_timestamp(), |
|
MitraMouLastUpdated datetime default current_timestamp() on update current_timestamp(), |
|
MitraMouM_UserID int, |
|
key (MitraMouM_MouID), |
|
key (MitraMouIsActive) |
|
); |
|
delimiter ;; |
|
drop function if exists fn_generate_mitra_id;; |
|
create function fn_generate_mitra_id ( |
|
) returns varchar(6) |
|
reads sql data |
|
begin |
|
set @branchCode = null; |
|
select M_BranchCode into @branchCode |
|
from m_branch |
|
where M_BranchIsDefault = 'Y' and M_BranchIsActive = 'Y'; |
|
if @branchCode is null then |
|
return "ERR.BR"; |
|
end if; |
|
set @counter =0; |
|
check_id: loop |
|
set @sec_key = null; |
|
select concat(@branchCode,substring('ACDEFGHJKLMNPQRSTUVWXYZ235679', rand()*29+1, 1), |
|
substring('ACDEFGHJKLMNPQRSTUVWXYZ235679', rand()*29+1, 1), |
|
substring('ACDEFGHJKLMNPQRSTUVWXYZ235679', rand()*29+1, 1), |
|
substring('ACDEFGHJKLMNPQRSTUVWXYZ235679', rand()*29+1, 1) |
|
) into @sec_key; |
|
return @sec_key; |
|
set @tot_sec = null; |
|
select count(*) into @tot_sec |
|
from mitra where MitraIDNo = @sec_key; |
|
if @tot_sec = 0 and length(@sec_key) <> 6 then |
|
return @sec_key; |
|
end if; |
|
if @counter > 10 then |
|
return "ERR.DUP"; |
|
end if; |
|
set @counter = @counter+1; |
|
end loop; |
|
end;; |
|
*/
|
|
|