Files
REG_IBL/one-api/application/controllers/mockup/mcu/Mcu_preregister.php
2026-05-25 20:01:37 +07:00

1045 lines
31 KiB
PHP

<?php
class Mcu_preregister extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Samplingcall API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function searchcompany(){
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_city 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 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_company rows",$this->db_onedev);
exit;
}
}
function searchtest()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$orderdate = $prm['orderdate'];
$mouid = $prm['mouid'];
$companyid = $prm['companyid'];
$sql = "SELECT count(*) as total
FROM (
SELECT T_PriceT_TestID as id,
T_TestName as pxname,
'TS' as type
FROM t_price
JOIN t_test ON T_PriceT_TestID = T_TestID
JOIN m_mou ON M_MouID = T_PriceM_MouID
AND M_MouStartDate <= '$orderdate'
AND M_MouEndDate >= '$orderdate'
WHERE
T_PriceM_CompanyID = $companyid
AND T_PriceM_MouID = $mouid
AND T_TestName like '%{$prm['search']}%'
AND T_PriceIsActive = 'Y'
UNION
SELECT T_PacketID as id,
T_PacketName as pxname,
T_PacketType as type
FROM t_packet
JOIN m_mou ON M_MouID = T_PacketM_MouID
AND M_MouStartDate <= '$orderdate'
AND M_MouEndDate >= '$orderdate'
WHERE
T_PacketM_CompanyID = $companyid
AND T_PacketM_MouID = $mouid
AND T_PacketName like '%{$prm['search']}%'
AND T_PacketIsActive = 'Y'
) x";
//echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_onedev);
exit;
}
$sql = "
SELECT T_PriceT_TestID as id,
T_TestName as pxname,
'TS' as type
FROM t_price
JOIN t_test ON T_PriceT_TestID = T_TestID
JOIN m_mou ON M_MouID = T_PriceM_MouID
AND M_MouStartDate <= '$orderdate'
AND M_MouEndDate >= '$orderdate'
WHERE
T_PriceM_CompanyID = $companyid
AND T_PriceM_MouID = $mouid
AND T_TestName like '%{$prm['search']}%'
AND T_PriceIsActive = 'Y'
UNION
SELECT T_PacketID as id,
T_PacketName as pxname,
T_PacketType as type
FROM t_packet
JOIN m_mou ON M_MouID = T_PacketM_MouID
AND M_MouStartDate <= '$orderdate'
AND M_MouEndDate >= '$orderdate'
WHERE
T_PacketM_CompanyID = $companyid
AND T_PacketM_MouID = $mouid
AND T_PacketName like '%{$prm['search']}%'
AND T_PacketIsActive = 'Y'
";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
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 {
// echo $this->db_onedev->last_query();
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getsampletypes(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$stationid = $prm['stationid'];
$statusid = $prm['statusid'];
$sql = "SELECT T_OrderDetailID,
T_OrderDetailT_TestCode,
T_OrderDetailT_TestName,
T_SampleTypeID,
T_SampleTypeName,
T_BahanName,
IF(ISNULL(T_SamplingSoID),'N',T_SamplingSoFlag) as status,
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURDATE(),'%d-%m-%Y'),DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as process_date,
IF(ISNULL(T_SamplingSoID),DATE_FORMAT(CURTIME(),'%H:%i'),DATE_FORMAT(T_SamplingSoProcessTime,'%H:%i')) as process_time,
IF(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P',DATE_FORMAT(CURDATE(),'%d-%m-%Y'),DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as done_date,
IF(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P',DATE_FORMAT(CURTIME(),'%H:%i'),DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as done_time
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid}
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_SampleTypeID = T_SampleTypeID AND T_SamplingSoIsActive = 'Y'
WHERE
T_OrderHeaderID = {$orderid} AND T_OrderHeaderIsActive = 'Y'
GROUP BY T_SampleTypeID";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$filter_company_id = $prm["filter_company"]["id"];
// echo $norm;
$sql_where = "";
if($filter_company_id != 0 || $filter_company_id != '0')
$sql_where = " AND Mcu_AgreementCustomerM_CompanyID = {$filter_company_id}";
//$sql_param = array();
$sql = " SELECT count(*) as total
FROM mcu_preregister
JOIN mcu_agreement ON Mcu_PreregisterMcu_AgreementID = Mcu_AgreementID
JOIN mcu_agreement_customer ON Mcu_AgreementCustomerMcu_AgreementID = Mcu_AgreementID
JOIN m_company ON Mcu_AgreementCustomerM_CompanyID = M_CompanyID
JOIN m_mou ON Mcu_AgreementCustomerM_MouID = M_MouID
WHERE
Mcu_PreregisterIsActive = 'Y' $sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$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;
}
$sql = "SELECT Mcu_PreregisterID as trx_id,
DATE_FORMAT(Mcu_PreregisterDate,'%d-%m-%Y') as trx_date,
Mcu_PreregisterNumbering as trx_numbering,
mcu_preregister.*,
Mcu_AgreementID, Mcu_AgreementNumbering, DATE_FORMAT(Mcu_AgreementDate,'%d-%m-%Y') as agreement_date,
M_CompanyID, M_CompanyName, M_MouID, M_MouName, '' as tests
FROM mcu_preregister
JOIN mcu_agreement ON Mcu_PreregisterMcu_AgreementID = Mcu_AgreementID
JOIN mcu_agreement_customer ON Mcu_AgreementCustomerMcu_AgreementID = Mcu_AgreementID
JOIN m_company ON Mcu_AgreementCustomerM_CompanyID = M_CompanyID
JOIN m_mou ON Mcu_AgreementCustomerM_MouID = M_MouID
WHERE
Mcu_PreregisterIsActive = 'Y' $sql_where
limit 0,20";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
/*if($rows){
foreach($rows as $k => $v){
$query =" SELECT mcu_preregister_details.*, Mcu_PreregisterDetailsID as trx_id,
'N' as chx,
M_SexName as sexname, DATE_FORMAT(Mcu_PreregisterDetailsDOB,'%d-%m-%Y') as dob,
CONCAT(IFNULL(M_TitleName,''),' ',Mcu_PreregisterDetailsPatientName) as patientname,
'' as tests
FROM mcu_preregister_details
LEFT JOIN m_title ON Mcu_PreregisterDetailsM_TitleID = M_TitleID
JOIN m_sex ON Mcu_PreregisterDetailsM_SexID = M_SexID
JOIN m_religion ON Mcu_PreregisterDetailsM_ReligionID = M_ReligionID
WHERE
Mcu_PreregisterDetailsMcu_PreregisterID = '{$v['trx_id']}' AND Mcu_PreregisterDetailsIsActive = 'Y'
";
//echo $query;
$rows[$k]['details'] = $this->db_onedev->query($query)->result_array();
}
}*/
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchdetail(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$headerid = $prm["headerid"];
// echo $norm;
$sql_where = "";
if($prm['search'] != '')
$sql_where = " AND Mcu_PreregisterDetailsPatientName LIKE CONCAT('%','{$prm['search']}','%')";
//$sql_param = array();
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$chx = "'N' as chx";
if($prm['count_px'] > 0)
$chx = "'Y' as chx";
$sql = " SELECT count(*) as total
FROM mcu_preregister_details
LEFT JOIN m_title ON Mcu_PreregisterDetailsM_TitleID = M_TitleID
JOIN m_sex ON Mcu_PreregisterDetailsM_SexID = M_SexID
JOIN m_religion ON Mcu_PreregisterDetailsM_ReligionID = M_ReligionID
WHERE
Mcu_PreregisterDetailsMcu_PreregisterID = '{$headerid}' AND Mcu_PreregisterDetailsIsActive = 'Y' $sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$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;
}
$sql = "SELECT mcu_preregister_details.*, Mcu_PreregisterDetailsID as trx_id,
$chx,
M_SexName as sexname, DATE_FORMAT(Mcu_PreregisterDetailsDOB,'%d-%m-%Y') as dob,
CONCAT(IFNULL(M_TitleName,''),' ',Mcu_PreregisterDetailsPatientName) as patientname,
'' as tests,
Mcu_PreregisterDetailsFlagAction as flagaction
FROM mcu_preregister_details
LEFT JOIN m_title ON Mcu_PreregisterDetailsM_TitleID = M_TitleID
JOIN m_sex ON Mcu_PreregisterDetailsM_SexID = M_SexID
JOIN m_religion ON Mcu_PreregisterDetailsM_ReligionID = M_ReligionID
WHERE
Mcu_PreregisterDetailsMcu_PreregisterID = '{$headerid}' AND Mcu_PreregisterDetailsIsActive = 'Y' $sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$query ="SELECT T_TestID as id, T_TestName as name, 'TS' as type
FROM mcu_preregister_tests
JOIN t_test ON Mcu_PreregisterTestsReffID = T_TestID AND Mcu_PreregisterTestsType = 'TS'
WHERE
Mcu_PreregisterTestsMcu_PreregisterDetailsID = '{$v['trx_id']}' AND Mcu_PreregisterTestsIsActive = 'Y'
UNION
SELECT T_PacketID as id, T_PacketName as name, T_PacketType as type
FROM mcu_preregister_tests
JOIN t_packet ON Mcu_PreregisterTestsReffID = T_PacketID AND Mcu_PreregisterTestsType = T_PacketType
WHERE
Mcu_PreregisterTestsMcu_PreregisterDetailsID = '{$v['trx_id']}' AND Mcu_PreregisterTestsIsActive = 'Y'
";
//echo $query;
$rows[$k]['tests'] = $this->db_onedev->query($query)->result_array();
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function checkpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$tot_count = 1;
$rows = [];
$dob = date('Y-m-d',strtotime($prm['dob']));
$query =" SELECT m_patient.*, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
M_TitleName,
m_sexname,
M_ReligionName,
IFNULL(M_CompanyStaffPositionID,0) as M_CompanyStaffPositionID,
M_CompanyStaffPositionName
FROM m_patient
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID
LEFT JOIN m_companystaffposition ON M_PatientM_CompanyStaffPositionID = M_CompanyStaffPositionID
WHERE
M_PatientName = '{$prm['patientname']}' AND
M_PatientDOB = '{$dob}' AND
M_PatientIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function titsexreg(){
//# cek token valid
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['sexs'] = $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 M_CompanyStaffPositionID as id, M_CompanyStaffPositionName as name
FROM m_companystaffposition
WHERE
M_CompanyStaffPositionIsActive = 'Y'
";
//echo $query;
$rows['staffpositions'] = $this->db_onedev->query($query)->result_array();
$rows['staffpositions'][] = array('id'=>'0','name'=>'Semua Jabatan');
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y'
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
$rows['statuses'] = array(array('id'=>0,'name'=>'New'));
$query =" SELECT T_SamplingQueueStatusID as id, T_SamplingQueueStatusName as name
FROM t_sampling_queue_status
WHERE
T_SamplingCallStatusIsActive = 'Y'
";
//echo $query;
$statuses = $this->db_onedev->query($query)->result_array();
//print_r($statuses);
foreach($statuses as $k=>$v){
array_push($rows['statuses'],$v);
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getagreementtype(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT Mcu_AgreementTypeID as id, Mcu_AgreementTypeName as name
FROM mcu_agreementtype
WHERE
Mcu_AgreementTypeIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$companyid = $prm['company']['id'];
$query =" SELECT M_MouID as id, M_MouName as name
FROM m_mou
WHERE
M_MouM_CompanyID = $companyid AND M_MouIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function updateaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$patient = $prm['patient'];
$userid = $this->sys_user["M_UserID"];
$patientid = $patient['Mcu_PreregisterDetailsM_PatientID'];
$dob = date('Y-m-d',strtotime($patient['Mcu_PreregisterDetailsDOB']));
if($patient['Mcu_PreregisterDetailsM_PatientID'] == 0 || $patient['Mcu_PreregisterDetailsM_PatientID'] == '0' ){
$query = " INSERT INTO m_patient (
M_PatientName,
M_PatientM_TitleID,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientDOB,
M_PatientHP,
M_PatientPhone,
M_PatientEmail,
M_PatientM_CompanyStaffPositionID,
M_PatientCreated,
M_PatientUserID
)VALUES(
'{$patient['Mcu_PreregisterDetailsPatientName']}',
'{$patient['Mcu_PreregisterDetailsM_TitleID']}',
'{$patient['Mcu_PreregisterDetailsM_SexID']}',
'{$patient['Mcu_PreregisterDetailsM_ReligionID']}',
'{$dob}',
'{$patient['Mcu_PreregisterDetailsHP']}',
'{$patient['Mcu_PreregisterDetailsPhone']}',
'{$patient['Mcu_PreregisterDetailsEmail']}',
'{$patient['Mcu_PreregisterDetailsM_CompanyStaffPositionID']}',
'NOW()',
'{$userid}'
)";
$this->db_onedev->query($query);
//echo $query;
$patientid = $this->db_onedev->insert_id();
$sql = "SELECT m_company.*
FROM mcu_preregister_details
JOIN mcu_preregister ON Mcu_PreregisterDetailsMcu_PreregisterID = Mcu_PreregisterID
JOIN mcu_agreement_customer ON Mcu_AgreementCustomerMcu_AgreementID = Mcu_PreregisterMcu_AgreementID
JOIN m_company ON Mcu_AgreementCustomerM_CompanyID = M_CompanyID
WHERE
Mcu_PreregisterDetailsID = {$patient['trx_id']}";
//echo $sql;
$company = $this->db_onedev->query($sql)->row();
$sql = "INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressNote,
M_PatientAddressDescription,
M_PatientAddressM_KelurahanID,
M_PatientAddressCreated
)
VALUES(
{$patientid},
'Utama',
'{$company->M_CompanyAddress}',
'{$company->M_CompanyM_KelurahanID}',
NOW()
)";
$this->db_onedev->query($sql);
}
else{
$sql = "UPDATE m_patient SET
M_PatientName = '{$patient['Mcu_PreregisterDetailsPatientName']}',
M_PatientM_TitleID = '{$patient['Mcu_PreregisterDetailsM_TitleID']}',
M_PatientM_SexID = '{$patient['Mcu_PreregisterDetailsM_SexID']}',
M_PatientM_ReligionID = '{$patient['Mcu_PreregisterDetailsM_ReligionID']}',
M_PatientDOB = '{$dob}',
M_PatientHP = '{$patient['Mcu_PreregisterDetailsHP']}',
M_PatientPhone = '{$patient['Mcu_PreregisterDetailsPhone']}',
M_PatientEmail = '{$patient['Mcu_PreregisterDetailsEmail']}',
M_PatientM_CompanyStaffPositionID = '{$patient['Mcu_PreregisterDetailsM_CompanyStaffPositionID']}',
M_PatientUserID = '{$userid}'
WHERE
M_PatientID = {$patientid}
";
$this->db_onedev->query($sql);
}
$query =" UPDATE mcu_preregister_details SET
Mcu_PreregisterDetailsFlagAction = 'N',
Mcu_PreregisterDetailsByUserID = 0
WHERE
Mcu_PreregisterDetailsByUserID = '{$userid}'
";
//echo $query;
$this->db_onedev->query($query);
$query =" UPDATE mcu_preregister_details SET
Mcu_PreregisterDetailsFlagAction = 'R',
Mcu_PreregisterDetailsM_PatientID = '{$patientid}',
Mcu_PreregisterDetailsByUserID = '{$userid}'
WHERE
Mcu_PreregisterDetailsID = {$patient['trx_id']}
";
//echo $query;
$this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => $prm,
);
$this->sys_ok($result);
exit;
}
function getagreement(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$companyid = $prm['company']['id'];
$query =" SELECT Mcu_AgreementID as id, Mcu_AgreementNumbering as name
FROM mcu_agreement
JOIN mcu_agreement_customer ON Mcu_AgreementCustomerMcu_AgreementID = Mcu_AgreementID AND
Mcu_AgreementCustomerM_CompanyID = $companyid
WHERE
Mcu_AgreementIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savepreregister(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$header_id = $prm['trx_id'];
$numbering = '';
if($header_id == '0' || $header_id == 0){
$numbering = $this->db_onedev->query("SELECT fn_numbering('PREREG') as numbering")->row()->numbering;
$query = "INSERT INTO mcu_preregister(
Mcu_PreregisterNumbering,
Mcu_PreregisterDate,
Mcu_PreregisterMcu_AgreementID,
Mcu_PreregisterUserID,
Mcu_PreregisterCreated
) VALUES(
'{$numbering}',
'{$prm['trx_date']}',
'{$prm['agreement']['id']}',
'{$userid}',
NOW()
)";
$r = $this->db_onedev->query($query);
$header_id = $this->db_onedev->insert_id();
}
else{
$numbering = $this->db_onedev->query("SELECT Mcu_PreregisterNumbering as numbering FROM mcu_preregister WHERE Mcu_AgreementID = '{$header_id}'")->row()->numbering;
}
$rows['trx_id'] = $header_id;
$rows['numbering'] = $numbering;
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$header_id = $prm['header_id'];
$trx_patient_id = $prm['trx_patient_id'];
$dob = date('Y-m-d',strtotime($prm['dob']));
$jabatan = $prm['staff_position']['id'];
if($prm['new_staff_position'] != ''){
$sql = "INSERT INTO m_companystaffposition (
M_CompanyStaffPositionName,
M_CompanyStaffPositionUserID,
M_CompanyStaffPositionCreated
)
VALUES(
'{$prm['new_staff_position']}',
{$userid},
NOW()
)";
$this->db_onedev->query($sql);
$jabatan = $this->db_onedev->insert_id();
}
if($trx_patient_id == '0' || $trx_patient_id == 0){
//$numbering = $this->db_onedev->query("SELECT fn_numbering('PREREG') as numbering")->row()->numbering;
$query = "INSERT INTO mcu_preregister_details(
Mcu_PreregisterDetailsMcu_PreregisterID,
Mcu_PreregisterDetailsM_PatientID,
Mcu_PreregisterDetailsM_TitleID,
Mcu_PreregisterDetailsPatientName,
Mcu_PreregisterDetailsM_SexID,
Mcu_PreregisterDetailsDOB,
Mcu_PreregisterDetailsM_ReligionID,
Mcu_PreregisterDetailsPhone,
Mcu_PreregisterDetailsHP,
Mcu_PreregisterDetailsEmail,
Mcu_PreregisterDetailsM_CompanyStaffPositionID,
Mcu_PreregisterDetailsUserID,
Mcu_PreregisterDetailsCreated
) VALUES(
'{$header_id}',
'{$prm['patientid']}',
'{$prm['titleid']}',
'{$prm['patientname']}',
'{$prm['sexid']}',
'{$dob}',
'{$prm['religionid']}',
'{$prm['phone']}',
'{$prm['hp']}',
'{$prm['email']}',
{$jabatan},
'{$userid}',
NOW()
)";
//echo $query;
$r = $this->db_onedev->query($query);
//$new_id = $this->db_onedev->insert_id();
}
if($prm['patientid'] !== '0' || $prm['patientid'] !== 0){
$sql = "UPDATE m_patient SET
M_PatientName = '{$prm['patientname']}',
M_PatientM_TitleID = '{$prm['titleid']}',
M_PatientM_SexID = '{$prm['sexid']}',
M_PatientM_ReligionID = '{$prm['religionid']}',
M_PatientDOB = '{$dob}',
M_PatientHP = '{$prm['hp']}',
M_PatientPhone = '{$prm['phone']}',
M_PatientEmail = '{$prm['email']}',
M_PatientM_CompanyStaffPositionID = '{$jabatan}',
M_PatientUserID = '{$userid}'
WHERE
M_PatientID = {$prm['patientid']}
";
//echo $sql;
$this->db_onedev->query($sql);
}
$rows['trx_id'] = $header_id;
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savepatienttest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$header_id = $prm['header_id'];
$details = $prm['details'];
//print_r($details);
if($details){
foreach($details as $k => $v){
//print_r($v);
$trx_id = $v['trx_id'];
$tests = $v['tests'];
//echo $trx_id;
//print_r($test);
if($tests){
$sql = "UPDATE mcu_preregister_tests SET Mcu_PreregisterTestsIsActive = 'N' WHERE Mcu_PreregisterTestsMcu_PreregisterDetailsID = '{$trx_id}' ";
$this->db_onedev->query($sql);
//echo $sql;
foreach($tests as $key => $value){
$type = $value['type'];
$sql = "INSERT INTO mcu_preregister_tests (
Mcu_PreregisterTestsMcu_PreregisterDetailsID,
Mcu_PreregisterTestsReffID,
Mcu_PreregisterTestsType,
Mcu_PreregisterTestsUserID,
Mcu_PreregisterTestsCreated
)
VALUES (
{$trx_id},
{$value['id']},
'{$type}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Mcu_PreregisterTestsReffID = {$value['id']},
Mcu_PreregisterTestsType = '{$type}',
Mcu_PreregisterTestsIsActive = 'Y',
Mcu_PreregisterTestsUserID = '{$userid}';";
//echo $sql;
$save = $this->db_onedev->query($sql);
}
}
}
}
$row = array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$header_id = $prm['header_id'];
$patient = $prm['patient'];
$sql = "UPDATE mcu_preregister_details SET Mcu_PreregisterDetailsIsActive = 'N' WHERE Mcu_PreregisterDetailsID = '{$patient['trx_id']}'";
$this->db_onedev->query($sql);
//echo $sql;
$row = array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$next_status = $prm['statusnextid'];
if($prm['act'] == 'samplingprocess'){
$sql = "INSERT INTO t_samplingso (
T_SamplingSoT_OrderHeaderID,
T_SamplingSoT_SampleTypeID,
T_SamplingSoProcessDate,
T_SamplingSoProcessTime,
T_SamplingSoProcessUserID,
T_SamplingSoCreated,
T_SamplingSoUserID
)
VALUES(
{$prm['id']},
{$prm['sample']['T_SampleTypeID']},
CURDATE(),
CURTIME(),
{$userid},
NOW(),
{$userid}
) ON DUPLICATE KEY UPDATE
T_SamplingSoProcessDate = CURDATE(),
T_SamplingSoProcessTime = CURTIME(),
T_SamplingSoFlag = 'P',
T_SamplingSoIsActive = 'Y',
T_SamplingSoProcessUserID = {$userid},
T_SamplingSoUserID = {$userid}";
$this->db_onedev->query($sql);
}
if($prm['act'] == 'samplingdone'){
$sql = "INSERT INTO t_samplingso (
T_SamplingSoT_OrderHeaderID,
T_SamplingSoT_SampleTypeID,
T_SamplingSoDoneDate,
T_SamplingSoDoneTime,
T_SamplingSoDoneUserID,
T_SamplingSoCreated,
T_SamplingSoUserID
)
VALUES(
{$prm['id']},
{$prm['sample']['T_SampleTypeID']},
CURDATE(),
CURTIME(),
{$userid},
NOW(),
{$userid}
) ON DUPLICATE KEY UPDATE
T_SamplingSoDoneDate = CURDATE(),
T_SamplingSoDoneTime = CURTIME(),
T_SamplingSoFlag = 'D',
T_SamplingSoIsActive = 'Y',
T_SamplingSoDoneUserID = {$userid},
T_SamplingSoUserID = {$userid}";
$this->db_onedev->query($sql);
$sql = "SELECT count(*) as xcount
FROM (SELECT *
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
T_SamplingSoIsActive = 'Y'
WHERE
T_OrderHeaderID = {$prm['id']} AND T_SamplingSoT_SampleTypeID <> {$prm['sample']['T_SampleTypeID']} AND
(ISNULL(T_SamplingSoID) OR T_SamplingSoFlag = 'P') AND T_OrderHeaderIsActive = 'Y'
GROUP BY T_SampleTypeID ) xx";
//echo $sql;
$xcount = $this->db_onedev->query($sql)->row()->xcount;
if($xcount == 0){
$next_status = 5;
}
}
if($prm['act'] !== 'samplingprocess'){
$dt_json = json_encode(array('T_SampleStationID'=>$prm['stationid'],'T_OrderHeaderID'=>$prm['id'],'T_SamplingQueueStatusID'=>$next_status));
$query = "INSERT INTO one_log.log_sampling_queue (Log_SamplingQueueDate,Log_SamplingQueueJSON,Log_SamplingQueueUserID)
VALUES(NOW(),'{$dt_json}',{$userid})";
//echo $query;
$rows = $this->db_onedev->query($query);
$sql = "SELECT *
FROM t_sampling_queue_last_status
WHERE
T_SamplingQueueLastStatusT_SampleStationID = {$prm['stationid']} AND
T_SamplingQueueLastStatusT_OrderHeaderID = {$prm['id']} AND
T_SamplingQueueLastStatusIsActive = 'Y'";
$data_last = $this->db_onedev->query($sql)->row();
$query = "INSERT INTO t_sampling_queue_last_status (
T_SamplingQueueLastStatusT_SampleStationID,
T_SamplingQueueLastStatusT_OrderHeaderID,
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
T_SamplingQueueLastStatusUserID)
VALUES(
{$prm['stationid']},
{$prm['id']},
{$next_status},
{$userid}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = {$next_status}";
//echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
}