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,361 @@
<?php
class Handling_patient extends MY_Controller
{
var $db_smartone;
var $nat_pos;
var $nat_pos_2;
public function index()
{
echo "Handling API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
$this->nat_pos = 'SAMP.VER';
$this->nat_pos_2 = 'PRE.AN';
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.From.Verification'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = '{$this->nat_pos}'")
->row();
$p_2 = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = '{$this->nat_pos_2}'")
->row();
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id, t_sampletypename sample_name,
T_OrderSampleID order_sample_id,
json_object('clott', IFNULL(T_OrderSampleAddonHandlingClott, 'N'),
'lipemik', IFNULL(T_OrderSampleAddonHandlingLipemik, 'N'),
'lisis', IFNULL(T_OrderSampleAddonHandlingLisis, 'N'),
'clott_note', IFNULL(T_OrderSampleAddonHandlingClottNote, ''),
'lipemik_note', IFNULL(T_OrderSampleAddonHandlingLipemikNote, ''),
'lisis_note', IFNULL(T_OrderSampleAddonHandlingLisisNote, ''),
'note', IFNULL(T_OrderSampleAddonVerificationNote, '')) data,
if (T_OrderSampleReceiveDate is not null and T_OrderSampleReceiveTime is not null,
timediff(now(), concat(T_OrderSampleReceiveDate, ' ', T_OrderSampleReceiveTime) ), '00:00:00') sampling_duration,
ifnull (ua.M_UserFullName, '-') user_sampling,
ifnull (ub.M_UserFullName, '-') user_receive,
ifnull (uc.M_UserFullName, '-') user_verification,
T_OrderSampleAddonVerificationNote verification_note, T_SampleTypeID sample_id,
IFNULL(sra.T_OrderSampleReqStatus, 'X') req_status_handling, IFNULL(sra.T_OrderSampleReqs, '[]') selected_reqs_handling,
IFNULL(srb.T_OrderSampleReqStatus, 'X') req_status_process, IFNULL(srb.T_OrderSampleReqs, '[]') selected_reqs_process
from t_ordersample
join t_sampletype on t_ordersamplet_sampletypeid = t_sampletypeid
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.From.Verification'
left join t_ordersampleaddon on t_ordersampleid = t_ordersampleaddont_ordersampleid
left join m_user ua on T_OrderSampleSamplingUserID = ua.M_UserID
left join m_user ub on T_OrderSampleReceiveUserID = ub.M_UserID
left join m_user uc on T_OrderSampleVerificationUserID = uc.M_UserID
left join t_ordersamplereq sra on sra.T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID
and sra.T_OrderSampleReqNat_PositionID = ?
and sra.T_OrderSampleReqT_OrderSampleID = T_OrderSampleID
left join t_ordersamplereq srb on srb.T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID
and srb.T_OrderSampleReqNat_PositionID = ?
and srb.T_OrderSampleReqT_OrderSampleID = T_OrderSampleID
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($p->id, $p_2->id, $nolab, $search));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
{
$rows[$k]['data'] = json_decode($v['data']);
$rows[$k]['selected_reqs_handling'] = json_decode($v['selected_reqs_handling']);
$rows[$k]['selected_reqs_process'] = json_decode($v['selected_reqs_process']);
$rows[$k]['reqs_handling'] = [];
$rows[$k]['reqs_process'] = [];
$sql = "SELECT fn_specimen_get_requirement(?, ?, ?) as x";
$query = $this->db_smartone->query($sql, [$v['T_OrderHeaderID'], $v['sample_id'], $this->nat_pos]);
if ($query)
{
$rowss = $query->row();
if ($rowss->x != null)
$rows[$k]['reqs_handling'] = json_decode($rowss->x);
}
$sql = "SELECT fn_specimen_get_requirement(?, ?, ?) as x";
$query = $this->db_smartone->query($sql, [$v['T_OrderHeaderID'], $v['sample_id'], $this->nat_pos_2]);
if ($query)
{
$rowss = $query->row();
if ($rowss->x != null)
$rows[$k]['reqs_process'] = json_decode($rowss->x);
}
}
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.From.Sampling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Verification.From.Sampling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function verify()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('PRC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
function reject()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('RJC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification reject", $this->db_smartone);
exit;
}
}
public function get_requirement()
{
$prm = $this->sys_input;
$sql = "SELECT fn_specimen_get_requirement(?, ?, ?) as x";
$query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['sample_id'], $this->nat_pos]);
if ($query)
{
$rows = $query->row();
$y = [];
if ($rows->x != null)
$y = json_decode($rows->x);
$this->sys_ok($y);
}
else
{
$this->sys_error_db("Get Requirement row", $this->db_smartone);
exit;
}
}
public function save_requirement()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$reqs = $prm['reqs'];
$status = $prm['status'];
$sample_id = $prm['sample_id'];
$pos_code = $this->nat_pos;
// GET POSITION
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = ?", [$pos_code])
->row();
$sql = "SELECT T_OrderSampleReqID id FROM t_ordersamplereq
JOIN nat_position on T_OrderSampleReqNat_PositionID = Nat_PositionID
AND Nat_PositionCode = ?
WHERE T_OrderSampleReqT_OrderHeaderID = ?
AND T_OrderSampleReqT_OrderSampleID = ?
AND T_OrderSampleReqIsActive = 'Y'";
$query = $this->db_smartone->query($sql, [$pos_code, $order_id, $sample_id]);
$r = $query->row();
if ($r)
{
$sql = "UPDATE t_ordersamplereq
SET T_OrderSampleReqStatus = ?, T_OrderSampleReqs = ?
WHERE T_OrderSampleReqID = ?";
$query = $this->db_smartone->query($sql, [$status, $reqs, $r->id]);
$this->sys_ok($r->id);
exit;
}
else
{
$sql = "INSERT INTO t_ordersamplereq(T_OrderSampleReqT_OrderHeaderID, T_OrderSampleReqT_OrderSampleID, T_OrderSampleReqStatus, T_OrderSampleReqs, T_OrderSampleReqNat_PositionID)
VALUES(?, ?, ?, ?, ?)";
$query = $this->db_smartone->query($sql, [$order_id, $sample_id, $status, $reqs, $p->id]);
if ($query)
{
$this->sys_ok($this->db_smartone->insert_id());
exit;
}
}
$this->sys_error_db("Sample Handling Req", $this->db_smartone);
}
// PROCESS SECTION
function verify_process()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('PRC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
function reject_process()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('RJC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification reject", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,184 @@
<?php
class Process_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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Handling.To.Process')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Handling.To.Process')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function send()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_handling_03_send_remove('SND', '{$prm['ids']}', '0')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling send process", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_handling_03_send_remove('RMV', '', '{$prm['id']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling remove process", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,188 @@
<?php
class Receive_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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.To.Handling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.To.Handling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Handling.From.Verification' OR
m_statussamplecode = 'SAMPLING.Handling.Process' OR
m_statussamplecode = 'SAMPLING.Handling.Reject')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Handling.From.Verification' OR
m_statussamplecode = 'SAMPLING.Handling.Process' OR
m_statussamplecode = 'SAMPLING.Handling.Reject')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function receive()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_handling_01_receive_remove('RCV', '0', '{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling receive", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_handling_01_receive_remove('RMV', '{$prm['id']}', '')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling receive remove", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,185 @@
<?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_list 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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
$status = $prm["status"];
$station = $prm["station"];
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
$q_sst = "";
if ($status == 'N')
$q_sst = "AND (helper_sststatus = 'N' OR helper_sststatus = 'X')";
elseif ($status == 'Y')
$q_sst = "AND (helper_sststatus = 'Y')";
// QUERY TOTAL
$sql = "select count(*) total
from t_orderheader
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join helper_sst on t_orderheaderid = helper_sstt_orderheaderid
and ((helper_sstt_samplestationid = ? and ? <> 0) or ? = 0)
{$q_sst}
where T_OrderHeaderLabNumber 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 M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)";
$query = $this->db_smartone->query($sql, array($station, $station, $station,
$nolab, $search, $search, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
// join last_status on Last_StatusT_OrderHeaderID = T_OrderHeaderID
// join m_status on Last_StatusM_StatusID = M_StatusID
// and (M_StatusCode = 'FO.Verification.Confirm'
// OR M_StatusCode = 'FO.Verification.Spv.Confirm'
// OR M_StatusCode = 'SAMPLING.Sampling.Partial'
// OR M_StatusCode = 'SAMPLING.Sampling.Full')
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderM_PatientAge,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientHP, M_PatientDOB, M_PatientNote, M_PatientPhoto,
concat(M_PatientAddressDescription, '\n\n', m_kelurahanname, ', ', m_districtname,
'\n', m_cityname, ', ', m_provincename) as M_PatientAddress,
M_PatientNote, Helper_SstStatus, T_OrderHeaderFoNote, T_OrderHeaderSamplingNote,
Helper_OrderSamplingVerificationPhoto ver_photo,
Helper_OrderSamplingVerificationPhotoNote ver_photo_note,
T_OrderMessageMessage note_supervisor,
T_SamplingQueueStatusID call_status_id, T_SamplingQueueStatusCode call_status_code,
Helper_SstStatus status_code,
IFNULL(T_OrderSampleReqStatus, 'X') req_status, IFNULL(T_OrderSampleReqs, '[]') reqs,
T_OrderHeaderM_PatientAge, M_SexName
from t_orderheader
left join helper_order on helper_ordert_orderheaderid = t_orderheaderid
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
join helper_sst on t_orderheaderid = helper_sstt_orderheaderid
and ((helper_sstt_samplestationid = ? and ? <> 0) or ? = 0)
{$q_sst}
left 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 t_ordermessage on t_ordermessaget_orderheaderid = t_orderheaderid
left join t_sampling_queue_last_status on T_SamplingQueueLastStatusT_OrderHeaderID = t_orderheaderid
and T_SamplingQueueLastStatusT_SampleStationID = ?
and T_SamplingQueueLastStatusIsActive = 'Y'
left join t_sampling_queue_status on T_SamplingQueueStatusID = T_SamplingQueueLastStatusT_SamplingQueueStatusID
left join t_ordersamplereq on T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID
AND T_OrderSampleReqT_SampleStationID = ? AND T_OrderSampleReqIsActive = 'Y'
where T_OrderHeaderLabNumber like ?
and ( M_PatientName LIKE ?
or ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
or ((M_PatientDOB LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL) )
group by t_orderheaderid
order by t_orderheaderlabnumber desc
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($station, $station, $station,
$station, $station, $nolab, $search, $search, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function get_stations()
{
$prm = $this->sys_input;
$uid = $this->sys_user['M_UserID'];
// QUERY TOTAL
$sql = "select count(*) total
from t_samplestation
join m_user on m_userid = ?
and ((m_userdefaultt_samplestationid = t_samplestationid and m_userdefaultt_samplestationid <> 0)
or m_userdefaultt_samplestationid = 0)
where t_samplestationisactive = 'Y'";
$query = $this->db_smartone->query($sql, array($uid));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("sample station count", $this->db_smartone);
exit;
}
$sql = "select t_samplestationid id, t_samplestationname text
from t_samplestation
join m_user on m_userid = ?
and ((m_userdefaultt_samplestationid = t_samplestationid and m_userdefaultt_samplestationid <> 0)
or m_userdefaultt_samplestationid = 0)
where t_samplestationisactive = 'Y'";
$query = $this->db_smartone->query($sql, array($uid));
if ($query) {
$rows = $query->result_array();
// $rows = [['id'=>'0', 'text'=>'Semua Station']] + $rows;
// array_unshift($rows, ['id'=>'0', 'text'=>'Semua Station']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("sample station rows", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,68 @@
<?php
class Queue extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function index()
{
echo "Queue API";
}
public function call_skip_process()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$station_id = $prm['station_id'];
$act = $prm['act'];
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_sampling_que_status('{$order_id}', '{$station_id}', '{$act}', '{$uid}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$x = $query->row();
if ($x->status == "OK")
{
$this->sys_ok($x);
return;
}
$this->sys_error_db("SAMPLING QUE : " . $x->message, $this->db_smartone);
exit;
}
$this->sys_error_db("SAMPLING QUE : " . $this->db_smartone->last_query(), $this->db_smartone);
exit;
}
public function recall()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$station_id = $prm['station_id'];
$sql = "CALL sp_sampling_recall('{$order_id}', '{$station_id}')";
$query = $this->db_smartone->query($sql);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
if ($query)
{
$row = $query->row();
if ($row->status == "OK")
{
$this->sys_ok($row);
exit;
}
}
$this->sys_error_db("Barcode ADD", $this->db_smartone);
}
}
?>

View File

@@ -0,0 +1,242 @@
<?php
class Sampling extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function index()
{
echo "Sampling API";
}
public function get_samples()
{
$prm = $this->sys_input;
$order_id = $prm['orderid'];
$station_id = $prm['stationid'];
if ($order_id == null)
$order_id = 0;
if ($station_id == null)
$station_id = 0;
$sql = "CALL sp_sampling_get_samples('{$order_id}', '$station_id')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
foreach($rows as $k => $v)
$rows[$k]['reqs'] = json_decode($v['reqs']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("Get Samples rows", $this->db_smartone);
exit;
}
}
public function get_sample()
{
$prm = $this->sys_input;
$order_id = $prm['orderid'];
$sample_id = $prm['sampleid'];
$barcode = $prm['barcode'];
if ($order_id == null)
$order_id = 0;
if ($sample_id == null)
$sample_id = 0;
$sql = "CALL sp_sampling_get_sample('{$order_id}', '{$sample_id}', '{$barcode}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->row();
$rows->reqs = json_decode($rows->reqs);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("Get Samples row", $this->db_smartone);
exit;
}
}
public function save()
{
$prm = $this->sys_input;
$order_id = $prm['orderid'];
$sample_id = $prm['sampleid'];
$barcode = $prm['barcode'];
$json = $prm['json_data'];
$json = json_encode($json);
$sql = "CALL sp_sampling_save('{$order_id}', '{$sample_id}', '{$barcode}', '{$json}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->row();
$rows->data = json_decode($rows->data);
$this->sys_ok($rows);
}
else {
$this->sys_error_db("Get Samples rows", $this->db_smartone);
exit;
}
}
public function save_2()
{
$prm = $this->sys_input;
$order_id = $prm['orderid'];
$sample_id = $prm['sampleid'];
$barcode = $prm['barcode'];
$json = $prm['json_data'];
$json = json_encode($json);
$sql = "CALL sp_sampling_save_2('{$order_id}', '{$sample_id}', '{$barcode}', '{$json}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->row();
$rows->data = json_decode($rows->data);
$this->sys_ok($rows);
}
else {
$this->sys_error_db("Get Samples rows", $this->db_smartone);
exit;
}
}
public function save_note_supervisor()
{
$prm = $this->sys_input;
$order_id = $prm['orderid'];
$message = $prm['message'];
$json = json_encode($json);
$sql = "CALL sp_sampling_save_note_supervisor('{$order_id}', '{$message}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$this->sys_ok($rows);
}
else {
$this->sys_error_db("Note Supervisor rows", $this->db_smartone);
exit;
}
}
public function barcode_add()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$sample_id = $prm['sample_id'];
$sql = "CALL sp_sampling_barcode_add('{$order_id}', '{$sample_id}')";
$query = $this->db_smartone->query($sql);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
if ($query)
{
$row = $query->row();
if ($row->status == "OK")
{
$row->data = json_decode($row->data);
$this->sys_ok($row->data);
exit;
}
}
$this->sys_error_db("Barcode ADD", $this->db_smartone);
}
public function get_requirement()
{
$prm = $this->sys_input;
$sql = "SELECT Nat_RequirementID, Nat_RequirementName FROM nat_requirement
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID
AND Nat_RequirementPositionIsActive = 'Y'
JOIN nat_position ON Nat_RequirementPositionNat_PositionID = Nat_PositionID
AND Nat_PositionCode = 'SPEC.COL'";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$this->sys_ok($rows);
}
else {
$this->sys_error_db("Get Requirement row", $this->db_smartone);
exit;
}
}
public function save_requirement()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$station_id = $prm['station_id'];
$reqs = $prm['reqs'];
$status = $prm['status'];
$pos_code = 'SPEC.COL';
// GET POSITION
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = ?", [$pos_code])
->row();
$sql = "SELECT T_OrderSampleReqID id FROM t_ordersamplereq
JOIN nat_position on T_OrderSampleReqNat_PositionID = Nat_PositionID
AND Nat_PositionCode = ?
WHERE T_OrderSampleReqT_OrderHeaderID = ?
AND T_OrderSampleReqT_SampleStationID = ?
AND T_OrderSampleReqIsActive = 'Y'";
$query = $this->db_smartone->query($sql, [$pos_code, $order_id, $station_id]);
$r = $query->row();
if ($r)
{
$sql = "UPDATE t_ordersamplereq
SET T_OrderSampleReqStatus = ?, T_OrderSampleReqs = ?
WHERE T_OrderSampleReqID = ?";
$query = $this->db_smartone->query($sql, [$status, $reqs, $r->id]);
$this->sys_ok($r->id);
exit;
}
else
{
$sql = "INSERT INTO t_ordersamplereq(T_OrderSampleReqT_OrderHeaderID, T_OrderSampleReqT_SampleStationID, T_OrderSampleReqStatus, T_OrderSampleReqs, T_OrderSampleReqNat_PositionID)
VALUES(?, ?, ?, ?, ?)";
$query = $this->db_smartone->query($sql, [$order_id, $station_id, $status, $reqs, $p->id]);
if ($query)
{
$this->sys_ok($this->db_smartone->insert_id());
exit;
}
}
$this->sys_error_db("Sample Req", $this->db_smartone);
}
}
?>

