Skip to content

Commit 1818856

Browse files
authored
Merge pull request #141 from C4G/pdorsaint/c4g-spr25-satellite-4
fix satellite lab filter patient search to apply only to satellite lab users
2 parents 107784d + 75bfd78 commit 1818856

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

htdocs/includes/db_lib.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6622,11 +6622,11 @@ function search_patients_by_id($q, $labsection = 0)
66226622
function search_patients_by_id_dyn($q, $cap, $counter, $labsection = 0, $satellite_lab_id)
66236623
{
66246624
# Searches for patients with similar name
6625-
global $con;
6625+
global $con, $LIS_SATELLITE_LAB_USER;
66266626
$offset = $cap * ($counter - 1);
66276627
$q = mysql_real_escape_string($q, $con);
66286628

6629-
6629+
if ($_SESSION['user_level'] == $LIS_SATELLITE_LAB_USER){
66306630
if($labsection == 0){
66316631
$query_string =
66326632
"SELECT * FROM patient ".
@@ -6638,6 +6638,20 @@ function search_patients_by_id_dyn($q, $cap, $counter, $labsection = 0, $satelli
66386638
"(select specimen_id from specimen where specimen_type_id in (select specimen_type_id from specimen_test where test_type_id in ".
66396639
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.ts DESC LIMIT $offset,$cap";
66406640
}
6641+
}
6642+
if(is_admin_check(get_user_by_id($_SESSION['user_id']))) {
6643+
if($labsection == 0){
6644+
$query_string =
6645+
"SELECT * FROM patient ".
6646+
"WHERE surr_id='$q' ORDER BY ts DESC LIMIT $offset,$cap";
6647+
} else {
6648+
$query_string =
6649+
"select distinct p.* from patient p, specimen s where ".
6650+
"p.surr_id ='$q' and p.patient_id = s.patient_id and s.specimen_id in ".
6651+
"(select specimen_id from specimen where specimen_type_id in (select specimen_type_id from specimen_test where test_type_id in ".
6652+
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.ts DESC LIMIT $offset,$cap";
6653+
}
6654+
}
66416655

66426656
$resultset = query_associative_all($query_string);
66436657
$patient_list = array();
@@ -6753,17 +6767,15 @@ function search_patients_by_name($q, $labsection = 0,$c="")
67536767
function search_patients_by_name_dyn($q, $cap, $counter, $c="", $labsection = 0, $satellite_lab_id)
67546768
{
67556769
# Searches for patients with similar name
6756-
global $con;
6770+
global $con, $LIS_SATELLITE_LAB_USER;
67576771
$offset = $cap * ($counter - 1);
67586772
$q = mysql_real_escape_string($q, $con);
67596773
if(empty($c))
67606774
$q.='%';
67616775
else
67626776
$q=str_replace('[pq]',$q,$c);
6763-
//echo "[]".$labsection;
6764-
$user = get_user_by_id($_SESSION['user_id']);
67656777

6766-
if(! is_admin_check($user)){
6778+
if ($_SESSION['user_level'] == $LIS_SATELLITE_LAB_USER){
67676779
if($labsection == 0){
67686780
$query_string =
67696781
"SELECT * FROM patient ".
@@ -6774,23 +6786,22 @@ function search_patients_by_name_dyn($q, $cap, $counter, $c="", $labsection = 0,
67746786
"p.name LIKE '$q' AND p.satellite_lab_id = $satellite_lab_id AND p.patient_id NOT IN (select r_id from removal_record where category='patient' AND removal_record.status=1) and p.patient_id = s.patient_id and s.specimen_id in ".
67756787
"(select specimen_id from specimen where specimen_type_id in (select specimen_type_id from specimen_test where test_type_id in ".
67766788
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.name ASC LIMIT $offset,$cap";
6777-
//;
67786789
}
6779-
} else {
6790+
}
6791+
if(is_admin_check(get_user_by_id($_SESSION['user_id']))) {
67806792
if($labsection == 0){
67816793
$query_string =
67826794
"SELECT * FROM patient ".
6783-
"WHERE name LIKE '$q' AND satellite_lab_id = $satellite_lab_id ORDER BY name ASC LIMIT $offset,$cap";
6795+
"WHERE name LIKE '$q' ORDER BY name ASC LIMIT $offset,$cap";
67846796
} else {
67856797
$query_string =
67866798
"select distinct p.* from patient p, specimen s where ".
6787-
"p.name LIKE '$q' and p.satellite_lab_id = $satellite_lab_id and p.patient_id = s.patient_id and s.specimen_id in ".
6799+
"p.name LIKE '$q' and p.patient_id = s.patient_id and s.specimen_id in ".
67886800
"(select specimen_id from specimen where specimen_type_id in (select specimen_type_id from specimen_test where test_type_id in ".
67896801
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.name ASC LIMIT $offset,$cap";
6790-
//;
67916802
}
67926803
}
6793-
//;
6804+
67946805
$resultset = query_associative_all($query_string);
67956806
$patient_list = array();
67966807
if(count($resultset) > 0)
@@ -6883,7 +6894,7 @@ function search_patients_by_addlid($q, $labsection = 0, $satellite_lab_id)
68836894

68846895
}
68856896
}
6886-
//;
6897+
68876898
$resultset = query_associative_all($query_string);
68886899
$patient_list = array();
68896900
if(count($resultset) > 0)
@@ -6900,12 +6911,12 @@ function search_patients_by_addlid($q, $labsection = 0, $satellite_lab_id)
69006911
function search_patients_by_addlid_dyn($q, $cap, $counter, $labsection = 0, $satellite_lab_id)
69016912
{
69026913
# Searches for patients with similar name
6903-
global $con;
6914+
global $con, $LIS_SATELLITE_LAB_USER;
69046915
$offset = $cap * ($counter - 1);
69056916
$q = mysql_real_escape_string($q, $con);
6917+
$user = get_user_by_id($_SESSION['user_id']);
69066918

6907-
if(is_admin_check(get_user_by_id($_SESSION['user_id']))){
6908-
6919+
if ($_SESSION['user_level'] == $LIS_SATELLITE_LAB_USER){
69096920
if($labsection == 0){
69106921
$query_string =
69116922
"SELECT * FROM patient ".
@@ -6918,21 +6929,22 @@ function search_patients_by_addlid_dyn($q, $cap, $counter, $labsection = 0, $sat
69186929
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.addl_id ASC LIMIT $offset,$cap";
69196930

69206931
}
6921-
} else{
6932+
}
6933+
if(is_admin_check(get_user_by_id($_SESSION['user_id']))){
69226934
if($labsection == 0){
69236935
$query_string =
69246936
"SELECT * FROM patient ".
6925-
"WHERE addl_id LIKE '%$q%' AND satellite_lab_id = $satellite_lab_id AND patient.patient_id NOT IN (select r_id from removal_record where category='patient' AND removal_record.status=1) ORDER BY addl_id ASC LIMIT $offset,$cap";
6937+
"WHERE addl_id LIKE '%$q%' AND patient.patient_id NOT IN (select r_id from removal_record where category='patient' AND removal_record.status=1) ORDER BY addl_id ASC LIMIT $offset,$cap";
69266938
} else {
69276939
$query_string =
69286940
"select distinct p.* from patient p, specimen s where ".
6929-
"p.addl_id LIKE '%$q%' AND p.satellite_lab_id = $satellite_lab_id AND p.patient_id NOT IN (select r_id from removal_record where category='patient' AND removal_record.status=1) and p.patient_id = s.patient_id and s.specimen_id in ".
6941+
"p.addl_id LIKE '%$q%' AND p.patient_id NOT IN (select r_id from removal_record where category='patient' AND removal_record.status=1) and p.patient_id = s.patient_id and s.specimen_id in ".
69306942
"(select specimen_id from specimen where specimen_type_id in (select specimen_type_id from specimen_test where test_type_id in ".
69316943
"(select test_type_id as lab_section from test_type where test_category_id = '$labsection'))) ORDER BY p.addl_id ASC LIMIT $offset,$cap";
69326944

69336945
}
69346946
}
6935-
//;
6947+
69366948
$resultset = query_associative_all($query_string);
69376949
$patient_list = array();
69386950
if(count($resultset) > 0)

0 commit comments

Comments
 (0)