1062 lines
39 KiB
PHP
1062 lines
39 KiB
PHP
<?php
|
|
class Request 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);
|
|
$this->db_onex = "one_aditya";
|
|
$this->db_bb = "one_bb";
|
|
}
|
|
|
|
// 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 Td_BloodRhesusCode like '$search'
|
|
OR Td_BloodTypeCode 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_BloodRequestOrderHeaderID) as total
|
|
from $this->db_bb.bb_bloodrequest_orderheader
|
|
join $this->db_bb.td_bloodtype
|
|
ON Bb_BloodRequestOrderHeaderTd_BloodTypeID = Td_BloodTypeID
|
|
AND Td_BloodTypeIsActive = 'Y'
|
|
join $this->db_bb.td_bloodrhesus
|
|
ON Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Td_BloodRhesusID
|
|
AND Td_BloodRhesusIsActive = 'Y'
|
|
$where";
|
|
|
|
$qry_total_filter = $this->db->query($count);
|
|
|
|
if(!$qry_total_filter){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("select count order header blood request");
|
|
exit;
|
|
}
|
|
// $total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
// $tot_count = count($qry_filter->result_array()[0]["total"]);
|
|
$tot_count = $qry_total_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
|
|
$sql_select_data = "SELECT
|
|
Bb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestOrderHeaderID as id,
|
|
DATE_FORMAT(Bb_BloodRequestOrderHeaderRequestDate,'%d-%m-%Y') as Bb_BloodRequestOrderHeaderRequestDate,
|
|
Bb_BloodRequestOrderHeaderReqNumber,
|
|
Bb_BloodRequestOrderHeaderM_PatientID,
|
|
Bb_BloodRequestOrderHeaderTd_BloodTypeID,
|
|
Td_BloodTypeCode,
|
|
Td_BloodTypeName,
|
|
Bb_BloodRequestOrderHeaderTd_BloodRhesusID,
|
|
Td_BloodRhesusCode,
|
|
Td_BloodRhesusName,
|
|
DATE_FORMAT(Bb_BloodRequestOrderHeaderDateNeeded,'%Y-%m-%d') as Bb_BloodRequestOrderHeaderDateNeeded,
|
|
DATE_FORMAT(Bb_BloodRequestOrderHeaderDateNeeded,'%d-%m-%Y') as Bb_BloodRequestOrderHeaderDateNeeded_view,
|
|
Bb_BloodRequestOrderHeaderDiagnosa,
|
|
Bb_BloodRequestOrderHeaderTypePatient,
|
|
Bb_BloodRequestOrderHeaderRoom,
|
|
Bb_BloodRequestOrderHeaderDoctor,
|
|
'' as order_detail
|
|
from $this->db_bb.bb_bloodrequest_orderheader
|
|
join $this->db_bb.td_bloodtype
|
|
ON Bb_BloodRequestOrderHeaderTd_BloodTypeID = Td_BloodTypeID
|
|
AND Td_BloodTypeIsActive = 'Y'
|
|
join $this->db_bb.td_bloodrhesus
|
|
ON Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Td_BloodRhesusID
|
|
AND Td_BloodRhesusIsActive = 'Y'
|
|
$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 $this->db_bb.bb_bloodrequest_orderdetail
|
|
JOIN $this->db_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);
|
|
}
|
|
}
|
|
|
|
// blood type
|
|
function get_blood_type()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodTypeID, Td_BloodTypeCode, Td_BloodTypeName
|
|
FROM $this->db_bb.td_bloodtype
|
|
where Td_BloodTypeIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(Td_BloodTypeID) as total
|
|
FROM $this->db_bb.td_bloodtype
|
|
where Td_BloodTypeIsActive = 'Y' ";
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// blood category
|
|
function get_blood_category()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodCategoryID, Td_BloodCategoryCode, Td_BloodCategoryName
|
|
FROM $this->db_bb.td_bloodcategory
|
|
where Td_BloodCategoryIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(Td_BloodCategoryID) as total
|
|
FROM $this->db_bb.td_bloodcategory
|
|
where Td_BloodCategoryIsActive = 'Y' ";
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// blood rhesus
|
|
function get_blood_rhesus()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodRhesusID, Td_BloodRhesusCode, Td_BloodRhesusName
|
|
FROM $this->db_bb.td_bloodrhesus
|
|
where Td_BloodRhesusIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(Td_BloodRhesusID) as total
|
|
FROM $this->db_bb.td_bloodrhesus
|
|
where Td_BloodRhesusIsActive = 'Y' ";
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// doctor
|
|
function get_doctor_by_param()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//begin transaction
|
|
$this->db->trans_begin();
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
// $id = $prm['id'];
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$search = "";
|
|
// $userid = 1;
|
|
|
|
$number_limit = 10;
|
|
$sql_search = '';
|
|
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
}else{
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
// if (isset($prm['search'])) {
|
|
// $search = trim($prm["search"]);
|
|
// if ($search != "") {
|
|
// $search = trim($prm['search']);
|
|
// }else{
|
|
// $search = '';
|
|
// }
|
|
// }
|
|
|
|
$sql_search = "select distinct M_DoctorID, M_DoctorCode,
|
|
CONCAT(M_DoctorName,' ',M_DoctorSufix) as M_DoctorName
|
|
from m_doctor
|
|
WHERE M_DoctorIsActive = 'Y'
|
|
AND (
|
|
M_DoctorName like ?
|
|
OR M_DoctorCode like ?
|
|
)
|
|
limit ?
|
|
";
|
|
|
|
$query_search = $this->db->query($sql_search,[
|
|
$search, $search, $number_limit
|
|
]);
|
|
|
|
if(!$query_search){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("itemcategory select");
|
|
exit;
|
|
}
|
|
|
|
$rows = $query_search->result_array();
|
|
|
|
$sql_filter = "SELECT COUNT(distinct M_DoctorID, M_DoctorCode, M_DoctorName)
|
|
as total
|
|
from m_doctor
|
|
WHERE M_DoctorIsActive = 'Y'
|
|
AND (
|
|
M_DoctorName like ?
|
|
OR M_DoctorCode like ?
|
|
)
|
|
limit ?";
|
|
|
|
$tot_count = 0;
|
|
$qry_filter = $this->db->query($sql_filter, [$search, $search, $number_limit]);
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("itemcategory count");
|
|
exit;
|
|
}
|
|
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
// $result = array ("total" => 1, "records" => array("xid" => 0));
|
|
|
|
$result = array(
|
|
"total"=> $tot_count,
|
|
"total_display"=>sizeof($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_doctorx()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT M_DoctorID, M_DoctorCode,
|
|
CONCAT(M_DoctorName,' ',M_DoctorSufix) as M_DoctorName
|
|
from m_doctor
|
|
WHERE M_DoctorIsActive = 'Y'";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(M_DoctorID) as total
|
|
FROM m_doctor
|
|
where M_DoctorIsActive = 'Y' ";
|
|
$qry_total_filter = $this->db->query($count);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// lookuppasien
|
|
function get_pasien_by_param()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = "";
|
|
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
}else{
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$sql = " select M_PatientID,
|
|
CONCAT(M_PatientPrefix,' ',M_PatientName,' ',M_PatientSuffix) as M_PatientName,
|
|
M_PatientDOB, M_PatientIDNumber, M_PatientAddressDescription, M_PatientHP, M_PatientPhone
|
|
from m_patient
|
|
join m_patientaddress
|
|
ON M_PatientID = M_PatientAddressM_PatientID
|
|
AND M_PatientAddressIsActive = 'Y'
|
|
AND M_PatientIsActive = 'Y'
|
|
AND (
|
|
M_PatientName like ?
|
|
OR M_PatientDOB like ?
|
|
OR M_PatientPhone like ?
|
|
OR M_PatientHP like ?
|
|
OR M_PatientIDNumber like ?
|
|
OR M_PatientAddressDescription like ?
|
|
)";
|
|
|
|
$qry = $this->db->query($sql,[
|
|
$search, $search, $search, $search, $search, $search,
|
|
]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
$count = "SELECT count(M_PatientID) as total
|
|
from m_patient
|
|
join m_patientaddress
|
|
ON M_PatientID = M_PatientAddressM_PatientID
|
|
AND M_PatientAddressIsActive = 'Y'
|
|
AND M_PatientIsActive = 'Y'
|
|
AND (
|
|
M_PatientName like ?
|
|
OR M_PatientDOB like ?
|
|
OR M_PatientPhone like ?
|
|
OR M_PatientHP like ?
|
|
OR M_PatientIDNumber like ?
|
|
OR M_PatientAddressDescription like ?
|
|
) ";
|
|
$qry_total_filter = $this->db->query($count,[
|
|
$search, $search, $search, $search, $search, $search,
|
|
]);
|
|
$last_qry_total_filter = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (!$qry_total_filter) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry_total_filter
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$total_filter = (int)$qry_total_filter->result_array()[0]["total"];
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"total_filter" => $total_filter,
|
|
"records" => $rows,
|
|
"sql" => $last_qry,
|
|
"count" => $last_qry_total_filter
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function generate_req_number()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql_generate_code = "select $this->db_bb.fn_numbering_bloodrequest_read('BloodRequest') as code";
|
|
$query_generate_code = $this->db->query($sql_generate_code);
|
|
|
|
if(!$query_generate_code){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("function generate read request number");
|
|
exit;
|
|
}
|
|
|
|
$get_code = $query_generate_code->row_array();
|
|
$code = $get_code['code'];
|
|
$result = array(
|
|
"LastRequestNumber" => $code,
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// add
|
|
function add_blood_request()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$Bb_BloodRequestOrderHeaderM_PatientID = 1;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
// $Bb_BloodRequestOrderHeaderRequestDate = "";
|
|
$Bb_BloodRequestOrderHeaderReqNumber = "";
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID = "";
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID = "";
|
|
$Bb_BloodRequestOrderHeaderDateNeeded = "";
|
|
$Bb_BloodRequestOrderHeaderRoom ="";
|
|
$Bb_BloodRequestOrderHeaderDoctor ="";
|
|
$Bb_BloodRequestOrderHeaderTypePatient ="";
|
|
$Bb_BloodRequestOrderHeaderDiagnosa ="";
|
|
$Bb_BloodRequestOrderHeaderUserID = $userid;
|
|
$Bb_BloodRequestOrderDetailUserID = $userid;
|
|
|
|
|
|
// if(!$prm['bloodTypeID'] || $prm['bloodTypeID'] == ""){
|
|
// $this->sys_error("Silahkan pilih golongan darah");
|
|
// exit;
|
|
// }
|
|
|
|
// if(!$prm['bloodRhesusID'] || $prm['bloodRhesusID'] == ""){
|
|
// $this->sys_error("Silahkan pilih rhesus");
|
|
// exit;
|
|
// }
|
|
|
|
// if(!$prm['order_detail'] || empty($prm['order_detail'])){
|
|
// $this->sys_error("Silahkan pilih blood category");
|
|
// exit;
|
|
// }
|
|
|
|
// $Bb_BloodRequestOrderHeaderRequestDate = "";
|
|
|
|
$this->db->trans_begin();
|
|
|
|
$Bb_BloodRequestOrderHeaderReqNumber = $prm['order_header']['no_request'];
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID = $prm['order_header']['bloodTypeID'];
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID = $prm['order_header']['bloodRhesusID'];
|
|
$Bb_BloodRequestOrderHeaderDateNeeded = $prm['order_header']['date_needed'];
|
|
$Bb_BloodRequestOrderHeaderRoom = $prm['order_header']['room'];
|
|
$Bb_BloodRequestOrderHeaderDoctor = $prm['order_header']['dokterForm'];
|
|
$Bb_BloodRequestOrderHeaderTypePatient = $prm['order_header']['tipePasienForm'];
|
|
$Bb_BloodRequestOrderHeaderDiagnosa = $prm['order_header']['diagnosa'];
|
|
|
|
$sql_insert = "INSERT INTO $this->db_bb.bb_bloodrequest_orderheader(
|
|
Bb_BloodRequestOrderHeaderRequestDate,
|
|
Bb_BloodRequestOrderHeaderReqNumber,
|
|
Bb_BloodRequestOrderHeaderM_PatientID,
|
|
Bb_BloodRequestOrderHeaderTd_BloodTypeID,
|
|
Bb_BloodRequestOrderHeaderTd_BloodRhesusID,
|
|
Bb_BloodRequestOrderHeaderDateNeeded,
|
|
Bb_BloodRequestOrderHeaderRoom,
|
|
Bb_BloodRequestOrderHeaderDoctor,
|
|
Bb_BloodRequestOrderHeaderTypePatient,
|
|
Bb_BloodRequestOrderHeaderDiagnosa,
|
|
Bb_BloodRequestOrderHeaderIsActive,
|
|
Bb_BloodRequestOrderHeaderCreated,
|
|
Bb_BloodRequestOrderHeaderUserID
|
|
) VALUES(
|
|
NOW(),
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
'Y',
|
|
NOW(),
|
|
?
|
|
)";
|
|
|
|
$qry_insert = $this->db->query($sql_insert,[
|
|
$Bb_BloodRequestOrderHeaderReqNumber,
|
|
$Bb_BloodRequestOrderHeaderM_PatientID,
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID,
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID,
|
|
$Bb_BloodRequestOrderHeaderDateNeeded,
|
|
$Bb_BloodRequestOrderHeaderRoom,
|
|
$Bb_BloodRequestOrderHeaderDoctor,
|
|
$Bb_BloodRequestOrderHeaderTypePatient,
|
|
$Bb_BloodRequestOrderHeaderDiagnosa,
|
|
$Bb_BloodRequestOrderHeaderUserID
|
|
]);
|
|
|
|
if(!$qry_insert){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("insert order header blood request");
|
|
exit;
|
|
}
|
|
|
|
$id_order_header = $this->db->insert_id();
|
|
|
|
if(count($prm['order_detail']> 0)){
|
|
foreach($prm['order_detail'] as $x=>$v){
|
|
$this->add_order_detail($id_order_header,
|
|
$v['Td_BloodCategoryID'], $v['amount'], $userid);
|
|
}
|
|
}else{
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("Blood Category ada yang belum di isi amount nya");
|
|
exit;
|
|
}
|
|
|
|
$sql_generate_code = "select $this->db_bb.fn_numbering_bloodrequest_add('BloodRequest')";
|
|
$query_generate_code = $this->db->query($sql_generate_code);
|
|
|
|
if(!$query_generate_code){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("bloodrequest call fn_numbering_bloodrequest_add");
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
|
|
$result = array(
|
|
"total_filter" => 1,
|
|
"records" => []
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
// $this->search();
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function add_order_detail($id_order_header,$id_blood_category, $amount, $userid)
|
|
{
|
|
$sql = "INSERT INTO $this->db_bb.bb_bloodrequest_orderdetail(
|
|
Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestOrderDetailTd_BloodCategoryID,
|
|
Bb_BloodRequestOrderDetailAmountBag,
|
|
Bb_BloodRequestOrderDetailIsActive,
|
|
Bb_BloodRequestOrderDetailCreated,
|
|
Bb_BloodRequestOrderDetailUserID)
|
|
VALUES(?,?,?,'Y',NOW(),?)";
|
|
|
|
$qry = $this->db->query($sql,[
|
|
$id_order_header,
|
|
$id_blood_category,
|
|
$amount,
|
|
$userid
|
|
]);
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("insert order detail blood request");
|
|
exit;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// edit
|
|
function edit_blood_request()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$Bb_BloodRequestOrderHeaderM_PatientID = 1;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
// $Bb_BloodRequestOrderHeaderRequestDate = "";
|
|
$Bb_BloodRequestOrderHeaderReqNumber = "";
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID = "";
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID = "";
|
|
$Bb_BloodRequestOrderHeaderDateNeeded = "";
|
|
$Bb_BloodRequestOrderHeaderRoom ="";
|
|
$Bb_BloodRequestOrderHeaderDoctor ="";
|
|
$Bb_BloodRequestOrderHeaderTypePatient ="";
|
|
$Bb_BloodRequestOrderHeaderDiagnosa ="";
|
|
$Bb_BloodRequestOrderHeaderUserID = $userid;
|
|
$Bb_BloodRequestOrderDetailUserID = $userid;
|
|
$Bb_BloodRequestOrderHeaderID = $prm['order_header']['id'];
|
|
|
|
|
|
// if(!$prm['bloodTypeID'] || $prm['bloodTypeID'] == ""){
|
|
// $this->sys_error("Silahkan pilih golongan darah");
|
|
// exit;
|
|
// }
|
|
|
|
// if(!$prm['bloodRhesusID'] || $prm['bloodRhesusID'] == ""){
|
|
// $this->sys_error("Silahkan pilih rhesus");
|
|
// exit;
|
|
// }
|
|
|
|
// if(!$prm['order_detail'] || empty($prm['order_detail'])){
|
|
// $this->sys_error("Silahkan pilih blood category");
|
|
// exit;
|
|
// }
|
|
|
|
// $Bb_BloodRequestOrderHeaderRequestDate = "";
|
|
|
|
$this->db->trans_begin();
|
|
|
|
$Bb_BloodRequestOrderHeaderReqNumber = $prm['order_header']['no_request'];
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID = $prm['order_header']['bloodTypeID'];
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID = $prm['order_header']['bloodRhesusID'];
|
|
$Bb_BloodRequestOrderHeaderDateNeeded = $prm['order_header']['date_needed'];
|
|
$Bb_BloodRequestOrderHeaderRoom = $prm['order_header']['room'];
|
|
$Bb_BloodRequestOrderHeaderDoctor = $prm['order_header']['dokterForm'];
|
|
$Bb_BloodRequestOrderHeaderTypePatient = $prm['order_header']['tipePasienForm'];
|
|
$Bb_BloodRequestOrderHeaderDiagnosa = $prm['order_header']['diagnosa'];
|
|
|
|
$sql_update = "UPDATE $this->db_bb.bb_bloodrequest_orderheader
|
|
SET
|
|
Bb_BloodRequestOrderHeaderM_PatientID = ?,
|
|
Bb_BloodRequestOrderHeaderTd_BloodTypeID = ?,
|
|
Bb_BloodRequestOrderHeaderTd_BloodRhesusID = ?,
|
|
Bb_BloodRequestOrderHeaderDateNeeded = ?,
|
|
Bb_BloodRequestOrderHeaderRoom = ?,
|
|
Bb_BloodRequestOrderHeaderDoctor = ?,
|
|
Bb_BloodRequestOrderHeaderTypePatient = ?,
|
|
Bb_BloodRequestOrderHeaderDiagnosa = ?,
|
|
Bb_BloodRequestOrderHeaderLastUpdate = NOW(),
|
|
Bb_BloodRequestOrderHeaderUserID = ?
|
|
WHERE
|
|
Bb_BloodRequestOrderHeaderID = ?";
|
|
|
|
$qry_update_order_header = $this->db->query($sql_update,[
|
|
$Bb_BloodRequestOrderHeaderM_PatientID,
|
|
$Bb_BloodRequestOrderHeaderTd_BloodTypeID,
|
|
$Bb_BloodRequestOrderHeaderTd_BloodRhesusID,
|
|
$Bb_BloodRequestOrderHeaderDateNeeded,
|
|
$Bb_BloodRequestOrderHeaderRoom,
|
|
$Bb_BloodRequestOrderHeaderDoctor,
|
|
$Bb_BloodRequestOrderHeaderTypePatient,
|
|
$Bb_BloodRequestOrderHeaderDiagnosa,
|
|
$userid,
|
|
$Bb_BloodRequestOrderHeaderID
|
|
]);
|
|
|
|
if(!$qry_update_order_header){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update order header blood request");
|
|
exit;
|
|
}
|
|
|
|
// update order detail
|
|
$sql = "UPDATE $this->db_bb.bb_bloodrequest_orderdetail
|
|
SET Bb_BloodRequestOrderDetailIsActive = 'N'
|
|
WHERE Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$Bb_BloodRequestOrderHeaderID
|
|
));
|
|
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update N order detail error", $this->db->last_query());
|
|
exit;
|
|
}
|
|
|
|
|
|
if(count($prm['order_detail']> 0)){
|
|
foreach($prm['order_detail'] as $x=>$v)
|
|
{
|
|
$Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = $prm['id'];
|
|
$Bb_BloodRequestOrderDetailTd_BloodCategoryID = $v['Td_BloodCategoryID'];
|
|
$Bb_BloodRequestOrderDetailAmountBag = $v['amount'];
|
|
$Bb_BloodRequestOrderDetailUserID = $userid;
|
|
if(intval($value['id']) > 0){
|
|
// update
|
|
$sql = "UPDATE $this->db_bb.bb_bloodrequest_orderdetail SET
|
|
Bb_BloodRequestOrderDetailTd_BloodCategoryID = ?,
|
|
Bb_BloodRequestOrderDetailAmountBag = ?,
|
|
Bb_BloodRequestOrderDetailIsActive = 'Y',
|
|
Bb_BloodRequestOrderDetailUserID = ?,
|
|
Bb_BloodRequestOrderDetailLastUpdate = NOW()
|
|
WHERE Bb_BloodRequestOrderDetailID = ?
|
|
";
|
|
|
|
$qry = $this->db->query($sql,
|
|
array(
|
|
$Bb_BloodRequestOrderDetailTd_BloodCategoryID,
|
|
$Bb_BloodRequestOrderDetailAmountBag,
|
|
$userid,
|
|
$value['id']
|
|
));
|
|
// echo $this->db->last_query();
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update order detail error", $this->db->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = $prm['id'];
|
|
$Bb_BloodRequestOrderDetailTd_BloodCategoryID = $v['Td_BloodCategoryID'];
|
|
$Bb_BloodRequestOrderDetailAmountBag = $v['amount'];
|
|
$Bb_BloodRequestOrderDetailUserID = $userid;
|
|
|
|
// insert detail
|
|
$sql_i = "INSERT INTO $this->db_bb.bb_bloodrequest_orderdetail(
|
|
Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestOrderDetailTd_BloodCategoryID,
|
|
Bb_BloodRequestOrderDetailAmountBag,
|
|
Bb_BloodRequestOrderDetailIsActive,
|
|
Bb_BloodRequestOrderDetailCreated,
|
|
Bb_BloodRequestOrderDetailUserID)
|
|
VALUES(?,?,?,'Y',NOW(),?)";
|
|
|
|
$qry_i = $this->db->query($sql_i,[
|
|
$Bb_BloodRequestOrderHeaderID,
|
|
$Bb_BloodRequestOrderDetailTd_BloodCategoryID,
|
|
$Bb_BloodRequestOrderDetailAmountBag,
|
|
$Bb_BloodRequestOrderDetailUserID
|
|
]);
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("insert order detail blood request");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->db->trans_complete();
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
}else{
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("Blood Category ada yang belum di isi amount nya");
|
|
exit;
|
|
}
|
|
|
|
// $this->db->trans_commit();
|
|
|
|
// $result = array(
|
|
// "total_filter" => 1,
|
|
// "records" => []
|
|
// );
|
|
|
|
// $this->sys_ok($result);
|
|
// $this->search();
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// delete
|
|
function delete()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//begin transaction
|
|
$this->db->trans_begin();
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$userid = $this->sys_user['M_UserID'];
|
|
// $userid = 1;
|
|
|
|
$sql_delete_orderheader = "UPDATE $this->db_bb.bb_bloodrequest_orderheader
|
|
SET Bb_BloodRequestOrderHeaderIsActive = 'N',
|
|
Bb_BloodRequestOrderHeaderLastUpdate = now(),
|
|
Bb_BloodRequestOrderHeaderUserID = ?
|
|
WHERE Bb_BloodRequestOrderHeaderID = ?";
|
|
|
|
$query_delete_order_header = $this->db->query($sql_delete_orderheader,[
|
|
$userid, $id
|
|
]);
|
|
|
|
if(!$query_delete_order_header){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("order header delete");
|
|
exit;
|
|
}
|
|
|
|
// detail
|
|
$sql_delete_orderdetail = "UPDATE $this->db_bb.bb_bloodrequest_orderdetail
|
|
SET Bb_BloodRequestOrderDetailIsActive = 'N',
|
|
Bb_BloodRequestOrderDetailLastUpdate = now(),
|
|
Bb_BloodRequestOrderDetailUserID = ?
|
|
WHERE Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = ?";
|
|
|
|
$query_delete_order_detail = $this->db->query($sql_delete_orderdetail,[
|
|
$userid, $id
|
|
]);
|
|
|
|
if(!$query_delete_order_detail){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("order detail delete");
|
|
exit;
|
|
}
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|