Initial import
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Rv_patient extends MY_Controller
|
||||
{
|
||||
var $db_smartone;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "RE Patient API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_smartone = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$max_rst = 10;
|
||||
|
||||
$nolab = '%' . $prm["nolab"] . '%';
|
||||
$search = '%' . $prm["search"] . '%';
|
||||
$page = $prm['page'];
|
||||
|
||||
if ($prm['nolab'] != '')
|
||||
$nolab = "%{$prm['nolab']}%";
|
||||
|
||||
if ($page == null)
|
||||
$page = 1;
|
||||
|
||||
$offset = ($page - 1) * $max_rst;
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "select count(*) total
|
||||
from t_orderheader
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
|
||||
JOIN m_company on T_OrderHeaderM_CompanyID = M_CompanyID
|
||||
JOIN m_mou on T_OrderHeaderM_MouID = M_MouID
|
||||
JOIN helper_order ON Helper_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND Helper_OrderIsLAB = 'Y'
|
||||
where T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderLabNumber like ?
|
||||
and
|
||||
( M_PatientName LIKE ?
|
||||
or ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL))
|
||||
or ((M_PatientDOB LIKE ? and M_PatientDOB IS NOT NULL))
|
||||
)
|
||||
order by T_OrderHeaderLabNumber DESC";
|
||||
$query = $this->db_smartone->query($sql, [$nolab, $search, $search, $search ]);
|
||||
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("re count", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderDate,
|
||||
M_PatientID, M_PatientNoReg, fn_global_patient_name(M_PatientID) M_PatientName,
|
||||
M_PatientDOB, T_OrderHeaderM_PatientAge, M_PatientHP, M_SexName,
|
||||
da.M_DoctorID doctor_pj_id, fn_global_doctor_name(da.M_DoctorID) doctor_pj_name,
|
||||
M_MouID, M_MouName, M_CompanyID, M_CompanyName,
|
||||
T_OrderHeaderFoNote, T_OrderHeaderSamplingNote, T_OrderHeaderResultNote, M_LangCode,
|
||||
T_OrderHeaderLangIsSI is_si
|
||||
from t_orderheader
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
|
||||
JOIN m_company on T_OrderHeaderM_CompanyID = M_CompanyID
|
||||
JOIN m_mou on T_OrderHeaderM_MouID = M_MouID
|
||||
JOIN m_sex on M_PatientM_SexID = M_SexID
|
||||
JOIN helper_order ON Helper_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND Helper_OrderIsLAB = 'Y'
|
||||
JOIN m_lang ON T_OrderHeaderM_LangID = M_LangID
|
||||
where T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderLabNumber like ?
|
||||
and
|
||||
( M_PatientName LIKE ?
|
||||
or ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL))
|
||||
or ((M_PatientDOB LIKE ? and M_PatientDOB IS NOT NULL))
|
||||
)
|
||||
order by T_OrderHeaderLabNumber DESC
|
||||
limit {$offset}, {$max_rst}";
|
||||
$query = $this->db_smartone->query($sql, [$nolab, $search, $search, $search ]);
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
foreach ($rows as $k => $v)
|
||||
$rows[$k]['data'] = json_decode($v['data']);
|
||||
$result = array("total" => $tot_count, "total_page" => ceil($tot_count/$max_rst), "cur_page" => $page, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("worklist rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
class Rv_px extends MY_Controller
|
||||
{
|
||||
var $db_smartone;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "RE Px API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_smartone = $this->load->database("onedev", true);
|
||||
$this->db_one = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$max_rst = 99;
|
||||
|
||||
$id = $prm["order_id"];
|
||||
|
||||
// QUERY TOTAL
|
||||
// $sql = "";
|
||||
// $query = $this->db_smartone->query($sql);
|
||||
|
||||
// if ($query) {
|
||||
// $tot_count = $query->result_array()[0]["total"];
|
||||
// }
|
||||
// else {
|
||||
// $this->sys_error_db("re count", $this->db_smartone);
|
||||
// exit;
|
||||
// }
|
||||
$tot_count = 0;
|
||||
|
||||
$sql = "SELECT T_TestID
|
||||
FROM t_orderdetail JOIN t_test ON T_OrderDetailT_TEstID = T_TestID
|
||||
WHERE T_OrderDetailT_OrderHeaderID = ?
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_TestParentT_TestID = 0";
|
||||
$query = $this->db_smartone->query($sql, [$id]);
|
||||
|
||||
if ($query) {
|
||||
$rst = [];
|
||||
$rows = $query->result_array();
|
||||
foreach ($rows as $k => $v)
|
||||
{
|
||||
$sql = "WITH RECURSIVE ancestors AS
|
||||
(
|
||||
SELECT t_testid, t_testname,
|
||||
T_OrderDetailResult result, T_OrderDetailNote note, T_OrderDetailID id,
|
||||
T_OrderDetailT_TestIsResult is_result, 1 level,
|
||||
T_OrderDetailVerDeltaCheck delta_check,
|
||||
T_OrderDetailVerTrendAnalysis trend_analysis,
|
||||
T_OrderDetailVerification verification,
|
||||
T_OrderDetailVerification verification_old,
|
||||
T_OrderDetailReqStatus sample_handling_perfect
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_OrderHeaderID = ?
|
||||
AND t_testid = ?
|
||||
|
||||
UNION
|
||||
|
||||
SELECT g.t_testid, g.t_testname,
|
||||
T_OrderDetailResult result, T_OrderDetailNote note, T_OrderDetailID id,
|
||||
T_OrderDetailT_TestIsResult is_result, level+1 level,
|
||||
T_OrderDetailVerDeltaCheck delta_check,
|
||||
T_OrderDetailVerTrendAnalysis trend_analysis,
|
||||
T_OrderDetailVerification verification,
|
||||
T_OrderDetailVerification verification_old,
|
||||
T_OrderDetailReqStatus sample_handling_perfect
|
||||
FROM ancestors a, t_orderdetail f
|
||||
JOIN t_test g ON f.T_OrderDetailT_TestID = g.T_TestID
|
||||
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_OrderHeaderID = ?
|
||||
AND g.t_testparentt_testid = a.t_testid and g.t_testisactive = 'Y' )
|
||||
SELECT * FROM ancestors;";
|
||||
$query = $this->db_smartone->query($sql, [$id, $v['T_TestID'], $id]);
|
||||
|
||||
$r = $query->result_array();
|
||||
foreach($r as $k => $v) {
|
||||
if ($v['delta_check'] == "X")
|
||||
{
|
||||
$tmp = $this->db_smartone->query("SELECT fn_process_re_deltacheck('{$v['id']}') x")
|
||||
->row();
|
||||
$v['delta_check'] = $tmp->x;
|
||||
}
|
||||
|
||||
if ($v['trend_analysis'] == "X")
|
||||
{
|
||||
$trend_sql = "SELECT fn_process_re_trendanalysis('{$v['id']}') x";
|
||||
$tmp = $this->db_smartone->query($trend_sql)
|
||||
->row();
|
||||
$j_trend_analysis= json_decode($tmp->x);
|
||||
$v['trend_analysis'] = $j_trend_analysis->status;
|
||||
}
|
||||
// Sample Handling & Verification Perfect
|
||||
// sipe always checked
|
||||
if (true || $v['sample_handling_perfect'] == 'X')
|
||||
{
|
||||
$y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$id}', '{$v['t_testid']}') c")
|
||||
->row();
|
||||
$v['sample_handling_perfect'] = $y->c;
|
||||
}
|
||||
|
||||
// Override
|
||||
if ($y->c == "N")
|
||||
{
|
||||
$v['delta_check'] = "N";
|
||||
$v['trend_analysis'] = "N";
|
||||
}
|
||||
$rst[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("RE Px rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$data = json_decode($prm["id"]);
|
||||
|
||||
if (sizeof($data) < 1)
|
||||
{
|
||||
$this->sys_error_db("RE Verification Confirmation", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($data as $k => $v)
|
||||
{
|
||||
$this->db_smartone->set('T_OrderDetailVerDeltaCheck', $v->delta)
|
||||
->set('T_OrderDetailVerTrendAnalysis', $v->trend)
|
||||
->set('T_OrderDetailVerification', $v->verification)
|
||||
->set('T_OrderDetailVerDate', date('Y-m-d H:i:s'))
|
||||
->set('T_OrderDetailVerUserID', $this->sys_user->M_UserID)
|
||||
->where('T_OrderDetailID', $v->id)
|
||||
->update('t_orderdetail');
|
||||
$ids[] = $v->id;
|
||||
}
|
||||
|
||||
$this->sys_ok($ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Rv_verification extends MY_Controller
|
||||
{
|
||||
var $db_smartone;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "RV Px API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_smartone = $this->load->database("onedev", true);
|
||||
$this->db_one= $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function requirement($id) {
|
||||
$sql = "call sp_result_verify_requirement(?)";
|
||||
$query = $this->db_one->query($sql, array($id));
|
||||
$this->clean_mysqli_connection($this->db_one);
|
||||
$rows = $query->result_array() ;
|
||||
$result = array();
|
||||
foreach( $rows as $r ) {
|
||||
$jdata = json_decode( $r["jdata"] );
|
||||
$a_pos = array();
|
||||
foreach($jdata as $req ) {
|
||||
$xreq = json_decode($req,true);
|
||||
foreach($xreq as $position => $req) {
|
||||
$a_req = explode("^",$req);
|
||||
$a_pos[$position] = $a_req;
|
||||
}
|
||||
}
|
||||
$result = $a_pos;
|
||||
}
|
||||
return $this->req_html($result);
|
||||
}
|
||||
function req_html($result) {
|
||||
$a_pos = $result;
|
||||
if (count($a_pos) == 0 ) return "";
|
||||
$html = "<table >\n";
|
||||
$html .= "<tr><th style='text-align:left;padding:5px;'>Position</th>
|
||||
<th style='text-align:left;padding:5px;' >Requirements</th></tr>\n";
|
||||
foreach($a_pos as $pos => $reqs) {
|
||||
$html .= "<tr valign='top' >\n";
|
||||
$html .= "<td style='text-align:left;padding:5px;'>$pos</td>";
|
||||
$html .= "<td style='text-align:left;padding:5px;'>";
|
||||
foreach($reqs as $r) {
|
||||
$html .= "$r<br/>";
|
||||
}
|
||||
$html .= "</td>";
|
||||
$html .= "</tr>";
|
||||
}
|
||||
$html .= "</table>";
|
||||
return $html;
|
||||
}
|
||||
public function trend_analysis()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm["order_id"];
|
||||
$image = "";
|
||||
$note = "";
|
||||
try {
|
||||
$sql = "select fn_process_re_trendanalysis(?) ta";
|
||||
$qry = $this->db_one->query($sql,array($id));
|
||||
if ($qry) {
|
||||
$row = $qry->row();
|
||||
$j_tmp = json_decode($row->ta);
|
||||
if ($j_tmp->image != "") {
|
||||
$image = $j_tmp->image . "&ts=" . date("Ymdhnis");
|
||||
}
|
||||
$note = $j_tmp->note;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
}
|
||||
$req_note =$this->requirement($id);
|
||||
if ($req_note != "" ) {
|
||||
$note = $req_note;
|
||||
$image = "";
|
||||
}
|
||||
$data = ["image"=>$image,
|
||||
"note"=> $note,
|
||||
"title"=>"Trend Analisis"];
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
|
||||
public function delta_check()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm["order_id"];
|
||||
|
||||
$data = ["image"=>"https://www.sec.gov/files/trendChart-2018.jpg",
|
||||
"note"=>$this->requirement($id),
|
||||
"title"=>"Delta Check"];
|
||||
$this->sys_ok($data);
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$data = json_decode($prm["data"]);
|
||||
|
||||
if (sizeof($data) < 1)
|
||||
{
|
||||
$this->sys_error_db("RE Verification Confirmation", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($data as $k => $v)
|
||||
{
|
||||
$this->db_smartone->set('T_OrderDetailVerDeltaCheck', $v->delta)
|
||||
->set('T_OrderDetailVerTrendAnalysis', $v->trend)
|
||||
->set('T_OrderDetailVerification', $v->verification)
|
||||
->set('T_OrderDetailVerDate', $v->verification == "Y" ? date('Y-m-d H:i:s') : null)
|
||||
->set('T_OrderDetailVerUserID', $this->sys_user['M_UserID'])
|
||||
->where('T_OrderDetailID', $v->id)
|
||||
->update('t_orderdetail');
|
||||
$ids[] = $v->id;
|
||||
}
|
||||
|
||||
// LOG Process
|
||||
$order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number', false)
|
||||
->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID')
|
||||
->where('T_OrderDetailID', $data[0]->id)
|
||||
->get('t_orderdetail')
|
||||
->row();
|
||||
|
||||
$dblog = $this->load->database("onelog", true);
|
||||
$dblog->set('Log_ProcessCode', 'PROCESS.Result.Verification')
|
||||
->set('Log_ProcessOrderID', $order->id)
|
||||
->set('Log_ProcessOrderNumber', $order->lab_number)
|
||||
->set('Log_ProcessJson', json_encode($data))
|
||||
->set('Log_ProcessUserID', $this->sys_user['M_UserID'])
|
||||
->insert('log_process');
|
||||
// END OF Log Process
|
||||
|
||||
$this->sys_ok($ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user