844 lines
34 KiB
PHP
844 lines
34 KiB
PHP
<?php
|
|
class Hiskirimorder extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $DOCTOR_ID = 0;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->DOCTOR_ID = 0;
|
|
}
|
|
function index()
|
|
{
|
|
echo "Api: Training Playground";
|
|
}
|
|
|
|
function insertlog()
|
|
{
|
|
try {
|
|
$param = $this->sys_input;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
//508
|
|
function process()
|
|
{
|
|
try {
|
|
$param = $this->sys_input;
|
|
// print_r($param);
|
|
$this->db->trans_begin();
|
|
$patient = $param['patient'];
|
|
$dokter = $param['clinician'];
|
|
$this->cek_dokter($dokter);
|
|
$this->cek_patient($patient);
|
|
$patientID = $this->get_patient($patient['regid']);
|
|
$doctorID = $this->get_dokter($dokter['code']);
|
|
$dokterSenderAddress = $this->get_dokter_address($doctorID);
|
|
$dokterPJ = $this->get_dokter_pjm();
|
|
$patientBirth = strtotime($patient['birth_dt']);
|
|
$patientBirthFormat = date('Y-m-d', $patientBirth);
|
|
$orderDate = strtotime($param['request_dt']);
|
|
$orderDateFormat = date('Y-m-d', $orderDate);
|
|
$patientAge = $this->get_age($patientBirthFormat, $orderDateFormat);
|
|
$this->generate_header($param, $patientID, $doctorID, $dokterPJ, $patientAge, $dokterSenderAddress);
|
|
// print_r($patientAge);
|
|
$this->db->trans_commit();
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function cek_patient($patient)
|
|
{
|
|
try {
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$sql = "SELECT COUNT(M_PatientID) AS patient_cek, M_PatientID FROM m_patient WHERE M_PatientNoReg = ?";
|
|
$qry = $this->db->query($sql, [$patient['regid']]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Cek patient error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
if ($userid == "") {
|
|
$userid = 0;
|
|
}
|
|
// print_r($userid);
|
|
// exit;
|
|
$patientID = $qry->row_array()['M_PatientID'];
|
|
$patientName = $patient['name'];
|
|
$regNumb = $patient['regid'];
|
|
$sex = $patient['sex'];
|
|
$mobilePhone = $patient['mobile_phone'];
|
|
$email = $patient['email'];
|
|
$birth = strtotime($patient['birth_dt']);
|
|
$birthFormat = date('Y-m-d', $birth);
|
|
$titleId = 2;
|
|
if ($sex == '2') {
|
|
$titleId = 6;
|
|
}
|
|
if ($qry->row_array()['patient_cek'] == 0) {
|
|
//Insert patient
|
|
$sql_insert = "INSERT INTO m_patient(
|
|
M_PatientNoReg,
|
|
M_PatientName,
|
|
M_PatientHP,
|
|
M_PatientEmail,
|
|
M_PatientM_SexID,
|
|
M_PatientDOB,
|
|
M_PatientM_TitleID)
|
|
VALUES(?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?)";
|
|
$qry_insert = $this->db->query($sql_insert, [$regNumb, $patientName, $mobilePhone, $email, $sex, $birthFormat, $titleId]);
|
|
if (!$qry_insert) {
|
|
$this->sys_error_db("Insert error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$insert_id = $this->db->insert_id();
|
|
for ($i = 0; $i < 4; $i++) {
|
|
$teks = "address$i";
|
|
$address = $patient[$teks];
|
|
if ($address != "") {
|
|
$sql_insert = "INSERT INTO m_patientaddress(
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressUserID)
|
|
VALUES( ?,
|
|
?, ?)
|
|
";
|
|
$qry_insert = $this->db->query($sql_insert, [$insert_id, $address, $userid]);
|
|
if (!$qry_insert) {
|
|
$this->sys_error_db("Insert address error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
//update patient
|
|
$sql_update = "UPDATE m_patient SET M_PatientName = ?,
|
|
M_PatientHP =?,
|
|
M_PatientEmail = ?,
|
|
M_PatientM_SexID=?,
|
|
M_PatientDOB=?,
|
|
M_PatientM_TitleID=? WHERE
|
|
M_PatientNoReg = ?";
|
|
$qry_update = $this->db->query($sql_update, [$patientName, $mobilePhone, $email, $sex, $birthFormat, $titleId, $regNumb]);
|
|
if (!$qry_update) {
|
|
$this->sys_error_db("update patient error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$sql_cek = "SELECT * FROM m_patientaddress
|
|
WHERE M_PatientAddressIsActive = 'Y'
|
|
AND M_PatientAddressM_PatientID = ?";
|
|
$qry_cek = $this->db->query($sql_cek, [$patientID]);
|
|
if (!$qry_cek) {
|
|
$this->sys_error_db("cek address error(update patient)", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$result_cek = $qry_cek->result_array();
|
|
// print_r(json_encode($patientID));
|
|
// exit;
|
|
$count_result = count($result_cek);
|
|
// print_r($count_result);
|
|
if ($count_result == 0) {
|
|
// print_r("Masuk insert ");
|
|
for ($i = 1; $i <= 4; $i++) {
|
|
$teks = "address$i";
|
|
$address = $patient[$teks];
|
|
if ($address != "") {
|
|
$sql_insert = "INSERT INTO m_patientaddress(
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressUserID)
|
|
VALUES( ?,
|
|
?, ?)
|
|
";
|
|
$qry_insert = $this->db->query($sql_insert, [$patientID, $address, $userid]);
|
|
if (!$qry_insert) {
|
|
$this->sys_error_db("Insert address error(update)", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for ($i = 1; $i <= 4; $i++) {
|
|
$teks = "address$i";
|
|
$address = $patient[$teks];
|
|
$addressID = $result_cek[$i - 1]['M_PatientAddressID'];
|
|
if ($i <= $count_result) {
|
|
if ($address != "") {
|
|
// print_r("Update address");
|
|
$sql_update = "UPDATE m_patientaddress SET M_PatientAddressDescription = ?,
|
|
M_PatientAddressUserID = ?
|
|
WHERE M_PatientAddressID = ?";
|
|
$qry_update = $this->db->query($sql_update, [$address, $userid, $addressID]);
|
|
if (!$qry_update) {
|
|
$this->sys_error_db("update address error(update)", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
} else if ($address == "") {
|
|
// print_r("Update address is active = N");
|
|
$sql_update = "UPDATE m_patientaddress SET M_PatientAddressIsActive= 'N',
|
|
M_PatientAddressUserID = ?
|
|
WHERE M_PatientAddressID = ?";
|
|
$qry_update = $this->db->query($sql_update, [$userid, $addressID]);
|
|
if (!$qry_update) {
|
|
$this->sys_error_db("update address error(update)", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
if ($address != "") {
|
|
// print_r("Masuk insert 2");
|
|
$sql_insert = "INSERT INTO m_patientaddress(
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressUserID)
|
|
VALUES( ?,
|
|
?, ?)
|
|
";
|
|
$qry_insert = $this->db->query($sql_insert, [$patientID, $address, $userid]);
|
|
if (!$qry_insert) {
|
|
$this->sys_error_db("Insert address error(update)", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function cek_dokter($dokter)
|
|
{
|
|
try {
|
|
// print_r($dokter);
|
|
$code = $dokter['code'];
|
|
$name = $dokter['name'];
|
|
$address = "$code - $name";
|
|
if (isset($dokter['address'])) {
|
|
$address = $dokter['address'];
|
|
}
|
|
|
|
$sql_cek = "SELECT * FROM m_doctor WHERE M_DoctorCode = ? AND M_DoctorIsActive = 'Y'";
|
|
|
|
$qry_cek = $this->db->query($sql_cek, [$code]);
|
|
if (!$qry_cek) {
|
|
$this->sys_error_db("Cek dokter error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$dokter_result = $qry_cek->result_array();
|
|
// print_r($dokter_result);
|
|
if (count($dokter_result) == 0) {
|
|
//insert dokter
|
|
// print_r('insert dokter');
|
|
$sql = "INSERT INTO m_doctor( M_DoctorCode, M_DoctorName, M_DoctorOldCode) VALUES(?, ?, ?)";
|
|
$qry = $this->db->query($sql, [$code, $name, $code]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("insert dokter error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$insert_id = $this->db->insert_id();
|
|
|
|
$sql_address = "INSERT INTO m_doctoraddress(
|
|
M_DoctorAddressM_DoctorID,
|
|
M_DoctorAddressNote,
|
|
M_DoctorAddressDescription,
|
|
M_DoctorAddressM_UserID)
|
|
VALUES(
|
|
?,
|
|
'PRAKTEK',
|
|
?,
|
|
?)";
|
|
$qry_address = $this->db->query(
|
|
$sql_address,
|
|
[$insert_id, $address, 3]
|
|
);
|
|
if (!$qry_address) {
|
|
$this->sys_error_db("insert address dokter error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
} else {
|
|
//update dokter
|
|
// print_r('update dokter');
|
|
$dokterID = $dokter_result[0]['M_DoctorID'];
|
|
$sql = "UPDATE m_doctor SET M_DoctorName = ? WHERE M_DoctorCode =?";
|
|
$qry = $this->db->query($sql, [$name, $code]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Update dokter error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
|
|
$sql_address = "UPDATE m_doctoraddress SET M_DoctorAddressDescription = ?
|
|
WHERE M_DoctorAddressM_DoctorID = ?";
|
|
$qry_address = $this->db->query($sql_address, [$address, $dokterID]);
|
|
if (!$qry_address) {
|
|
$this->sys_error_db("Update dokter address error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
function generate_header($order, $patientID, $dokterID, $dokterPJ, $patientAge, $dokterSenderAddressID)
|
|
{
|
|
try {
|
|
$sql_cek = "SELECT * FROM t_orderheader WHERE T_OrderHeaderLabNumberExt = ?";
|
|
$qry_cek = $this->db->query($sql_cek, [$order['reglab']]);
|
|
$userID = 0;
|
|
if (!$qry_cek) {
|
|
$this->sys_error_db("Error cek order", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$rst = $qry_cek->result_array();
|
|
$idcek = 0;
|
|
if (count($rst) != 0) {
|
|
$idcek = $rst[0]['T_OrderHeaderID'];
|
|
}
|
|
// print_r($rst);
|
|
// print_r($idcek);
|
|
// exit;
|
|
$companyID = 1222;
|
|
$mouID = 2759;
|
|
$xheader = [
|
|
"date" => date("Y-m-d H:i:s"),
|
|
"patient_id" => $patientID,
|
|
"age" => $patientAge,
|
|
"sender_doctor_id" => $dokterID,
|
|
"sender_address_id" => $dokterSenderAddressID,
|
|
"pj_doctor_id" => $dokterPJ,
|
|
"company_id" => $companyID,
|
|
"mou_id" => $mouID,
|
|
"lang_id" => "1",
|
|
"lang_si" => "N",
|
|
"doctor_note" => "",
|
|
"fo_note" => "",
|
|
"queue" => "",
|
|
"received_sample" => "N",
|
|
"lang_id_2" => "0",
|
|
"lang_si_2" => "N",
|
|
"diagnose" => $order['diagnose']
|
|
];
|
|
|
|
$xdel = [[
|
|
"address_id" => 0,
|
|
"delivery_id" => 1,
|
|
"delivery_type_id" => 1,
|
|
"senderdoctorid" => $dokterID,
|
|
"senderaddressid" => $dokterSenderAddressID,
|
|
"note" => "",
|
|
"kelurahan" => 0,
|
|
]];
|
|
$arrTes = $order['order_testid'];
|
|
|
|
$tes = implode(",", $arrTes);
|
|
$sql = "SELECT * FROM one_his.service_test JOIN
|
|
one_aditya.t_test ON service_test.T_TestID = one_aditya.t_test.T_TestID
|
|
AND one_aditya.t_test.T_TestIsActive = 'Y'
|
|
JOIN one_his.service
|
|
ON one_his.service.service_id = one_his.service_test.service_id
|
|
WHERE service_testIsActive ='Y' AND service_code IN ($tes) ";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error get tes", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$testResult = $qry->result_array();
|
|
$xdetail = array();
|
|
foreach ($testResult as $key => $value) {
|
|
|
|
$xdetail[] = [
|
|
"t_id" => $value["T_TestID"],
|
|
"t_cito" => "N", //N
|
|
"t_price" => 0,
|
|
"t_disc" => 0,
|
|
"t_discrp" => 0,
|
|
"t_req" => "Y",
|
|
"t_reqnote" => "",
|
|
"t_ispacket" => "N", //N
|
|
"t_packettype" => "PX", //PX
|
|
"t_packetid" => 0, //0
|
|
];
|
|
}
|
|
$xreq = [
|
|
"status" => "Y",
|
|
"reqs" => "[]",
|
|
];
|
|
$header_json = json_encode($xheader);
|
|
$delivery_json = json_encode($xdel);
|
|
$detail_json = json_encode($xdetail);
|
|
$req_json = json_encode($xreq);
|
|
$sql = "CALL `sp_fo_register_save_online`(
|
|
'{$idcek}',
|
|
'{$header_json}',
|
|
'{$delivery_json}',
|
|
'{$detail_json}',
|
|
'{$req_json}',
|
|
'{$userID}'
|
|
)";
|
|
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Err sp_fo_register_save_online ", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$result = $qry->row_array();
|
|
|
|
if ($result['status'] != 'OK') {
|
|
$this->sys_error($result);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$headerID = json_decode($result['data'])->id;
|
|
|
|
$this->clean_mysqli_connection($this->db->conn_id);
|
|
$sql = "UPDATE t_orderheader SET T_OrderHeaderLabNumberExt = ? WHERE T_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, [$order['reglab'], $headerID]);
|
|
$this->generate_order_his($order, $idcek);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error update lab numb ext", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
// print_r($result);
|
|
$this->sys_ok($result);
|
|
if (count($rst) == 0) {
|
|
$this->do_order_log($headerID, $delivery_json);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_patient($regNum)
|
|
{
|
|
try {
|
|
$sql = "SELECT M_PatientID FROM m_patient WHERE M_PatientNoReg = ?";
|
|
$qry = $this->db->query($sql, [$regNum]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get patient error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$patient = $qry->row_array();
|
|
return $patient['M_PatientID'];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_dokter_address($dokterID)
|
|
{
|
|
try {
|
|
$sql = "SELECT * FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = ? ";
|
|
$qry = $this->db->query($sql, [$dokterID]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get doctor address error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$patient = $qry->row_array();
|
|
return $patient['M_DoctorAddressID'];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_dokter($dokterCode)
|
|
{
|
|
try {
|
|
// print_r($dokterCode);
|
|
$sql_cek = "SELECT * FROM m_doctor WHERE M_DoctorCode = ? AND M_DoctorIsActive = 'Y'";
|
|
|
|
$qry_cek = $this->db->query($sql_cek, [$dokterCode]);
|
|
if (!$qry_cek) {
|
|
$this->sys_error_db("get dokter error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$dokter_result = $qry_cek->row_array();
|
|
// print_r($dokter_result);
|
|
return $dokter_result['M_DoctorID'];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_dokter_pjm()
|
|
{
|
|
try {
|
|
$sql_cek = "select * from m_doctorpj where M_DoctorPjIsActive = 'Y' and M_DoctorPjIsDefaultPJ='Y'";
|
|
|
|
$qry_cek = $this->db->query($sql_cek, []);
|
|
if (!$qry_cek) {
|
|
$this->sys_error_db("Get dokter pjm error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$dokter_result = $qry_cek->row_array();
|
|
// print_r($dokter_result);
|
|
return $dokter_result['M_DoctorPjID'];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
public function get_age($dob, $order_date)
|
|
{
|
|
$sql = "select fn_global_age_count(?,?) xage";
|
|
$qry = $this->db->query($sql, [$dob, $order_date]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("get age error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
return "";
|
|
}
|
|
return $rows[0]["xage"];
|
|
}
|
|
|
|
function coba_sp()
|
|
{
|
|
try {
|
|
$userID = 3;
|
|
$companyID = 1222;
|
|
$mouID = 2759;
|
|
$xheader = [
|
|
"date" => date("Y-m-d H:i:s"),
|
|
"patient_id" => 1500112,
|
|
"age" => "20 tahun",
|
|
"sender_doctor_id" => 25872,
|
|
"sender_address_id" => 0,
|
|
"pj_doctor_id" => 4,
|
|
"company_id" => $companyID,
|
|
"mou_id" => $mouID,
|
|
"lang_id" => "1",
|
|
"lang_si" => "N",
|
|
"doctor_note" => "",
|
|
"fo_note" => "",
|
|
"queue" => "",
|
|
"received_sample" => "N",
|
|
"lang_id_2" => "0",
|
|
"lang_si_2" => "N",
|
|
"diagnose" => "sakit"
|
|
];
|
|
|
|
$xdel = [[
|
|
"address_id" => 0,
|
|
"delivery_id" => 1,
|
|
"delivery_type_id" => 1,
|
|
"senderdoctorid" => 1500112,
|
|
"senderaddressid" => 0,
|
|
"note" => "",
|
|
"kelurahan" => 0,
|
|
]];
|
|
$arrTes = [
|
|
"11116",
|
|
"11111",
|
|
"11131",
|
|
"11231",
|
|
"11181",
|
|
"11176",
|
|
"11181",
|
|
"11206",
|
|
"11311",
|
|
"11411"
|
|
];
|
|
|
|
$tes = implode(",", $arrTes);
|
|
$sql = "SELECT * FROM one_his.service_test JOIN
|
|
one_aditya.t_test ON service_test.T_TestID = one_aditya.t_test.T_TestID
|
|
AND one_aditya.t_test.T_TestIsActive = 'Y'
|
|
JOIN one_his.service
|
|
ON one_his.service.service_id = one_his.service_test.service_id
|
|
WHERE service_testIsActive ='Y' AND service_code IN ($tes) ";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error get tes", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$testResult = $qry->result_array();
|
|
$xdetail = array();
|
|
foreach ($testResult as $key => $value) {
|
|
|
|
$xdetail[] = [
|
|
"t_id" => $value["T_TestID"],
|
|
"t_cito" => "N", //N
|
|
"t_price" => 0,
|
|
"t_disc" => 0,
|
|
"t_discrp" => 0,
|
|
"t_req" => "Y",
|
|
"t_reqnote" => "",
|
|
"t_ispacket" => "N", //N
|
|
"t_packettype" => "PX", //PX
|
|
"t_packetid" => 0, //0
|
|
];
|
|
}
|
|
$xreq = [
|
|
"status" => "Y",
|
|
"reqs" => "[]",
|
|
];
|
|
$header_json = json_encode($xheader);
|
|
$delivery_json = json_encode($xdel);
|
|
$detail_json = json_encode($xdetail);
|
|
$req_json = json_encode($xreq);
|
|
print_r($req_json);
|
|
$sql = "CALL `sp_fo_register_save_online`(
|
|
0,
|
|
'{$header_json}',
|
|
'{$delivery_json}',
|
|
'{$detail_json}',
|
|
'{$req_json}',
|
|
'{$userID}'
|
|
)";
|
|
|
|
$qry = $this->db->query($sql);
|
|
print_r($this->db->last_query());
|
|
if (!$qry) {
|
|
$this->sys_error_db("Err sp_fo_register_save_online ", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
print_r($rows);
|
|
$this->clean_mysqli_connection($this->db->conn_id);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function do_order_log($orderHeaderID, $json_delivery)
|
|
{
|
|
try {
|
|
$sql = "SELECT *
|
|
FROM t_orderheader
|
|
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
|
|
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderHeaderID}";
|
|
//echo $sql;
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Insert log | Get order header error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
$x_header = $qry->row_array();
|
|
// print_r($x_header);
|
|
// $this->db->trans_rollback();
|
|
// exit;
|
|
|
|
$sql = "SELECT *
|
|
FROM t_orderdetail
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderHeaderID} AND
|
|
T_OrderDetailT_TestIsPrice = 'Y' AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
|
|
$x_details = $this->db->query($sql)->result_array();
|
|
$x_details = json_encode($x_details);
|
|
$x_deliveries = $json_delivery;
|
|
|
|
$sql = "SELECT *
|
|
FROM t_orderpromise
|
|
WHERE
|
|
T_OrderPromiseT_OrderHeaderID = {$orderHeaderID} AND T_OrderPromiseIsActive = 'Y'";
|
|
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Insert log | Get order promise error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
$x_promises = json_encode($qry->result_array());
|
|
|
|
$sql = "INSERT INTO order_log(
|
|
OrderLogT_OrderHeaderID,
|
|
OrderLogM_PatientDOB,
|
|
OrderLogM_CompanyID,
|
|
OrderLogM_MouID,
|
|
OrderLogM_DoctorSenderID,
|
|
OrderLogM_DoctorSenderAddressID,
|
|
orderLogT_OrderHeaderAddOnAliasDoctorName,
|
|
orderLogT_OrderHeaderAddOnAliasDoctorAddress,
|
|
OrderLogAge,
|
|
OrderLogFoNote,
|
|
OrderLogSubtotal,
|
|
OrderLogTotal,
|
|
OrderLogUserID,
|
|
OrderLogDetails,
|
|
OrderLogDeliveries,
|
|
OrderLogPromises
|
|
)
|
|
VALUES(
|
|
{$orderHeaderID},
|
|
'{$x_header["M_PatientDOB"]}',
|
|
{$x_header["T_OrderHeaderM_CompanyID"]},
|
|
{$x_header["T_OrderHeaderM_MouID"]},
|
|
{$x_header["T_OrderHeaderSenderM_DoctorID"]},
|
|
{$x_header["T_OrderHeaderSenderM_DoctorAddressID"]},
|
|
'{$x_header["T_OrderHeaderAddOnAliasDoctorName"]}',
|
|
'{$x_header["T_OrderHeaderAddOnAliasDoctorAddress"]}',
|
|
'{$x_header["T_OrderHeaderM_PatientAge"]}',
|
|
'{$x_header["T_OrderHeaderFoNote"]}',
|
|
'{$x_header["T_OrderHeaderSubTotal"]}',
|
|
'{$x_header["T_OrderHeaderTotal"]}',
|
|
3,
|
|
'{$x_details}',
|
|
'{$x_deliveries}',
|
|
'{$x_promises}'
|
|
)";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
$this->sys_error_db("Insert log | Insert log error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function generate_order_his($order, $orderID)
|
|
{
|
|
try {
|
|
$regLab = $order['reglab'];
|
|
$medRec = $order['patient']['medrec'];
|
|
$sourceCode = $order['source']['code'];
|
|
$sourceName = $order['source']['name'];
|
|
$sourceRoomNum = $order['source']['room_no'];
|
|
$clinicianCode = $order['clinician']['code'];
|
|
$clinicianName = $order['clinician']['name'];
|
|
$userID = 3;
|
|
if ($orderID == 0) {
|
|
//insert order his
|
|
$sql_insert = " INSERT INTO t_orderheader_his(
|
|
T_OrderHeaderHisRegLab,
|
|
T_OrderHeaderHisMedRec,
|
|
T_OrderHeaderHisSourceCode,
|
|
T_OrderHeaderHisSourceName,
|
|
T_OrderHeaderHisSourceRoomNumber,
|
|
T_OrderHeaderHisClinicianCode,
|
|
T_OrderHeaderHisClinicianName,
|
|
T_OrderHeaderHisJson,
|
|
T_OrderHeaderHisCreated,
|
|
T_OrderHeaderHisLastUpdated,
|
|
T_OrderHeaderHisIsActive,
|
|
T_OrderHeaderHisUserID)
|
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
$qry_insert = $this->db->query($sql_insert, [
|
|
$regLab,
|
|
$medRec,
|
|
$sourceCode,
|
|
$sourceName,
|
|
$sourceRoomNum,
|
|
$clinicianCode,
|
|
$clinicianName,
|
|
json_encode($order),
|
|
date("Y-m-d H:i:s"),
|
|
date("Y-m-d H:i:s"),
|
|
'Y',
|
|
$userID
|
|
]);
|
|
if (!$qry_insert) {
|
|
$this->sys_error_db("insert order his error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
} else {
|
|
//update order his
|
|
$sql_update = "UPDATE t_orderheader_his SET
|
|
T_OrderHeaderHisMedRec = ?,
|
|
T_OrderHeaderHisSourceCode= ?,
|
|
T_OrderHeaderHisSourceName= ?,
|
|
T_OrderHeaderHisSourceRoomNumber= ?,
|
|
T_OrderHeaderHisClinicianCode= ?,
|
|
T_OrderHeaderHisClinicianName= ?,
|
|
T_OrderHeaderHisJson= ?,
|
|
T_OrderHeaderHisLastUpdated= ?,
|
|
T_OrderHeaderHisUserID= ? WHERE T_OrderHeaderHisRegLab = ?";
|
|
$qry_update = $this->db->query($sql_update, [
|
|
$medRec,
|
|
$sourceCode,
|
|
$sourceName,
|
|
$sourceRoomNum,
|
|
$clinicianCode,
|
|
$clinicianName,
|
|
json_encode($order),
|
|
date("Y-m-d H:i:s"),
|
|
$userID,
|
|
$regLab
|
|
]);
|
|
if (!$qry_update) {
|
|
$this->sys_error_db("Update order his error", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|