Files
BE_IBL/application/controllers/mcu_api/Pre_riwayat.php
2026-04-15 15:23:57 +07:00

101 lines
3.3 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Pre_riwayat extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
// Check if pre_eresult exists and return pre_eresultID and JSON-encoded pre_eresultRiwayat
public function check($so_resultentry_fisik_umum_id)
{
try {
$query = $this->db->query("
SELECT pre.pre_eresultID,
pre_eresultRiwayat
FROM pre_eresult pre
JOIN mcu_preregister_patients mpd
ON pre.pre_eresultMcu_PreregisterDetailsID = mpd.Mcu_PreregisterDetailsID
JOIN t_orderheader toh
ON mpd.Mcu_PreregisterDetailsT_OrderHeaderID = toh.T_OrderHeaderID
JOIN so_resultentry sre
ON toh.T_OrderHeaderID = sre.So_ResultEntryT_OrderHeaderID
JOIN so_resultentry_fisik_umum srfu
ON sre.So_ResultEntryID = srfu.So_ResultEntryFisikUmumSo_ResultEntryID
WHERE srfu.So_ResultEntryFisikUmumID = ?
LIMIT 1", [$so_resultentry_fisik_umum_id]);
if (!$query) {
throw new Exception($this->db->error()['message']);
}
$result = $query->row_array();
if ($result) {
$this->output_json([
'status' => 'OK',
'data' => $result
]);
} else {
throw new Exception('No matching record found');
}
} catch (Exception $e) {
$this->output_json([
'status' => 'ERR',
'message' => $e->getMessage()
]);
}
}
// Update So_ResultEntryFisikUmumDetails from pre_eresultRiwayat
public function update($so_resultentry_fisik_umum_id)
{
try {
$sql = "
UPDATE so_resultentry_fisik_umum srfu
JOIN so_resultentry sre
ON srfu.So_ResultEntryFisikUmumSo_ResultEntryID = sre.So_ResultEntryID
JOIN t_orderheader toh
ON sre.So_ResultEntryT_OrderHeaderID = toh.T_OrderHeaderID
JOIN mcu_preregister_patients mpd
ON toh.T_OrderHeaderID = mpd.Mcu_PreregisterDetailsT_OrderHeaderID
JOIN pre_eresult pre
ON pre.pre_eresultMcu_PreregisterDetailsID = mpd.Mcu_PreregisterDetailsID
SET srfu.So_ResultEntryFisikUmumDetails = pre.pre_eresultRiwayat
WHERE srfu.So_ResultEntryFisikUmumID = ?
AND srfu.So_ResultEntryFisikUmumType = 'riwayat'";
$this->db->query($sql, [$so_resultentry_fisik_umum_id]);
// echo $this->db->last_query();
// echo "\n\n\n";
if ($this->db->affected_rows() > 0) {
$this->output_json([
'status' => 'OK',
'message' => 'Update successful'
]);
} else {
$this->output_json([
'status' => 'OK',
'message' => 'Update successful'
]);
//throw new Exception('No rows updated, check if data exists');
}
} catch (Exception $e) {
$this->output_json([
'status' => 'ERR',
'message' => $e->getMessage()
]);
}
}
// Helper function to output JSON
private function output_json($data)
{
header('Content-Type: application/json');
echo (json_encode($data));
}
}