Initial import
This commit is contained in:
@@ -0,0 +1,671 @@
|
||||
<?php
|
||||
class Destroystorage extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Destroystorage 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"];
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_where = "WHERE (T_SampleStorageDestroyDate BETWEEN CONCAT(?,' ','00:00:00') AND CONCAT(?,' ','23:59:59')) AND T_SampleStorageDestroyIsActive = 'Y'";
|
||||
$sql_param = array($start_date,$end_date);
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_samplestoragedestroy
|
||||
|
||||
$sql_where
|
||||
";
|
||||
//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("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_SampleStorageDestroyID as id,
|
||||
T_SampleStorageDestroyNumbering as trx_number,
|
||||
CONCAT(DATE_FORMAT(T_SampleStorageDestroyDate,'%d-%m-%Y'),' ',DATE_FORMAT(T_SampleStorageDestroyTime,'%H:%i') ) as trx_datetime,
|
||||
T_SampleStorageDestroyNote as trx_note,
|
||||
DATE_FORMAT(T_SampleStorageDestroyDate,'%d-%m-%Y') as xdate,
|
||||
DATE_FORMAT(T_SampleStorageDestroyTime,'%H:%i') as xtime,
|
||||
T_SampleStorageDestroyM_StaffID as trx_staffid,
|
||||
M_StaffName as trx_staffname,
|
||||
T_SampleStorageDestroySampleWeight as trx_sampleweight,
|
||||
'' as details,
|
||||
'' as detailnonsamples
|
||||
FROM t_samplestoragedestroy
|
||||
JOIN m_staff ON T_SampleStorageDestroyM_StaffID = M_StaffID
|
||||
$sql_where
|
||||
ORDER BY T_SampleStorageDestroyNumbering ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$query = " SELECT T_SampleStorageDestroyDetailID as id,
|
||||
T_SampleStorageDestroyDetailBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
T_SampleStorageDestroyDetailRowPosition as row,
|
||||
T_SampleStorageDestroyDetailColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(M_TitleName,' ',M_PatientName) as patientname, T_OrderSampleID as ordersampleid
|
||||
FROM t_samplestoragedestroy_detail
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDestroyDetailT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON T_SampleStorageDestroyDetailM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON T_SampleStorageDestroyDetailM_RackID = M_RackID
|
||||
WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = '{$v['id']}' AND T_SampleStorageDestroyDetailIsActive = 'Y'";
|
||||
$ddata = $this->db_onedev->query($query)->result();
|
||||
if($ddata){
|
||||
foreach($ddata as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$k]['details'] = $ddata;
|
||||
$query = " SELECT T_SampleStorageDestroyDetailNonSampleID as xid,
|
||||
T_SampleStorageDestroyDetailNonSampleM_NonSampleID as id,
|
||||
M_NonSampleName as name,
|
||||
T_SampleStorageDestroyDetailNonSampleWeight as weight
|
||||
FROM t_samplestoragedestroy_detailnonsample
|
||||
JOIN m_nonsample ON T_SampleStorageDestroyDetailNonSampleM_NonSampleID = M_NonSampleID
|
||||
WHERE
|
||||
T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = '{$v['id']}' AND T_SampleStorageDestroyDetailNonSampleIsActive = 'Y'";
|
||||
$ddatanonsample = $this->db_onedev->query($query)->result();
|
||||
$rows[$k]['detailnonsamples'] = $ddatanonsample;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$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['almaries'] = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['vendors'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
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' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} 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_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['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, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$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('SD') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestoragedestroy (
|
||||
T_SampleStorageDestroyNumbering,
|
||||
T_SampleStorageDestroyDate,
|
||||
T_SampleStorageDestroyTime,
|
||||
T_SampleStorageDestroySampleWeight,
|
||||
T_SampleStorageDestroyM_StaffID,
|
||||
T_SampleStorageDestroyNote,
|
||||
T_SampleStorageDestroyUserID,
|
||||
T_SampleStorageDestroyCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['sampleweight']}',
|
||||
'{$prm['staffid']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detail (
|
||||
T_SampleStorageDestroyDetailT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailT_OrderSampleID,
|
||||
T_SampleStorageDestroyDetailBarcode,
|
||||
T_SampleStorageDestroyDetailM_AlmariID,
|
||||
T_SampleStorageDestroyDetailM_RackID,
|
||||
T_SampleStorageDestroyDetailRowPosition,
|
||||
T_SampleStorageDestroyDetailColPosition,
|
||||
T_SampleStorageDestroyDetailUserID,
|
||||
T_SampleStorageDestroyDetailCreated
|
||||
)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if($prm['detailnonsamples']){
|
||||
foreach($prm['detailnonsamples'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detailnonsample (
|
||||
T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailNonSampleM_NonSampleID,
|
||||
T_SampleStorageDestroyDetailNonSampleWeight,
|
||||
T_SampleStorageDestroyDetailNonSampleUserID,
|
||||
T_SampleStorageDestroyDetailNonSampleCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['id']}',
|
||||
'{$v['weight']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetailnonsample = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CREATED.DESTROY',
|
||||
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 deletetrx(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$datarows = [];
|
||||
$query ="UPDATE t_samplestoragedestroy SET T_SampleStorageDestroyIsActive = 'N', T_SampleStorageDestroyUserID = '{$userid}'
|
||||
WHERE T_SampleStorageDestroyID = '{$prm['id']}'";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query);
|
||||
$last_id = $prm['id'];
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CANCEL.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function checkbarcode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$datarows = [];
|
||||
$query =" SELECT CONCAT(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;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = '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_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName 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_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,608 @@
|
||||
<?php
|
||||
class Emptystorage extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Emptystorage 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"];
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_where = "WHERE (T_SampleStorageEmptyDate BETWEEN CONCAT(?,' ','00:00:00') AND CONCAT(?,' ','23:59:59')) AND T_SampleStorageEmptyIsActive = 'Y'";
|
||||
$sql_param = array($start_date,$end_date);
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_samplestorageempty
|
||||
|
||||
$sql_where
|
||||
";
|
||||
//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("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_SampleStorageEmptyID as id,
|
||||
T_SampleStorageEmptyNumbering as trx_number,
|
||||
CONCAT(DATE_FORMAT(T_SampleStorageEmptyDate,'%d-%m-%Y'),' ',DATE_FORMAT(T_SampleStorageEmptyTime,'%H:%i') ) as trx_datetime,
|
||||
T_SampleStorageEmptyNote as trx_note,
|
||||
DATE_FORMAT(T_SampleStorageEmptyDate,'%d-%m-%Y') as xdate,
|
||||
DATE_FORMAT(T_SampleStorageEmptyTime,'%H:%i') as xtime,
|
||||
T_SampleStorageEmptyTransporter as trx_transporter,
|
||||
T_SampleStorageEmptyReffNumber as trx_reffnumber,
|
||||
'' as details
|
||||
FROM t_samplestorageempty
|
||||
$sql_where
|
||||
ORDER BY T_SampleStorageEmptyNumbering ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$query = " SELECT T_SampleStorageEmptyDetailID as xid,
|
||||
T_SampleStorageDestroyID as id,
|
||||
T_SampleStorageDestroyNumbering as numbering,
|
||||
T_SampleStorageDestroySampleWeight as sampleweight,
|
||||
SUM(T_SampleStorageDestroyDetailNonSampleWeight) as nonsampleweight
|
||||
FROM t_samplestorageemptydetail
|
||||
JOIN t_samplestoragedestroy ON T_SampleStorageEmptyDetailT_SampleStorageDestroyID = T_SampleStorageDestroyID
|
||||
JOIN t_samplestoragedestroy_detailnonsample ON T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = T_SampleStorageDestroyID AND
|
||||
T_SampleStorageDestroyDetailNonSampleIsActive = 'Y'
|
||||
WHERE T_SampleStorageEmptyDetailIsActive = 'Y' AND T_SampleStorageEmptyDetailT_SampleStorageEmptyID = {$v['id']}
|
||||
GROUP BY T_SampleStorageDestroyID";
|
||||
$ddata = $this->db_onedev->query($query)->result();
|
||||
|
||||
$rows[$k]['details'] = $ddata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getitems(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT T_SampleStorageDestroyID as id, T_SampleStorageDestroyNumbering as numbering,
|
||||
T_SampleStorageDestroySampleWeight as sampleweight,
|
||||
SUM(T_SampleStorageDestroyDetailNonSampleWeight) as nonsampleweight
|
||||
FROM t_samplestoragedestroy
|
||||
JOIN t_samplestoragedestroy_detailnonsample ON T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = T_SampleStorageDestroyID AND
|
||||
T_SampleStorageDestroyDetailNonSampleIsActive = 'Y'
|
||||
WHERE T_SampleStorageDestroyFlagEmpty = 'N' AND T_SampleStorageDestroyIsActive = 'Y'
|
||||
GROUP BY T_SampleStorageDestroyID
|
||||
";
|
||||
//echo $query;
|
||||
$rows['details'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
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' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} 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_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['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, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$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('SE') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestorageempty (
|
||||
T_SampleStorageEmptyNumbering,
|
||||
T_SampleStorageEmptyDate,
|
||||
T_SampleStorageEmptyTime,
|
||||
T_SampleStorageEmptyReffNumber,
|
||||
T_SampleStorageEmptyTransporter,
|
||||
T_SampleStorageEmptyNote,
|
||||
T_SampleStorageEmptyUserID,
|
||||
T_SampleStorageEmptyCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['reffnumber']}',
|
||||
'{$prm['transportername']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestorageemptydetail (
|
||||
T_SampleStorageEmptyDetailT_SampleStorageEmptyID,
|
||||
T_SampleStorageEmptyDetailT_SampleStorageDestroyID,
|
||||
T_SampleStorageEmptyDetailUserID,
|
||||
T_SampleStorageEmptyDetailCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['id']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestorageempty WHERE T_SampleStorageEmptyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestorageemptydetail WHERE T_SampleStorageEmptyDetailT_SampleStorageEmptyID = {$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.EMPTY',
|
||||
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 deletetrx(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$datarows = [];
|
||||
$query ="UPDATE t_samplestorageempty SET T_SampleStorageEmptyIsActive = 'N', T_SampleStorageEmptyUserID = '{$userid}'
|
||||
WHERE T_SampleStorageEmptyID = '{$prm['id']}'";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query);
|
||||
$last_id = $prm['id'];
|
||||
$sql = "SELECT * FROM t_samplestorageempty WHERE T_SampleStorageEmptyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestorageemptydetail WHERE T_SampleStorageEmptyDetailT_SampleStorageEmptyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$last_id = $prm['id'];
|
||||
$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(
|
||||
'CANCEL.EMPTY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function checkbarcode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$datarows = [];
|
||||
$query =" SELECT CONCAT(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;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = '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_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName 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_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
class Outstorage extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Outstorage 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"];
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_where = "WHERE (T_SampleStorageOutDate BETWEEN CONCAT(?,' ','00:00:00') AND CONCAT(?,' ','23:59:59')) AND T_SampleStorageOutIsActive = 'Y'";
|
||||
$sql_param = array($start_date,$end_date);
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_samplestorageout
|
||||
$sql_where
|
||||
";
|
||||
//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("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_SampleStorageOutID as id,
|
||||
T_SampleStorageOutNumbering as trx_number,
|
||||
CONCAT(DATE_FORMAT(T_SampleStorageOutDate,'%d-%m-%Y'),' ',DATE_FORMAT(T_SampleStorageOutTime,'%H:%i') ) as trx_datetime,
|
||||
T_SampleStorageOutNote as trx_note,
|
||||
DATE_FORMAT(T_SampleStorageOutDate,'%d-%m-%Y') as xdate,
|
||||
DATE_FORMAT(T_SampleStorageOutTime,'%H:%i') as xtime,
|
||||
'' as details
|
||||
FROM t_samplestorageout
|
||||
$sql_where
|
||||
ORDER BY T_SampleStorageOutNumbering ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$query = " SELECT T_SampleStorageOutDetailID as id,
|
||||
T_SampleStorageOutDetailBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
T_SampleStorageOutDetailRowPosition as row,
|
||||
T_SampleStorageOutDetailColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(M_TitleName,' ',M_PatientName) as patientname, T_OrderSampleID as ordersampleid
|
||||
FROM t_samplestorageout_detail
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageOutDetailT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON T_SampleStorageOutDetailM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON T_SampleStorageOutDetailM_RackID = M_RackID
|
||||
WHERE T_SampleStorageOutDetailT_SampleStorageOutID = '{$v['id']}' AND T_SampleStorageOutDetailIsActive = 'Y'";
|
||||
$ddata = $this->db_onedev->query($query)->result();
|
||||
if($ddata){
|
||||
foreach($ddata as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$k]['details'] = $ddata;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$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 getrackcontent(){
|
||||
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' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} 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_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['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, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$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('SX') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestorageout (
|
||||
T_SampleStorageOutNumbering,
|
||||
T_SampleStorageOutDate,
|
||||
T_SampleStorageOutTime,
|
||||
T_SampleStorageOutNote,
|
||||
T_SampleStorageOutUserID,
|
||||
T_SampleStorageOutCreated
|
||||
)
|
||||
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_samplestorageout_detail (
|
||||
T_SampleStorageOutDetailT_SampleStorageOutID,
|
||||
T_SampleStorageOutDetailT_OrderSampleID,
|
||||
T_SampleStorageOutDetailBarcode,
|
||||
T_SampleStorageOutDetailM_AlmariID,
|
||||
T_SampleStorageOutDetailM_RackID,
|
||||
T_SampleStorageOutDetailRowPosition,
|
||||
T_SampleStorageOutDetailColPosition,
|
||||
T_SampleStorageOutDetailUserID,
|
||||
T_SampleStorageOutDetailCreated
|
||||
)
|
||||
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_samplestorageout WHERE T_SampleStorageOutID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestorageout_detail WHERE T_SampleStorageOutDetailT_SampleStorageOutID = {$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.OUT',
|
||||
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(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;
|
||||
}
|
||||
|
||||
/*function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_samplestorage_detail ON T_SampleStorageDetailID = Summary_SampleStorageReffID
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDetailT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_SampleStorageDetailBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(M_TitleName,' ',M_PatientName) as patientname, T_SampleStorageDetailT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_samplestorage_detail ON T_SampleStorageDetailID = Summary_SampleStorageReffID
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDetailT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}*/
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
class Savestorage 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"];
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_where = "WHERE (T_SampleStorageDate BETWEEN CONCAT(?,' ','00:00:00') AND CONCAT(?,' ','23:59:59')) AND T_SampleStorageIsActive = 'Y'";
|
||||
$sql_param = array($start_date,$end_date);
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_samplestorage
|
||||
$sql_where
|
||||
";
|
||||
//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("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_SampleStorageID as id,
|
||||
T_SampleStorageNumbering as trx_number,
|
||||
CONCAT(DATE_FORMAT(T_SampleStorageDate,'%d-%m-%Y'),' ',DATE_FORMAT(T_SampleStorageTime,'%H:%i') ) as trx_datetime,
|
||||
T_SampleStorageNote as trx_note,
|
||||
DATE_FORMAT(T_SampleStorageDate,'%d-%m-%Y') as xdate,
|
||||
DATE_FORMAT(T_SampleStorageTime,'%H:%i') as xtime,
|
||||
'' as details
|
||||
FROM t_samplestorage
|
||||
$sql_where
|
||||
ORDER BY T_SampleStorageNumbering ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$query = " SELECT T_SampleStorageDetailID as id,
|
||||
T_SampleStorageDetailBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
T_SampleStorageDetailRowPosition as row,
|
||||
T_SampleStorageDetailColumnPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, T_OrderSampleID as ordersampleid
|
||||
FROM t_samplestorage_detail
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDetailT_OrderSampleID
|
||||
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
|
||||
JOIN m_almari ON T_SampleStorageDetailM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON T_SampleStorageDetailM_RackID = M_RackID
|
||||
WHERE T_SampleStorageDetailT_SampleStorageID = '{$v['id']}' AND T_SampleStorageDetailIsActive = 'Y'";
|
||||
$ddata = $this->db_onedev->query($query)->result();
|
||||
if($ddata){
|
||||
foreach($ddata as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$k]['details'] = $ddata;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user