Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,213 @@
<?php
class Area extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "AREA API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search_province()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_province
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_province count",$this->db_smartone);
exit;
}
$sql = "select M_ProvinceID, M_ProvinceName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_province
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_provinceid = M_ProvinceID
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'
order by M_ProvinceName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_province rows",$this->db_smartone);
exit;
}
}
public function search_city()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_city
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_smartone);
exit;
}
$sql = "select M_CityID, M_CityName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_city
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_cityid = M_CityID
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?
order by M_CityName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$rows = $query->result_array();
$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_smartone);
exit;
}
}
public function search_district()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_district
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_smartone);
exit;
}
$sql = "select M_DistrictID, M_DistrictName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_district
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_districtid = M_DistrictID
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?
order by M_DistrictName
-- limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_smartone);
exit;
}
}
public function search_kelurahan()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_kelurahan
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_kelurahan count",$this->db_smartone);
exit;
}
$sql = "select M_KelurahanID, M_KelurahanName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_kelurahan
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_kelurahanid = M_KelurahanID
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?
order by M_KelurahanName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_kelurahan rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
class Conf extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "CONF API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$tot_count = 1;
$sql = "SELECT * FROM conf_clinic";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->row();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("CONF rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
class Diagnose extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Diagnose API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_diagnose count",$this->db_smartone);
exit;
}
$sql = "select M_DiagnoseID, M_DiagnoseName
from m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_diagnose rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
class Doctor extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Doctor API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
where M_DoctorIsActive = 'Y'
and M_DoctorPJIsClinic = 'Y'
and M_DoctorName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "select M_DoctorID, M_DoctorIsDefault, M_DoctorIsPJ,
concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) as M_DoctorName,
IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID) SEPARATOR ','), ']'), '[]') as address
from m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
left join m_doctoraddress on M_DoctorAddressIsActive = 'Y'
and M_DoctorAddressM_DoctorID = M_DoctorID
where M_DoctorPJIsActive = 'Y'
and M_DoctorIsClinic = 'Y'
and concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) like ?
group by M_DoctorID";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['address'] = json_decode($v['address']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Gcs extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "GCS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_gcs count",$this->db_smartone);
exit;
}
$sql = "select M_GcsID, M_GcsName
from m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_gcs rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$header_json = json_encode($prm['header']);
$payment_json = json_encode($prm['payment']);
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_fo_save('{$prm['order_id']}', '{$header_json}', '{$payment_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
// if ($rst->status == "OK")
// {
// // persiapkan curl
// $ch = curl_init();
// // set url
// curl_setopt($ch, CURLOPT_URL, "http://anggrek.aplikasi.web.id:9090/ticket/KLINIK");
// // return the transfer as a string
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// // $output contains the output string
// $output = json_decode(curl_exec($ch));
// // tutup curl
// curl_close($ch);
// // menampilkan hasil curl
// // echo $output;
// if ($output != null)
// if ($output->status == "OK")
// $rst->data->queue = $output->data[0]->number;
// }
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,264 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%'
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(distinct m_patientid) total
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "SELECT M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName,
M_PatientHP, M_PatientPOB, M_PatientDOB, M_PatientNote,
concat(M_PatientAddressDescription, '\n\n', m_kelurahanname, ', ', m_districtname,
'\n', m_cityname, ', ', m_provincename) as M_PatientAddress,
M_PatientAddressDescription, M_PatientM_IdTypeID, M_PatientIDNumber,
IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp,
fn_fo_patient_visit(M_PatientID) info,
M_KelurahanID, M_DistrictID, M_CityID, M_ProvinceID, M_PatientM_ReligionID,
IFNULL(M_ReligionName, '-') M_ReligionName
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_sex on M_PatientM_SexID = M_SexID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
left join m_kelurahan on m_patientaddressm_kelurahanid = m_kelurahanid
left join m_district on m_kelurahanm_districtid = m_districtid
left join m_city on m_districtm_cityid = m_cityid
left join m_province on m_citym_provinceid = m_provinceid
left join m_religion on m_patientm_religionid = m_religionid
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?
group by m_patientid
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['info'] = json_decode($v['info']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "query" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
function add_new()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$ptn = [
'M_PatientName' => $prm['M_PatientName'],
'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'],
'M_PatientSuffix' => $prm['M_PatientSuffix'],
'M_PatientM_SexID' => $prm['M_PatientM_SexID'],
'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'],
'M_PatientDOB' => $prm['M_PatientDOB'],
'M_PatientPOB' => $prm['M_PatientPOB'],
'M_PatientHP' => $prm['M_PatientHP'],
'M_PatientPhone' => $prm['M_PatientPhone'],
'M_PatientEmail' => $prm['M_PatientEmail'],
'M_PatientM_IdTypeID' => $prm['M_PatientM_IdTypeID'],
'M_PatientIDNumber' => $prm['M_PatientIDNumber'],
'M_PatientNote' => $prm['M_PatientNote']
];
$this->db_smartone->insert('m_patient', $ptn);
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $this->db_smartone->insert_id();
// LOG FO
$ptn = json_encode($ptn);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADD', '{$ptn}', '0')");
// save address
$add = [
'M_PatientAddressM_PatientID' => $id,
'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
];
$this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
$add = json_encode($add);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
function edit()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$this->db_smartone->set('M_PatientName', $prm['M_PatientName'])
->set('M_PatientM_TitleID', $prm['M_PatientM_TitleID'])
->set('M_PatientSuffix', $prm['M_PatientSuffix'])
->set('M_PatientM_SexID', $prm['M_PatientM_SexID'])
->set('M_PatientM_ReligionID', $prm['M_PatientM_ReligionID'])
->set('M_PatientDOB', $prm['M_PatientDOB'])
->set('M_PatientPOB', $prm['M_PatientPOB'])
->set('M_PatientHP', $prm['M_PatientHP'])
->set('M_PatientPhone', $prm['M_PatientPhone'])
->set('M_PatientEmail', $prm['M_PatientEmail'])
->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID'])
->set('M_PatientIDNumber', $prm['M_PatientIDNumber'])
->set('M_PatientNote', $prm['M_PatientNote'])
->where('M_PatientID', $prm['id'])
->update('m_patient');
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $prm['id'];
// LOG FO
unset($prm['token']);
$ptn = json_encode($prm);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.EDIT', '{$ptn}', '{$this->sys_user['M_UserID']}')");
// save address
// $add = [
// 'M_PatientAddressM_PatientID' => $id,
// 'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
// 'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
// ];
// $this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
// $add = json_encode($add);
// $this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
public function search_idtype()
{
$prm = $this->sys_input;
$sql = "SELECT M_IdTypeID, M_IdTypeName
FROM m_idtype
WHERE M_IdTypeIsActive = 'Y'
ORDER BY M_IdTypeName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("records" => $rows);
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_idtype rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,217 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Payment API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function get_order() {
$prm = $this->sys_input;
$rst = ["order_header"=>[], "order_detail"=>[]];
$sql = "
select T_OrderHeaderID as order_id,
T_OrderHeaderLabNumber as order_no,
T_OrderHeaderDate as order_date,
T_OrderHeaderSubTotal as order_subtotal,
T_OrderHeaderRounding as order_rounding,
T_OrderHeaderTotal as order_total,
M_PatientName as patient_name,
M_PatientNoReg as patient_mr,
M_MouName as order_mou,
M_CompanyName as order_company
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
join m_mou on T_OrderHeaderM_MouID = M_MouID
where T_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = (array) $query->row();
$rst['order_header'] = $rows;
// $result = array("status" => "OK" , "data" => $rst);
// $this->sys_ok($result);
// exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
// { n:1, d_id:1, t_id:1, t_name:'SGOT', t_price:80000, t_disctotal:7000, t_total:73000 },
// { n:2, d_id:2, t_id:2, t_name:'SGPT', t_price:75000, t_disctotal:8000, t_total:67000 }
// T_OrderDetailPrice double [0]
// T_OrderDetailPriceForDisc double [0]
// T_OrderDetailDisc double [0]
// T_OrderDetailDiscAmount double [0]
// T_OrderDetailTotal
$sql = "
select T_OrderDetailID as d_id,
T_OrderDetailT_TestID as t_id,
T_OrderDetailT_TestName as t_name,
T_OrderDetailPrice as t_price,
T_OrderDetailDiscTotal as t_disctotal,
T_OrderDetailTotal as t_total
from t_orderdetail
where T_OrderDetailT_OrderHeaderID = ?
and T_ORderDetailIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->result_array();
$rst['order_detail'] = $rows;
$result = array("status" => "OK" , "data" => $rst);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
}
public function search()
{
$this->db_smartone = $this->load->database("onedev", true);
$prm = $this->sys_input;
$max_rst = 100;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_paymenttype count",$this->db_smartone);
exit;
}
$sql = "select M_PaymentTypeID payment_type_id, M_PaymentTypeName payment_type_name, M_PaymentTypeCode payment_type_code,
0 payment_amount, '' payment_note, 'Nomor Kartu' payment_note_label, 'N' payment_enable,
0 payment_change, 0 payment_actual, 0 payment_card_id, 0 payment_edc_id, 0 payment_account_id
from m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v) {
if ($v['payment_type_code'] == 'CASH')
$v['payment_note_label'] = 'Kembali';
if ($v['payment_type_code'] == 'VOUCHER')
$v['payment_note_label'] = 'Nomor Voucher';
$rows[$k] = $v;
}
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_paymenttype rows",$this->db_smartone);
exit;
}
}
function save()
{
$prm = $this->sys_input;
$payment_json = json_encode($prm['payments']);
$sql = "CALL sp_fo_payment('{$prm['order_id']}', '{$payment_json}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
echo json_encode($rst);
}
else
{
$this->sys_error_db("save payment", $this->db_smartone);
exit;
}
}
function log_nota()
{
$prm = $this->sys_input;
$dblog = $this->load->database('onelog', true);
$p = $this->db_smartone->where('c_orderheaderid', $prm['order_id'])
->get('c_orderheader')
->row();
$uid = $this->sys_user['M_UserID'];
$q = $dblog->set("Log_ClinicUserID", $uid)
->set("Log_ClinicJson", json_encode(["order_id"=>$prm['order_id'], "patient_id"=>$p->C_OrderHeaderM_PatientID]))
->set("Log_ClinicCode", "CLINIC.PRINT.RECEIPT")
->insert('log_clinic');
if ($q) {
$id = $dblog->insert_id();
$this->sys_ok($id);
}
else {
$this->sys_error_db("LOG Nota",$this->db_smartone);
exit;
}
}
public function search_bank()
{
$prm = $this->sys_input;
// QUERY TOTAL
$sql = "SELECT Nat_BankID, Nat_BankName
FROM nat_bank ORDER BY Nat_BankName ASC";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$this->sys_ok(["records"=>$rows, "total"=>sizeof($rows)]);
}
else
{
$this->sys_error_db("NAT BANK",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
class Photo extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Photo API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
$this->load->library('ImageManipulator');
}
public function upload()
{
$inp = $this->sys_input;
$home_dir = "/home/one/Web/";
$target_dir = $home_dir . "one-media/one-photo/patient/" . date("Y") . "/";
$y = $this->regenerateOldPhoto($home_dir, $inp['id']);
// get patient mr
$p = $this->db_smartone->select("M_PatientNoReg")
->where("M_PatientID", $inp['id'])
->get('m_patient')
->row();
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$target_path = $target_dir . $p->M_PatientNoReg . ".jpg";
$this->base64_to_jpeg($inp['data'], $target_path);
// CROP Image
$im = new ImageManipulator($target_path);
$w = $im->getWidth();
$h = $im->getHeight();
$mw = ceil(3 * $h / 4);
if ($w <= $mw)
{
$x1 = 0;
$y1 = 0;
$x2 = $w;
$y2 = $h;
}
else
{
$x1 = floor(($w - $mw) / 2);
$y1 = 0;
$x2 = ceil($w - (($w - $mw) / 2));
$y2 = $h;
}
$im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically
$im->save($target_path);
$x = $this->generateThumbnail($target_path, 75, 100);
// Save to DB
$this->db_smartone->set("M_PatientPhoto", "/" . str_replace($home_dir, "", $target_path))
->set("M_PatientPhotoThumb", "/" . str_replace($home_dir, "", $x))
->set('M_PatientPhotoCounter', '`M_PatientPhotoCounter` + 1', false)
->where('M_PatientID', $inp['id'])
->update('m_patient');
// LOGGING
$code = $y ? "PHOTO.PATIENT.EDIT" : "PHOTO.PATIENT.ADD";
$one_log = $this->load->database('onelog', true);
$one_log->set('Log_PhotoCode', $code)
->set('Log_PhotoM_PatientID', $inp['id'])
->set('Log_PhotoUrl', $y ? $y : "/" . str_replace($home_dir, "", $target_path))
->insert('log_photo');
$this->sys_ok(["rename"=>$y, "patient_id"=>$inp['id'], "patient_mr"=>$p->M_PatientNoReg, "photo_url"=>"http://" . $_SERVER['SERVER_NAME'] . "/" . str_replace($home_dir, "", $target_path) . "?d=" . date("YmdHis")]);
}
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( $output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}
function generateThumbnail($img, $width, $height, $quality = 90)
{
if (is_file($img)) {
$imagick = new Imagick(realpath($img));
$imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality($quality);
$imagick->thumbnailImage($width, $height, false, false);
$filename_no_ext = reset(explode('.', $img));
if (file_put_contents($filename_no_ext . '_thumb' . '.jpg', $imagick) === false) {
throw new Exception("Could not put contents.");
}
return $filename_no_ext . '_thumb' . '.jpg';
}
else {
throw new Exception("No valid image provided with {$img}.");
}
}
function regenerateOldPhoto($home_dir, $id)
{
$r = $this->db_smartone->select('m_patientphoto, m_patientphotocounter', false)
->where('m_patientid', $id)
->get('m_patient')
->row();
if ($r->m_patientphoto != null && $r->m_patientphotocounter > 0) {
$full_path = substr_replace($home_dir ,"", -1) . $r->m_patientphoto;
$path_parts = pathinfo($full_path);
$rename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '-' . $r->m_patientphotocounter . '.' . $path_parts['extension'];
rename($full_path, $rename);
// echo $path_parts['dirname'], "\n";
// echo $path_parts['extension'], "\n";
// echo $path_parts['filename'], "\n";
return "/" . str_replace($home_dir, "", $rename);
}
return false;
}
}

