343 lines
11 KiB
PHP
343 lines
11 KiB
PHP
<?php
|
|
class Done extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "SampleStorage 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;
|
|
}
|
|
|
|
$start_date = $prm["startdate"];
|
|
$end_date = $prm["enddate"];
|
|
$search = $prm["search"];
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql_where = "WHERE (T_OrderHeaderDate BETWEEN CONCAT('{$start_date}',' ','00:00:00') AND CONCAT('{$end_date}',' ','23:59:59')) AND T_OrderHeaderIsActive = 'Y'";
|
|
if($search != ''){
|
|
$sql_where = "WHERE (T_OrderHeaderLabNumber LIKE '%{$search}%' OR M_PatientName LIKE '%{$search}%' ) AND T_OrderHeaderIsActive = 'Y'";
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM(
|
|
SELECT
|
|
T_OrderHeaderID,
|
|
fn_fo_verification_last_status(T_OrderHeaderID,3) as check_status,
|
|
fn_fo_verification_status_done(T_OrderHeaderID) as check_status_spv,
|
|
fn_check_so_sample(T_OrderHeaderID) as xcountsosampled
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN m_status ON Last_StatusM_StatusID = M_StatusID
|
|
LEFT JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressNote = 'utama'
|
|
LEFT JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
|
|
LEFT JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
|
LEFT JOIN m_city ON M_DistrictM_CityID = M_CityID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
JOIN m_doctoraddress ON T_OrderHeaderSenderM_DoctorAddressID = M_DoctorAddressID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
$sql_where
|
|
HAVING ( check_status > 0 OR check_status_spv > 0 ) AND xcountsosampled = 0
|
|
ORDER BY T_OrderHeaderID ASC
|
|
) x
|
|
";
|
|
//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("t_samplestorage count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_PatientNoReg,
|
|
fn_fo_verification_get_paid(T_OrderHeaderID) as paid,
|
|
T_OrderHeaderTotal,
|
|
M_MouIsBill,
|
|
IF(M_MouIsBill = 'N','Tidak ditagihkan','Ditagihkan') as texttagihan,
|
|
CONCAT(M_TitleName,' ',M_PatientName) as M_PatientName,
|
|
M_PatientHP,
|
|
T_OrderHeaderM_PatientAge,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
|
|
M_PatientAddressDescription as M_PatientAddress,
|
|
M_CityName as CityUtama,
|
|
M_PatientNote,
|
|
M_PatientHP,
|
|
M_DoctorHP,
|
|
T_OrderHeaderID as ohid,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderDate,
|
|
IF(M_StatusID = 2,'Baru',IF(M_StatusID = 3,'Verified','Ditolak')) as M_StatusName,
|
|
T_OrderHeaderID, M_SexName,
|
|
M_CompanyName,
|
|
T_OrderHeaderM_CompanyID,
|
|
T_OrderHeaderM_MouID,
|
|
CONCAT(M_MouName,' ( ',DATE_FORMAT(M_MouStartDate,'%d-%m-%Y') ,' s/d ' , DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'),' )') as mou,
|
|
M_DoctorName,
|
|
M_DoctorAddressDescription as M_DoctorAddress,
|
|
T_OrderHeaderVerificationNote as verification_note,
|
|
fn_fo_verification_last_status(T_OrderHeaderID,3) as check_status,
|
|
fn_fo_verification_status_done(T_OrderHeaderID) as check_status_spv,
|
|
T_OrderHeaderDate as orderdate,
|
|
fn_check_so_sample(T_OrderHeaderID) as xcountsosampled
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN m_status ON Last_StatusM_StatusID = M_StatusID
|
|
LEFT JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressNote = 'utama'
|
|
LEFT JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
|
|
LEFT JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
|
LEFT JOIN m_city ON M_DistrictM_CityID = M_CityID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
JOIN m_doctoraddress ON T_OrderHeaderSenderM_DoctorAddressID = M_DoctorAddressID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
$sql_where
|
|
HAVING ( check_status > 0 OR check_status_spv > 0 ) AND xcountsosampled = 0
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
//echo $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getalmaries(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$rows = [];
|
|
$query =" SELECT M_AlmariID as id, CONCAT('[ ',M_AlmariCode,' ] ', M_AlmariName) as name, M_AlmariCode as code
|
|
FROM m_almari
|
|
WHERE
|
|
M_AlmariIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getracks(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$rows = [];
|
|
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
|
FROM summary_samplestorage
|
|
WHERE
|
|
Summary_SampleStorageStatus = 'FILLED'
|
|
";
|
|
//echo $query;
|
|
$filledrows = $this->db_onedev->query($query)->result_array();
|
|
$query =" SELECT {$prm['id']} as almariid,
|
|
M_RackID as id,
|
|
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
|
M_RackCode as code,
|
|
M_RackRows as row,
|
|
M_RackColumns as col,
|
|
'' as rackcontens
|
|
FROM m_rack
|
|
WHERE
|
|
M_RackM_AlmariID = {$prm['id']} AND M_RackIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$datarows = $this->db_onedev->query($query)->result_array();
|
|
foreach($datarows as $k => $v){
|
|
$rows = $v['row'];
|
|
$cols = $v['col'];
|
|
$rackcontens = array();
|
|
for ($x = 1; $x <= $rows; $x++) {
|
|
$children = array();
|
|
for ($i = 1; $i <= $cols; $i++) {
|
|
$content = $x.' x '.$i;
|
|
$xrow = $x;
|
|
$xcol = $i;
|
|
$status = $this->checkexistfilled($filledrows, $v['id'],$xrow,$xcol);
|
|
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>'N'));
|
|
}
|
|
array_push($rackcontens,$children);
|
|
}
|
|
$datarows[$k]['rackcontens'] = $rackcontens;
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => count($datarows) ,
|
|
"records" => $datarows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
function checkexistfilled($datas,$rackid,$row,$col){
|
|
$rtn = 'N';
|
|
foreach($datas as $k => $v){
|
|
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
|
$rtn = 'Y';
|
|
}
|
|
}
|
|
return $rtn;
|
|
}
|
|
|
|
function save(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$numbering = $this->db_onedev->query("SELECT fn_numbering('SS') as numbering")->row()->numbering;
|
|
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
|
$query ="INSERT INTO t_samplestorage (
|
|
T_SampleStorageNumbering,
|
|
T_SampleStorageDate,
|
|
T_SampleStorageTime,
|
|
T_SampleStorageNote,
|
|
T_SampleStorageUserID,
|
|
T_SampleStorageCreated
|
|
)
|
|
VALUES(
|
|
'{$numbering}',
|
|
'{$xdate}',
|
|
'{$prm['time']}',
|
|
'{$prm['note']}',
|
|
'{$userid}',
|
|
NOW()
|
|
)
|
|
";
|
|
//echo $query;
|
|
$saveheader = $this->db_onedev->query($query);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
if($saveheader){
|
|
foreach($prm['details'] as $k => $v){
|
|
$query ="INSERT INTO t_samplestorage_detail (
|
|
T_SampleStorageDetailT_SampleStorageID,
|
|
T_SampleStorageDetailT_OrderSampleID,
|
|
T_SampleStorageDetailBarcode,
|
|
T_SampleStorageDetailM_AlmariID,
|
|
T_SampleStorageDetailM_RackID,
|
|
T_SampleStorageDetailRowPosition,
|
|
T_SampleStorageDetailColumnPosition,
|
|
T_SampleStorageDetailUserID,
|
|
T_SampleStorageDetailCreated
|
|
)
|
|
VALUES(
|
|
'{$last_id}',
|
|
'{$v['ordersampleid']}',
|
|
'{$v['barcode']}',
|
|
'{$v['almari']['id']}',
|
|
'{$v['rack']['id']}',
|
|
'{$v['row']}',
|
|
'{$v['col']}',
|
|
'{$userid}',
|
|
NOW()
|
|
)";
|
|
//echo $query;
|
|
$savedetail = $this->db_onedev->query($query);
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT * FROM t_samplestorage WHERE T_SampleStorageID = {$last_id}";
|
|
$data_log_header = $this->db_onedev->query($sql)->result();
|
|
$sql = "SELECT * FROM t_samplestorage_detail WHERE T_SampleStorageDetailT_SampleStorageID = {$last_id}";
|
|
$data_log_details = $this->db_onedev->query($sql)->result();
|
|
|
|
$data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details));
|
|
$sql = "INSERT INTO one_log.log_samplestorage (
|
|
Log_SampleStorageCode,
|
|
Log_SampleStorageDate,
|
|
Log_SampleStorageJSON,
|
|
Log_SampleStorageUserID
|
|
)
|
|
VALUES(
|
|
'CREATED.SAVE',
|
|
CURDATE(),
|
|
'{$data_log}',
|
|
{$userid}
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK'),
|
|
"numbering" => $numbering,
|
|
"id" => $last_id
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function checkbarcode(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$datarows = [];
|
|
$query =" SELECT CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, T_OrderSampleID
|
|
FROM t_ordersample
|
|
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
WHERE T_OrderSampleBarcode = '{$prm['barcode']}' AND T_OrderSampleIsActive = 'Y' ORDER BY T_OrderSampleID DESC LIMIT 1
|
|
";
|
|
//echo $query;
|
|
$datarows = $this->db_onedev->query($query)->row();
|
|
|
|
$result = array(
|
|
"total" => count($datarows) ,
|
|
"records" => $datarows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
} |