Files
BE_IBL/application/controllers/xdoc/Lookup_patient.php
2026-04-15 15:23:57 +07:00

65 lines
1.8 KiB
PHP

<?php
class Lookup_patient extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->db->query("use pat_lookup");
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function corss()
{
global $_SERVER;
if (isset($_SERVER["HTTP_ORIGIN"])) {
header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
} else {
header('Access-Control-Allow-Origin: */*');
}
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization');
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
http_response_code(200);
echo json_encode("OK");
exit;
}
}
function search()
{
$this->corss();
$param = $this->get_param();
$regionID = $param["regionalID"];
$search = $param["search"];
$tok = strtok($search, " ");
$ft_search = "";
while ($tok != "") {
$ft_search .= "+" . $tok . "* ";
$tok = strtok(" ");
}
$sql = "select
patientBizoneID,patientName,patientDOB,patientAddress,patientHP, patientEmail,
patientSex, ifnull(patientNIK,'') patientNIK,
patientText
from patient_v2 where patientRegionalID = ?
and match(patientText) against(? in boolean mode)
group by patientBizoneID
limit 0,20";
$qry = $this->db->query($sql, [$regionID, $ft_search]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" =>
$this->db->error()["message"] .
" | " .
$this->db->last_query(),
]);
exit();
}
$rows = $qry->result_array();
echo json_encode(["status" => "OK", "rows" => $rows]);
}
}