From 38bb2e04d3f50a7cacbb1b26cfdde0e5740b9121 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Fri, 26 Sep 2025 16:33:54 +0700 Subject: [PATCH] add location param --- app/Controllers/Location.php | 21 +++++++++++++++++---- app/Controllers/PatVisit.php | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Controllers/Location.php b/app/Controllers/Location.php index bde886d..4b2c6fa 100644 --- a/app/Controllers/Location.php +++ b/app/Controllers/Location.php @@ -8,6 +8,9 @@ use CodeIgniter\Database\RawSql; class Location extends Controller { use ResponseTrait; + protected $db; + protected $rules; + public function __construct() { $this->db = \Config\Database::connect(); $this->rules = [ @@ -17,11 +20,18 @@ class Location extends Controller { } public function index() { - $rows = $this->db->table('location l') + $LocName = $this->request->getVar('LocName'); + $LocCode = $this->request->getVar('LocCode'); + + $sql = $this->db->table('location l') ->select("l.LocationID, LocCode, Parent, LocFull, LocType, v.VDesc ") ->join("locationaddress la", "l.LocationID=la.LocationID", 'left') - ->join("valueset v", "v.VSetID=12 and v.VValue=l.loctype", 'left') - ->get()->getResultArray(); + ->join("valueset v", "v.VSetID=12 and v.VValue=l.loctype", 'left'); + + if($LocName != '') { $sql->like('LocFull', $LocName, 'both'); $rows[] = 'LocName'; } + if($LocCode != '') { $sql->like('LocCode', $LocCode, 'both'); $rows[] = 'LocCode'; } + + $rows[] = $sql->get()->getResultArray(); if (empty($rows)) { return $this->respond([ @@ -156,7 +166,7 @@ class Location extends Controller { $input = $this->request->getJSON(true); $LocationID = $input["LocationID"]; if (!$LocationID) { - return $this->failValidationError('LocationID is required.'); + return $this->failValidationErrors('LocationID is required.'); } @@ -211,6 +221,9 @@ class Location extends Controller { "PostCode" => $input['PostCode'] ?? null, "GeoLocationSystem" => $input['GeoLocationSystem'] ?? null, "GeoLocationData" => $input['GeoLocationData'] ?? null, + "Email" => $input['Email'] ?? null, + "Phone" => $input['Phone'] ?? null, + "Mobile" => $input['Mobile'] ?? null, ]; return $data; diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index 6779bb8..77c72de 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -51,7 +51,7 @@ class PatVisit extends Controller { $input = $this->request->getJSON(true); try { - if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); } + if (!$input) { return $this->respond( ['status' => 'error', 'message' => 'Invalid JSON input'], 400); } if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); } $InternalPVID = $input["InternalPVID"];