View File

@@ -0,0 +1,165 @@
<?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_list 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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Sampling.Sampled'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Sampling.Sampled'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
order by t_orderheaderlabnumber desc
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Sampling.To.Verification'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Sampling.To.Verification' or
m_statussamplecode = 'SAMPLING.Verification.From.Sampling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
class Verification extends MY_Controller
{
var $db_smartone;
function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
function send()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_send_to_verification('{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("sampling send", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_remove_from_verification('{$prm['id']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("sampling remove", $this->db_smartone);
exit;
}
}
}
?>

View File

@@ -0,0 +1,184 @@
<?php
class Handling_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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.Verify'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.Verify'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Verification.To.Handling' or m_statussamplecode = 'SAMPLING.Handling.From.Verification')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Verification.To.Handling' or m_statussamplecode = 'SAMPLING.Handling.From.Verification')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function send()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_verification_send_to_handling('{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification send handling", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_verification_remove_from_handling('{$prm['id']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification remove handling", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,165 @@
<?php
class Receive_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;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Sampling.To.Verification'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Sampling.To.Verification'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.From.Sampling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Verification.From.Sampling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function receive()
{
$prm = $this->sys_input;
$sql = "CALL sp_sampling_verification_receive('{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification receive", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,297 @@
<?php
class Verification_patient extends MY_Controller
{
var $db_smartone;
var $nat_pos;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
$this->nat_pos = 'SPEC.VER';
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.From.Sampling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = '{$this->nat_pos}'")
->row();
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id, t_sampletypename sample_name,
T_OrderSampleID order_sample_id, t_sampletypeid sample_id,
json_object('quality', IFNULL(T_OrderSampleAddonVerificationQuality, 'N'),
'quantity', IFNULL(T_OrderSampleAddonVerificationQuantity, 'N'),
'sample', IFNULL(T_OrderSampleAddonVerificationSampleType, 'N'),
'quality_note', IFNULL(T_OrderSampleAddonVerificationQualityNote, ''),
'quantity_note', IFNULL(T_OrderSampleAddonVerificationQuantityNote, ''),
'sample_note', IFNULL(T_OrderSampleAddonVerificationSampleTypeNote, ''),
'note', IFNULL(T_OrderSampleAddonVerificationNote, '')) data,
if (T_OrderSampleReceiveDate is not null and T_OrderSampleReceiveTime is not null,
timediff(now(), concat(T_OrderSampleReceiveDate, ' ', T_OrderSampleReceiveTime) ), '00:00:00') sampling_duration,
ifnull (ua.M_UserFullName, '-') user_sampling,
ifnull (ub.M_UserFullName, '-') user_receive,
IFNULL(T_OrderSampleReqStatus, 'X') req_status, IFNULL(T_OrderSampleReqs, '[]') selected_reqs
from t_ordersample
join t_sampletype on t_ordersamplet_sampletypeid = t_sampletypeid
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.From.Sampling'
left join t_ordersampleaddon on t_ordersampleid = t_ordersampleaddont_ordersampleid
left join m_user ua on T_OrderSampleSamplingUserID = ua.M_UserID
left join m_user ub on T_OrderSampleReceiveUserID = ub.M_UserID
left join t_ordersamplereq on T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID
and T_OrderSampleReqNat_PositionID = ?
and T_OrderSampleReqT_OrderSampleID = T_OrderSampleID
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($p->id, $nolab, $search));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
{
$rows[$k]['reqs'] = [];
$sql = "SELECT fn_specimen_get_requirement(?, ?, ?) as x";
$query = $this->db_smartone->query($sql, [$v['T_OrderHeaderID'], $v['sample_id'], $this->nat_pos]);
if ($query)
{
$rows[$k]['reqq'] = $this->db_smartone->last_query();
$rowss = $query->row();
if ($rowss->x != null)
$rows[$k]['reqs'] = json_decode($rowss->x);
}
$rows[$k]['data'] = json_decode($v['data']);
$rows[$k]['selected_reqs'] = json_decode($v['selected_reqs']);
}
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Verification.From.Sampling'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'SAMPLING.Verification.From.Sampling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows", $this->db_smartone);
exit;
}
}
function verify()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_verification_verify('{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}', '{$this->sys_user['M_UserID']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
function reject()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_verification_reject('{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
public function get_requirement()
{
$prm = $this->sys_input;
$sql = "SELECT fn_specimen_get_requirement(?, ?, ?) as x";
$query = $this->db_smartone->query($sql, [$prm['order_id'], $prm['sample_id'], $this->nat_pos]);
if ($query)
{
$rows = $query->row();
$y = [];
if ($rows->x != null)
$y = json_decode($rows->x);
$this->sys_ok($y);
}
else {
$this->sys_error_db("Get Requirement row", $this->db_smartone);
exit;
}
}
public function save_requirement()
{
$prm = $this->sys_input;
$order_id = $prm['order_id'];
$reqs = $prm['reqs'];
$status = $prm['status'];
$sample_id = $prm['sample_id'];
$pos_code = $this->nat_pos;
// GET POSITION
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = ?", [$pos_code])
->row();
$sql = "SELECT T_OrderSampleReqID id FROM t_ordersamplereq
JOIN nat_position on T_OrderSampleReqNat_PositionID = Nat_PositionID
AND Nat_PositionCode = ?
WHERE T_OrderSampleReqT_OrderHeaderID = ?
AND T_OrderSampleReqT_OrderSampleID = ?
AND T_OrderSampleReqIsActive = 'Y'";
$query = $this->db_smartone->query($sql, [$pos_code, $order_id, $sample_id]);
$r = $query->row();
if ($r)
{
$sql = "UPDATE t_ordersamplereq
SET T_OrderSampleReqStatus = ?, T_OrderSampleReqs = ?
WHERE T_OrderSampleReqID = ?";
$query = $this->db_smartone->query($sql, [$status, $reqs, $r->id]);
$this->sys_ok($r->id);
exit;
}
else
{
$sql = "INSERT INTO t_ordersamplereq(T_OrderSampleReqT_OrderHeaderID, T_OrderSampleReqT_OrderSampleID, T_OrderSampleReqStatus, T_OrderSampleReqs, T_OrderSampleReqNat_PositionID)
VALUES(?, ?, ?, ?, ?)";
$query = $this->db_smartone->query($sql, [$order_id, $sample_id, $status, $reqs, $p->id]);
if ($query)
{
$this->sys_ok($this->db_smartone->insert_id());
exit;
}
}
$this->sys_error_db("Sample verification Req", $this->db_smartone);
}
}