Files
2026-04-15 15:24:12 +07:00

1127 lines
34 KiB
Plaintext

<?php
class Setup extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$status = isset($prm["status"]["id"])?$prm["status"]["id"]:'N';
$company = isset($prm["company"])?intval($prm["company"]):0;
// echo $norm;
$filter_company = '';
if($company > 0){
$filter_company = " AND McuOfflinePrepareM_CompanyID = {$company}";
}
$sql_where = "WHERE McuOfflinePrepareIsActive = 'Y' AND McuOfflinePrepareIsDownloaded = '{$status}' $filter_company";
$sql_param = array();
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = " SELECT count(*) as total
FROM mcu_offline_prepare
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_patient count", $this->db_onedev);
exit;
}
$sql = " SELECT mcu_offline_prepare.*, M_CompanyName,
DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as start_date,
DATE_FORMAT(McuOfflinePrepareEndDate, '%d.%m.%Y') as end_date,
McuOfflinePreparePromiseDate as promise_date,
McuOfflinePreparePromiseTime as promise_time,
McuOfflinePrepareDoctors as doctors,
McuOfflinePrepareMous as mous,
McuOfflinePrepareDeliveries as deliveries,
'' as allmous,
McuOfflinePrepareM_MouDefaultID as mou_default_id,
M_MouName as mou_default_name,
CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_default_name,
McuOfflinePrepareM_DoctorDefaultID as doctor_default_id,
'' as default_mou,
'' as default_doctor,
'' as default_doctor_address,
M_DoctorAddressID as doctor_address_id,
M_DoctorAddressNote as doctor_address_label,
M_DoctorAddressDescription as doctor_address_description,
'' as doctor_address,
'' as packets,
'' as tests
FROM mcu_offline_prepare
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID
JOIN m_doctor ON McuOfflinePrepareM_DoctorDefaultID = M_DoctorID
JOIN m_doctoraddress ON McuOfflinePrepareM_DoctorAddressDefaultID = M_DoctorAddressID
$sql_where
ORDER BY McuOfflinePrepareCode ASC
limit $number_limit offset $number_offset
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$v['doctors'] = preg_replace("/\\n/", "___n___", $v['doctors']);
$rows[$k]['doctors'] = json_decode($v['doctors']);
//print_r($v['doctors']);
$v['mous'] = preg_replace("/\\n/", "___n___", $v['mous']);
$rows[$k]['mous'] = json_decode($v['mous']);
$v['deliveries'] = preg_replace("/\\n/", "___n___", $v['deliveries']);
$rows[$k]['deliveries'] = json_decode($v['deliveries']);
$rows[$k]['default_mou'] = array('id'=>$v['mou_default_id'],'name'=>$v['mou_default_name']);
$rows[$k]['packets'] = array();
$rows[$k]['tests'] = array();
$join_test = '';
$filter_paket = "AND T_PacketSasCode IN ('')";
$filter_test = "AND T_TestSasCode IN ('')";
if($v['McuOfflinePrepareTests'] != ''){
$xjoin_tests = explode(',',$v['McuOfflinePrepareTests']);
//print_r($xjoin_tests);
if($xjoin_tests){
foreach($xjoin_tests as $kjt => $vjt){
if($join_test != '')
$join_test .= ",";
$join_test .= "'{$vjt}'";
}
}
//echo $join_test;
$filter_paket = "AND T_PacketSasCode IN ({$join_test})";
$filter_test = "AND T_TestSasCode IN ({$join_test}) ";
}
$sql = "SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID = {$v['mou_default_id']} AND is_packet = 'Y' $filter_paket";
//echo $sql;
$rows[$k]['packets'] = $this->db_onedev->query($sql)->result_array();
if($rows[$k]['packets']){
foreach($rows[$k]['packets'] as $kp => $vp){
$rows[$k]['packets'][$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$sql = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
FROM ss_price_mou
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID = {$v['mou_default_id']} AND is_packet = 'N' AND
T_PriceIsCito = 'N' $filter_test";
//echo $sql;
$rows[$k]['tests'] = $this->db_onedev->query($sql)->result_array();
if($rows[$k]['tests']){
foreach($rows[$k]['tests'] as $kp => $vp){
$rows[$k]['tests'][$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$sql = "SELECT M_MouID as id, M_MouName as name
FROM m_mou
WHERE
M_MouM_CompanyID = {$v['McuOfflinePrepareM_CompanyID']} AND
( '{$v['McuOfflinePrepareStartDate']}' >= M_MouStartDate) AND
( '{$v['McuOfflinePrepareEndDate']}' <= M_MouEndDate ) AND
M_MouIsActive = 'Y' AND M_MouIsReleased = 'Y'";
//echo $sql;
$rows[$k]['allmous'] = $this->db_onedev->query($sql)->result_array();
$rows[$k]['default_doctor_address'] = array('id'=>$v['doctor_address_id'],'label'=>$v['doctor_address_label'],'description'=>$v['doctor_address_description']);
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressNote as label, M_DoctorAddressDescription as description FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['doctor_default_id']} AND M_DoctorAddressIsActive = 'Y'";
//echo $sql;
$rows[$k]['doctor_address'] = $this->db_onedev->query($sql)->result_array();
$rows[$k]['default_doctor'] = array('id'=>$v['doctor_default_id'],'name'=>$v['doctor_default_name'],'xaddress'=>$rows[$k]['doctor_address']);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function getdatapackets(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "SELECT count(*) as total
FROM (
SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') )
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$query ="
SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') )
ORDER BY T_PacketSasCode ASC
limit $number_limit offset $number_offset
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if($rows){
foreach($rows as $kp => $vp){
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$result = array(
"total" => $tot_page ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdatatests(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "SELECT count(*) as total
FROM (
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
FROM ss_price_mou
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
T_PriceIsCito = 'N'
GROUP BY Ss_PriceMouID
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$query ="
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
FROM ss_price_mou
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND is_packet = 'N'
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
T_PriceIsCito = 'N'
GROUP BY Ss_PriceMouID
ORDER BY T_TestSasCode ASC
limit $number_limit offset $number_offset
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if($rows){
foreach($rows as $kp => $vp){
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$result = array(
"total" => $tot_page ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getmou(){
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
//$prm['start_date'] = strtotime($prm['start_date']);
//$prm['end_date'] = strtotime($prm['end_date']);
$query =" SELECT M_MouID as id, M_MouName as name, M_MouNumber as code
FROM m_mou
WHERE
M_MouM_CompanyID = {$prm['id']} AND
M_MouIsActive = 'Y' AND
( M_MouStartDate >= '{$prm['start_date']}' ) AND
('{$prm['end_date']}' <= M_MouEndDate ) AND
M_MouIsReleased = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdeliveries(){
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
//$prm['start_date'] = strtotime($prm['start_date']);
//$prm['end_date'] = strtotime($prm['end_date']);
$type = 'mou';
$sql = "SELECT * FROM m_mou WHERE M_MouID = {$id}";
$data_mou = $this->db_onedev->query($sql)->row_array();
$sql = " SELECT 0 as kelurahan,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
'' as description,
'N' as chex,
'' as note,
'origin' as typeform,
'patient' as type,
M_DeliveryTypeCode as delivery_code
FROM m_delivery
JOIN m_deliverytype ON M_DeliveryTypeCode = 'PICKUP' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
WHERE
M_DeliverySource = 'patient' AND M_DeliveryIsActive = 'Y'
UNION
SELECT M_CompanyM_KelurahanID as kelurahan,
M_CompanyID as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
CONCAT(M_CompanyAddress,' ',M_KelurahanName,', ',M_DistrictName,', ',M_CityName) as description,
'N' as chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_company
JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
JOIN m_kelurahan ON M_CompanyM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_CompanyID = {$data_mou['M_MouM_CompanyID']}
UNION
SELECT 0 as kelurahan,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
IFNULL(M_MouEmail,'Belum ada email agreement') as description,
IFNULL(M_MouEmailIsDefault,'N') as chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_mou
JOIN m_delivery ON M_DeliverySource = 'mou' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
WHERE
M_MouID = {$id}";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_title
WHERE
M_TitleIsActive = 'Y'
";
//echo $query;
$rows['titles'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM m_religion
WHERE
M_ReligionIsActive = 'Y'
";
//echo $query;
$rows['religions'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM m_idtype
WHERE
M_IdTypeIsActive = 'Y'
";
//echo $query;
$rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcity(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function searchcompany(){
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function filtersearchcompany(){
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
array_push($rows,array('id'=>0,'name'=>'Semua'));
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function searchdoctor(){
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_doctor
WHERE
M_DoctorName like ?
AND M_DoctorIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_DoctorID as id, CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name, '' as xaddress
FROM m_doctor
WHERE
CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) like '{$q['search']}'
AND M_DoctorIsActive = 'Y'
group by M_DoctorID
ORDER BY M_DoctorName ASC
LIMIT 20
";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressNote as label, M_DoctorAddressDescription as description FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'";
$rows[$k]['xaddress'] = $this->db_onedev->query($sql)->result();
}
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_onedev);
exit;
}
}
function savesetup(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$sdate = date('Y-m-d',strtotime($prm["startdate"]));
$edate = date('Y-m-d',strtotime($prm["enddate"]));
$promise_date = date('Y-m-d',strtotime($prm["promise_date"]));
$promise_time = date('H:i:s',strtotime($prm["promise_time"]));
$mous = json_encode($prm["mous"]);
$deliveries = json_encode($prm["deliveries"]);
$doctors = addslashes(str_replace('\n', '\\\n', json_encode($prm["doctors"])));
$packettests = array();
if(count($prm['selected_packets']) > 0){
foreach($prm['selected_packets'] as $kp => $vp){
array_push($packettests,$vp['code']);
}
}
if(count($prm['selected_tests']) > 0){
foreach($prm['selected_tests'] as $kt => $vt){
array_push($packettests,$vt['code']);
}
}
if(count($packettests) > 0){
$McuOfflinePrepareTests = join(',',$packettests);
}
if($prm["act"] == 'new'){
$query =" INSERT INTO mcu_offline_prepare(
McuOfflinePrepareStartDate,
McuOfflinePrepareEndDate,
McuOfflinePrepareM_CompanyID,
McuOfflinePrepareMous,
McuOfflinePrepareDoctors,
McuOfflinePrepareM_MouDefaultID,
McuOfflinePrepareM_DoctorDefaultID,
McuOfflinePrepareM_DoctorAddressDefaultID,
McuOfflinePreparePromiseDate,
McuOfflinePreparePromiseTime,
McuOfflinePrepareDeliveries,
McuOfflinePrepareTests,
McuOfflinePrepareUserID,
McuOfflinePrepareCreated
)
VALUES(
'{$sdate}',
'{$edate}',
{$prm["company"]["id"]},
'{$mous}',
'{$doctors}',
{$prm["default_mou"]["id"]},
{$prm["default_doctor"]["id"]},
{$prm["default_doctor_address"]["id"]},
'{$promise_date}',
'{$promise_time}',
'{$deliveries}',
'{$McuOfflinePrepareTests}',
{$userid},
NOW()
)
";
//echo $query;
$this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
}
else{
$query =" UPDATE mcu_offline_prepare SET
McuOfflinePrepareStartDate = '{$sdate}',
McuOfflinePrepareEndDate = '{$edate}',
McuOfflinePrepareM_CompanyID = {$prm["company"]["id"]},
McuOfflinePrepareMous = '{$mous}',
McuOfflinePrepareDeliveries = '{$deliveries}',
McuOfflinePrepareDoctors = '{$doctors}',
McuOfflinePreparePromiseDate = '{$promise_date}',
McuOfflinePreparePromiseTime = '{$promise_time}',
McuOfflinePrepareM_MouDefaultID = {$prm["default_mou"]["id"]},
McuOfflinePrepareM_DoctorDefaultID = {$prm["default_doctor"]["id"]},
McuOfflinePrepareM_DoctorAddressDefaultID = {$prm["default_doctor_address"]["id"]},
McuOfflinePrepareUserID = {$userid}
WHERE
McuOfflinePrepareID = {$prm["xid"]}
";
$this->db_onedev->query($query);
$last_id = $prm["xid"];
}
//echo $query;
$sql = "SELECT McuOfflinePrepareCode as xnumber FROM mcu_offline_prepare WHERE McuOfflinePrepareID = {$last_id}";
//echo $sql;
$row = $this->db_onedev->query($sql)->row_array();
$result = array(
"total" => 1 ,
"records" => $row,
);
$this->sys_ok($result);
exit;
}
function getdistrict(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_district
WHERE
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getkelurahan(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_kelurahan
WHERE
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientPrefix = '{$prm['M_PatientPrefix']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientSuffix = '{$prm['M_PatientSuffix']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientPOB = '{$prm['M_PatientPOB']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}',
M_PatientNIK = '{$prm['M_PatientNIK']}',
M_PatientJabatan = '{$prm['M_PatientJabatan']}',
M_PatientKedudukan = '{$prm['M_PatientKedudukan']}',
M_PatientPJ = '{$prm['M_PatientPJ']}',
M_PatientLocation = '{$prm['M_PatientLocation']}',
M_PatientJob = '{$prm['M_PatientJob']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.EDIT', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function newpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="INSERT INTO m_patient (
M_PatientM_TitleID,
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientDOB,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientEmail,
M_PatientPOB,
M_PatientHP,
M_PatientPhone,
M_PatientM_IdTypeID,
M_PatientIDNumber,
M_PatientNote,
M_PatientNIK,
M_PatientJabatan,
M_PatientKedudukan,
M_PatientPJ,
M_PatientLocation,
M_PatientJob,
M_PatientUserID
)
VALUES(
'{$prm['M_PatientM_TitleID']}',
'{$prm['M_PatientPrefix']}',
'{$prm['M_PatientName']}',
'{$prm['M_PatientSuffix']}',
'{$pdob}',
'{$prm['M_PatientM_SexID']}',
'{$prm['M_PatientM_ReligionID']}',
'{$prm['M_PatientEmail']}',
'{$prm['M_PatientPOB']}',
'{$prm['M_PatientHP']}',
'{$prm['M_PatientPhone']}',
'{$prm['M_PatientM_IdTypeID']}',
'{$prm['M_PatientIDNumber']}',
'{$prm['M_PatientNote']}',
'{$prm['M_PatientNIK']}',
'{$prm['M_PatientJabatan']}',
'{$prm['M_PatientKedudukan']}',
'{$prm['M_PatientPJ']}',
'{$prm['M_PatientLocation']}',
'{$prm['M_PatientJob']}',
$userid
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$ptn = $prm;
$ptn["M_PatientID"] = $last_id;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query ="UPDATE mcu_offline_prepare SET
McuOfflinePrepareIsActive = 'N'
WHERE
McuOfflinePrepareID = '{$prm['id']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT m_patientaddress.*,
M_KelurahanName,
M_DistrictID,
M_DistrictName,
M_CityID,
M_CityName,
'' as action
FROM m_patientaddress
JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
//echo $this->db_onedev->last_query();
if($count_addrs == 0){
$prm['M_PatientAddressNote'] = 'Utama';
}
else{
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
if($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama'){
$rx = date('YmdHis');
$prm['M_PatientAddressNote'] = 'Utama_'.$rx;
}
}
$query ="INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressNote,
M_PatientAddressDescription,
M_PatientAddressM_KelurahanID,
M_PatientAddressCreated
)
VALUES(
'{$prm['M_PatientAddressM_PatientID']}',
'{$prm['M_PatientAddressNote']}',
'{$prm['M_PatientAddressDescription']}',
'{$prm['M_PatientAddressM_KelurahanID']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function saveeditaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query ="UPDATE m_patientaddress SET
M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}',
M_PatientAddressNote = '{$prm['M_PatientAddressNote']}',
M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}',
M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}'
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deleteaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query ="UPDATE m_patientaddress SET
M_PatientAddressIsActive = 'N'
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
}