|
|
|
<?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 delete()
|
|
|
|
{
|
|
|
|
$param = $this->sys_input;
|
|
|
|
$user = $this->sys_user;
|
|
|
|
$userID = $user["M_UserID"];
|
|
|
|
|
|
|
|
$this->db->trans_begin();
|
|
|
|
|
|
|
|
$sql = "update mitra
|
|
|
|
set MitraIsActive = 'Y',
|
|
|
|
MitraM_UserID=?
|
|
|
|
where MitraID = ?";
|
|
|
|
$qry = $this->db->query($sql, [
|
|
|
|
$userID, $param["mitraID"]
|
|
|
|
]);
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$mitraID = $param["mitraID"];
|
|
|
|
$sql = "update mitra_mou set MitraMouIsActive ='N',
|
|
|
|
MitraMouM_UserID = ?
|
|
|
|
where
|
|
|
|
MitraMouMitraID = ? ";
|
|
|
|
$qry = $this->db->query($sql, [$userID, $param["mitraID"]]);
|
|
|
|
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->trans_commit();
|
|
|
|
echo json_encode(["status" => "OK"]);
|
|
|
|
}
|
|
|
|
function edit()
|
|
|
|
{
|
|
|
|
$param = $this->sys_input;
|
|
|
|
$user = $this->sys_user;
|
|
|
|
$userID = $user["M_UserID"];
|
|
|
|
|
|
|
|
$this->db->trans_begin();
|
|
|
|
|
|
|
|
if ($param["password"] == "") {
|
|
|
|
$sql = "update mitra
|
|
|
|
set MitraM_CompanyID=?, MitraM_DoctorID=?,
|
|
|
|
MitraM_DoctorAddressID=?,MitraUsername=?,
|
|
|
|
MitraM_UserID=?
|
|
|
|
where MitraID = ?";
|
|
|
|
$qry = $this->db->query($sql, [
|
|
|
|
$param["companyID"], $param["doctorID"],
|
|
|
|
$param["doctorAddressID"], $param["login"],
|
|
|
|
$userID, $param["mitraID"]
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$sql = "update mitra
|
|
|
|
set MitraM_CompanyID=?, MitraM_DoctorID=?,
|
|
|
|
MitraM_DoctorAddressID=?,MitraUsername=?,
|
|
|
|
MitraM_UserID=?, MitraPassword = md5(?)
|
|
|
|
where MitraID = ?";
|
|
|
|
$qry = $this->db->query($sql, [
|
|
|
|
$param["companyID"], $param["doctorID"],
|
|
|
|
$param["doctorAddressID"], $param["login"],
|
|
|
|
$userID, $param["password"], $param["mitraID"]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$mitraID = $param["mitraID"];
|
|
|
|
$s_mouID = implode(",", $param["mouID"]);
|
|
|
|
if ($s_mouID == "") {
|
|
|
|
$s_mouID = "0";
|
|
|
|
}
|
|
|
|
$sql = "update mitra_mou set MitraMouIsActive ='N' where
|
|
|
|
MitraMouMitraID = ? and MitraMouM_MouID not in ($s_mouID)";
|
|
|
|
$qry = $this->db->query($sql, [$param["mitraID"]]);
|
|
|
|
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$sql = "select * from mitra_mou where MitraMouMitraID =? and MitraMouIsActive ='Y'";
|
|
|
|
$qry = $this->db->query($sql, [$param["mitraID"]]);
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$rows_mouid = [];
|
|
|
|
foreach ($qry->result_array() as $r) {
|
|
|
|
$rows_mouid[] = $r["MitraMouM_MouID"];
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "insert into mitra_mou(MitraMouMitraID,MitraMouM_MouID,
|
|
|
|
MitraMouM_UserID)
|
|
|
|
values(?,?,?)";
|
|
|
|
|
|
|
|
foreach ($param["mouID"] as $mouID) {
|
|
|
|
if (in_array($mouID, $rows_mouid)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$qry = $this->db->query($sql, [$mitraID, $mouID, $userID]);
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
|
|
echo json_encode(["status" => "OK"]);
|
|
|
|
}
|
|
|
|
function add()
|
|
|
|
{
|
|
|
|
$param = $this->sys_input;
|
|
|
|
$user = $this->sys_user;
|
|
|
|
$userID = $user["M_UserID"];
|
|
|
|
|
|
|
|
$this->db->trans_begin();
|
|
|
|
$sql = "insert into mitra(MitraM_CompanyID, MitraM_DoctorID,
|
|
|
|
MitraM_DoctorAddressID,MitraUsername,
|
|
|
|
MitraPassword, MitraM_UserID,
|
|
|
|
MitraIDNo, MitraCommitment)
|
|
|
|
values(?,?, ?,?, ?,?, fn_generate_mitra_id(),'')";
|
|
|
|
$qry = $this->db->query($sql, [
|
|
|
|
$param["companyID"], $param["doctorID"],
|
|
|
|
$param["doctorAddressID"], $param["login"],
|
|
|
|
$param["password"], $userID
|
|
|
|
]);
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$mitraID = $this->db->insert_id();
|
|
|
|
$sql = "insert into mitra_mou(MitraMouMitraID,MitraMouM_MouID,
|
|
|
|
MitraMouM_UserID)
|
|
|
|
values(?,?,?)";
|
|
|
|
|
|
|
|
foreach ($param["mouID"] as $mouID) {
|
|
|
|
$qry = $this->db->query($sql, [$mitraID, $mouID, $userID]);
|
|
|
|
if (!$qry) {
|
|
|
|
echo json_encode([
|
|
|
|
"status" => "ERR",
|
|
|
|
"message" => $this->db->error()["message"],
|
|
|
|
]);
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
|
|
echo json_encode(["status" => "OK"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
group_concat(M_MouID separator ',') aggrementID,
|
|
|
|
M_DoctorName
|
|
|
|
from mitra
|
|
|
|
join m_company
|
|
|
|
on MitraM_CompanyID = M_CompanyID
|
|
|
|
and MitraIsActive = 'Y'
|
|
|
|
and (
|
|
|
|
MitraUsername like ?
|
|
|
|
or M_CompanyName like ?)
|
|
|
|
join m_doctor on MitraM_DoctorID = M_DoctorID
|
|
|
|
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,
|
|
|
|
MitraM_DoctorID int,
|
|
|
|
MitraM_DoctorAddressID int,
|
|
|
|
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;;
|
|
|
|
*/
|