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

416 lines
14 KiB
PHP

<?php
class Uploaderbiodata extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function get_param()
{
$raw = file_get_contents("php://input");
return json_decode($raw, true);
}
function get_company($companyID)
{
$sql = "select M_CompanyID, M_CompanyOldID, M_BranchID M_CompanyM_BranchID, M_CompanyName, M_CompanyNumber,
M_CompanyIDParent, M_CompanyM_CompanyTypeID, M_CompanyM_CompanyBusinessID,
M_CompanyM_ProvinceID, M_CompanyM_CityID, M_CompanyM_DistrictID, M_CompanyM_KelurahanID,
M_CompanyAddress, M_CompanyPhone, M_CompanyFax, M_CompanyEmail, M_CompanyPIC,
M_CompanyM_StaffID, M_CompanyNat_CompanyLevelID, M_CompanyNat_HierarchyID,
M_CompanyIsLabFrom, M_CompanyIsLabTo, M_CompanyIsDefault, M_CompanyM_DoctorID,
M_CompanyCreated, M_CompanyLastUpdated, M_CompanyIsActive, M_CompanyAddressLocation,
M_CompanyHp, M_CompanyPrivateRequest
from m_company
join m_branch on M_CompanyID = ?
and M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
$qry = $this->db->query($sql, [$companyID]);
if (!$qry) {
$this->reply_gz(
json_encode([
"status" => "ERR",
"message" => $this->db->error()["message"],
])
);
}
$rows = $qry->result_array();
$this->reply_gz(
json_encode([
"status" => "OK",
"data" => $rows,
])
);
}
//Get Detail Mou
function reply_gz($resp)
{
echo gzcompress($resp);
exit();
}
function get_branch()
{
$sql =
"select M_BranchID,M_BranchCode from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault ='Y'";
$resp = $this->get_row($sql);
if ($resp["status"] != 1) {
echo json_encode($resp);
exit();
}
return [$resp["data"]["M_BranchID"], $resp["data"]["M_BranchCode"]];
}
function log($msg)
{
$dt = date("Y-m-d H:i:s");
echo "$dt $msg\n";
}
function error_reply_gz($msg)
{
echo gzcompress(json_encode(["status" => "ERR", "message" => $msg]));
}
function reply($resp, $type = 1)
{
echo json_encode($resp);
}
function error_reply($msg)
{
echo json_encode(["status" => "ERR", "message" => $msg]);
}
function getCompanyNumber($companyID)
{
$sql = "select M_CompanyNumber from m_company where M_CompanyID = ?";
$resp = $this->get_row($sql, [$companyID]);
if ($resp["status"] == -1) {
$this->error_reply(
"Err Get Company from $companyID: " . $resp["message"]
);
exit();
}
if ($resp["status"] == 0) {
return "";
}
$r = $resp["data"];
return $r["M_CompanyNumber"];
}
//
function process($headerID)
{
// branch
$sql_get_branch = "
select IFNULL(M_BranchID,'') as M_BranchID,
IFNULL(M_BranchCode,'') as M_BranchCode,
IFNULL(M_BranchName,'') as M_BranchName,
IFNULL(S_RegionalID,'') as S_RegionalID,
IFNULL(S_RegionalName,'') as S_RegionalName
from m_branch
LEFT JOIN s_regional ON S_RegionalID = M_BranchS_RegionalID
WHERE M_BranchIsDefault='Y'
AND M_BranchIsActive ='Y'
";
$query_m_branch = $this->db->query($sql_get_branch);
if (!$query_m_branch) {
$this->db->trans_rollback();
$message = $this->db->error();
$this->sys_error($message);
exit;
}
$rows_branch = $query_m_branch->result_array();
if (count($rows_branch) == 0) {
$this->db->trans_rollback();
$this->sys_error('Cabang Tidak Ketemu');
exit;
}
$branch_id = $rows_branch[0]['M_BranchID'];
$branch_code = $rows_branch[0]['M_BranchCode'];
$branch_name = $rows_branch[0]['M_BranchName'];
$regional_id = $rows_branch[0]['S_RegionalID'];
$regional_name = $rows_branch[0]['S_RegionalName'];
$sql_field = "SELECT
T_OrderHeaderID,
'{$branch_id}' as branch_id,
'{$branch_code}' as branch_code,
'{$branch_name}' as branch_name,
'{$regional_id}' as regional_id,
'{$regional_name}' as regional_name,
M_PatientIDNumber as NIK,
T_OrderHeaderLabNumber as NO_REG,
M_PatientNoReg as PID,
M_PatientHP as NO_HP,
M_PatientID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
AND M_PatientIsActive = 'Y'
AND T_OrderHeaderID = ?
LEFT JOIN biodata_confirm ON T_OrderHeaderID = BiodataConfirmT_OrderHeaderID
AND (BiodataConfirmRetry < 10 OR BiodataConfirmRetry = 0)
AND (BiodataConfirmIsActive = 'Y' OR BiodataConfirmIsActive = 0)
WHERE BiodataConfirmStatus IS NULL OR (BiodataConfirmStatus = 'R' OR BiodataConfirmStatus = 'E')";
$qry_field = $this->db->query($sql_field, [$headerID]);
if (!$qry_field) {
$this->db->trans_rollback();
$this->sys_error_db("select biodata_confirm by order_id", $this->db);
exit;
}
$rows_field = $qry_field->result_array();
// print_r($rows_field);
// exit;
$result = [];
if (count($rows_field) > 0) {
$result = $rows_field;
}
// m_patient
$sql_m_patient_field = "SELECT *
FROM m_patient
WHERE M_PatientIsActive = 'Y'
AND M_PatientID = ?";
$qry = $this->db->query($sql_m_patient_field, [$result[0]['M_PatientID']]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select m_patient by patientId", $this->db);
exit;
}
$rows_m_patient = $qry->result_array();
$m_patient_all = [];
if (count($rows_m_patient) > 0) {
$m_patient_all = $rows_m_patient;
}
echo json_encode(
[
"status" => "OK",
"message" => "Data Ditemukan",
"T_OrderHeaderID" => $result[0]['T_OrderHeaderID'],
'branch_id' => $result[0]['branch_id'],
'branch_code' => $result[0]['branch_code'],
'branch_name' => $result[0]['branch_name'],
'regional_id' => $result[0]['regional_id'],
'regional_name' => $result[0]['regional_name'],
"NIK" => $result[0]['NIK'],
"NO_REG" => $result[0]['NO_REG'],
"PID" => $result[0]['PID'],
"NO_HP" => $result[0]['NO_HP'],
"M_PatientID" => $result[0]['M_PatientID'],
"patient" => $m_patient_all[0],
]
);
}
function update($orderheaderID, $status)
{
$sql_cek = "SELECT BiodataConfirmID,
BiodataConfirmT_OrderHeaderID,
BiodataConfirmStatus
FROM biodata_confirm
WHERE BiodataConfirmT_OrderHeaderID = ?";
$qry_cek = $this->db->query($sql_cek, [$orderheaderID]);
if (!$qry_cek) {
$this->db->trans_rollback();
$this->sys_error_db("select biodata_confirm", $this->db);
exit;
}
$row = $qry_cek->result_array();
if (count($row) > 0) {
$sql_update = "UPDATE biodata_confirm SET
BiodataConfirmT_OrderHeaderID = ?,
BiodataConfirmStatus = ?,
BiodataConfirmRetry = ?,
BiodataConfirmLastUpdated = NOW()
WHERE BiodataConfirmID = ?";
$qry_update = $this->db->query($sql_update, [$orderheaderID, $status, '0', $row[0]['BiodataConfirmID']]);
$last_qry = $this->db->last_query();
if (!$qry_update) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
} else {
$sql_insert = "INSERT INTO biodata_confirm (
BiodataConfirmT_OrderHeaderID,
BiodataConfirmStatus,
BiodataConfirmRetry,
BiodataConfirmCreated,
BiodataConfirmLastUpdated)
VALUES(?,?,'0',now(),now())";
$qry_insert = $this->db->query($sql_insert, [$orderheaderID, $status]);
$last_qry = $this->db->last_query();
if (!$qry_insert) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
}
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function get_mou($companyID)
{
$sql = "select M_MouID,M_MouName, M_MouNumber
from m_mou
where M_MouIsActive = 'Y' and M_MouM_CompanyID = ?";
$resp = $this->get_rows($sql, [$companyID]);
if ($resp["status"] == -1) {
$this->error_reply("Error Get MOU by Company $companyID");
exit();
}
echo json_encode([
"status" => "OK",
"data" => $resp["data"],
]);
}
function step_debug($rows)
{
print_r($rows);
exit();
}
function get_rows($sql, $param = false)
{
if ($param) {
$qry = $this->db->query($sql, $param);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
return [
"status" => -1,
"message" =>
$this->db->last_query() .
"|" .
$this->db->error()["message"],
];
}
return ["status" => 0, "data" => $qry->result_array()];
}
function get_row($sql, $param = false)
{
$resp = $this->get_rows($sql, $param);
if ($resp["status"] == -1) {
return $resp;
}
if (count($resp["data"]) == 0) {
return ["status" => 0, "message" => "Not found."];
}
return ["status" => 1, "data" => $resp["data"][0]];
}
// get_field_m_patient_address_by_m_patient_id
function get_field_m_patient_address_by_m_patient_id($M_PatientID)
{
// kolom fields
$sql_m_patient_address_field = "SELECT *
from m_patientaddress
WHERE M_PatientAddressM_PatientID = ?";
$qry = $this->db->query($sql_m_patient_address_field, [$M_PatientID]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select m_patientaddress by patientId", $this->db);
exit;
}
$rows_m_patient_address = $qry->result_array();
// echo json_encode($result_header);
if (count($rows_m_patient_address) > 0) {
return $rows_m_patient_address;
}
return $rows_m_patient_address;
}
// get_field_m_patient_by_m_patient_id
function get_field_m_patient_by_m_patient_id($M_PatientID)
{
// kolom fields
$sql_m_patient_field = "SELECT *
from m_patient
WHERE
M_PatientIsActive = 'Y'
AND M_PatientID = ?";
$qry = $this->db->query($sql_m_patient_field, [$M_PatientID]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select m_patient by patientId", $this->db);
exit;
}
$rows_m_patient = $qry->result_array();
$result = [];
if (count($rows_m_patient) > 0) {
foreach ($rows_m_patient as $key => $value) {
$result = $value;
}
$data_address = $this->get_field_m_patient_address_by_m_patient_id($M_PatientID);
$result['m_address_json'] = $data_address;
}
return $result;
}
// get_field_m_company_by_m_company_id
function get_field_m_company_by_m_company_id($M_CompanyID)
{
// kolom fields
$sql_m_company_field = "SELECT *
from m_company
WHERE M_CompanyID = ? AND M_CompanyIsActive = 'Y'";
$qry = $this->db->query($sql_m_company_field, [$M_CompanyID]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select m_company by companyId", $this->db);
exit;
}
$rows_m_company = $qry->result_array();
if (count($rows_m_company) > 0) {
return $rows_m_company[0];
}
return $rows_m_company;
}
}