Initial import
This commit is contained in:
434
application/controllers/klinik/Order.php
Normal file
434
application/controllers/klinik/Order.php
Normal file
@@ -0,0 +1,434 @@
|
||||
<?php
|
||||
class Order extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_klinik = $this->load->database("onedev", true);
|
||||
$one_db = "one_aditya";
|
||||
}
|
||||
|
||||
function calculateAge($tanggal_lahir) {
|
||||
// Ambil tanggal sekarang
|
||||
$tanggal_sekarang = new DateTime();
|
||||
|
||||
// Ubah tanggal lahir ke objek DateTime
|
||||
$tanggal_lahir = new DateTime($tanggal_lahir);
|
||||
|
||||
// Hitung selisih antara tanggal sekarang dan tanggal lahir
|
||||
$perbedaan = $tanggal_sekarang->diff($tanggal_lahir);
|
||||
|
||||
// Dapatkan tahun, bulan, dan hari dari selisih
|
||||
$umur_tahun = $perbedaan->y;
|
||||
$umur_bulan = $perbedaan->m;
|
||||
$umur_hari = $perbedaan->d;
|
||||
|
||||
return array($umur_tahun, $umur_bulan, $umur_hari);
|
||||
}
|
||||
function createOrder(){
|
||||
try{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM m_patient
|
||||
WHERE
|
||||
M_PatientID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['patient_id'],
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error select patient",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_patient = $query->row_array();
|
||||
list($umur_tahun, $umur_bulan, $umur_hari) = $this->calculateAge($data_patient['M_PatientDOB']);
|
||||
|
||||
$sql = "INSERT INTO one_klinik.order (
|
||||
orderNumber,
|
||||
orderM_PatientID,
|
||||
orderAge,
|
||||
orderM_DoctorID,
|
||||
orderDiagnosisAwal,
|
||||
orderDiagnosisAkhir,
|
||||
orderSubtotal,
|
||||
orderDiscountAmount,
|
||||
orderDiscountPercent,
|
||||
orderDiscountTotal,
|
||||
orderTotal,
|
||||
orderCreated,
|
||||
orderUserID
|
||||
)
|
||||
VALUES (
|
||||
fn_numbering('K'),
|
||||
?,?,?,?,?,?,?,?,?,?,NOW(),?
|
||||
)";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['patient_id'],
|
||||
$umur_tahun.' Tahun '.$umur_bulan.' Bulan '. $umur_hari.' Hari',
|
||||
$prm['doctor_id'],
|
||||
$prm['diagnosis_awal'],
|
||||
$prm['diagnosis_akhir'],
|
||||
$prm['subtotal'],
|
||||
$prm['discount_amount'],
|
||||
$prm['diagnosis_percent'],
|
||||
$prm['diagnosis_total'],
|
||||
$prm['total'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error create order",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db_klinik->insert_id();
|
||||
$sql = "INSERT INTO one_klinik.`order_status`(
|
||||
orderStatusOrderID,
|
||||
orderStatusOrderID,
|
||||
orderStatusValue,
|
||||
orderStatusUserID
|
||||
)
|
||||
VALUES(
|
||||
'R',?,'D',?
|
||||
)";
|
||||
$query = $this->db_klinik->query($sql,array($last_id,$userID));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error insert order status",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO one_klinik.`order_status`(
|
||||
orderStatusOrderID,
|
||||
orderStatusOrderID,
|
||||
orderStatusValue,
|
||||
orderStatusUserID
|
||||
)
|
||||
VALUES(
|
||||
'SA',?,'D',?
|
||||
)";
|
||||
$query = $this->db_klinik->query($sql,array($last_id,$userID));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error insert order status",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT * FROM one_klinik.order WHERE orderID = ?";
|
||||
$query = $this->db_klinik->query($sql,array($last_id));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error select order",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $query->row_array();
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getOrder($orderID){
|
||||
try{
|
||||
|
||||
$sql = "SELECT orderID,
|
||||
orderNumber,
|
||||
orderM_PatientID,
|
||||
orderM_DoctorID,
|
||||
orderDiagnosisAwal,
|
||||
orderDiagnosisAkhir,
|
||||
orderSubtotal,
|
||||
orderDiscountAmount,
|
||||
orderDiscountPercent,
|
||||
orderDiscountTotal,
|
||||
orderTotal,
|
||||
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')),IF(M_PatientPrefix IS NULL,'',CONCAT(M_PatientPrefix,'. ')),M_PatientName,IF(M_PatientSuffix IS NULL,'',CONCAT(M_PatientSuffix,'. '))) as patient_fullname,
|
||||
M_PatientName as patient_name,
|
||||
M_DoctorName as doctor_name,
|
||||
CONCAT(IF(M_DoctorPrefix IS NULL,'',CONCAT(M_DoctorPrefix,'. ')),IF(M_DoctorPrefix2 IS NULL,'',CONCAT(M_DoctorPrefix2,'. ')),M_DoctorName,IF(M_DoctorSufix IS NULL,'',CONCAT(M_DoctorSufix,'. ')),IF(M_DoctorSufix2 IS NULL,'',CONCAT(M_DoctorSufix2,'. ')),IF(M_DoctorSufix3 IS NULL,'',CONCAT(M_DoctorSufix3,'. '))) as doctor_fullname
|
||||
FROM one_klinik.order
|
||||
JOIN m_patient ON orderM_PatientID = M_PatientID
|
||||
JOIN m_doctor ON orderM_DoctorID = M_DoctorID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE
|
||||
orderID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$orderID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get order",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $query->row_array();
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveAnamnesis(){
|
||||
try{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql = "INSERT INTO one_klinik.order_anamnesis (
|
||||
orderAnamnesisOrderID,
|
||||
orderAnamnesisKeluhanUtama,
|
||||
orderAnamnesisRiwayatPenyakitDahulu,
|
||||
orderAnamnesisRiwayatPenyakitSekarang,
|
||||
orderAnamnesisRiwayatPenyakitKeluarga,
|
||||
orderAnamnesisRiwayatPengobatan,
|
||||
orderAnamnesisRiwayatSosial,
|
||||
orderAnamnesisRiwayatOperasi,
|
||||
orderAnamnesisRiwayatAlergi,
|
||||
orderAnamnesisCreated,
|
||||
orderAnamnesisUserID
|
||||
)
|
||||
VALUES (
|
||||
?,?,?,?,?,?,?,?,?,NOW(),?
|
||||
)";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['order_id'],
|
||||
$prm['keluhan_utama'],
|
||||
$prm['penyakit_dahulu'],
|
||||
$prm['penyakit_sekarang'],
|
||||
$prm['penyakit_keluarga'],
|
||||
$prm['pengobatan'],
|
||||
$prm['sosial'],
|
||||
$prm['operasi'],
|
||||
$prm['alergi'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error create order_anamnesis",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array('status' => true);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateAnamnesis(){
|
||||
try{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql = "UPDATE one_klinik.order_anamnesis SET
|
||||
orderAnamnesisOrderID = ?,
|
||||
orderAnamnesisKeluhanUtama = ?,
|
||||
orderAnamnesisRiwayatPenyakitDahulu = ?,
|
||||
orderAnamnesisRiwayatPenyakitSekarang = ?,
|
||||
orderAnamnesisRiwayatPenyakitKeluarga = ?,
|
||||
orderAnamnesisRiwayatPengobatan = ?,
|
||||
orderAnamnesisRiwayatSosial = ?,
|
||||
orderAnamnesisRiwayatOperasi = ?,
|
||||
orderAnamnesisRiwayatAlergi = ? ,
|
||||
orderAnamnesisLastUpdated = NOW(),
|
||||
orderAnamnesisUserID = ?
|
||||
WHERE
|
||||
orderAnamnesisID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['orderID'],
|
||||
$prm['orderAnamnesisKeluhanUtama'],
|
||||
$prm['orderAnamnesisRiwayatPenyakitDahulu'],
|
||||
$prm['orderAnamnesisRiwayatPenyakitSekarang'],
|
||||
$prm['orderAnamnesisRiwayatPenyakitKeluarga'],
|
||||
$prm['orderAnamnesisRiwayatPengobatan'],
|
||||
$prm['orderAnamnesisRiwayatSosial'],
|
||||
$prm['orderAnamnesisRiwayatOperasi'],
|
||||
$prm['orderAnamnesisRiwayatAlergi'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error update order_anamnesis",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array('status' => true);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDoctorPage(){
|
||||
try{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql = "UPDATE one_klinik.order SET
|
||||
orderDiagnosisAwal = ?,
|
||||
orderDiagnosisAkhir = ?,
|
||||
orderLastUpdated = NOW(),
|
||||
orderUserID = ?
|
||||
WHERE
|
||||
orderID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['orderDiagnosisAwal'],
|
||||
$prm['orderDiagnosisAkhir'],
|
||||
$userID,
|
||||
$prm['orderID']
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error update order diagnosis",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
if($prm['orderReceiptText'] && $prm['orderReceiptText'] != ''){
|
||||
$sql = "INSERT INTO one_klinik.order_receipt (
|
||||
orderReceiptOrderID,
|
||||
orderReceiptText,
|
||||
orderReceiptCreated,
|
||||
orderReceiptUserID
|
||||
)
|
||||
VALUES(
|
||||
?,?,NOW(),?
|
||||
) ON DUPLICATE KEY UPDATE orderReceiptText = ?, orderReceiptUserID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['orderID'],
|
||||
$prm['orderReceiptText'],
|
||||
$userID,
|
||||
$prm['orderReceiptText'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error insert/update order_receipt",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($prm['order_penunjang']) > 0){
|
||||
$sql = "UPDATE one_klinik.order_penunjang SET
|
||||
orderPenunjangIsActive = 'N',
|
||||
orderPenunjangUserID= ?,
|
||||
orderPenunjangLastUpdated = NOW()
|
||||
WHERE
|
||||
orderPenunjangOrderID = ?";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['orderID'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error nonactive order_penunjang",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($prm['order_penunjang'] as $key => $value) {
|
||||
$sql = "INSERT INTO one_klinik.order_penunjang (
|
||||
orderPenunjangOrderID,
|
||||
orderPenunjangT_TestID,
|
||||
orderPenunjangCreated,
|
||||
orderPenunjangUserID
|
||||
)
|
||||
VALUES(
|
||||
?,?,NOW(),?
|
||||
) ";
|
||||
$query = $this->db_klinik->query($sql,array(
|
||||
$prm['orderID'],
|
||||
$prm['orderPenunjangT_TestID'],
|
||||
$userID
|
||||
));
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error insert/update order_penunjang",$this->db_klinik);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$result = array('status' => true);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function searchTest()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count = 0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] == '') {
|
||||
$rows = array();
|
||||
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
$sql = "SELECT T_TestID as id, T_TestName as name, T_TestSasCode as code
|
||||
FROM t_test
|
||||
WHERE
|
||||
T_TestName like ? AND
|
||||
T_TestIsPrice = 'Y' AND
|
||||
T_TestIsActive = 'Y'
|
||||
ORDER BY T_TestName ASC, T_TestSasCode ASC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$this->sys_error_db("t_test rows", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user