310 lines
11 KiB
PHP
310 lines
11 KiB
PHP
<?php
|
|
|
|
class History extends MY_Controller
|
|
{
|
|
public $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "History API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function search_v2()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$orderID = $prm["order_id"];
|
|
$sql = "select T_OrderHeaderM_PatientID from t_orderheader where T_OrderHeaderID=?";
|
|
$query = $this->db_smartone->query($sql, array($orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$this->sys_error_db("No Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$patientID = $rows[0]["T_OrderHeaderM_PatientID"];
|
|
|
|
$maxOrder = 5;
|
|
$sql = "select min(T_OrderHeaderID) minID
|
|
from t_orderheader
|
|
where T_OrderHeaderM_PatientID = ?
|
|
and T_OrderHeaderID < ?
|
|
and T_OrderHeaderIsActive = 'Y'
|
|
order by T_OrderHeaderID desc
|
|
limit 0, $maxOrder";
|
|
$query = $this->db_smartone->query($sql, array($patientID, $orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$this->sys_error_db("No Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$minOrderID = $rows[0]["minID"];
|
|
|
|
$sql = "select date(T_OrderHeaderDate) T_OrderHeaderDate, T_OrderHeaderLabNumber,T_OrderHeaderID,
|
|
T_TestID,
|
|
T_TestShortName , T_OrderDetailResult, T_TestIsResult, T_OrderDetailResultFlag,
|
|
(length(T_TestSasCode) - 6 ) / 2 Level, T_TestSasCode, Nat_UnitName
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderM_PatientID = ?
|
|
and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderID < ?
|
|
and T_OrderHeaderID >= ?
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
left join nat_unit on T_OrderDetailNat_UnitID = Nat_UnitID
|
|
join group_resultdetail on T_TestID = Group_ResultDetailT_TestID
|
|
and Group_ResultDetailGroup_ResultID = 1
|
|
order by T_TestSasCode";
|
|
|
|
|
|
$query = $this->db_smartone->query($sql, array($patientID, $orderID, $minOrderID ));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : History ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$arr_result = array();
|
|
$prev_date = "";
|
|
$cur_idx = 0;
|
|
$prev_id = 0;
|
|
$arr_px = array();
|
|
$arr_code = array();
|
|
|
|
$arr_date = array();
|
|
$index_px = 0;
|
|
$arr_test = array();
|
|
|
|
foreach ($rows as $r) {
|
|
$is_result = $r["T_TestIsResult"];
|
|
if ($is_result == "N") {
|
|
continue;
|
|
}
|
|
$order_id = $r["T_OrderHeaderID"];
|
|
|
|
$date = $r["T_OrderHeaderDate"];
|
|
$px_name = $r["T_TestShortName"] ;
|
|
$result = $r["T_OrderDetailResult"] ;
|
|
// if (is_numeric($result)) {
|
|
// $dec = strlen(substr(strrchr($str, "."), 1));
|
|
// $result = number_format($result, $dec, ".", ",");
|
|
// }
|
|
$result .= " ". $r["T_OrderDetailResultFlag"];
|
|
|
|
$px_code = $r["T_TestSasCode"];
|
|
if (! isset($arr_code[$px_code])) {
|
|
$arr_result[] = array(
|
|
"px_name" => $px_name,
|
|
"code" => $r["T_TestSasCode"],
|
|
"unit" => $r["Nat_UnitName"],
|
|
"result" => array()
|
|
);
|
|
$arr_code[$px_code] = true;
|
|
$arr_px[$px_name] = array("code" => $r["T_TestSasCode"], "name" => $px_name);
|
|
$arr_test[] = array("code" => $r["T_TestSasCode"], "name" => $px_name);
|
|
$index_px = count($arr_result) - 1;
|
|
}
|
|
if (! in_array($date, $arr_date)) {
|
|
$arr_date[] = $date;
|
|
}
|
|
$arr_result[$index_px]["result"][$date] = $result;
|
|
$prev_id = $order_id;
|
|
$px_code = "";
|
|
}
|
|
foreach ($arr_result as $idx => $v) {
|
|
foreach ($arr_date as $date) {
|
|
if (! isset($v["result"][$date])) {
|
|
$arr_result[$idx]["result"][$date] = "";
|
|
}
|
|
}
|
|
}
|
|
sort($arr_date);
|
|
|
|
$result = array("pxs" => $arr_test, "result" => $arr_result, "dates" => $arr_date);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
public function old_search_v2()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$orderID = $prm["order_id"];
|
|
$sql = "select T_OrderHeaderM_PatientID from t_orderheader where T_OrderHeaderID=?";
|
|
$query = $this->db_smartone->query($sql, array($orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$this->sys_error_db("No Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$patientID = $rows[0]["T_OrderHeaderM_PatientID"];
|
|
|
|
$maxOrder = 5;
|
|
$sql = "select min(T_OrderHeaderID) minID
|
|
from t_orderheader
|
|
where T_OrderHeaderM_PatientID = ?
|
|
and T_OrderHeaderID < ?
|
|
and T_OrderHeaderIsActive = 'Y'
|
|
order by T_OrderHeaderID desc
|
|
limit 0, $maxOrder";
|
|
$query = $this->db_smartone->query($sql, array($patientID, $orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$this->sys_error_db("No Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$minOrderID = $rows[0]["minID"];
|
|
|
|
$sql = "select date(T_OrderHeaderDate) T_OrderHeaderDate, T_OrderHeaderLabNumber,T_OrderHeaderID,
|
|
T_TestID,
|
|
T_TestShortName , T_OrderDetailResult, T_TestIsResult, T_OrderDetailResultFlag,
|
|
(length(T_TestSasCode) - 6 ) / 2 Level, T_TestSasCode, Nat_UnitName
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderM_PatientID = ?
|
|
and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderID < ?
|
|
and T_OrderHeaderID >= ?
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
join nat_unit on T_OrderDetailNat_UnitID = Nat_UnitID
|
|
join group_resultdetail on T_TestID = Group_ResultDetailT_TestID
|
|
and Group_ResultDetailGroup_ResultID = 1
|
|
order by T_TestSasCode";
|
|
|
|
$query = $this->db_smartone->query($sql, array($patientID, $orderID, $minOrderID ));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : History ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$arr_result = array();
|
|
$prev_date = "";
|
|
$cur_idx = 0;
|
|
$prev_id = 0;
|
|
$arr_px = array();
|
|
|
|
$arr_date = array();
|
|
$index_px = 0;
|
|
$arr_test = array();
|
|
|
|
foreach ($rows as $r) {
|
|
$is_result = $r["T_TestIsResult"];
|
|
if ($is_result == "N") {
|
|
continue;
|
|
}
|
|
$order_id = $r["T_OrderHeaderID"];
|
|
|
|
$date = $r["T_OrderHeaderDate"];
|
|
$px_name = $r["T_TestShortName"] ;
|
|
$result = $r["T_OrderDetailResult"] . $r["T_OrderDetailResultFlag"];
|
|
|
|
if (! isset($arr_px[$px_name])) {
|
|
$arr_result[] = array(
|
|
"px_name" => $px_name,
|
|
"code" => $r["T_TestSasCode"],
|
|
"unit" => $r["Nat_UnitName"],
|
|
"result" => array()
|
|
);
|
|
$arr_px[$px_name] = array("code" => $r["T_TestSasCode"], "name" => $px_name);
|
|
$arr_test[] = array("code" => $r["T_TestSasCode"], "name" => $px_name);
|
|
$index_px = count($arr_result) - 1;
|
|
}
|
|
if (! in_array($date, $arr_date)) {
|
|
$arr_date[] = $date;
|
|
}
|
|
$arr_result[$index_px]["result"][$date] = $result;
|
|
$prev_id = $order_id;
|
|
}
|
|
foreach ($arr_result as $idx => $v) {
|
|
foreach ($arr_date as $date) {
|
|
if (! isset($v["result"][$date])) {
|
|
$arr_result[$idx]["result"][$date] = "";
|
|
}
|
|
}
|
|
}
|
|
sort($arr_date);
|
|
|
|
$result = array("pxs" => $arr_test, "result" => $arr_result, "dates" => $arr_date);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$orderID = $prm["order_id"];
|
|
$sql = "select T_OrderHeaderM_PatientID from t_orderheader where T_OrderHeaderID=?";
|
|
$query = $this->db_smartone->query($sql, array($orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$this->sys_error_db("No Patient", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$patientID = $rows[0]["T_OrderHeaderM_PatientID"];
|
|
$sql = "select T_OrderHeaderDate, T_OrderHeaderLabNumber,T_OrderHeaderID,
|
|
T_TestShortName , T_OrderDetailResult, T_TestIsResult, T_OrderDetailResultFlag,
|
|
(length(T_TestSasCode) - 6 ) / 2 Level
|
|
from t_orderheader
|
|
join t_orderdetail on T_OrderHeaderM_PatientID = ?
|
|
and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderHeaderID < ?
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
join group_resultdetail on T_TestID = Group_ResultDetailT_TestID
|
|
and Group_ResultDetailGroup_ResultID = 1
|
|
order by T_OrderHeaderID, T_TestSasCode";
|
|
|
|
$query = $this->db_smartone->query($sql, array($patientID, $orderID));
|
|
if (!$query) {
|
|
$this->sys_error_db("Err : History ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$result = array();
|
|
$prev_date = "";
|
|
$cur_idx = 0;
|
|
$max_hist = 4;
|
|
foreach ($rows as $r) {
|
|
$date = $r["T_OrderHeaderDate"];
|
|
if ($prev_date != $date) {
|
|
if ($cur_idx == $max_hist) {
|
|
break;
|
|
}
|
|
$result[]["date"] = $date;
|
|
$cur_idx = count($result) - 1;
|
|
$result[$cur_idx]["data"] = array();
|
|
$result[$cur_idx]["id"] = $r["T_OrderHeaderID"];
|
|
}
|
|
$result[$cur_idx]["data"][] = array(
|
|
"px_name" => $r["T_TestShortName"],
|
|
"is_result" => $r["T_TestIsResult"],
|
|
"result" => $r["T_OrderDetailResult"],
|
|
"flag" => $r["T_OrderDetailResultFlag"],
|
|
"level" => $r["Level"]
|
|
);
|
|
$prev_date = $date ;
|
|
}
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|