View File

@@ -0,0 +1,409 @@
<?php
//diberi tambahan pembeda IsFromPanel
//utk contoh kasus yg ndak bisa di delete
//sementara profile di ambilkan dari panel juga dengan IsFromPanel = N
class Px extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Px API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function profile() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid ) ";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function panel() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'Y' IsFromPanel,T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid )
order by T_TestPanelID";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_old()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql_param = array("%$search%");
$sql = "select count(distinct T_TestID) total
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_company count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ?
limit 0,20
";
$query = $this->db_smartone->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_v2()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder_v2(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite_v2(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
function get_price()
{
$prm = $this->sys_input;
$r = [];
$sql_param = array($prm['test_id'], date('Y-m-d'), $prm['cito'], $prm['mou_id']);
$sql = "select fn_price(?, ?, ?, ?) as price";
$query = $this->db_smartone->query($sql, $sql_param);
if ($query) {
$r = $query->result_array()[0];
$r = json_decode($r['price']);
$this->sys_ok($r);
exit;
} else {
$this->sys_error_db("get price", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Religion extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Religion API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_religion count",$this->db_smartone);
exit;
}
$sql = "select M_ReligionID, M_ReligionName
from m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_religion rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
class Sex extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Sex API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName, concat('[', group_concat(json_object('M_TitleID', M_TitleID, 'M_TitleName', M_TitleName) separator ','), ']') as title
from m_sex
left join m_title on m_titlem_sexid = m_sexid and m_titleisactive = 'Y'
where M_SexIsActive = 'Y'
and M_SexName like ?
group by m_sexid
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['title'] = json_decode($v['title']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
class Title extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Title API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%',
'sex_id' => 0
];
if ($prm['search'] != '')
$q['search'] = "%{$prm['search']}%";
if ($prm['sex_id'] != '')
$q['sex_id'] = $prm['sex_id'];
// QUERY TOTAL
$sql = "select count(*) total
from
m_title
where M_TitleIsActive = 'Y'
and M_TitleName like ?
and ((M_TitleM_SexID = {$q['sex_id']} and {$q['sex_id']} <> 0) or {$q['sex_id']} = 0)";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName
from m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$prm['header']['suggestion'] = str_replace(PHP_EOL, '<br>', $prm['header']['suggestion']);
$header_json = json_encode($prm['header']);
$header_json = str_replace("\\", "\\\\", "$header_json");
$lab_json = json_encode($prm['lab']);
$med_json = json_encode($prm['med']);
$server = "http";
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_poly_save('{$prm['order_id']}', '{$header_json}', '{$med_json}', '{$lab_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
if ($rst->data->is_lab == "Y" && $rst->status == "OK")
{
// persiapkan curl
$ch = curl_init();
// set url
global $_SERVER;
$current_host = $_SERVER["SERVER_ADDR"];
if ($server == "https")
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "{$server}://{$current_host}:9090/ticket/UMUM");
//file_put_contents("/xtmp/url", "{$server}://{$current_host}:9090/ticket/UMUM" );
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = json_decode(curl_exec($ch));
// tutup curl
curl_close($ch);
// menampilkan hasil curl
// echo $output;
if ($output != null)
if ($output->status == "OK") {
$rst->data->queue = $output->data[0]->number;
$x = json_encode($output->data[0]);
$sql = "CALL sp_clinic_fo_labqueue('{$rst->data->id}', '{$rst->data->queue}', '{$x}');";
$query = $this->db_smartone->query($sql);
}
}
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function process()
{
$prm = $this->sys_input;
$sql = "CALL sp_clinic_poly_process('{$prm['order_id']}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function get_one()
{
$prm = $this->sys_input;
$sql = "select *
from c_orderheader
where C_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->row();
$rows->C_OrderHeaderQueueJSON = json_decode($rows->C_OrderHeaderQueueJSON);
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient get",$this->db_smartone);
exit;
}
}
function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'nolab' => '%',
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%',
'status' => 0
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['nolab'] != '')
$q['nolab'] = "%{$prm['nolab']}%";
if ($prm['status'] != '')
$q['status'] = $prm['status'];
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and M_PatientHP LIKE ?
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
// set locales
$this->db_smartone->query("SET @@lc_time_names = 'id_ID'");
$sql = "select M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientHP, M_PatientDOB, M_PatientNote, 'X' as M_PatientAddress,
M_PatientNote, C_OrderHeaderID, C_OrderHeaderNumber, M_StatusCode,
C_OrderHeaderM_PatientAge, C_OrderHeaderComplaint, C_OrderHeaderIsLab, C_OrderHeaderIsReceipt,
C_OrderHeaderDate, dayname(C_OrderHeaderDate) `day`
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
join m_status on c_orderheaderm_statusid = m_statusid
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Status extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "STATUS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_status count",$this->db_smartone);
exit;
}
$sql = "select M_StatusID, M_StatusName
from m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// $rows = $rows;
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_status rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
### Auth API
- Functions
- login x
- logout
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Auth extends MY_Controller {
var $db_onedev;
public function index()
{
echo "AUTH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function isLogin() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
} else {
$prm = $this->sys_input;
$data = array(
"user" => $this->sys_user
);
$this->sys_ok($data);
}
}
function login() {
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt . $prm["password"] .
$this->one_salt);
$query = $this->db_onedev->query("select M_UserID, M_UserUsername,
M_UserGroupDashboard
from m_user
join m_usergroup on m_userm_usergroupid = m_usergroupid
where M_UserUsername=? and M_UserPassword=?
and M_UserIsActive = 'Y'
",array($prm["username"], $sm_password));
echo $query;
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['M_UserGroupDashboard'] = "https://{$_SERVER['SERVER_NAME']}/{$user['M_UserGroupDashboard']}";
$token = JWT::encode($user,$this->SECRET_KEY);
$data = array(
"user" => $user,
"token" => $token
);
$query = $this->db_onedev->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now() WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout() {
$this->sys_error("ok");
}
}
?>