FHM09062601IBL - tambah fitur tindakan medis: table order_tindakan + 4 endpoint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3403,5 +3403,205 @@ function get_data_order_anamnesis($orderID){
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── TINDAKAN MEDIS ────────────────────────────────────────────────────────
|
||||
|
||||
// Autocomplete jenis tindakan dari ss_price_mou berdasarkan MOU order
|
||||
function get_tindakan()
|
||||
{
|
||||
if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; }
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$orderid = intval($prm['orderid'] ?? 0);
|
||||
$search = trim($prm['search'] ?? '');
|
||||
|
||||
if (!$orderid) { $this->sys_error("orderid required"); exit; }
|
||||
|
||||
$order_row = $this->db_oneklinik->query(
|
||||
"SELECT orderM_MouID FROM one_klinik.`order` WHERE orderID = ? LIMIT 1",
|
||||
[$orderid]
|
||||
)->row_array();
|
||||
|
||||
if (!$order_row || !$order_row['orderM_MouID']) {
|
||||
$this->sys_ok(['records' => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$mou_id = intval($order_row['orderM_MouID']);
|
||||
$search_esc = $this->db_onedev->escape_str($search);
|
||||
|
||||
$sql = "SELECT
|
||||
spm.Ss_PriceMouID as ss_price_mou_id,
|
||||
spm.Ss_PriceMouM_MouID as mouid,
|
||||
0 as xid,
|
||||
spm.Nat_TestID as nat_testid,
|
||||
spm.nat_test,
|
||||
spm.is_packet,
|
||||
spm.packet_id,
|
||||
spm.px_type as type,
|
||||
spm.T_TestID as pxid,
|
||||
t.T_TestCode as pxcode,
|
||||
t.T_TestSasCode as pxsascode,
|
||||
t.T_TestName as test_name,
|
||||
CONCAT(t.T_TestSasCode,' ',t.T_TestName) as pxname,
|
||||
t.T_TestIsResult as isresult,
|
||||
JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceAmount')) as bruto,
|
||||
JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDisc')) as discountpersen,
|
||||
JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDiscRp')) as discountrp,
|
||||
if(JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDisc')) <> 0,
|
||||
(((JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDisc')) / 100)
|
||||
* JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceAmount')))
|
||||
+ JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDiscRp'))),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDiscRp'))
|
||||
) as discount,
|
||||
( JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceAmount'))
|
||||
- ((JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDisc')) / 100)
|
||||
* JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceAmount')))
|
||||
- JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(spm.Ss_PriceMouID),'$.T_PriceDiscRp'))
|
||||
) as total,
|
||||
spm.child_test
|
||||
FROM one_lab.ss_price_mou spm
|
||||
JOIN one_lab.t_test t ON spm.T_TestID = t.T_TestID AND t.T_TestIsActive = 'Y'
|
||||
WHERE spm.Ss_PriceMouM_MouID = {$mou_id}
|
||||
AND spm.is_packet = 'N'
|
||||
AND spm.px_type = 'PX'
|
||||
AND CONCAT(t.T_TestSasCode,' ',t.T_TestName) LIKE CONCAT('%', '{$search_esc}', '%')
|
||||
ORDER BY t.T_TestName
|
||||
LIMIT 50";
|
||||
|
||||
$q = $this->db_onedev->query($sql);
|
||||
if (!$q) { $this->sys_error_db("get jenis tindakan", $this->db_onedev); exit; }
|
||||
|
||||
$records = array_map(function($row) {
|
||||
$row['nat_test'] = json_decode($row['nat_test'] ?? '[]', true) ?: [];
|
||||
$row['child_test'] = json_decode($row['child_test'] ?? '[]', true) ?: [];
|
||||
return $row;
|
||||
}, $q->result_array());
|
||||
|
||||
$this->sys_ok(['records' => $records]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// List tindakan yang sudah tersimpan untuk satu order
|
||||
function list_order_tindakan()
|
||||
{
|
||||
if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; }
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$orderid = intval($prm['orderid'] ?? 0);
|
||||
if (!$orderid) { $this->sys_error("orderid required"); exit; }
|
||||
|
||||
$sql = "SELECT
|
||||
ot.*,
|
||||
t.T_TestName as jenis_tindakan_name,
|
||||
t.T_TestSasCode as jenis_tindakan_code,
|
||||
d.M_DoctorName as dokter_name
|
||||
FROM one_klinik.order_tindakan ot
|
||||
LEFT JOIN one_lab.t_test t ON ot.orderTindakanT_TestID = t.T_TestID
|
||||
LEFT JOIN one_klinik.m_doctor d ON ot.orderTindakanM_DoctorID = d.M_DoctorID
|
||||
WHERE ot.orderTindakanOrderID = ?
|
||||
AND ot.orderTindakanIsActive = 'Y'
|
||||
ORDER BY ot.orderTindakanCreated ASC";
|
||||
|
||||
$q = $this->db_oneklinik->query($sql, [$orderid]);
|
||||
if (!$q) { $this->sys_error_db("list order_tindakan", $this->db_oneklinik); exit; }
|
||||
|
||||
$this->sys_ok(['records' => $q->result_array()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function save_tindakan()
|
||||
{
|
||||
if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; }
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$orderid = intval($prm['orderid'] ?? 0);
|
||||
$tindakan_id = intval($prm['tindakan_id'] ?? 0); // orderTindakanID; 0 = insert baru
|
||||
$t_test_id = intval($prm['t_test_id'] ?? 0);
|
||||
|
||||
if (!$orderid || !$t_test_id) {
|
||||
$this->sys_error("orderid dan t_test_id wajib diisi");
|
||||
exit;
|
||||
}
|
||||
|
||||
$doctor_id = isset($prm['doctor_id']) && $prm['doctor_id'] ? intval($prm['doctor_id']) : null;
|
||||
$performed_at = trim($prm['performed_at'] ?? '');
|
||||
$catatan = trim($prm['catatan'] ?? '');
|
||||
$ss_price_mou_id = isset($prm['ss_price_mou_id']) && $prm['ss_price_mou_id'] ? intval($prm['ss_price_mou_id']) : null;
|
||||
$bruto = floatval($prm['bruto'] ?? 0);
|
||||
$disc_persen = floatval($prm['discountpersen'] ?? 0);
|
||||
$disc_rp = floatval($prm['discountrp'] ?? 0);
|
||||
$total = floatval($prm['total'] ?? 0);
|
||||
|
||||
$performed_at_sql = ($performed_at && strtotime($performed_at))
|
||||
? date('Y-m-d H:i:s', strtotime($performed_at))
|
||||
: date('Y-m-d H:i:s');
|
||||
|
||||
if ($tindakan_id > 0) {
|
||||
$ok = $this->db_oneklinik->query(
|
||||
"UPDATE one_klinik.order_tindakan SET
|
||||
orderTindakanT_TestID = ?,
|
||||
orderTindakanSsPriceMouID = ?,
|
||||
orderTindakanBruto = ?,
|
||||
orderTindakanDiscPersen = ?,
|
||||
orderTindakanDiscRp = ?,
|
||||
orderTindakanTotal = ?,
|
||||
orderTindakanM_DoctorID = ?,
|
||||
orderTindakanPerformedAt = ?,
|
||||
orderTindakanCatatan = ?,
|
||||
orderTindakanUserID = ?
|
||||
WHERE orderTindakanID = ? AND orderTindakanOrderID = ?",
|
||||
[
|
||||
$t_test_id, $ss_price_mou_id, $bruto, $disc_persen, $disc_rp, $total,
|
||||
$doctor_id, $performed_at_sql, $catatan ?: null,
|
||||
$userID, $tindakan_id, $orderid
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$ok = $this->db_oneklinik->query(
|
||||
"INSERT INTO one_klinik.order_tindakan
|
||||
(orderTindakanOrderID, orderTindakanT_TestID,
|
||||
orderTindakanSsPriceMouID, orderTindakanBruto, orderTindakanDiscPersen,
|
||||
orderTindakanDiscRp, orderTindakanTotal,
|
||||
orderTindakanM_DoctorID, orderTindakanPerformedAt,
|
||||
orderTindakanCatatan, orderTindakanUserID)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?)",
|
||||
[
|
||||
$orderid, $t_test_id,
|
||||
$ss_price_mou_id, $bruto, $disc_persen, $disc_rp, $total,
|
||||
$doctor_id, $performed_at_sql, $catatan ?: null, $userID
|
||||
]
|
||||
);
|
||||
$tindakan_id = $this->db_oneklinik->insert_id();
|
||||
}
|
||||
|
||||
if (!$ok) { $this->sys_error_db("save order_tindakan", $this->db_oneklinik); exit; }
|
||||
|
||||
$this->sys_ok(['orderTindakanID' => $tindakan_id]);
|
||||
exit;
|
||||
}
|
||||
|
||||
function delete_tindakan()
|
||||
{
|
||||
if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; }
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$tindakan_id = intval($prm['orderTindakanID'] ?? 0);
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
if (!$tindakan_id) { $this->sys_error("orderTindakanID required"); exit; }
|
||||
|
||||
$ok = $this->db_oneklinik->query(
|
||||
"UPDATE one_klinik.order_tindakan SET orderTindakanIsActive = 'N', orderTindakanUserID = ?
|
||||
WHERE orderTindakanID = ?",
|
||||
[$userID, $tindakan_id]
|
||||
);
|
||||
if (!$ok) { $this->sys_error_db("delete order_tindakan", $this->db_oneklinik); exit; }
|
||||
|
||||
$this->sys_ok(['msg' => 'deleted']);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user