Files
2026-04-15 15:23:57 +07:00

1157 lines
33 KiB
PHP

<?php
class Doctor extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_oneklinik = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "SELECT orderID,
orderDate,
orderNumber,
orderIsAnamnese,
orderIsCheck,
orderAge as patient_age,
DATE_FORMAT(orderDate,'%d-%m-%Y') as order_date,
'N' divider,
M_PatientID,
M_PatientNoReg,
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientHP,
M_PatientEmail,
M_PatientPOB,
M_PatientPhone,
M_PatientIDNumber,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
M_PatientNote,
M_PatientNIK,
M_PatientJabatan,
M_PatientKedudukan,
M_PatientPJ,
M_PatientLocation,
M_PatientJob,
M_PatientM_SexID,
M_SexName,
M_PatientM_TitleID,
M_TitleName,
M_PatientM_ReligionID,
M_ReligionName,
M_PatientM_IdTypeID,
M_IdTypeName,
M_PatientIDNumber,
IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status,
M_PatientAddressM_KelurahanID M_KelurahanID,
0 M_DistrictID,
0 M_CityID,
0 M_ProvinceID
FROM one_klinik.order
JOIN m_patient ON M_PatientID = orderM_PatientID AND M_PatientIsActive = 'Y'
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
LEFT JOIN m_idtype ON M_IdTypeID = M_PatientM_IdTypeID AND M_IdTypeIsActive = 'Y'
LEFT JOIN m_religion ON m_patientm_religionid = m_religionid
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
WHERE
orderNumber = '{$id}' AND
M_PatientSuspendID IS NULL
GROUP BY M_PatientID";
//echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
{
$rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']);
$rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']);
$patient_name = str_replace("'", "\\'", $prm['M_PatientName']);
$sql = "SELECT *, concat('{$rows[$k]['M_PatientAddressDescription'] }', '\n\n',
m_kelurahanname, ', ',
m_districtname,'\n',
m_cityname, ', ',
m_provincename) as xaddress
FROM m_kelurahan
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
JOIN m_province ON M_CityM_ProvinceID = M_ProvinceID
WHERE
M_KelurahanID = {$v['M_KelurahanID']} ";
//echo $sql;
$row_address = $this->db_onedev->query($sql)->row_array();
$rows[$k]['M_PatientAddress'] = stripslashes($row_address['xaddress']);
$rows[$k]['M_DistrictID'] = $row_address['M_DistrictID'];
$rows[$k]['M_CityID'] = $row_address['M_CityID'];
$rows[$k]['M_ProvinceID'] = $row_address['M_ProvinceID'];
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row();
$rows[$k]['info'] = json_decode($info->info);
}
$result = array("total" => 1, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_onedev);
exit;
}
}
function get_data(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$result = array('data' => '');
if($prm['type_field'] == 'TEXT'){
if($prm['selected_tab']['id'] == 'VITAL' && $prm['type_field'] == 'TEXT'){
$sql = "SELECT IFNULL(orderDoctorVitalSign,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'RECEIPT'){
$sql = "SELECT IFNULL(orderDoctorReceipt,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'DIAGPRIMER'){
$sql = "SELECT IFNULL(orderDoctorDiagnosePrimer,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'DIAGSEKUNDER'){
$sql = "SELECT IFNULL(orderDoctorDiagnoseSekunder,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'MEDIC' && $prm['type_field'] == 'TEXT'){
$sql = "SELECT IFNULL(orderDoctorMedic,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'SARAN'){
$sql = "SELECT IFNULL(orderDoctorSaran,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
}
if($prm['selected_tab']['id'] == 'ADDITIONAL'){
$sql = "SELECT Nat_GroupID as id, Nat_GroupName as name
FROM nat_group
WHERE
Nat_GroupIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
if(!$query){
$this->sys_error("Invalid get nat_group");
exit;
}
if($prm['selected_tab']['id'] != 'ADDITIONAL'){
$rst = $query->row_array();
if($rst){
$result['data'] = $rst['value'];
}else{
$result['data'] = '';
}
}
if($prm['selected_tab']['id'] === 'ADDITIONAL'){
$group_tests = $query->result_array();
if($group_tests){
$result['group_tests'] = $group_tests ;
$group_id = $group_tests[0]['id'];
$result['subgroups'] = $this->get_subgroup($group_id );
$result['tests'] = $this->get_tests($group_id ,[],'');
//$mouID = $this->getMouID();
$sql = "SELECT settingM_MouID as id
FROM one_klinik.setting
WHERE
settingIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql);
if(!$query){
$this->sys_error("error get setting");
return 0;
}
$mouID = $query->row()->id;
$result['selected_test'] = $this->getSelectedTest($prm['orderid'],$mouID);
}else{
$result['data'] = '';
}
}
}
if($prm['selected_tab']['id'] == 'VITAL' && $prm['type_field'] == 'FORM'){
$sql = "SELECT IFNULL(orderDoctorVitalSign,'') as value
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = 'FORM' AND orderDoctorIsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
if(!$query){
$this->sys_error("Invalid get orderDoctorVitalSign FORM");
exit;
}
$data_vital = $query->row_array();
if($data_vital){
$jsonData = stripslashes(html_entity_decode($data_vital['value']));
$vital_sign =json_decode($jsonData,true);
$result['data'] = $vital_sign;
}else{
$result['data'] = $this->get_form_vital($prm['orderid']);
}
}
if($prm['selected_tab']['id'] == 'DIAGPRIMER'){
$result['icd10'] = array();
$xcount = $this->check_exist_icd10_row($prm['orderid']);
//echo $xcount;
if($xcount > 0){
$sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name
FROM one_klinik.order_diagnose_icd10
JOIN one_terminology.terminology ON code = orderDiagnoseIcd10Primary AND attribute_path = 'icd10'
WHERE
orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
if(!$query){
$this->sys_error("Invalid get order_diagnose_icd10");
exit;
}
$result['icd10'] = $query->row_array();
}
}
if($prm['selected_tab']['id'] == 'DIAGSEKUNDER'){
$result['icd10'] = array();
$xcount = $this->check_exist_icd10_row($prm['orderid']);
if($xcount > 0){
$sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name
FROM one_klinik.order_diagnose_icd10
JOIN one_terminology.terminology ON code = orderDiagnoseIcd10Sekunder AND attribute_path = 'icd10'
WHERE
orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y'
LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
if(!$query){
$this->sys_error("Invalid get order_diagnose_icd10");
exit;
}
$result['icd10'] = $query->row_array();
}
}
$sql = "SELECT M_DoctorID as id,
M_DoctorMcuDefaultKlinik as isDefault,
CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name
FROM m_doctormcu
JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID
WHERE
M_DoctorMcuIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if(!$query){
$this->sys_error("error get doctors");
echo $this->db_onedev->last_query();
exit;
}
$result['doctors'] = $query->result_array();
$sql = "SELECT IFNULL(M_DoctorID,0) as id,
IFNULL(M_DoctorMcuDefaultKlinik,'N') as isDefault,
CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',IFNULL(M_DoctorName,''),' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name
FROM one_klinik.order
LEFT JOIN m_doctor ON orderM_DoctorID = M_DoctorID
LEFT JOIN m_doctormcu ON M_DoctorMcuM_DoctorID = M_DoctorID
WHERE
orderID = ?";
$query = $this->db_onedev->query($sql,array($prm['orderid']));
if(!$query){
$this->sys_error("error get doctor order");
echo $this->db_onedev->last_query();
exit;
}
$selected_doctor = $query->row_array();
if($selected_doctor['id'] == 0){
$selected_doctor = array();
foreach ($result['doctors'] as $key => $value) {
if($value['isDefault'] == 'Y'){
$selected_doctor = $value;
}
}
}
$result['selected_doctor'] = $selected_doctor;
$this->sys_ok($result);
exit;
}
function getSelectedTest($orderID,$mouID){
$sql = "SELECT ss_price_mou.*, 'N' as selected
FROM ss_price_mou
JOIN t_test xtest ON xtest.T_TestID = ss_price_mou.T_TestID AND xtest.T_TestIsActive = 'Y'
JOIN one_klinik.`order_penunjang` ON orderPenunjangOrderID = ? AND orderPenunjangT_TestID = xtest.T_TestID AND
orderPenunjangIsActive = 'Y'
WHERE
T_PriceM_MouID = ? AND is_packet = 'N'
GROUP BY ss_price_mou.T_TestID
";
$query = $this->db_onedev->query($sql,array($orderID,$mouID));
if(!$query){
$this->sys_error("error get ss_price_mou");
echo $this->db_onedev->last_query();
exit;
}
$rst = $query->result_array();
foreach ($rst as $k => $v) {
if($v['selected'] == 'N')
$rst[$k]['selected'] = false;
$rst[$k]['nat_test'] = json_decode($v['nat_test']);
$child_test = json_decode($v['child_test']);
if($v['px_type'] == 'PR' || $v['px_type'] == 'PXR'){
foreach ($child_test as $key => $value) {
//print_r($child_test[$key]);
$child_test[$key] = $this->objToArray($value);
$child_test[$key]['Ss_PriceMouID'] = $v['Ss_PriceMouID'];
}
}
$rst[$k]['child_test'] = $child_test;
}
return $rst;
}
function get_subgroup($group_id){
$sql = "SELECT Nat_SubGroupID as id, Nat_SubGroupName as name
FROM nat_subgroup
WHERE
Nat_SubGroupIsActive = 'Y' AND Nat_SubGroupNat_GroupID = ?";
$query = $this->db_onedev->query($sql,array($group_id));
if(!$query){
$this->sys_error("error get nat_subgroup");
exit;
}
$subgroups = $query->result_array();
return $subgroups;
}
function getMouID(){
$sql = "SELECT settingM_MouID as id
FROM one_klinik.setting
WHERE
settingIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql);
if(!$query){
$this->sys_error("error get setting");
return 0;
}
return $query->row()->id;
}
function get_tests($group_id,$filter_subgroup,$search_test){
//$mouID = $this->getMouID();
$sql = "SELECT settingM_MouID as id
FROM one_klinik.setting
WHERE
settingIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql);
if(!$query){
$this->sys_error("error get setting");
return 0;
}
$mouID = $query->row()->id;
//echo $mouID;
$query_filter_subgroup = "";
if(count($filter_subgroup) > 0){
//echo count($filter_subgroup) ;
$query_filter_subgroup = " AND ( ";
foreach ($filter_subgroup as $key => $value) {
if($key > 0)
$query_filter_subgroup .= " OR ";
$query_filter_subgroup .= " Nat_TestNat_SubGroupID = {$value['id']}";
}
$query_filter_subgroup .= " ) ";
}
$query_search_test = "";
if($search_test != ''){
$query_search_test = "WHERE xtest.T_TestName LIKE CONCAT('%','{$search_test}','%')";
}
$sql = "SELECT ss_price_mou.*, 'N' as selected
FROM t_test xtest
JOIN nat_test ON Nat_TestNat_GroupID = ? AND nat_test.Nat_TestID = xtest.T_TestNat_TestID AND
Nat_TestIsActive = 'Y' AND
xtest.T_TestIsActive = 'Y'
{$query_filter_subgroup}
JOIN ss_price_mou ON T_PriceM_MouID = ? AND xtest.T_TestID = ss_price_mou.T_TestID AND is_packet = 'N'
{$query_search_test}
GROUP BY ss_price_mou.T_TestID
LIMIT 50";
/*$sql = "SELECT ss_price_mou.*, 'N' as selected
FROM ss_price_mou
JOIN t_test xtest ON xtest.T_TestID = ss_price_mou.T_TestID AND xtest.T_TestIsActive = 'Y' AND T_PriceM_MouID = ? AND is_packet = 'N'
JOIN nat_test ON nat_test.Nat_TestID = xtest.T_TestNat_TestID AND Nat_TestIsActive = 'Y' AND Nat_TestNat_GroupID = ?
{$query_filter_subgroup}
{$query_search_test}
GROUP BY ss_price_mou.T_TestID
LIMIT 50
";*/
$query = $this->db_onedev->query($sql,array($group_id,$mouID));
//echo $this->db_onedev->last_query();
if(!$query){
$this->sys_error("error get ss_price_mou");
echo $this->db_onedev->last_query();
exit;
}
//echo $this->db_onedev->last_query();
$tests = $query->result_array();
foreach ($tests as $k => $v) {
if($v['selected'] == 'N')
$tests[$k]['selected'] = false;
$tests[$k]['nat_test'] = json_decode($v['nat_test']);
$child_test = json_decode($v['child_test']);
if($v['px_type'] == 'PR' || $v['px_type'] == 'PXR'){
foreach ($child_test as $key => $value) {
//print_r($child_test[$key]);
$child_test[$key] = $this->objToArray($value);
$child_test[$key]['Ss_PriceMouID'] = $v['Ss_PriceMouID'];
}
}
$tests[$k]['child_test'] = $child_test;
}
return $tests;
}
protected function objToArray($obj)
{
// Not an object or array
if (!is_object($obj) && !is_array($obj)) {
return $obj;
}
// Parse array
foreach ($obj as $key => $value) {
$arr[$key] = $this->objToArray($value);
}
// Return parsed array
return $arr;
}
function do_gettests(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
//print_r($prm['subgroup']);
$result['tests'] = $this->get_tests($prm['group_id']['id'],$prm['subgroup'],$prm['search']);
$result['subgroups'] = $this->get_subgroup($prm['group_id']['id']);
$this->sys_ok($result);
exit;
}
function get_doctorpj(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$result = array();
/*$sql = "SELECT M_DoctorID as doctor_id,
CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_name
FROM m_doctor_schedule
JOIN one_aditya.m_doctor ON M_DoctorScheduleM_DoctorID = M_DoctorID
WHERE
M_DoctorScheduleM_RegDayID = DAYOFWEEK(DATE(NOW())) AND
M_DoctorScheduleIsActive = 'Y'";
*/
$sql =" SELECT M_DoctorID as doctor_id,
CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_name
FROM one_klinik.`order`
JOIN m_doctor ON orderM_DoctorID = M_DoctorID
WHERE
orderNumber = ?";
$query = $this->db_oneklinik->query($sql,array($prm['orderNumber']));
//echo $this->db_oneklinik->last_query();
if(!$query){
$this->sys_error("Invalid Query m_doctor_schedule");
exit;
}
$rst = $query->row_array();
if($rst){
$result['doctor_pj'] = $rst;
}else{
$result['doctor_pj'] = [];
}
$this->sys_ok($result);
exit;
}
function save_text(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userID = $this->sys_user['M_UserID'];
$result = array();
$sql = "UPDATE one_klinik.`order` SET orderM_DoctorID = ?, orderUserID = ?
WHERE
orderID = ?";
$query = $this->db_oneklinik->query($sql,array($prm['doctor']['id'],$userID,$prm['orderid']));
if(!$query){
echo $this->db_oneklinik->last_query();
$this->sys_error("Invalid update doctor");
exit;
}
$sql = "SELECT COUNT(*) as xcount
FROM one_klinik.order_doctor
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql,array($prm['orderid'],$prm['type']));
if(!$query){
$this->sys_error("Invalid Query XCOUNT");
exit;
}
//echo $this->db_oneklinik->last_query();
$xcount_exist = $query->row()->xcount;
if($xcount_exist == 0){
$sql = "INSERT INTO one_klinik.order_doctor (
orderDoctorType,
orderDoctorOrderID,
orderDoctorVitalSign,
orderDoctorReceipt,
orderDoctorDiagnosePrimer,
orderDoctorDiagnoseSekunder,
orderDoctorSaran,
orderDoctorUserID,
orderDoctorCreated
)
VALUES(
?,?,'','','','','',?,NOW()
)";
$query = $this->db_oneklinik->query($sql,array($prm['type'],
$prm['orderid'],
$userID
));
//echo $this->db_oneklinik->last_query();
if(!$query){
$this->sys_error("Invalid INSERT NEW VITAL SIGN");
exit;
}
}
if($prm['selected_tab']['id'] == 'VITAL'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorVitalSign = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
}
if($prm['selected_tab']['id'] == 'RECEIPT'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorReceipt = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
}
if($prm['selected_tab']['id'] == 'MEDIC'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorMedic = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
}
if($prm['selected_tab']['id'] == 'DIAGPRIMER'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorDiagnosePrimer = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
}
if($prm['selected_tab']['id'] == 'DIAGSEKUNDER'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorDiagnoseSekunder = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
//echo $sql;
}
if($prm['selected_tab']['id'] == 'SARAN'){
$sql = "UPDATE one_klinik.order_doctor SET
orderDoctorSaran = ?, orderDoctorUserID = ?
WHERE
orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'";
}
$value = $prm['note'];
if($prm['type'] == 'FORM'){
$vital_sign = str_replace('\'', '\\\'', json_encode($prm["vital_sign"],JSON_UNESCAPED_UNICODE | JSON_HEX_APOS | JSON_HEX_QUOT));
//$value = addslashes(str_replace('\"', '\\\"',$vital_sign));
$value = $vital_sign;
}
$query = $this->db_oneklinik->query($sql,array($value,$userID,$prm['orderid'],$prm['type']));
//echo $this->db_oneklinik->last_query();
if(!$query){
$this->sys_error("Invalid Query update ".$prm['selected_tab']['id']);
exit;
}
if($prm['icd10_primer'])
$save_icd10 = $this->save_icd10_primer($prm['orderid'],$prm['icd10_primer']['code'],$prm['icd10_primer']['display']);
if($prm['icd10_sekunder'])
$save_icd10 = $this->save_icd10_sekunder($prm['orderid'],$prm['icd10_sekunder']['code'],$prm['icd10_sekunder']['display']);
$this->sys_ok($result);
exit;
}
function save_px(){
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 orderM_DoctorID = ?, orderUserID = ?
WHERE
orderID = ?";
$query = $this->db_oneklinik->query($sql,array($prm['doctor']['id'],$userID,$prm['orderid']));
if(!$query){
$this->sys_error("Invalid update doctor");
exit;
}
if(count($prm['selected_test']) > 0){
$sql = "UPDATE one_klinik.order_penunjang SET orderPenunjangIsActive = 'N'
WHERE
orderPenunjangOrderID = ? AND orderPenunjangIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
//echo $this->db_oneklinik->last_query();
if(!$query){
$this->sys_error("Invalid Query Is Active N");
exit;
}
foreach ($prm['selected_test'] as $key => $value) {
$sql = "INSERT INTO one_klinik.order_penunjang(
orderPenunjangOrderID,
orderPenunjangT_TestID,
orderPenunjangCreated
)
VALUES(
?,?,NOW()
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderid'],$value['T_TestID']));
//echo $this->db_oneklinik->last_query();
if(!$query){
$this->sys_error("Invalid Query Insert ".$value['T_TestName']);
exit;
}
}
}
//$mouID = $this->getMouID();
$sql = "SELECT settingM_MouID as id
FROM one_klinik.setting
WHERE
settingIsActive = 'Y'";
$query = $this->db_oneklinik->query($sql);
if(!$query){
$this->sys_error("error get setting");
return 0;
}
$mouID = $query->row()->id;
$result['selected_test'] = $this->getSelectedTest($prm['orderid'],$mouID);
$this->sys_ok($result);
exit;
}
function get_form_vital($orderID){
$sql = "SELECT *
FROM one_klinik.`order`
WHERE
orderID = ?
";
$query = $this->db_oneklinik->query($sql,$orderID);
if(!$query){
$this->sys_error("error get language");
echo $this->db_oneklinik->last_query();
return array("data" => 'error languange');
}
$langID = $query->row()->orderM_LanguageID;
$sql = "SELECT *
FROM fisik_templateresult
WHERE
Fisik_TemplateResultM_LangID = ? AND
Fisik_TemplateResultType = 'fisik' AND
Fisik_TemplateResultIsActive = 'Y' LIMIT 1
";
$query = $this->db_onedev->query($sql,array($langID));
if(!$query){
$this->sys_error("error get fisik template");
echo $this->db_onedev->last_query();
return array("data" => 'error');
}
$fisik = json_decode($query->row()->Fisik_TemplateResultText);
$tanda_vital = [];
foreach ($fisik as $key => $value) {
if($value->title == 'TANDA VITAL' || $value->title == 'STATUS GIZI')
$tanda_vital[] = $value;
}
return $tanda_vital;
}
public function list_patient()
{
$prm = $this->sys_input;
$max_rst = 20;
$tot_count = 0;
$number_limit = 20;
$number_offset = (!isset($prm['current_page'])?1:$prm['current_page'] - 1) * $number_limit ;
$xdate = $prm['date'];
$status = $prm['status'];
$sql = "SELECT 'N' divider,
CONCAT(M_TitleName,' ',IF(M_PatientPrefix = NULL,'',CONCAT(M_PatientPrefix,' ')),M_PatientName,IF(M_PatientPrefix = NULL,'',CONCAT(M_PatientSuffix,' '))) as patient_name,
`order`.*,DATE_FORMAT(orderDate,'%d-%m-%Y') as date_order,
'' as kode_status, '' as status
FROM one_klinik.`order`
JOIN m_patient ON orderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
orderIsActive = 'Y' AND DATE(orderDate) = ? AND orderIsAnamnese = 'D' AND orderIsCheck = ?
LIMIT $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_oneklinik->query($sql,array($xdate,$status));
//echo $this->db_oneklinik->last_query();
if ($query) {
$rows = $query->result_array();
foreach ($rows as $key => $value) {
$sql = "SELECT
FROM one_klinik.order_status
WHERE
orderStatusOrderID = ?
ORDER BY ";
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_onedev);
exit;
}
}
function process_now(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$sql = "INSERT INTO one_klinik.order_status (
orderStatusOrderID,
orderStatusCode,
orderStatusValue,
orderStatusUserID
)
VALUES(
?,?,?,?
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'C','Y',$userID));
if(!$query){
$this->sys_error("Gagal Process");
}
$sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'Y', orderUserID = ?
WHERE
orderID = ?";
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
if(!$query){
$this->sys_error("Gagal Update");
}
$result = array('process'=>'OK');
$this->sys_ok($result);
exit;
}
function cancel_now(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$sql = "INSERT INTO one_klinik.order_status (
orderStatusOrderID,
orderStatusCode,
orderStatusValue,
orderStatusUserID
)
VALUES(
?,?,?,?
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'C','N',$userID));
if(!$query){
$this->sys_error("Gagal Process");
}
$sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'N', orderUserID = ?
WHERE
orderID = ?";
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
if(!$query){
$this->sys_error("Gagal Process");
}
$result = array('process'=>'OK');
$this->sys_ok($result);
exit;
}
function end_session(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$sql = "INSERT INTO one_klinik.order_status (
orderStatusOrderID,
orderStatusCode,
orderStatusValue,
orderStatusUserID
)
VALUES(
?,?,?,?
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'C','D',$userID));
if(!$query){
$this->sys_error("Gagal End");
}
$sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'D', orderUserID = ?
WHERE
orderID = ?";
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
if(!$query){
$this->sys_error("Gagal ENd");
}
$result = array('process'=>'OK');
$this->sys_ok($result);
exit;
}
function search_icd10(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name
FROM one_terminology.terminology
WHERE
attribute_path = 'icd10' AND ( code LIKE CONCAT('%',?,'%') OR MATCH (display) AGAINST (? IN NATURAL LANGUAGE MODE) OR CONCAT(code,' | ', display) LIKE CONCAT('%',?,'%'))
GROUP BY code";
$query = $this->db_onedev->query($sql,array($prm['search'],$prm['search'],$prm['search']));
if(!$query){
$this->sys_error("Gagal cari End");
}
$result = $query->result_array();
$this->sys_ok($result);
exit;
}
function save_icd10_primer($orderID,$icd10_code,$icd10_display){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$prm = $this->sys_input;
$prm['orderID'] = $orderID;
$prm['icd10']['code'] = $icd10_code;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$sql = "SELECT COUNT(*) as xcount
FROM one_klinik.order_diagnose_icd10
WHERE
orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($prm['orderID']));
if(!$query){
$this->sys_error("Gagal hitung");
}
$xcount = $query->row()->xcount;
if($xcount == 0){
$sql = "INSERT INTO one_klinik.order_diagnose_icd10 (
orderDiagnoseIcd10OrderID,
orderDiagnoseIcd10Created,
orderDiagnoseIcd10UserID
)
VALUES(
?,NOW(),?
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],$userID));
if(!$query){
$this->sys_error("Gagal insert");
}
}
$sql = "UPDATE one_klinik.order_diagnose_icd10 SET orderDiagnoseIcd10Primary = ?, orderDiagnoseIcd10PrimaryText = ?, orderDiagnoseIcd10UserID = ?
WHERE
orderDiagnoseIcd10OrderID = ? ";
$query = $this->db_oneklinik->query($sql,array($prm['icd10']['code'],$icd10_display, $userID,$prm['orderID']));
if(!$query){
$this->sys_error("Gagal update");
}
$this->sys_ok($result);
exit;
}
function check_exist_icd10_row($orderID){
$sql = "SELECT COUNT(*) as xcount
FROM one_klinik.order_diagnose_icd10
WHERE
orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1";
$query = $this->db_oneklinik->query($sql,array($orderID));
if(!$query){
$this->sys_error("Gagal hitung");
}
return $query->row()->xcount;
}
function save_icd10_sekunder($orderID,$icd10_code,$icd10_display){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$prm = $this->sys_input;
$prm['orderID'] = $orderID;
$prm['icd10']['code'] = $icd10_code;
$userID = $this->sys_user['M_UserID'];
//print_r($prm['subgroup']);
$xcount = $this->check_exist_icd10_row($prm['orderID']);
if($xcount == 0){
$sql = "INSERT INTO one_klinik.order_diagnose_icd10 (
orderDiagnoseIcd10OrderID,
orderDiagnoseIcd10Created,
orderDiagnoseIcd10UserID
)
VALUES(
?,NOW(),?
)";
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],$userID));
if(!$query){
$this->sys_error("Gagal insert");
}
}
$sql = "UPDATE one_klinik.order_diagnose_icd10 SET orderDiagnoseIcd10Sekunder = ?, orderDiagnoseIcd10SekunderText = ?, orderDiagnoseIcd10UserID = ?
WHERE
orderDiagnoseIcd10OrderID = ? ";
$query = $this->db_oneklinik->query($sql,array($prm['icd10']['code'], $icd10_display, $userID,$prm['orderID']));
if(!$query){
$this->sys_error("Gagal update");
}
$this->sys_ok($result);
exit;
}
}