db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["name"];
// echo $norm;
$sql_where = "WHERE NonlabTemplateIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " Nat_TestName like ? ";
$sql_param[] = "%$nama%";
}
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 100';
}
$number_limit = 100;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
$sql = "
SELECT
NonlabTemplateMappingID,
NonlabTemplateID,
NonlabTemplateMappingNat_TestID,
NonlabTemplateMappingNonlabTemplateID,
Nat_TestName
FROM nonlab_template_mapping
JOIN nat_test ON NonlabTemplateMappingNat_TestID = Nat_TestID
JOIN nonlab_template ON NonlabTemplateMappingNonlabTemplateID = NonlabTemplateID AND
NonlabTemplateFlagOther = 'N' AND
NonlabTemplateIsActive = 'Y' AND NonlabTemplateMappingIsActive = 'Y'
$sql_where
ORDER BY Nat_TestName ASC
limit 100
";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']);
}
}
//$this->_add_address($rows);
$result = array("total" => 1, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function gettemplatedetail(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$sql ="SELECT nonlab_template_detail.*,
{$prm['NonlabTemplateID']} as NonlabTemplateID,
IFNULL(NonlabTemplateMcuID,0) as xid,
IF(ISNULL(NonlabTemplateMcuID),'N','Y') as xcheck,
M_LangName,
M_LangID as lang_id,
NonlabTemplateMappingNat_TestID as nat_testid
FROM nonlab_template_detail
JOIN nonlab_template ON NonlabTemplateID = NonlabTemplateDetailNonlabTemplateID AND NonlabTemplateDetailIsActive = 'Y'
JOIN nonlab_template_mapping ON NonlabTemplateMappingNonlabTemplateID = NonlabTemplateID AND NonlabTemplateMappingNat_TestID = {$prm['NonlabTemplateMappingNat_TestID']} AND
NonlabTemplateMappingIsActive = 'Y'
JOIN m_lang ON NonlabTemplateDetaiM_LangID = M_LangID
LEFT JOIN nonlab_template_mcu ON NonlabTemplateMcuNat_TestID = NonlabTemplateMappingNat_TestID AND
NonlabTemplateMcuNonlabTemplateDetailID = NonlabTemplateDetailID AND
NonlabTemplateMcuIsActive = 'Y'
WHERE
NonlabTemplateDetailNonlabTemplateID = {$prm['NonlabTemplateID']} AND
NonlabTemplateDetailIsActive = 'Y'
GROUP BY NonlabTemplateDetailID
ORDER BY NonlabTemplateDetailID, NonlabTemplateDetaiM_LangID
";
//echo $query;
$query = $this->db_onedev->query($sql);
if(!$query){
echo $this->db_onedev->last_query();
$this->sys_error_db("nonlab_template_detail",$this->db_onedev);
exit;
}
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$sql = "SELECT *
FROM ";
$rows[$k]['xcheck'] = false;
if($v['xcheck'] == 'Y')
$rows[$k]['xcheck'] = true;
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcity(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName DESC
";
$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("m_city rows",$this->db_onedev);
exit;
}
}
function getdistrict(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_district
WHERE
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getkelurahan(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_kelurahan
WHERE
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
//echo $sql;
foreach($prm['details'] as $k => $v){
if($v['xcheck']){
$sql = "UPDATE nonlab_template_mcu SET NonlabTemplateMcuIsActive = 'N', NonlabTemplateMcuDeleted = NOW(), NonlabTemplateMcuDeletedUserID = {$userid}
WHERE
NonlabTemplateMcuNat_TestID = {$v['nat_testid']} AND
NonlabTemplateMcuM_LangID = {$v['lang_id']} AND
NonlabTemplateMcuIsActive = 'Y'";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "INSERT INTO nonlab_template_mcu (
NonlabTemplateMcuM_LangID,
NonlabTemplateMcuNat_TestID,
NonlabTemplateMcuNonlabTemplateDetailID,
NonlabTemplateMcuNonlabTemplateDetailName,
NonlabTemplateMcuCreatedUserID,
NonlabTemplateMcuCreated
)
VALUES(
{$v['lang_id']},
{$v['nat_testid']},
{$v['NonlabTemplateDetailID']},
'{$v['NonlabTemplateDetailName']}',
{$userid},
NOW()
)";
//echo $sql;
$this->db_onedev->query($sql);
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_PatientDOB"] = $pdob;
$xbefore = json_encode($rows_before);
$ptn = json_encode($ptn);
/*$this->db_onedev->query("INSERT INTO one_log.log_patient (
Log_PatientCode,
Log_PatientJson,
Log_PatientJsonBefore,
Log_PatientUserID
)
VALUES(
'PATIENT.EDIT',
'{$ptn}',
'{$xbefore}',
'{$userid}'
)");*/
$this->sys_ok($result);
exit;
}
function newpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="INSERT INTO m_patient (
M_PatientM_TitleID,
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientDOB,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientEmail,
M_PatientPOB,
M_PatientHP,
M_PatientPhone,
M_PatientM_IdTypeID,
M_PatientIDNumber,
M_PatientNote,
M_PatientNIK,
M_PatientJabatan,
M_PatientKedudukan,
M_PatientPJ,
M_PatientLocation,
M_PatientJob,
M_PatientUserID
)
VALUES(
'{$prm['M_PatientM_TitleID']}',
'{$prm['M_PatientPrefix']}',
'{$prm['M_PatientName']}',
'{$prm['M_PatientSuffix']}',
'{$pdob}',
'{$prm['M_PatientM_SexID']}',
'{$prm['M_PatientM_ReligionID']}',
'{$prm['M_PatientEmail']}',
'{$prm['M_PatientPOB']}',
'{$prm['M_PatientHP']}',
'{$prm['M_PatientPhone']}',
'{$prm['M_PatientM_IdTypeID']}',
'{$prm['M_PatientIDNumber']}',
'{$prm['M_PatientNote']}',
'{$prm['M_PatientNIK']}',
'{$prm['M_PatientJabatan']}',
'{$prm['M_PatientKedudukan']}',
'{$prm['M_PatientPJ']}',
'{$prm['M_PatientLocation']}',
'{$prm['M_PatientJob']}',
$userid
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$ptn = $prm;
$ptn["M_PatientID"] = $last_id;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query ="UPDATE m_patient SET
M_PatientIsActive = 'N',
M_PatientUserID = {$userid}
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.DELETE', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function getaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT m_patientaddress.*,
M_KelurahanName,
M_DistrictID,
M_DistrictName,
M_CityID,
M_CityName,
'' as action
FROM m_patientaddress
JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['action'] = 'delete';
$rows[$k]['action'] .= 'edit';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
//echo $this->db_onedev->last_query();
if($count_addrs == 0){
$prm['M_PatientAddressNote'] = 'Utama';
}
else{
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
if($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama'){
$rx = date('YmdHis');
$prm['M_PatientAddressNote'] = 'Utama_'.$rx;
}
}
$query ="INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressNote,
M_PatientAddressDescription,
M_PatientAddressM_KelurahanID,
M_PatientAddressCreated,
M_PatientAddressUserID
)
VALUES(
'{$prm['M_PatientAddressM_PatientID']}',
'{$prm['M_PatientAddressNote']}',
'{$prm['M_PatientAddressDescription']}',
'{$prm['M_PatientAddressM_KelurahanID']}',
NOW(),
'{$userid}'
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function saveeditaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$prm['M_PatientAddressID']}";
$rows_before = $this->db_onedev->query($sql)->row_array();
$query ="UPDATE m_patientaddress SET
M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}',
M_PatientAddressNote = '{$prm['M_PatientAddressNote']}',
M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}',
M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}',
M_PatientAddressUserID = {$userid}
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$xbefore = json_encode($rows_before);
$ptn = json_encode($ptn);
/*$this->db_onedev->query("INSERT INTO one_log.log_patient (
Log_PatientCode,
Log_PatientJson,
Log_PatientJsonBefore,
Log_PatientUserID
)
VALUES(
'PATIENT.ADDR_EDIT',
'{$ptn}',
'{$xbefore}',
'{$userid}'
)");*/
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deleteaddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query ="UPDATE m_patientaddress SET
M_PatientAddressIsActive = 'N',
M_PatientAddressUserID = {$userid}
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
}