203 lines
7.9 KiB
PHP
203 lines
7.9 KiB
PHP
<?php
|
|
class Distribution extends MY_Controller {
|
|
|
|
var $db_onedev;
|
|
// var $db_inventory;
|
|
// var $db_inventory_log;
|
|
var $db;
|
|
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
// search
|
|
function search()
|
|
{
|
|
try {
|
|
/*if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
*/
|
|
$prm = $this->sys_input;
|
|
$where = "WHERE Bb_BloodRequestOrderHeaderIsActive = 'Y'";
|
|
$search = "";
|
|
|
|
if(isset($prm['start_date']) && isset($prm['end_date'])){
|
|
$start_date = date('Y-m-d', strtotime($prm['start_date']));
|
|
$end_date = date('Y-m-d', strtotime($prm['end_date']));
|
|
|
|
$where .= " AND (DATE_FORMAT(Bb_BloodRequestOrderHeaderRequestDate,'%Y-%m-%d') >= '$start_date'
|
|
AND DATE_FORMAT(Bb_BloodRequestOrderHeaderRequestDate,'%Y-%m-%d') <= '$end_date') ";
|
|
}
|
|
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
$where .= "AND (
|
|
Bb_BloodRequestOrderHeaderReqNumber like '$search'
|
|
OR Bb_BloodRequestOrderHeaderM_PatientName like '$search'
|
|
)
|
|
";
|
|
}
|
|
}
|
|
|
|
$all = $prm['all'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
|
|
// sort
|
|
$sortBy = $prm['sortBy'];
|
|
$sortStatus = $prm['sortStatus'];
|
|
$q_sort = '';
|
|
if($sortBy){
|
|
$q_sort = "ORDER BY ".$sortBy." ".$sortStatus;
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
// $number_limit = 2;
|
|
if($prm['current_page'] > 0) {
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
}
|
|
|
|
$count = "SELECT count(Bb_DistributionID) as total
|
|
from one_bb.bb_bloodrequest_orderheader
|
|
left join one_bb.bb_distribution ON Bb_DistributionBb_OrderHeaderID = Bb_BloodRequestOrderHeaderID AND Bb_DistributionIsActive = 'Y'
|
|
left join one_bb.bb_distributiondetail ON Bb_DistributionDetailBb_DistributionID = Bb_DistributionID AND Bb_DistributionDetailIsActive = 'Y'
|
|
left join one_bb.bb_bloodentry ON Bb_BloodEntryID = Bb_DistributionDetailBb_BloodEntryID AND Bb_BloodEntryIsActive = 'Y'
|
|
join one_bb.td_bloodtype ON Td_BloodTypeID = Bb_BloodRequestOrderHeaderTd_BloodTypeID
|
|
join one_bb.td_bloodrhesus ON Td_BloodRhesusID = Bb_BloodRequestOrderHeaderTd_BloodRhesusID
|
|
$where";
|
|
|
|
$qry_total_filter = $this->db->query($count);
|
|
|
|
if(!$qry_total_filter){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("select count distribution");
|
|
exit;
|
|
}
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
$tot_count = $qry_total_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
|
|
$sql_select_data = "SELECT
|
|
Bb_BloodRequestOrderHeaderID as id,
|
|
Bb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestOrderHeaderRequestDate,
|
|
Bb_BloodRequestOrderHeaderReqNumber,
|
|
Bb_BloodRequestOrderHeaderM_PatientID,
|
|
Bb_BloodRequestOrderHeaderM_PatientName,
|
|
Bb_BloodRequestOrderHeaderTd_BloodTypeID,
|
|
Td_BloodTypeID,
|
|
Td_BloodTypeName,
|
|
Bb_BloodRequestOrderHeaderTd_BloodRhesusID,
|
|
Td_BloodRhesusID,
|
|
Td_BloodRhesusName,
|
|
Bb_BloodRequestOrderHeaderDateNeeded,
|
|
DATE_FORMAT(Bb_BloodRequestOrderHeaderDateNeeded,'%d-%m-%Y') as tanggal_needed,
|
|
Bb_BloodRequestOrderHeaderRoom,
|
|
Bb_BloodRequestOrderHeaderDoctor,
|
|
Bb_BloodRequestOrderHeaderTypePatient,
|
|
Bb_BloodRequestOrderHeaderDiagnosa,
|
|
Bb_DistributionID,
|
|
Bb_DistributionNumber,
|
|
Bb_DistributionOfficerName,
|
|
Bb_DistributionDate,
|
|
DATE_FORMAT(Bb_DistributionDate,'%d-%m-%Y') as tanggal_distribusi,
|
|
|
|
|
|
'' as order_detail
|
|
from one_bb.bb_bloodrequest_orderheader
|
|
left join one_bb.bb_distribution ON Bb_DistributionBb_OrderHeaderID = Bb_BloodRequestOrderHeaderID AND Bb_DistributionIsActive = 'Y'
|
|
left join one_bb.bb_distributiondetail ON Bb_DistributionDetailBb_DistributionID = Bb_DistributionID AND Bb_DistributionDetailIsActive = 'Y'
|
|
left join one_bb.bb_bloodentry ON Bb_BloodEntryID = Bb_DistributionDetailBb_BloodEntryID AND Bb_BloodEntryIsActive = 'Y'
|
|
join one_bb.td_bloodtype ON Td_BloodTypeID = Bb_BloodRequestOrderHeaderTd_BloodTypeID
|
|
join one_bb.td_bloodrhesus ON Td_BloodRhesusID = Bb_BloodRequestOrderHeaderTd_BloodRhesusID
|
|
$where
|
|
$q_sort
|
|
limit ? offset ?";
|
|
|
|
$qry_data = $this->db->query($sql_select_data,[
|
|
$number_limit,
|
|
$number_offset
|
|
]);
|
|
|
|
// print_r( $this->db->last_query());
|
|
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if(!$qry_data){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("select order header blood request");
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry_data->result_array();
|
|
|
|
// if(count($rows) > 0){
|
|
/* if(!empty($rows)){
|
|
foreach($rows as $key => $value){
|
|
$sql = "SELECT Bb_BloodRequestOrderDetailID,
|
|
Bb_BloodRequestOrderDetailTd_BloodCategoryID,
|
|
Td_BloodCategoryName,
|
|
Bb_BloodRequestOrderDetailAmountBag
|
|
from one_bb.bb_bloodrequest_orderdetail
|
|
JOIN one_bb.td_bloodcategory
|
|
ON Bb_BloodRequestOrderDetailTd_BloodCategoryID = Td_BloodCategoryID
|
|
AND Td_BloodCategoryIsActive = 'Y'
|
|
Where
|
|
Bb_BloodRequestOrderDetailIsActive = 'Y'
|
|
AND Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = ?
|
|
";
|
|
|
|
$qry = $this->db->query($sql, array($value['Bb_BloodRequestOrderHeaderID']));
|
|
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("select order header blood request");
|
|
exit;
|
|
}
|
|
|
|
$detail = $qry->result_array();
|
|
$rows[$key]['order_detail'] = $detail;
|
|
}
|
|
}
|
|
*/
|
|
// else{
|
|
// $rows[0]['order_detail'] = [];
|
|
// }
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"total_filter" => count($rows),
|
|
// "total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
'sql'=> $last_qry,
|
|
'q_sort'=> $q_sort,
|
|
'param' => $prm
|
|
// "qry_data" => $last_qry
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|