Files
2026-04-15 15:23:57 +07:00

83 lines
2.9 KiB
PHP

<?php
class Demografi extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "DATA BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function get($labExternal)
{
// transaction begin
$this->db->trans_begin();
$sql = "SELECT
M_PatientID,M_PatientNoReg,
CONCAT(
IFNULL(M_TitleName, ''),
IF(M_TitleName IS NOT NULL, ' ', ''),
IF(M_PatientPrefix IS NOT NULL, M_PatientPrefix, ''),
IF(M_PatientPrefix IS NOT NULL, ' ', ''),
IF(M_PatientName IS NOT NULL, M_PatientName, ''),
IF(M_PatientName IS NOT NULL, ' ', ''),
IF(M_PatientSuffix IS NOT NULL, M_PatientSuffix, '')
) AS PatientName,
m_sexname,M_PatientInitialVisit,M_PatientLastVisit,
M_ReligionName,M_PatientPOB,M_PatientDOB,
M_PatientHP,M_PatientPhone,M_PatientEmail,
M_IdTypeName,M_PatientIDNumber,M_PatientNote,
M_PatientM_CompanyStaffPositionID, M_CompanyName,M_PatientCreated,
M_PatientLastUpdated,M_PatientUserID,M_PatientIsActive,
M_PatientOldID,M_PatientNIK,M_PatientJabatan,
M_PatientKedudukan,M_PatientPJ,M_PatientLocation,
M_PatientJob,'' as M_PatientOldCode, T_TestName, So_TemplateName
FROM
t_orderheader
JOIN
m_patient ON T_OrderHeaderLabNumberExt = '{$labExternal}' AND T_OrderHeaderM_PatientID = M_PatientID
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultResumeMcu = 'FISIK'
JOIN so_testtemplate ON So_TestTemplateT_TestID = T_TestID AND So_TestTemplateIsActive = 'Y'
JOIN so_template ON So_TestTemplateSo_TemplateID = So_TemplateID
LEFT JOIN
m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN
m_idtype ON M_PatientM_IdTypeID = M_IdTypeID
LEFT JOIN
m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN
m_religion ON M_PatientM_ReligionID = M_ReligionID
LEFT JOIN
m_company ON M_PatientM_CompanyStaffPositionID = M_CompanyM_StaffID
";
$qry = $this->db->query($sql);
$qry_check = $this->db->last_query();
if (!$qry) {
$error = array(
"status" => "ERR",
"message" => $this->db->error()["message"],
"sql" => $qry_check
);
$this->sys_error_db($error);
// transaction reversal if query error
$this->db->trans_rollback();
exit;
}
$result = $qry->result_array();
// echo json_encode(["status" => "OK", "data" => $result]);
echo json_encode($result);
// transaction end
$this->db->trans_commit();
}
}