Initial import
This commit is contained in:
498
one-api/application/controllers/one_mitra/Registration.php
Normal file
498
one-api/application/controllers/one_mitra/Registration.php
Normal file
@@ -0,0 +1,498 @@
|
||||
<?php
|
||||
|
||||
class Registration extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
var $load;
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userID = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql_cek_token = "SELECT M_UserActiveToken
|
||||
from one_mitra.m_user
|
||||
WHERE M_UserID = ?
|
||||
AND M_UserActiveToken IS NOT NULL";
|
||||
|
||||
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
||||
if (!$qry_token) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_token = $qry_token->result_array();
|
||||
if (count($rows_token) == 0) {
|
||||
$this->sys_error('Invalid token');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function getfilter()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql_gender = "SELECT M_SexID AS id,
|
||||
m_sexname AS name
|
||||
FROM m_sex
|
||||
WHERE M_SexIsActive = 'Y'";
|
||||
$query_gender = $this->db->query($sql_gender, []);
|
||||
if (!$query_gender) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$genders = $query_gender->result_array();
|
||||
$sql_title = "SELECT M_TitleID AS id,
|
||||
M_TitleM_SexID AS type,
|
||||
M_TitleName AS name
|
||||
FROM m_title WHERE M_TitleIsActive = 'Y'";
|
||||
$query_title = $this->db->query($sql_title, []);
|
||||
if (!$query_title) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$titles = $query_title->result_array();
|
||||
|
||||
$sql_regional = "SELECT
|
||||
S_RegionalID AS regional_id,
|
||||
S_RegionalName AS regional_name
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y'";
|
||||
$query_regional = $this->db->query($sql_regional, []);
|
||||
if (!$query_regional) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$regionals = $query_regional->result_array();
|
||||
$sql_branch = "SELECT
|
||||
M_BranchID AS branch_id,
|
||||
M_BranchCode AS branch_code,
|
||||
M_BranchName AS branch_name,
|
||||
M_BranchS_RegionalID AS regional_id
|
||||
FROM m_branch Where M_BranchIsActive = 'Y'";
|
||||
$query_branch = $this->db->query($sql_branch, []);
|
||||
if (!$query_branch) {
|
||||
$message = $this->db->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$branchs = $query_branch->result_array();
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
$regionals[$i]['branch'] = [];
|
||||
}
|
||||
for ($i = 0; $i < count($regionals); $i++) {
|
||||
for ($j = 0; $j < count($branchs); $j++) {
|
||||
if ($regionals[$i]['regional_id'] == $branchs[$j]['regional_id']) {
|
||||
$regionals[$i]['branch'][] = $branchs[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = array(
|
||||
"titles" => $titles,
|
||||
"gender" => $genders,
|
||||
"regional" => $regionals
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getsampletype()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$arr_test = 0;
|
||||
if (isset($prm['arr_test'])) {
|
||||
$arr_test = $prm['arr_test'];
|
||||
} else {
|
||||
$this->sys_error("arr_test is mandatory");
|
||||
}
|
||||
// print_r($arr_test);
|
||||
$result = array();
|
||||
for ($i = 0; $i < count($arr_test); $i++) {
|
||||
$test = $arr_test[$i];
|
||||
$sasCode = substr($test['sasCode'], 0, 8) . "%";
|
||||
$sql = "SELECT T_TestID AS id
|
||||
FROM t_test
|
||||
WHERE T_TestSasCode LIKE ?
|
||||
AND T_TestIsActive = 'Y'";
|
||||
$qry = $this->db_regional->query($sql, [$sasCode]);
|
||||
if (!$qry) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$allTest = $qry->result_array();
|
||||
$arr = [];
|
||||
for ($k = 0; $k < count($allTest); $k++) {
|
||||
$arr[] = $allTest[$k]['id'];
|
||||
}
|
||||
// print_r($arr);
|
||||
|
||||
$implodeTest = implode(",", $arr);
|
||||
|
||||
$sql_specimen = "SELECT Nat_TestID,
|
||||
Nat_TestName,
|
||||
T_TestID,
|
||||
T_TestName,
|
||||
Nat_SampleTypeID,
|
||||
Nat_SampleTypeNat_BahanID,
|
||||
Nat_SampleTypeName,
|
||||
Nat_BahanID,
|
||||
Nat_BahanName
|
||||
FROM nat_test
|
||||
JOIN t_test
|
||||
ON Nat_TestID = T_TestNat_TestID
|
||||
AND T_TestID IN ($implodeTest)
|
||||
AND T_TestIsActive = 'Y'
|
||||
JOIN nat_sampletype
|
||||
ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
|
||||
AND Nat_SampleTypeIsActive = 'Y'
|
||||
JOIN nat_bahan
|
||||
ON Nat_SampleTypeNat_BahanID = Nat_BahanID
|
||||
WHERE Nat_TestIsActive = 'Y'
|
||||
|
||||
";
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_SampleTypeID, '^', Nat_SampleTypeName)) AS sampletype,
|
||||
// GROUP_CONCAT(DISTINCT CONCAT(Nat_BahanID, '^', Nat_BahanName)) AS nat_bahan
|
||||
// GROUP BY Nat_SampleTypeID, Nat_BahanID
|
||||
$qry_specimen = $this->db_regional->query($sql_specimen, []);
|
||||
// echo $this->db_regional->last_query();
|
||||
// exit;
|
||||
if (!$qry_specimen) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$specimen = $qry_specimen->result_array();
|
||||
// print_r($specimen);
|
||||
// exit;
|
||||
$data = array(
|
||||
"id" => $test['id'],
|
||||
"tab" => $test['tab'],
|
||||
"specimen" => [],
|
||||
"bahan" => []
|
||||
);
|
||||
// print_r($specimen);
|
||||
// if (count($specimen) > 0) {
|
||||
// if ($specimen[0]['sampletype'] != null && $specimen[0]['nat_bahan'] != null) {
|
||||
|
||||
// $sampleType = explode(',', $specimen[0]['sampletype']);
|
||||
// $natBahan = explode(',', $specimen[0]['nat_bahan']);
|
||||
// // print_r($sampleType);
|
||||
// // print_r($natBahan);
|
||||
|
||||
|
||||
// for ($i = 0; $i < count($sampleType); $i++) {
|
||||
// $temp = explode('^', $sampleType[$i]);
|
||||
// $data['specimen'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// for ($i = 0; $i < count($natBahan); $i++) {
|
||||
// $temp = explode('^', $natBahan[$i]);
|
||||
// $data['bahan'][] = array(
|
||||
// "id" => $temp[0],
|
||||
// "name" => $temp[1]
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for ($j = 0; $j < count($specimen); $j++) {
|
||||
$sp = $specimen[$j];
|
||||
$tempSp = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
$tempBhn = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
if (!in_array($tempSp, $data['specimen'])) {
|
||||
$data['specimen'][] = array(
|
||||
"id" => $sp["Nat_SampleTypeID"],
|
||||
"name" => $sp['Nat_SampleTypeName']
|
||||
);
|
||||
}
|
||||
if (!in_array($tempBhn, $data['bahan'])) {
|
||||
$data['bahan'][] = array(
|
||||
"id" => $sp["Nat_BahanID"],
|
||||
"name" => $sp['Nat_BahanName']
|
||||
);
|
||||
}
|
||||
}
|
||||
$result[] = $data;
|
||||
}
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function addpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
||||
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
||||
$mouID = $this->sys_user["M_UserM_MouID"];
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$patient = $prm['patient_data'];
|
||||
$paket = $prm['paket'];
|
||||
$patientDOB = date('Y-m-d', strtotime($patient['dob']));
|
||||
$withoutNIK = $patient['without_nik'];
|
||||
$nik = $patient['nik'];
|
||||
$tests = $prm['tests'];
|
||||
$specimens = $prm['specimens'];
|
||||
$bahan = $prm['bahan'];
|
||||
$userMou = $prm['userMouID'];
|
||||
$patientID = $prm['patient_id'];
|
||||
// $this->db->trans_begin();
|
||||
// $this->db->trans_rollback();
|
||||
// $this->db->trans_commit();
|
||||
// print_r($this->sys_user);
|
||||
// exit;
|
||||
$isNIK = 'N';
|
||||
|
||||
$this->db->trans_begin();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$nik = "0";
|
||||
}
|
||||
if ($patientID == "new") {
|
||||
if ($withoutNIK == "N") {
|
||||
$isNIK = 'Y';
|
||||
}
|
||||
$ptn = [
|
||||
"M_PatientPrefix" => $patient['prefix'],
|
||||
"M_PatientTitleID" => $patient['saluation'],
|
||||
"M_PatientName" => $patient['name'],
|
||||
"M_PatientSuffix" => $patient['suffix'],
|
||||
"M_PatientDOB" => $patientDOB,
|
||||
"M_PatientNIK" => $nik,
|
||||
"M_PatientNIP" => $patient['nip'],
|
||||
"M_PatientIsNIK" => $isNIK,
|
||||
"M_PatientM_SexID" => $patient['gender'],
|
||||
"M_PatientHP" => $patient['hp'],
|
||||
"M_PatientAddress" => $patient['address'],
|
||||
"M_PatientNoRM" => $patient['noRM'],
|
||||
"M_PatientM_CompanyID" => $companyID,
|
||||
"M_PatientUserID" => $userid,
|
||||
"M_PatientJabatan" => $patient['jabatan'],
|
||||
"M_PatientKedudukan" => $patient['kedudukan'],
|
||||
"M_PatientLocation" => $patient['lokasi'],
|
||||
"M_PatientJob" => $patient['pekerjaan'],
|
||||
|
||||
];
|
||||
$this->db->insert('one_mitra.m_patient', $ptn);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT PATIENT", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$patientID = $this->db->insert_id();
|
||||
if ($withoutNIK == 'Y') {
|
||||
$awalan = sprintf("%05s", intval($companyID)) . $patientID;
|
||||
// print_r($awalan);
|
||||
$nik = str_pad($awalan, 16, "0");
|
||||
// print_r($nik);
|
||||
$this->db->set("M_PatientNIK", $nik)->where("M_PatientID", $patientID)->update('one_mitra.m_patient');
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("m_patient rows", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT one_mitra.fn_numbering('MT') as number";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if (!$qry) {
|
||||
$message = $this->db->error();
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$number = $qry->result_array()[0]['number'];
|
||||
$total = intval($prm['total']);
|
||||
|
||||
$order = [
|
||||
"T_OrderNumber" => $number,
|
||||
"T_OrderM_PatientID" => $patientID,
|
||||
"T_OrderM_MouID" => $userMou,
|
||||
"T_OrderM_CompanyID" => $companyID,
|
||||
"T_OrderS_RegionalID" => $regionalID,
|
||||
"T_OrderNote" => $patient['note'],
|
||||
"T_OrderDiagnosis" => $patient['diagnosis'],
|
||||
"T_OrderUserID" => $userid,
|
||||
"T_OrderTotal" => $total,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_order', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$orderId = $this->db->insert_id();
|
||||
|
||||
for ($i = 0; $i < count($tests); $i++) {
|
||||
// T_OrderDetailID int(11) Auto Increment
|
||||
// T_OrderDetailOrderID int(11)
|
||||
// T_OrderDetailTestID int(11)
|
||||
// T_OrderDetailTestName varchar(30)
|
||||
// T_OrderDetailTotal int(11)
|
||||
// T_OrderDetailUserID
|
||||
$coba = strtotime($tests[$i]['date']);
|
||||
$dt = date('Y-m-d H:i:s', $coba);
|
||||
|
||||
$order = [
|
||||
"T_OrderDetailOrderID" => $orderId,
|
||||
"T_OrderDetailTestID" => $tests[$i]['id'],
|
||||
"T_OrderDetailTestName" => $tests[$i]['name'],
|
||||
"T_OrderDetailTotal" => $tests[$i]['price'],
|
||||
"T_OrderDetailTestDate" => $dt,
|
||||
"T_OrderDetailUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetail', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($specimens); $i++) {
|
||||
// T_OrderDetailSampleT_OrderID int(11)
|
||||
// T_OrderDetailSampleNat_SampleTypeID int(11)
|
||||
// T_OrderDetailSampleName varchar(200)
|
||||
// T_OrderDetailSampleQty varchar(200)
|
||||
// T_OrderDetailSampleUserID
|
||||
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
||||
$order = [
|
||||
"T_OrderDetailSampleT_OrderID" => $orderId,
|
||||
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
||||
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
||||
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
||||
"T_OrderDetailSampleUserID" => $userid,
|
||||
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($bahan); $i++) {
|
||||
// T_OrderDetailBahanT_OrderID int(11)
|
||||
// T_OrderDetailBahanNat_BahanID int(11)
|
||||
// T_OrderDetailBahanName int(11)
|
||||
// T_OrderDetailBahanQty varchar(200)
|
||||
// T_OrderDetailBahanUserID
|
||||
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailBahanT_OrderID" => $orderId,
|
||||
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
||||
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
||||
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
||||
"T_OrderDetailBahanUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < count($paket); $i++) {
|
||||
//T_OrderDetailPacketID int(11) Auto Increment
|
||||
// T_OrderDetailPacketT_PacketID int(11)
|
||||
// T_OrderDetailPacketName varchar(250)
|
||||
// T_OrderDetailPacketIsActive char(1) [Y]
|
||||
// T_OrderDetailPacketUserID int(11)
|
||||
// T_OrderDetailPacketCreated datetime [current_timestamp()]
|
||||
// T_OrderDetailPacketLastUpdated
|
||||
|
||||
# code...
|
||||
$order = [
|
||||
"T_OrderDetailPacketOrderID" => $orderId,
|
||||
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
||||
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
||||
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
||||
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
||||
"T_OrderDetailPacketUserID" => $userid,
|
||||
];
|
||||
|
||||
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
||||
$err = $this->db->error();
|
||||
if (
|
||||
$err['message'] != ""
|
||||
) {
|
||||
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = [
|
||||
"patientID" => $patientID,
|
||||
"orderID" => $orderId,
|
||||
"orderNumber" => $number,
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user