623 lines
22 KiB
PHP
623 lines
22 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function index()
|
|
{
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "LIST PATIENT";
|
|
}
|
|
|
|
function getcompany()
|
|
{
|
|
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_CompanyID as id,
|
|
M_CompanyName as name
|
|
FROM m_company
|
|
WHERE M_CompanyName LIKE ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName DESC";
|
|
$query = $this->db->query($sql, array($search));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows, array('id' => '0', 'name' => 'Semua'));
|
|
// echo $this->db->last_query();
|
|
// exit;
|
|
} else {
|
|
$this->sys_error_db("m_company error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array("total_display" => sizeof($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search()
|
|
{
|
|
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 = "%%";
|
|
}
|
|
}
|
|
$startdate = $prm["startdate"];
|
|
$enddate = $prm["enddate"];
|
|
$companyid = $prm["companyid"];
|
|
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
|
|
|
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
|
|
|
if ($search != "") {
|
|
$where .= " AND ( M_PatientName LIKE '{$search}' OR T_OrderHeaderLabNumber LIKE '{$search}' OR T_OrderHeaderLabNumberExt LIKE '{$search}' )";
|
|
}
|
|
|
|
if ($companyid != 0 || $companyid != "0") {
|
|
$filter_company = " AND T_OrderHeaderM_CompanyID = {$companyid}";
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total FROM(
|
|
SELECT T_OrderHeaderID
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
WHERE $where $filter_company
|
|
group by T_OrderHeaderID) x";
|
|
$qry_filter = $this->db->query($sql_filter);
|
|
|
|
$tot_count = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("orderheader count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM(
|
|
SELECT T_OrderHeaderID,
|
|
'' as rownumber,
|
|
DATE(T_OrderHeaderDate) as order_date,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderLabNumberExt,
|
|
M_PatientNoReg,
|
|
concat(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
|
M_CompanyName
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
WHERE $where $filter_company
|
|
group by T_OrderHeaderID) x
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit 0, $tot_count";
|
|
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select order error", $this->db);
|
|
exit;
|
|
}
|
|
foreach ($rows as $k => $v) {
|
|
$xno = ($k + 1);
|
|
$rows[$k]['rownumber'] = $xno;
|
|
}
|
|
$result = array(
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function gettest()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$orderheaderid = $prm["orderheaderid"];
|
|
|
|
$sql = "SELECT T_OrderDetailID,
|
|
T_OrderDetailT_TestName as testname
|
|
FROM t_orderdetail
|
|
WHERE T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderDetailT_TestIsPrice = 'Y'
|
|
AND T_OrderDetailT_OrderHeaderID = '{$orderheaderid}'";
|
|
$qry_detail = $this->db->query($sql);
|
|
if ($qry_detail) {
|
|
$rows = $qry_detail->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select detail order error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchconsumable()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$orderheaderid = $prm["orderheaderid"];
|
|
|
|
if ($orderheaderid) {
|
|
$sql_check_selection = "SELECT T_ConsumableID FROM t_consumable
|
|
WHERE T_ConsumableIsActive = 'Y'
|
|
AND T_ConsumableT_OrderHeaderID = ?";
|
|
$qry_check_selection = $this->db->query($sql_check_selection, array($orderheaderid));
|
|
|
|
if ($qry_check_selection) {
|
|
$total_selected = $qry_check_selection->result_array();
|
|
} else {
|
|
$this->sys_error_db("error checking selection", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if (count($total_selected) > 0) {
|
|
$sql_filter = "SELECT COUNT(*) as total
|
|
FROM t_consumable
|
|
JOIN t_orderheader ON T_ConsumableT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
JOIN m_consumable ON T_ConsumableM_ConsumableID = M_ConsumableID
|
|
AND M_ConsumableIsActive = 'Y'
|
|
LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
WHERE T_ConsumableIsActive = 'Y'
|
|
AND M_ConsumableDefaultShow = 'Y'
|
|
AND T_ConsumableT_OrderHeaderID = ?
|
|
ORDER BY T_ConsumableID";
|
|
$qry_filter = $this->db->query($sql_filter, array($orderheaderid));
|
|
} else {
|
|
$sql_filter = "SELECT COUNT(*) as total
|
|
FROM m_consumable
|
|
LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
WHERE M_ConsumableIsActive = 'Y' AND M_ConsumableDefaultShow = 'Y'";
|
|
$qry_filter = $this->db->query($sql_filter);
|
|
}
|
|
|
|
$tot_count = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("consumable count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if (count($total_selected) > 0) {
|
|
$sql = "SELECT T_ConsumableID,
|
|
M_ConsumableID,
|
|
M_ConsumableCode,
|
|
M_ConsumableName,
|
|
M_ConsumableDefaultM_SatuanID,
|
|
M_ConsumableDefaultShow,
|
|
M_ConsumableDefaultQty,
|
|
M_SatuanName,
|
|
M_SatuanID,
|
|
T_ConsumableQty,
|
|
T_ConsumableM_SatuanID as M_SatuanID,
|
|
'' as isHidden,
|
|
'' as units
|
|
FROM t_consumable
|
|
JOIN t_orderheader ON T_ConsumableT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
JOIN m_consumable ON T_ConsumableM_ConsumableID = M_ConsumableID
|
|
AND M_ConsumableIsActive = 'Y'
|
|
LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
WHERE T_ConsumableIsActive = 'Y'
|
|
AND T_ConsumableT_OrderHeaderID = ?
|
|
ORDER BY T_ConsumableID";
|
|
|
|
$qry = $this->db->query($sql, array($orderheaderid));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select consumable error", $this->db);
|
|
exit;
|
|
}
|
|
} else {
|
|
$sql = "SELECT M_ConsumableID,
|
|
M_ConsumableCode,
|
|
M_ConsumableName,
|
|
M_ConsumableDefaultM_SatuanID,
|
|
M_ConsumableDefaultQty,
|
|
M_SatuanID,
|
|
M_SatuanName,
|
|
'' as isHidden,
|
|
'' as units
|
|
FROM m_consumable
|
|
LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
WHERE M_ConsumableIsActive = 'Y' AND M_ConsumableDefaultShow = 'Y'";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select consumable all show error", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql_unit = "SELECT M_SatuanID,
|
|
M_SatuanName
|
|
FROM m_satuan
|
|
WHERE M_SatuanIsActive ='Y'";
|
|
$qry_unit = $this->db->query($sql_unit);
|
|
if ($qry_unit) {
|
|
$rows_unit = $qry_unit->result_array();
|
|
} else {
|
|
$this->sys_error_db("Select m_satuan error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
|
|
foreach ($rows as $key => $value) {
|
|
if (count($total_selected) > 0) {
|
|
$rows[$key]["isHidden"] = true;
|
|
} else {
|
|
$rows[$key]["isHidden"] = false;
|
|
}
|
|
|
|
$rows[$key]["units"] = $rows_unit;
|
|
}
|
|
$result = array(
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_satuan()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$consumableid = $prm["consumableid"];
|
|
|
|
$sql = "SELECT M_ConsumableSatuanID,
|
|
M_ConsumableSatuanM_ConsumableID,
|
|
M_ConsumableSatuanM_SatuanID,
|
|
M_SatuanID,
|
|
M_SatuanName
|
|
FROM m_consumablesatuan
|
|
JOIN m_satuan ON M_ConsumableSatuanM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
WHERE M_ConsumableSatuanIsActive = 'Y'
|
|
AND M_ConsumableSatuanM_ConsumableID = ?";
|
|
|
|
$qry = $this->db->query($sql, array($consumableid));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("Satuan error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_item()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$orderheaderid = $prm["orderheaderid"];
|
|
|
|
$sql = "SELECT DISTINCT M_ConsumableID as consumableid,
|
|
M_ConsumableCode,
|
|
M_ConsumableName,
|
|
M_ConsumableDefaultM_SatuanID,
|
|
M_ConsumableDefaultQty,
|
|
M_SatuanName
|
|
FROM m_consumable
|
|
LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID
|
|
AND M_SatuanIsActive = 'Y'
|
|
LEFT JOIN t_consumable ON M_ConsumableID = T_ConsumableM_ConsumableID
|
|
AND T_ConsumableIsActive = 'Y'
|
|
WHERE M_ConsumableIsActive = 'Y'
|
|
AND M_ConsumableID NOT IN (SELECT
|
|
T_ConsumableM_ConsumableID
|
|
FROM t_consumable
|
|
WHERE T_ConsumableIsActive = 'Y' AND T_ConsumableT_OrderHeaderID = ?)";
|
|
$qry = $this->db->query($sql, array($orderheaderid));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("get item error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function addconsumable()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$orderheaderid = $prm["orderheaderid"];
|
|
$consumableid = $prm["consumableid"];
|
|
$satuanid = $prm["satuanid"];
|
|
$qty = $prm["qty"];
|
|
|
|
$sql = "INSERT INTO t_consumable(
|
|
T_ConsumableT_OrderHeaderID,
|
|
T_ConsumableM_ConsumableID,
|
|
T_ConsumableM_SatuanID,
|
|
T_ConsumableQty,
|
|
T_ConsumableIsActive,
|
|
T_ConsumableCreated,
|
|
T_ConsumableLastUpdated,
|
|
T_ConsumableUserID
|
|
) VALUES(?,?,?,?,'Y',NOW(),NOW(),?)";
|
|
|
|
$qry = $this->db->query($sql, array(
|
|
$orderheaderid,
|
|
$consumableid,
|
|
$satuanid,
|
|
$qty,
|
|
$userid
|
|
));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("insert error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function reset()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$tconsumableid = $prm["tconsumableid"];
|
|
$orderheaderid = $prm["orderheaderid"];
|
|
|
|
$sql = "UPDATE t_consumable SET
|
|
T_ConsumableIsActive = 'N',
|
|
T_ConsumableLastUpdated = NOW(),
|
|
T_ConsumableUserID = ?
|
|
WHERE T_ConsumableT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$userid,
|
|
$orderheaderid
|
|
));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 0
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function saveAllConsumable()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$data = [];
|
|
if (isset($prm['data'])) {
|
|
$data = $prm['data'];
|
|
}
|
|
// print_r($data);
|
|
// exit;
|
|
|
|
if (count($data) > 0) {
|
|
for ($i = 0; $i < count($data); $i++) {
|
|
$item = $data[$i];
|
|
|
|
$orderheaderid = $item["orderheaderId"];
|
|
$consumableid = $item["consumableId"];
|
|
$satuanid = $item["satuanId"]["M_SatuanID"];
|
|
$qty = $item["consumableQty"];
|
|
$type = $item["type"];
|
|
|
|
// $qry_check = "SELECT T_ConsumableID,
|
|
// T_ConsumableM_ConsumableID,
|
|
// T_ConsumableT_OrderHeaderID,
|
|
// 'X' as typee
|
|
// FROM t_consumable
|
|
// WHERE T_ConsumableIsActive = 'Y'
|
|
// AND T_ConsumableT_OrderHeaderID = ?";
|
|
// $qry_check = $this->db->query($qry_check, array($orderheaderid));
|
|
|
|
// if ($qry_check) {
|
|
// $rows_check = $qry_check->result_array();
|
|
// } else {
|
|
// $this->sys_error_db("error check", $this->db);
|
|
// exit;
|
|
// }
|
|
|
|
if ($type === false) {
|
|
// jika belum ada maka insert data
|
|
if ($qty != 0 || $qty != '0') {
|
|
$sql = "INSERT INTO t_consumable(
|
|
T_ConsumableT_OrderHeaderID,
|
|
T_ConsumableM_ConsumableID,
|
|
T_ConsumableM_SatuanID,
|
|
T_ConsumableQty,
|
|
T_ConsumableIsActive,
|
|
T_ConsumableCreated,
|
|
T_ConsumableLastUpdated,
|
|
T_ConsumableUserID
|
|
) VALUES(?,?,?,?,'Y',NOW(),NOW(),?)";
|
|
|
|
$qry = $this->db->query($sql, array(
|
|
$orderheaderid,
|
|
$consumableid,
|
|
$satuanid,
|
|
$qty,
|
|
$userid
|
|
));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("insert consumable error", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
if ($qty != 0 || $qty != '0') {
|
|
$sql_update = "UPDATE t_consumable SET
|
|
T_ConsumableM_SatuanID = ?,
|
|
T_ConsumableQty = ?,
|
|
T_ConsumableLastUpdated = NOW(),
|
|
T_ConsumableUserID = ?
|
|
WHERE T_ConsumableT_OrderHeaderID = ? AND T_ConsumableM_ConsumableID = ?";
|
|
$qry_update = $this->db->query($sql_update, array(
|
|
$satuanid,
|
|
$qty,
|
|
$userid,
|
|
$orderheaderid,
|
|
$consumableid
|
|
));
|
|
if (!$qry_update) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update t_consumable error", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 0,
|
|
"qry" => $this->db->last_query()
|
|
);
|
|
$this->db->trans_commit();
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|