Initial import
This commit is contained in:
853
application/controllers/one-doctor/Downloader.php
Normal file
853
application/controllers/one-doctor/Downloader.php
Normal file
@@ -0,0 +1,853 @@
|
||||
<?php
|
||||
class Downloader extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: Download Patient Devone";
|
||||
}
|
||||
|
||||
public function getRegionalIPAddress()
|
||||
{
|
||||
$sql_get = "SELECT S_SystemIPAddressRegional
|
||||
FROM one.conf_systems
|
||||
WHERE S_SystemsIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql_get);
|
||||
if(!$qry){
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("get ip regional failed", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $qry->result_array();
|
||||
return $data[0]['S_SystemIPAddressRegional'];
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT M_BranchID, M_BranchCode FROM m_branch
|
||||
WHERE M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array());
|
||||
if (!$qry) {
|
||||
$$response = [
|
||||
'status' => false,
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error get branch data ",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
return $response;
|
||||
}
|
||||
$result = $qry->row_array();
|
||||
return [
|
||||
'status' => true,
|
||||
'branchId' => $result['M_BranchID'],
|
||||
'branchCode' => $result['M_BranchCode']
|
||||
];
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $message
|
||||
];
|
||||
}
|
||||
}
|
||||
function download()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$getBranch = $this->getBranch();
|
||||
if ($getBranch['status'] = false) {
|
||||
$this->sys_error($getBranch['message']);
|
||||
exit;
|
||||
}
|
||||
$limit = 20;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = $getBranch['branchId'];
|
||||
$branchCode = $getBranch['branchCode'];
|
||||
$data = array('branchId' => $branchId, 'branchCode' => $branchCode, 'limit' => $limit);
|
||||
// print_r($data);
|
||||
// exit;
|
||||
// $resp = $this->post("http://devbandungraya.aplikasi.web.id/one-api/app_doctor/DownloadOrderPatient/download", json_encode($data));
|
||||
|
||||
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
||||
$resp = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadOrderPatient/download", json_encode($data));
|
||||
$respUnc = gzuncompress($resp);
|
||||
$response = json_decode($respUnc);
|
||||
// print_r($respUnc);
|
||||
// exit;
|
||||
if ($response->status != 'OK') {
|
||||
|
||||
$this->sys_error($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dataPatient = $response->data;
|
||||
$this->db->trans_begin();
|
||||
$arrOrderPatientId = array();
|
||||
foreach ($dataPatient as $key => $valPatient) {
|
||||
$val = (array)$valPatient;
|
||||
|
||||
$orderPatientId = intval($val['OrderPatientID']);
|
||||
|
||||
$sqlCekFo = "SELECT EXISTS(SELECT OrderFoOrderPatientID FROM one_doctor.order_fo
|
||||
WHERE OrderFoOrderPatientID = ? AND OrderFoIsActive = 'Y') as result";
|
||||
$qryCekFo = $this->db->query($sqlCekFo, array(intval($orderPatientId)));
|
||||
if (!$qryCekFo) {
|
||||
$$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error cek patient exist",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$resultCekFo = $qryCekFo->row_array();
|
||||
if (intval($resultCekFo['result']) == 0) {
|
||||
$sqlCek = "SELECT EXISTS(SELECT OrderPatientID FROM one_doctor.order_patient
|
||||
WHERE OrderPatientID = ? ) as result";
|
||||
$qry = $this->db->query($sqlCek, array(intval($orderPatientId)));
|
||||
if (!$qry) {
|
||||
$$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error cek patient exist",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$result = $qry->row_array();
|
||||
$doctorId = intval($val['OrderPatientM_DoctorID']);
|
||||
$patientDate = $val['OrderPatientDate'];
|
||||
$mouId = intval($val['OrderPatientM_MouID']);
|
||||
$companyId = intval($val['M_MouM_CompanyID']);
|
||||
$patientQrCode = $val['OrderPatientQrCode'];
|
||||
$patientFullName = $val['OrderPatientFullName'];
|
||||
$patientDOB = $val['OrderPatientDOB'];
|
||||
$patientAddress = is_null(trim($val['OrderPatientAddress'])) ? ' ' : $val['OrderPatientAddress'];
|
||||
$patientNIK = $val['OrderPatientNIK'];
|
||||
$patientHp = $val['OrderPatientHp'];
|
||||
$patientDiagnose = $val['OrderPatientDiagnosa'];
|
||||
$patientNote = $val['OrderPatientNote'];
|
||||
$patientisConfirmed = $val['OrderPatientIsConfirmed'];
|
||||
$patientIsActive = $val['OrderPatientIsActive'];
|
||||
$patientUserId = intval($val['OrderPatientUserID']);
|
||||
$patientCreated = $val['OrderPatientCreated'];
|
||||
$patientLastUpdated = $val['OrderPatientLastUpdated'];
|
||||
$details = $val['details'];
|
||||
if (intval($result['result']) == 0) {
|
||||
$sql = "INSERT INTO one_doctor.order_patient (
|
||||
OrderPatientID,
|
||||
OrderPatientM_DoctorID,
|
||||
OrderPatientM_CompanyID,
|
||||
OrderPatientM_MouID,
|
||||
OrderPatientDate,
|
||||
OrderPatientQrCode,
|
||||
OrderPatientFullName,
|
||||
OrderPatientDOB,
|
||||
OrderPatientAddress,
|
||||
OrderPatientNIK,
|
||||
OrderPatientHp,
|
||||
OrderPatientDiagnosa,
|
||||
OrderPatientNote,
|
||||
OrderPatientIsConfirmed,
|
||||
OrderPatientIsActive,
|
||||
OrderPatientUserID,
|
||||
OrderPatientCreated,
|
||||
OrderPatientLastUpdated)
|
||||
VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$orderPatientId,
|
||||
$doctorId,
|
||||
$companyId,
|
||||
$mouId,
|
||||
$patientDate,
|
||||
$patientQrCode,
|
||||
$patientFullName,
|
||||
$patientDOB,
|
||||
$patientAddress,
|
||||
$patientNIK,
|
||||
$patientHp,
|
||||
$patientDiagnose,
|
||||
$patientNote,
|
||||
$patientisConfirmed,
|
||||
$patientIsActive,
|
||||
$patientUserId,
|
||||
$patientCreated,
|
||||
$patientLastUpdated
|
||||
));
|
||||
if (!$qry) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error insert patient ",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$insertDetail = $this->insertDetail($details);
|
||||
if (!$insertDetail['status']) {
|
||||
$response = [
|
||||
'status' => $insertDetail,
|
||||
'message' => $insertDetail['msg'],
|
||||
'msg' => "error insert detail 1"
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} elseif (intval($result['result']) == 1) {
|
||||
$sqlUpdate = "UPDATE one_doctor.order_patient
|
||||
SET OrderPatientM_DoctorID = ?,
|
||||
OrderPatientM_CompanyID = ?,
|
||||
OrderPatientM_MouID = ?,
|
||||
OrderPatientDate = ?,
|
||||
OrderPatientQrCode = ?,
|
||||
OrderPatientFullName = ?,
|
||||
OrderPatientDOB = ?,
|
||||
OrderPatientAddress = ?,
|
||||
OrderPatientNIK = ?,
|
||||
OrderPatientHp = ?,
|
||||
OrderPatientDiagnosa = ?,
|
||||
OrderPatientNote = ?,
|
||||
OrderPatientIsConfirmed = ?,
|
||||
OrderPatientIsActive = ?,
|
||||
OrderPatientUserID = ?,
|
||||
OrderPatientCreated = ?
|
||||
WHERE OrderPatientID = ?";
|
||||
$qryUpdate = $this->db->query($sqlUpdate, array(
|
||||
$doctorId,
|
||||
$companyId,
|
||||
$mouId,
|
||||
$patientDate,
|
||||
$patientQrCode,
|
||||
$patientFullName,
|
||||
$patientDOB,
|
||||
$patientAddress,
|
||||
$patientNIK,
|
||||
$patientHp,
|
||||
$patientDiagnose,
|
||||
$patientNote,
|
||||
$patientisConfirmed,
|
||||
$patientIsActive,
|
||||
$patientUserId,
|
||||
$patientCreated,
|
||||
$orderPatientId
|
||||
));
|
||||
if (!$qryUpdate) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error update patient ",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$insertDetail = $this->insertDetail($details);
|
||||
if (!$insertDetail['status']) {
|
||||
|
||||
$response = [
|
||||
'status' => $insertDetail,
|
||||
'message' => $insertDetail['msg'],
|
||||
'msg' => "error insert detail 2"
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
$arrOrderPatientId[] = $orderPatientId;
|
||||
}
|
||||
//DEBUG
|
||||
// exit;
|
||||
$paramLog = array(
|
||||
"branchId" => $branchId, "arrOrderPatientId" => $arrOrderPatientId
|
||||
);
|
||||
|
||||
$z_param = gzcompress(json_encode($paramLog));
|
||||
// $respLog = $this->post("http://devbandungraya.aplikasi.web.id/one-api/app_doctor/DownloadOrderPatient/updateLog", $z_param);
|
||||
|
||||
$respLog = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadOrderPatient/updateLog", $z_param);
|
||||
$this->db->trans_commit();
|
||||
|
||||
$respLog = (array) json_decode($respLog);
|
||||
|
||||
if ($respLog['status'] != 'OK') {
|
||||
$this->sys_error($respLog);
|
||||
} else {
|
||||
$this->sys_ok($respLog);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function insertDetail($prm)
|
||||
{
|
||||
try {
|
||||
if (count($prm) > 0) {
|
||||
foreach ($prm as $key => $dtlOrder) {
|
||||
$dtl = (array)$dtlOrder;
|
||||
$detailId = intval($dtl['OrderPatientDetailsID']);
|
||||
$sqlCek = "SELECT EXISTS(SELECT OrderPatientDetailsID FROM one_doctor.order_patient_details
|
||||
WHERE OrderPatientDetailsID = ? ) as result";
|
||||
$qry = $this->db->query($sqlCek, array(intval($detailId)));
|
||||
$result = $qry->row_array();
|
||||
$patientId = intval($dtl['OrderPatientDetailsOrderPatientID']);
|
||||
$testId = intval($dtl['OrderPatientDetailsT_TestID']);
|
||||
$testName = $dtl['OrderPatientDetailsT_TestName'];
|
||||
$isPrice = doubleval($dtl['OrderPatientDetailsPrice']);
|
||||
$isActive = $dtl['OrderPatientDetailsIsActive'];
|
||||
$userId = intval($dtl['OrderPatientDetailsUserID']);
|
||||
$created = $dtl['OrderPatientDetailsCreated'];
|
||||
$lastUpdated = $dtl['OrderPatientDetailsLastUpdated'];
|
||||
if (intval($result['result']) == 0) {
|
||||
$sqlInsert = "INSERT INTO one_doctor.order_patient_details(
|
||||
OrderPatientDetailsID,
|
||||
OrderPatientDetailsOrderPatientID,
|
||||
OrderPatientDetailsT_TestID,
|
||||
OrderPatientDetailsT_TestName,
|
||||
OrderPatientDetailsPrice,
|
||||
OrderPatientDetailsIsActive,
|
||||
OrderPatientDetailsUserID,
|
||||
OrderPatientDetailsCreated,
|
||||
OrderPatientDetailsLastUpdated)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
$qryInsert = $this->db->query($sqlInsert, array(
|
||||
$detailId,
|
||||
$patientId,
|
||||
$testId,
|
||||
$testName,
|
||||
$isPrice,
|
||||
$isActive,
|
||||
$userId,
|
||||
$created,
|
||||
$lastUpdated
|
||||
));
|
||||
if (!$qryInsert) {
|
||||
return [
|
||||
'status' => false,
|
||||
'msg' => 'error insert',
|
||||
'error' => $this->db->error()["message"],
|
||||
|
||||
];
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} elseif (intval($result['result']) == 1) {
|
||||
$sqlUpdate = "UPDATE one_doctor.order_patient_details
|
||||
SET OrderPatientDetailsOrderPatientID = ?,
|
||||
OrderPatientDetailsT_TestID = ?,
|
||||
OrderPatientDetailsT_TestName = ?,
|
||||
OrderPatientDetailsPrice = ?,
|
||||
OrderPatientDetailsIsActive = ?,
|
||||
OrderPatientDetailsUserID = ?,
|
||||
OrderPatientDetailsCreated = ?
|
||||
WHERE OrderPatientDetailsID = ?";
|
||||
$qryUpdate = $this->db->query($sqlUpdate, array(
|
||||
$patientId,
|
||||
$testId,
|
||||
$testName,
|
||||
$isPrice,
|
||||
$isActive,
|
||||
$userId,
|
||||
$created,
|
||||
$detailId
|
||||
));
|
||||
if (!$qryUpdate) {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => $this->db->error()["message"],
|
||||
'msg' => 'error update'
|
||||
];
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => true,
|
||||
'msg' => ''
|
||||
];
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return [
|
||||
'status' => false,
|
||||
'msg' => $message
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
function insertSaran($prm)
|
||||
{
|
||||
try {
|
||||
if (count($prm) > 0) {
|
||||
foreach ($prm as $key => $e) {
|
||||
|
||||
$value = (array) $e;
|
||||
$saranId = intval($value['OrderSaranID']);
|
||||
$sqlCek = "SELECT EXISTS(SELECT OrderSaranID FROM one_doctor.order_saran
|
||||
WHERE OrderSaranID = ? ) as result";
|
||||
$qry = $this->db->query($sqlCek, array(intval($saranId)));
|
||||
if (!$qry) {
|
||||
return [
|
||||
'status' => false,
|
||||
'msg' => 'error insert',
|
||||
'error' => $this->db->error()["message"],
|
||||
|
||||
];
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$result = $qry->row_array();
|
||||
$patientId = intval($value['OrderSaranOrderPatientID']);
|
||||
$kesimpullan = $value['OrderKesimpulan'];
|
||||
$saran = $value['OrderSaran'];
|
||||
$isActive = $value['OrderSaranIsActive'];
|
||||
$userId = intval($value['OrderSaranUserID']);
|
||||
$created = $value['OrderSaranCreated'];
|
||||
$lastUpdated = $value['OrderSaranLastUpdated'];
|
||||
if (intval($result['result']) == 0) {
|
||||
|
||||
$sqlInsert = "INSERT INTO one_doctor.order_saran
|
||||
(OrderSaranID,
|
||||
OrderSaranOrderPatientID,
|
||||
OrderKesimpulan,
|
||||
OrderSaran,
|
||||
OrderSaranIsActive,
|
||||
OrderSaranUserID,
|
||||
OrderSaranCreated,
|
||||
OrderSaranLastUpdated)
|
||||
VALUES(?,?,?,?,?,?,?,?)";
|
||||
$qryInsert = $this->db->query($sqlInsert, array(
|
||||
$saranId,
|
||||
$patientId,
|
||||
$kesimpullan,
|
||||
$saran,
|
||||
$isActive,
|
||||
$userId,
|
||||
$created,
|
||||
$lastUpdated
|
||||
));
|
||||
if (!$qryInsert) {
|
||||
return [
|
||||
'status' => false,
|
||||
'msg' => 'error insert',
|
||||
'error' => $this->db->error()["message"],
|
||||
|
||||
];
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} elseif (intval($result['result']) == 1) {
|
||||
$sqlUpdate = "UPDATE one_doctor.order_saran SET
|
||||
OrderKesimpulan = ?,
|
||||
OrderSaran = ?,
|
||||
OrderSaranUserID = ?
|
||||
WHERE
|
||||
OrderSaranID = ?";
|
||||
$qryUpdate = $this->db->query($sqlUpdate, array(
|
||||
$kesimpullan,
|
||||
$saran,
|
||||
$userId,
|
||||
$saranId
|
||||
));
|
||||
if (!$qryUpdate) {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => $this->db->error()["message"],
|
||||
'msg' => 'error update'
|
||||
];
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => true,
|
||||
'msg' => ''
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => true,
|
||||
'msg' => ''
|
||||
];
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
return [
|
||||
'status' => false,
|
||||
'msg' => $message
|
||||
];
|
||||
}
|
||||
}
|
||||
function downloadSaran()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$getBranch = $this->getBranch();
|
||||
if ($getBranch['status'] = false) {
|
||||
$this->sys_error($getBranch['message']);
|
||||
exit;
|
||||
}
|
||||
$limit = 20;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
// $branchId = $prm['branchId'];
|
||||
// $branchCode = $prm['branchCode'];
|
||||
$branchId = $getBranch['branchId'];
|
||||
$branchCode = $getBranch['branchCode'];
|
||||
$data = array('branchId' => $branchId, 'branchCode' => $branchCode, 'limit' => $limit);
|
||||
// print_r($data);
|
||||
// exit;
|
||||
|
||||
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
||||
$resp = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadOrderPatient/downloadSaran", json_encode($data));
|
||||
$respUnc = gzuncompress($resp);
|
||||
$response = json_decode($respUnc);
|
||||
// print_r($respUnc);
|
||||
// exit;
|
||||
if ($response->status != 'OK') {
|
||||
|
||||
$this->sys_error($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dataorderSaran = $response->data;
|
||||
$this->db->trans_begin();
|
||||
$arrOrderSaranId = array();
|
||||
if (count($dataorderSaran) > 0) {
|
||||
foreach ($dataorderSaran as $key => $e) {
|
||||
|
||||
$value = (array) $e;
|
||||
$saranId = intval($value['OrderSaranID']);
|
||||
$sqlCek = "SELECT EXISTS(SELECT OrderSaranID FROM one_doctor.order_saran
|
||||
WHERE OrderSaranID = ? ) as result";
|
||||
$qry = $this->db->query($sqlCek, array(intval($saranId)));
|
||||
if (!$qry) {
|
||||
$response = [
|
||||
'msg' => 'error insert',
|
||||
'error' => $this->db->error()["message"],
|
||||
|
||||
];
|
||||
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$result = $qry->row_array();
|
||||
$patientId = intval($value['OrderSaranOrderPatientID']);
|
||||
$kesimpullan = $value['OrderKesimpulan'];
|
||||
$saran = $value['OrderSaran'];
|
||||
$isActive = $value['OrderSaranIsActive'];
|
||||
$userId = intval($value['OrderSaranUserID']);
|
||||
$created = $value['OrderSaranCreated'];
|
||||
$lastUpdated = $value['OrderSaranLastUpdated'];
|
||||
if (intval($result['result']) == 0) {
|
||||
|
||||
$sqlInsert = "INSERT INTO one_doctor.order_saran
|
||||
(OrderSaranID,
|
||||
OrderSaranOrderPatientID,
|
||||
OrderKesimpulan,
|
||||
OrderSaran,
|
||||
OrderSaranIsActive,
|
||||
OrderSaranUserID,
|
||||
OrderSaranCreated,
|
||||
OrderSaranLastUpdated)
|
||||
VALUES(?,?,?,?,?,?,?,?)";
|
||||
$qryInsert = $this->db->query($sqlInsert, array(
|
||||
$saranId,
|
||||
$patientId,
|
||||
$kesimpullan,
|
||||
$saran,
|
||||
$isActive,
|
||||
$userId,
|
||||
$created,
|
||||
$lastUpdated
|
||||
));
|
||||
if (!$qryInsert) {
|
||||
$response = [
|
||||
'msg' => 'error insert',
|
||||
'error' => $this->db->error()["message"],
|
||||
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} elseif (intval($result['result']) == 1) {
|
||||
$sqlUpdate = "UPDATE one_doctor.order_saran SET
|
||||
OrderKesimpulan = ?,
|
||||
OrderSaran = ?,
|
||||
OrderSaranUserID = ?
|
||||
WHERE
|
||||
OrderSaranID = ?";
|
||||
$qryUpdate = $this->db->query($sqlUpdate, array(
|
||||
$kesimpullan,
|
||||
$saran,
|
||||
$userId,
|
||||
$saranId
|
||||
));
|
||||
if (!$qryUpdate) {
|
||||
$response = [
|
||||
'error' => $this->db->error()["message"],
|
||||
'msg' => 'error update'
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$arrOrderSaranId[] = $saranId;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
|
||||
$paramLog = array(
|
||||
"branchId" => $branchId, "arrOrderSaranId" => $arrOrderSaranId
|
||||
);
|
||||
// print_r(json_encode($paramLog));
|
||||
// exit;
|
||||
$z_param = gzcompress(json_encode($paramLog));
|
||||
$respLog = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadOrderPatient/updateSaranLog", $z_param);
|
||||
$this->db->trans_commit();
|
||||
|
||||
$respLog = (array) json_decode($respLog);
|
||||
|
||||
if ($respLog['status'] != 'OK') {
|
||||
$this->sys_error($respLog);
|
||||
} else {
|
||||
$this->sys_ok($respLog);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// download pesan khusus
|
||||
function download_pesan_khusus()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$getBranch = $this->getBranch();
|
||||
if ($getBranch['status'] = false) {
|
||||
$this->sys_error($getBranch['message']);
|
||||
exit;
|
||||
}
|
||||
$limit = 20;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm['limit']);
|
||||
}
|
||||
$branchId = $getBranch['branchId'];
|
||||
$branchCode = $getBranch['branchCode'];
|
||||
$data = array('branchId' => $branchId, 'branchCode' => $branchCode, 'limit' => $limit);
|
||||
// print_r($data);
|
||||
// exit;
|
||||
// $resp = $this->post("http://devbandungraya.aplikasi.web.id/one-api/app_doctor/DownloadOrderPatient/download", json_encode($data));
|
||||
|
||||
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
||||
$resp = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadPesanKhusus/download", json_encode($data));
|
||||
$respUnc = gzuncompress($resp);
|
||||
$response = json_decode($respUnc);
|
||||
// print_r($respUnc);
|
||||
// exit;
|
||||
if ($response->status != 'OK') {
|
||||
|
||||
$this->sys_error($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dataPatient = $response->data;
|
||||
$this->db->trans_begin();
|
||||
$arrOrderPatientId = array();
|
||||
|
||||
foreach ($dataPatient as $key => $valPatient) {
|
||||
$val = (array)$valPatient;
|
||||
|
||||
$orderPatientId = intval($val['DoctorMessageOrderPatientID']);
|
||||
|
||||
$sqlCekDoctorMessage = "SELECT EXISTS(SELECT OrderFoOrderPatientID FROM one_doctor.order_fo
|
||||
WHERE OrderFoOrderPatientID = $orderPatientId
|
||||
AND OrderFoIsActive = 'Y') as result";
|
||||
// $qryCekDoctorMessage = $this->db->query($sqlCekDoctorMessage, array(intval($orderPatientId)));
|
||||
$qryCekDoctorMessage = $this->db->query($sqlCekDoctorMessage);
|
||||
if (!$qryCekDoctorMessage) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error cek doctor message exist",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$resultCekDoctorMessage = $qryCekDoctorMessage->row_array();
|
||||
|
||||
// print_r($sqlCekDoctorMessage);
|
||||
// exit;
|
||||
|
||||
if (intval($resultCekDoctorMessage['result']) > 0) {
|
||||
|
||||
$sqlCek = "SELECT EXISTS(SELECT DoctorMessageOrderPatientID
|
||||
FROM one_doctor.doctor_message
|
||||
WHERE DoctorMessageOrderPatientID = ? ) as result";
|
||||
$qry = $this->db->query($sqlCek, array(intval($orderPatientId)));
|
||||
if (!$qry) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error cek doctor message exist",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$result = $qry->row_array();
|
||||
|
||||
// data dari regional
|
||||
$reg_order_id = intval($val['DoctorMessageOrderPatientID']);
|
||||
$reg_pesan = is_null(trim($val['DoctorMessagePesan'])) ? ' ' : $val['DoctorMessagePesan'];
|
||||
$reg_status_download = $val['DoctorMessageStatusDownload'];
|
||||
$reg_is_active = $val['DoctorMessageIsActive'];
|
||||
$reg_user_id = intval($val['DoctorMessageUserID']);
|
||||
$reg_created = $val['DoctorMessageCreated'];
|
||||
$reg_updated = $val['DoctorMessageUpdated'];
|
||||
|
||||
if (intval($result['result']) == 0) {
|
||||
$sql = "INSERT INTO one_doctor.doctor_message (
|
||||
DoctorMessageOrderPatientID,
|
||||
DoctorMessagePesan,
|
||||
DoctorMessageStatusDownload,
|
||||
DoctorMessageIsActive,
|
||||
DoctorMessageUserID,
|
||||
DoctorMessageCreated,
|
||||
DoctorMessageUpdated)
|
||||
VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$reg_order_id,
|
||||
$reg_pesan,
|
||||
$reg_status_download,
|
||||
$reg_is_active,
|
||||
$reg_user_id,
|
||||
$reg_created,
|
||||
$reg_updated
|
||||
));
|
||||
if (!$qry) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error insert doctor message ",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
} elseif (intval($result['result']) == 1) {
|
||||
$sqlUpdate = "UPDATE one_doctor.doctor_message
|
||||
SET DoctorMessagePesan = ?,
|
||||
DoctorMessageStatusDownload = ?,
|
||||
DoctorMessageIsActive = ?,
|
||||
DoctorMessageUserID = ?,
|
||||
DoctorMessageCreated = ?,
|
||||
DoctorMessageUpdated = ?
|
||||
WHERE DoctorMessageOrderPatientID = ?";
|
||||
$qryUpdate = $this->db->query($sqlUpdate, array(
|
||||
$reg_pesan,
|
||||
$reg_status_download,
|
||||
$reg_is_active,
|
||||
$reg_user_id,
|
||||
$reg_created,
|
||||
$reg_updated,
|
||||
$reg_order_id
|
||||
));
|
||||
if (!$qryUpdate) {
|
||||
$response = [
|
||||
"message" => $this->db->error()["message"],
|
||||
"msg" => "error update doctor message ",
|
||||
'query' => $this->db->last_query()
|
||||
];
|
||||
$this->sys_error($response);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$arrOrderPatientId[] = $orderPatientId;
|
||||
}
|
||||
|
||||
// print_r($arrOrderPatientId);
|
||||
// exit;
|
||||
|
||||
//DEBUG
|
||||
// exit;
|
||||
|
||||
$paramLog = array(
|
||||
"branchId" => $branchId, "arrOrderPatientId" => $arrOrderPatientId
|
||||
);
|
||||
|
||||
$z_param = gzcompress(json_encode($paramLog));
|
||||
// $respLog = $this->post("http://devbandungraya.aplikasi.web.id/one-api/app_doctor/DownloadOrderPatient/updateLog", $z_param);
|
||||
|
||||
$respLog = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadPesanKhusus/updateLog", $z_param);
|
||||
$this->db->trans_commit();
|
||||
|
||||
$respLog = (array) json_decode($respLog);
|
||||
|
||||
if ($respLog['status'] != 'OK') {
|
||||
$this->sys_error($respLog);
|
||||
} else {
|
||||
$this->sys_ok($respLog);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Http Error : " . curl_error($ch),
|
||||
]);
|
||||
curl_close($ch);
|
||||
exit();
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user