Files
2026-05-25 20:01:37 +07:00

1174 lines
39 KiB
PHP

<?php
class Physic extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Physic API";
/*
truncate t_orderphysic_allergy;
truncate t_orderphysic_chestabdomen;
truncate t_orderphysic_complaintnote;
truncate t_orderphysic_conclusion;
truncate t_orderphysic_drugconsumption;
truncate t_orderphysic_eyes;
truncate t_orderphysic_generalcondition;
truncate t_orderphysic_lifestyle;
truncate t_orderphysic_medicalhistory;
truncate t_orderphysic_nerve;
truncate t_orderphysic_suggestion;
truncate t_orderphysic_tht;
truncate t_orderphysic_tooth;
*/
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["namelab"];
$status = $prm["stationid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql_where = "WHERE T_OrderPhysicStatus = '{$status}' AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND T_OrderPhysicIsActive = 'Y'";
//$sql_param = array();
if ($search != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$search%' OR M_PatientName like '%$search%' ) ";
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = " SELECT count(*) as total
FROM t_orderphysic
JOIN t_orderheader ON T_OrderPhysicT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN m_doctor ON T_OrderPhysicM_DoctorID = M_DoctorID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_orderphysic count", $this->db_onedev);
exit;
}
$sql = "SELECT
T_OrderPhysicID as trx_id,
T_OrderHeaderID as orderid,
T_OrderPhysicCode as code,
T_OrderHeaderLabNumber as ordernumber,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
UPPER(M_SexName) as sexname,
M_CompanyName as companyname,
M_CompanyAddress as companyaddress,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_DoctorID as doctor_id,
CONCAT(M_DoctorPrefix,' ',UPPER(M_DoctorName),' ',M_DoctorSufix) as doctor_fullname,
'' as details,
CASE
WHEN T_OrderPhysicStatus = 'NEW' THEN 'BARU'
WHEN T_OrderPhysicStatus = 'VER' THEN 'VERIFIKASI'
WHEN T_OrderPhysicStatus = 'VAL' THEN 'VALIDASI'
END as status_name,
T_OrderPhysicStatus as status
FROM t_orderphysic
JOIN t_orderheader ON T_OrderPhysicT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN m_doctor ON T_OrderPhysicM_DoctorID = M_DoctorID
$sql_where
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC
limit $number_limit offset $number_offset";
//echo $sql;
//v-bind:class="backgroundInp(tooth.value)"
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$details = array();
$types = explode("+",$v['code']);
foreach($types as $ki=>$vi){
//$details['pasien'] = array();
//$details['doctor'] = array();
if($vi == 'DFLT'){
$sql = "SELECT T_OrderPhysicComplaintNoteValue as value
FROM t_orderphysic_complaintnote
WHERE
T_OrderPhysicComplaintNoteT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicComplaintNoteIsActive = 'Y'";
$rows[$k]['details']['complaint'] = $this->db_onedev->query($sql)->row()->value;
$rows[$k]['details']['medicalhistory'] = $this->getmedicalhistory($v['orderid']);
$rows[$k]['details']['allergy'] = $this->getfromsp('sp_physic_dflt_get_allergy',$v['orderid']);
$rows[$k]['details']['drugconsumption'] = $this->getfromsp('sp_physic_dflt_get_drugconsumption',$v['orderid']);
$rows[$k]['details']['lifestyle'] = $this->getfromsp('sp_physic_dflt_get_lifestyle',$v['orderid']);
$rows[$k]['details']['vitalsign'] = $this->getvitalsign($v['orderid']);
$rows[$k]['details']['generalcondition'] = $this->getfromsp('sp_physic_dflt_get_generalcondition',$v['orderid']);
$rows[$k]['details']['eyes'] = $this->getfromsp('sp_physic_dflt_get_eyes',$v['orderid']);
$rows[$k]['details']['tooth'] = $this->getfromsp('sp_physic_dflt_get_tooth',$v['orderid']);
$rows[$k]['details']['tht'] = $this->getfromsp('sp_physic_dflt_get_tht',$v['orderid']);
$rows[$k]['details']['chestabdomen'] = $this->getfromsp('sp_physic_dflt_get_chestabdomen',$v['orderid']);
$rows[$k]['details']['nerve'] = $this->getfromsp('sp_physic_dflt_get_nerve',$v['orderid']);
$sql = "SELECT T_OrderPhysicConclusionValue as value
FROM t_orderphysic_conclusion
WHERE
T_OrderPhysicConclusionT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicConclusionIsActive = 'Y'";
$rows[$k]['details']['conslusion'] = $this->db_onedev->query($sql)->row()->value;
$sql = "SELECT T_OrderPhysicSuggestionValue as value
FROM t_orderphysic_suggestion
WHERE
T_OrderPhysicSuggestionT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicSuggestionIsActive = 'Y'";
$rows[$k]['details']['suggestion'] = $this->db_onedev->query($sql)->row()->value;
}
if($vi == 'K3'){
$rows[$k]['details']['workplacehazards'] = $this->getfromsp('sp_physic_k3_workplace_hazards',$v['orderid']);
$rows[$k]['details']['workplaceaccident'] = $this->getworkplaceaccident($v['orderid']);
}
}
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function temp_default(){
}
public function search_old()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["namelab"];
$status = $prm["stationid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql_where = "WHERE T_OrderPhysicStatus = '{$status}' AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND T_OrderPhysicIsActive = 'Y'";
//$sql_param = array();
if ($search != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$search%' OR M_PatientName like '%$search%' ) ";
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = " SELECT count(*) as total
FROM t_orderphysic
JOIN t_orderheader ON T_OrderPhysicT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN m_doctor ON T_OrderPhysicM_DoctorID = M_DoctorID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_orderphysic count", $this->db_onedev);
exit;
}
$sql = "SELECT
T_OrderPhysicID as trx_id,
T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as ordernumber,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
UPPER(M_SexName) as sexname,
M_CompanyName as companyname,
M_CompanyAddress as companyaddress,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
UPPER(T_OrderHeaderM_PatientAge) as umur,
M_DoctorID as doctor_id,
CONCAT(M_DoctorPrefix,' ',UPPER(M_DoctorName),' ',M_DoctorSufix) as doctor_fullname,
'' as details,
CASE
WHEN T_OrderPhysicStatus = 'NEW' THEN 'BARU'
WHEN T_OrderPhysicStatus = 'VER' THEN 'VERIFIKASI'
WHEN T_OrderPhysicStatus = 'VAL' THEN 'VALIDASI'
END as status_name,
T_OrderPhysicStatus as status
FROM t_orderphysic
JOIN t_orderheader ON T_OrderPhysicT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN m_doctor ON T_OrderPhysicM_DoctorID = M_DoctorID
$sql_where
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC
limit $number_limit offset $number_offset";
//echo $sql;
//v-bind:class="backgroundInp(tooth.value)"
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$sql = "SELECT T_OrderPhysicComplaintNoteValue as value
FROM t_orderphysic_complaintnote
WHERE
T_OrderPhysicComplaintNoteT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicComplaintNoteIsActive = 'Y'";
$rst_complaint = $this->db_onedev->query($sql)->row()->value;
$rst_medicalhistory = $this->getmedicalhistory($v['orderid']);
$rst_allergy = $this->getfromsp('sp_physic_dflt_get_allergy',$v['orderid']);
$rst_drugconsumption = $this->getfromsp('sp_physic_dflt_get_drugconsumption',$v['orderid']);
$rst_lifestyle = $this->getfromsp('sp_physic_dflt_get_lifestyle',$v['orderid']);
$rst_vitalsign = $this->getvitalsign($v['orderid']);
$rst_generalcondition = $this->getfromsp('sp_physic_dflt_get_generalcondition',$v['orderid']);
$rst_eyes = $this->getfromsp('sp_physic_dflt_get_eyes',$v['orderid']);
$rst_tooth = $this->getfromsp('sp_physic_dflt_get_tooth',$v['orderid']);
$rst_tht = $this->getfromsp('sp_physic_dflt_get_tht',$v['orderid']);
$rst_chestabdomen = $this->getfromsp('sp_physic_dflt_get_chestabdomen',$v['orderid']);
$rst_nerve = $this->getfromsp('sp_physic_dflt_get_nerve',$v['orderid']);
$sql = "SELECT T_OrderPhysicConclusionValue as value
FROM t_orderphysic_conclusion
WHERE
T_OrderPhysicConclusionT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicConclusionIsActive = 'Y'";
$rst_conclusion = $this->db_onedev->query($sql)->row()->value;
$sql = "SELECT T_OrderPhysicSuggestionValue as value
FROM t_orderphysic_suggestion
WHERE
T_OrderPhysicSuggestionT_OrderPhysicID = '{$v['trx_id']}' AND
T_OrderPhysicSuggestionIsActive = 'Y'";
$rst_suggestion = $this->db_onedev->query($sql)->row()->value;
$rows[$k]['details'] = array(
'complaint'=>$rst_complaint,
'medicalhistory'=>$rst_medicalhistory,
'allergy'=>$rst_allergy,
'drugconsumption'=>$rst_drugconsumption,
'lifestyle'=>$rst_lifestyle,
'vitalsign'=>$rst_vitalsign,
'generalcondition'=>$rst_generalcondition,
'eyes'=>$rst_eyes,
'tooth'=>$rst_tooth,
'tht'=>$rst_tht,
'chestabdomen'=>$rst_chestabdomen,
'nerve'=>$rst_nerve,
'conslusion'=>$rst_conclusion,
'suggestion'=>$rst_suggestion
);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function getmedicalhistory($orderid){
$sql = "CALL `sp_physic_dflt_get_medicalhistory`('{$orderid}')";
$r = $this->db_onedev->query($sql)->result();
$this->clean_mysqli_connection($this->db_onedev->conn_id);
$data_return = array();
if($r){
$i = 1;
$tem_arr = array();
foreach($r as $k => $v){
array_push($tem_arr,$v);
if($i == 2){
array_push($data_return,$tem_arr);
$tem_arr = array();
$i = 0;
}
$i++;
}
}
return $data_return;
}
function getworkplaceaccident($orderid){
$sql = "CALL `sp_physic_k3_workplace_accident`('{$orderid}')";
//echo $sql;
$r = $this->db_onedev->query($sql)->result();
$this->clean_mysqli_connection($this->db_onedev->conn_id);
$data_return = array();
if($r){
$i = 1;
$tem_arr = array();
foreach($r as $k => $v){
array_push($tem_arr,$v);
if($i == 2){
array_push($data_return,$tem_arr);
$tem_arr = array();
$i = 0;
}
$i++;
}
}
return $data_return;
}
function getvitalsign($orderid){
$sql = "CALL `sp_physic_dflt_get_vitalsign`('{$orderid}')";
$r = $this->db_onedev->query($sql)->result();
$this->clean_mysqli_connection($this->db_onedev->conn_id);
$data_return = array();
if($r){
$i = 1;
$tem_arr = array();
foreach($r as $k => $v){
array_push($tem_arr,$v);
if($i == 2){
array_push($data_return,$tem_arr);
$tem_arr = array();
$i = 0;
}
$i++;
}
}
return $data_return;
}
function getfromsp($spname,$orderid){
$sql = "CALL `{$spname}`('{$orderid}')";
$r = $this->db_onedev->query($sql)->result();
$this->clean_mysqli_connection($this->db_onedev->conn_id);
return $r;
}
function getordersamples(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$doctorid = $prm['doctorid'];
$doctoraddressid = $prm['doctoraddressid'];
$sql = "SELECT
0 as idx,
M_SexName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
T_SampleTypeName as samplename,
T_OrderHeaderLabNumber as labnumber,
T_OrderHeaderID as orderid,
T_SampleTypeID as sampleid,
'Y' as active,
'N' as flag_image
FROM t_samplingso
JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
JOIN t_sampletype ON T_SamplingSoT_SampleTypeID = T_SampleTypeID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
WHERE
T_SamplingSoM_DoctorID = {$doctorid} AND T_SamplingSoM_DoctorAddressID = {$doctoraddressid} AND T_SamplingSoVerifyFlagWL = 'N' AND T_SamplingSoIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getstation(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y'
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
//print_r($statuses);
foreach($statuses as $k=>$v){
array_push($rows['statuses'],$v);
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctoraddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$details = $prm['details'];
$userid = $this->sys_user["M_UserID"];
if($prm['act'] === 'save'){
$sql = "UPDATE t_orderphysic SET T_OrderPhysicUserID = '{$userid}', T_OrderPhysicLastUpdate = NOW() WHERE T_OrderPhysicID = {$prm['trx']['trx_id']}";
}
if($prm['act'] === 'ver'){
$sql = "UPDATE t_orderphysic SET
T_OrderPhysicUserID = '{$userid}',
T_OrderPhysicLastUpdate = NOW(),
T_OrderPhysicVerification = 'Y',
T_OrderPhysicStatus = 'VER'
WHERE T_OrderPhysicID = {$prm['trx']['trx_id']}";
}
if($prm['act'] === 'unver'){
$sql = "UPDATE t_orderphysic SET
T_OrderPhysicUserID = '{$userid}',
T_OrderPhysicLastUpdate = NOW(),
T_OrderPhysicVerification = 'N',
T_OrderPhysicStatus = 'NEW'
WHERE T_OrderPhysicID = {$prm['trx']['trx_id']}";
}
if($prm['act'] === 'val'){
$sql = "UPDATE t_orderphysic SET
T_OrderPhysicUserID = '{$userid}',
T_OrderPhysicLastUpdate = NOW(),
T_OrderPhysicValidation = 'Y',
T_OrderPhysicStatus = 'VAL'
WHERE T_OrderPhysicID = {$prm['trx']['trx_id']}";
}
if($prm['act'] === 'unval'){
$sql = "UPDATE t_orderphysic SET
T_OrderPhysicUserID = '{$userid}',
T_OrderPhysicLastUpdate = NOW(),
T_OrderPhysicValidation = 'N',
T_OrderPhysicStatus = 'VER'
WHERE T_OrderPhysicID = {$prm['trx']['trx_id']}";
}
$header_update = $this->db_onedev->query($sql);
$workplacehazards = $details['workplacehazards'];
foreach($workplacehazards as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_workplacehazards (
T_OrderPhysicWorkPlaceHazardsT_OrderPhysicID,
T_OrderPhysicWorkPlaceHazardsM_K3WorkPLaceHazardsID,
T_OrderPhysicWorkPlaceHazardsHour,
T_OrderPhysicWorkPlaceHazardsYear,
T_OrderPhysicWorkPlaceHazardsUserID,
T_OrderPhysicWorkPlaceHazardsCreated,
T_OrderPhysicWorkPlaceHazardsLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['val_hour']}',
'{$v['val_year']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
else{
$sql = "UPDATE t_orderphysic_workplacehazards SET
T_OrderPhysicWorkPlaceHazardsT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicWorkPlaceHazardsM_K3WorkPLaceHazardsID = '{$v['id']}',
T_OrderPhysicWorkPlaceHazardsHour = '{$v['val_hour']}',
T_OrderPhysicWorkPlaceHazardsYear = '{$v['val_year']}',
T_OrderPhysicWorkPlaceHazardsLastUpdated = NOW(),
T_OrderPhysicWorkPlaceHazardsUserID = '{$userid}'
WHERE
T_OrderPhysicWorkPlaceHazardsID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$workplaceaccident = $details['workplaceaccident'];
foreach($workplaceaccident as $i => $vx){
foreach($vx as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_workplaceaccident (
T_OrderPhysicWorkPlaceAccidentT_OrderPhysicID,
T_OrderPhysicWorkPlaceAccidentM_K3WorkPlazeAccidentID,
T_OrderPhysicWorkPlaceAccidentValue,
T_OrderPhysicWorkPlaceAccidentUserID,
T_OrderPhysicWorkPlaceAccidentCreated,
T_OrderPhysicWorkPlaceAccidentLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_workplaceaccident SET
T_OrderPhysicWorkPlaceAccidentT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicWorkPlaceAccidentM_K3WorkPlazeAccidentID = '{$v['id']}',
T_OrderPhysicWorkPlaceAccidentValue = '{$v['value']}',
T_OrderPhysicMedicalHistoryLastUpdated = NOW(),
T_OrderPhysicWorkPlaceAccidentLastUpdated = '{$userid}'
WHERE
T_OrderPhysicMedicalHistoryID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
}
$allergy = $details['allergy'];
//print_r();
foreach($allergy as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_allergy (
T_OrderPhysicAllergyT_OrderPhysicID,
T_OrderPhysicAllergyM_DFLT_AllergyID,
T_OrderPhysicAllergyCheckbox,
T_OrderPhysicAllergyValue,
T_OrderPhysicAllergyUserID,
T_OrderPhysicAllergyCreated,
T_OrderPhysicAllergyLasUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbx']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
else{
$sql = "UPDATE t_orderphysic_allergy SET
T_OrderPhysicAllergyT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicAllergyM_DFLT_AllergyID = '{$v['id']}',
T_OrderPhysicAllergyCheckbox = '{$v['cbx']}',
T_OrderPhysicAllergyValue = '{$v['value']}',
T_OrderPhysicAllergyLasUpdated = NOW(),
T_OrderPhysicAllergyUserID = '{$userid}'
WHERE
T_OrderPhysicAllergyID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$lifestyle = $details['lifestyle'];
//print_r();
foreach($lifestyle as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_lifestyle (
T_OrderPhysicLifeStyleT_OrderPhysicID,
T_OrderPhysicLifeStyleM_DFLT_LifeStyleID,
T_OrderPhysicLifeStyleCheckbox,
T_OrderPhysicLifeStyleValue,
T_OrderPhysicLifeStyleUserID,
T_OrderPhysicLifeStyleCreated,
T_OrderPhysicLifeStyleLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbx']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
}
else{
$sql = "UPDATE t_orderphysic_lifestyle SET
T_OrderPhysicLifeStyleT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicLifeStyleM_DFLT_LifeStyleID = '{$v['id']}',
T_OrderPhysicLifeStyleCheckbox = '{$v['cbx']}',
T_OrderPhysicLifeStyleValue = '{$v['value']}',
T_OrderPhysicLifeStyleLastUpdated = NOW(),
T_OrderPhysicLifeStyleUserID = '{$userid}'
WHERE
T_OrderPhysicLifeStyleID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$chestabdomen = $details['chestabdomen'];
foreach($chestabdomen as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_chestabdomen (
T_OrderPhysicChestAbdomenT_OrderPhysicID,
T_OrderPhysicChestAbdomenM_DFLT_ChestAbdomenID,
T_OrderPhysicChestAbdomenCheckboxN,
T_OrderPhysicChestAbdomenCheckboxT,
T_OrderPhysicChestAbdomenValue,
T_OrderPhysicChestAbdomenUserID,
T_OrderPhysicChestAbdomenCreated,
T_OrderPhysicChestAbdomenLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxN']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_chestabdomen SET
T_OrderPhysicChestAbdomenT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicChestAbdomenM_DFLT_ChestAbdomenID = '{$v['id']}',
T_OrderPhysicChestAbdomenCheckboxN = '{$v['cbxN']}',
T_OrderPhysicChestAbdomenCheckboxT = '{$v['cbxT']}',
T_OrderPhysicChestAbdomenValue = '{$v['value']}',
T_OrderPhysicChestAbdomenLastUpdated = NOW(),
T_OrderPhysicChestAbdomenUserID = '{$userid}'
WHERE
T_OrderPhysicChestAbdomenID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$drugconsumption = $details['drugconsumption'];
foreach($drugconsumption as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_drugconsumption (
T_OrderPhysicDrugConsumptionT_OrderPhysicID,
T_OrderPhysicDrugConsumptionM_DFLT_DrugConsumptionID,
T_OrderPhysicDrugConsumptionDose,
T_OrderPhysicDrugConsumptionValue,
T_OrderPhysicDrugConsumptionUserID,
T_OrderPhysicDrugConsumptionCreated,
T_OrderPhysicDrugConsumptionLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['dose']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_drugconsumption SET
T_OrderPhysicDrugConsumptionT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicDrugConsumptionM_DFLT_DrugConsumptionID = '{$v['id']}',
T_OrderPhysicDrugConsumptionDose = '{$v['dose']}',
T_OrderPhysicDrugConsumptionValue = '{$v['value']}',
T_OrderPhysicDrugConsumptionLastUpdated = NOW(),
T_OrderPhysicDrugConsumptionUserID = '{$userid}'
WHERE
T_OrderPhysicDrugConsumptionID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$eyes = $details['eyes'];
foreach($eyes as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_eyes (
T_OrderPhysicEyesT_OrderPhysicID,
T_OrderPhysicEyesM_DFLT_EyesID,
T_OrderPhysicEyesCheckboxN,
T_OrderPhysicEyesCheckboxT,
T_OrderPhysicEyesValue,
T_OrderPhysicEyesUserID,
T_OrderPhysicEyesCreated,
T_OrderPhysicEyesLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxN']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_eyes SET
T_OrderPhysicEyesT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicEyesM_DFLT_EyesID = '{$v['id']}',
T_OrderPhysicEyesCheckboxN = '{$v['cbxN']}',
T_OrderPhysicEyesCheckboxT = '{$v['cbxT']}',
T_OrderPhysicEyesValue = '{$v['value']}',
T_OrderPhysicEyesLastUpdated = NOW(),
T_OrderPhysicEyesUserID = '{$userid}'
WHERE
T_OrderPhysicEyesID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$generalcondition = $details['generalcondition'];
foreach($generalcondition as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_generalcondition (
T_OrderPhysicGeneralConditionT_OrderPhysicID,
T_OrderPhysicGeneralConditionM_DFLT_GeneralConditionID,
T_OrderPhysicGeneralConditionCheckboxY,
T_OrderPhysicGeneralConditionCheckboxT,
T_OrderPhysicGeneralConditionValue,
T_OrderPhysicGeneralConditionUserID,
T_OrderPhysicGeneralConditionCreated,
T_OrderPhysicGeneralConditionLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxY']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_generalcondition SET
T_OrderPhysicGeneralConditionT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicGeneralConditionM_DFLT_GeneralConditionID = '{$v['id']}',
T_OrderPhysicGeneralConditionCheckboxY = '{$v['cbxY']}',
T_OrderPhysicGeneralConditionCheckboxT = '{$v['cbxT']}',
T_OrderPhysicGeneralConditionValue = '{$v['value']}',
T_OrderPhysicGeneralConditionLastUpdated = NOW(),
T_OrderPhysicGeneralConditionUserID = '{$userid}'
WHERE
T_OrderPhysicGeneralConditionID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$medicalhistory = $details['medicalhistory'];
foreach($medicalhistory as $i => $vx){
foreach($vx as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_medicalhistory (
T_OrderPhysicMedicalHistoryT_OrderPhysicID,
T_OrderPhysicMedicalHistoryM_DFLT_MedicalHistoryID,
T_OrderPhysicMedicalHistoryCheckboxY,
T_OrderPhysicMedicalHistoryCheckboxT,
T_OrderPhysicMedicalHistoryValue,
T_OrderPhysicMedicalHistoryUserID,
T_OrderPhysicMedicalHistoryCreated,
T_OrderPhysicMedicalHistoryLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxY']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_medicalhistory SET
T_OrderPhysicMedicalHistoryT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicMedicalHistoryM_DFLT_MedicalHistoryID = '{$v['id']}',
T_OrderPhysicMedicalHistoryCheckboxY = '{$v['cbxY']}',
T_OrderPhysicMedicalHistoryCheckboxT = '{$v['cbxT']}',
T_OrderPhysicMedicalHistoryValue = '{$v['value']}',
T_OrderPhysicMedicalHistoryLastUpdated = NOW(),
T_OrderPhysicMedicalHistoryUserID = '{$userid}'
WHERE
T_OrderPhysicMedicalHistoryID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
}
$nerve = $details['nerve'];
foreach($nerve as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_nerve (
T_OrderPhysicNerveT_OrderPhysicID,
T_OrderPhysicNerveM_DFLT_NerveID,
T_OrderPhysicNerveCheckboxN,
T_OrderPhysicNerveCheckboxT,
T_OrderPhysicNerveValue,
T_OrderPhysicNerveUserID,
T_OrderPhysicNerveCreated,
T_OrderPhysicNerveLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxN']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_nerve SET
T_OrderPhysicNerveT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicNerveM_DFLT_NerveID = '{$v['id']}',
T_OrderPhysicNerveCheckboxN = '{$v['cbxN']}',
T_OrderPhysicNerveCheckboxT = '{$v['cbxT']}',
T_OrderPhysicNerveValue = '{$v['value']}',
T_OrderPhysicNerveLastUpdated = NOW(),
T_OrderPhysicNerveUserID = '{$userid}'
WHERE
T_OrderPhysicNerveID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$tht = $details['tht'];
foreach($tht as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_tht (
T_OrderPhysic_THTT_OrderPhysicID,
T_OrderPhysic_THTM_DFLT_THTID,
T_OrderPhysic_THTCheckboxN,
T_OrderPhysic_THTCheckboxT,
T_OrderPhysic_THTValue,
T_OrderPhysic_THTUserID,
T_OrderPhysic_THTCreated,
T_OrderPhysic_THTLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbxN']}',
'{$v['cbxT']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_tht SET
T_OrderPhysic_THTT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysic_THTM_DFLT_THTID = '{$v['id']}',
T_OrderPhysic_THTCheckboxN = '{$v['cbxN']}',
T_OrderPhysic_THTCheckboxT = '{$v['cbxT']}',
T_OrderPhysic_THTValue = '{$v['value']}',
T_OrderPhysic_THTLastUpdated = NOW(),
T_OrderPhysic_THTUserID = '{$userid}'
WHERE
T_OrderPhysic_THTID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$tooth = $details['tooth'];
foreach($tooth as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderphysic_tooth (
T_OrderPhysicToothT_OrderPhysicID,
T_OrderPhysicToothM_DFLT_ToothID,
T_OrderPhysicToothValue,
T_OrderPhysicToothUserID,
T_OrderPhysicToothCreated,
T_OrderPhysicToothLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_tooth SET
T_OrderPhysicToothT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicToothM_DFLT_ToothID = '{$v['id']}',
T_OrderPhysicToothValue = '{$v['value']}',
T_OrderPhysicToothLastUpdated = NOW(),
T_OrderPhysicToothLastUpdated = '{$userid}'
WHERE
T_OrderPhysicToothID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
$vitalsign = $details['vitalsign'];
foreach($vitalsign as $i => $vx){
foreach($vx as $k => $v){
if($v['idx'] === '0' || $v['idx'] === 0){
$sql = "INSERT INTO t_orderpysic_vitalsign (
T_OrderPhysicVitalSignT_OrderPhysicID,
T_OrderPhysicVitalSignM_DFLT_VitalSignID,
T_OrderPhysicVitalSignCheckbox1,
T_OrderPhysicVitalSignCheckbox2,
T_OrderPhysicVitalSignValue,
T_OrderPhysicVitalSignUserID,
T_OrderPhysicVitalSignCreated,
T_OrderPhysicVitalSignLastUpdated
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$v['id']}',
'{$v['cbx1']}',
'{$v['cbx2']}',
'{$v['value']}',
'{$userid}',
NOW(),
NOW()
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderpysic_vitalsign SET
T_OrderPhysicVitalSignT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicVitalSignM_DFLT_VitalSignID = '{$v['id']}',
T_OrderPhysicVitalSignCheckbox1 = '{$v['cbx1']}',
T_OrderPhysicVitalSignCheckbox2 = '{$v['cbx2']}',
T_OrderPhysicVitalSignValue = '{$v['value']}',
T_OrderPhysicVitalSignLastUpdated = NOW(),
T_OrderPhysicVitalSignUserID = '{$userid}'
WHERE
T_OrderPhysicVitalSignID = '{$v['idx']}'
";
$x_upd = $this->db_onedev->query($sql);
}
}
}
$idx_complaint = 0;
$sql ="SELECT * FROM t_orderphysic_complaintnote WHERE T_OrderPhysicComplaintNoteT_OrderPhysicID = '{$prm['trx']['trx_id']}' AND T_OrderPhysicComplaintNoteIsActive = 'Y' ";
$idx_complaint = $this->db_onedev->query($sql)->row()->T_OrderPhysicComplaintNoteID;
if($idx_complaint == 0){
$sql = "INSERT INTO t_orderphysic_complaintnote (
T_OrderPhysicComplaintNoteT_OrderPhysicID,
T_OrderPhysicComplaintNoteValue,
T_OrderPhysicComplaintNoteCreated,
T_OrderPhysicComplaintNoteLastUpdated,
T_OrderPhysicComplaintNoteUserID
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$prm['details']['complaint']}',
NOW(),
NOW(),
'{$userid}'
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_complaintnote SET
T_OrderPhysicComplaintNoteT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicComplaintNoteValue = '{$prm['details']['complaint']}',
T_OrderPhysicComplaintNoteLastUpdated = NOW(),
T_OrderPhysicComplaintNoteUserID = '{$userid}'
WHERE
T_OrderPhysicComplaintNoteID = '{$idx_complaint}'
";
$x_upd = $this->db_onedev->query($sql);
}
$idx_conclusion = 0;
$sql ="SELECT * FROM t_orderphysic_conclusion WHERE T_OrderPhysicConclusionT_OrderPhysicID = '{$prm['trx']['trx_id']}' AND T_OrderPhysicConclusionIsActive = 'Y' ";
$idx_conclusion = $this->db_onedev->query($sql)->row()->T_OrderPhysicConclusionID;
if($idx_conclusion == 0){
$sql = "INSERT INTO t_orderphysic_conclusion (
T_OrderPhysicConclusionT_OrderPhysicID,
T_OrderPhysicConclusionValue,
T_OrderPhysicConclusionCreated,
T_OrderPhysicConclusionLastUpdated,
T_OrderPhysicConclusionUserID
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$prm['details']['conslusion']}',
NOW(),
NOW(),
'{$userid}'
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_conclusion SET
T_OrderPhysicConclusionT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicConclusionValue = '{$prm['details']['conslusion']}',
T_OrderPhysicConclusionLastUpdated = NOW(),
T_OrderPhysicConclusionUserID = '{$userid}'
WHERE
T_OrderPhysicConclusionID = '{$idx_conclusion}'
";
$x_upd = $this->db_onedev->query($sql);
}
$idx_suggestion = 0;
$sql ="SELECT * FROM t_orderphysic_suggestion WHERE T_OrderPhysicSuggestionT_OrderPhysicID = '{$prm['trx']['trx_id']}' AND T_OrderPhysicSuggestionIsActive = 'Y' ";
$idx_suggestion = $this->db_onedev->query($sql)->row()->T_OrderPhysicSuggestionID;
if($idx_suggestion == 0){
$sql = "INSERT INTO t_orderphysic_suggestion (
T_OrderPhysicSuggestionT_OrderPhysicID,
T_OrderPhysicSuggestionValue,
T_OrderPhysicSuggestionCreated,
T_OrderPhysicSuggestionLastUpdated,
T_OrderPhysicSuggestionUserID
)
VALUES(
'{$prm['trx']['trx_id']}',
'{$prm['details']['suggestion']}',
NOW(),
NOW(),
'{$userid}'
)";
$x_ins = $this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderphysic_suggestion SET
T_OrderPhysicSuggestionT_OrderPhysicID = '{$prm['trx']['trx_id']}',
T_OrderPhysicSuggestionValue = '{$prm['details']['suggestion']}',
T_OrderPhysicSuggestionLastUpdated = NOW(),
T_OrderPhysicSuggestionUserID = '{$userid}'
WHERE
T_OrderPhysicSuggestionID = '{$idx_suggestion}'
";
$x_upd = $this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
}