corss(); $this->load->database("default"); $max_result = 30; $param = $this->get_param(); if ($param["search"] == "") { $sql = "select * from place_holder.drug_allergy limit 0,$max_result"; $qry = $this->db->query($sql); } else { $param["search"] = "%" . $param["search"] . "%"; $sql = "select * from place_holder.drug_allergy where CODE like ? or STR like ? limit 0,$max_result"; $qry = $this->db->query($sql,[$param["search"]]); } if ($qry) { echo json_encode(["status"=>"ERR","message" => $this->db->error()["message"]]); exit; } echo json_encode(["status"=>"OK","rows"=>$this->db->result_array()]); } function search_location() { // metode search : 1. search kelurahan ( limit 20) , jika < 20 search kecamatan limit 20 - hasil kelurahan, jika < 20 search city dst $max_result = 30; $param = $this->get_param(); $param["search"] = "%" . $param["search"] . "%"; $a_loc = []; if ($param["queryLoc"] != "") { $a_loc = explode(",",$param["queryLoc"]); } $filter_loc = ""; if (count($a_loc) > 0) { if (count($a_loc) == 1) { $filter_loc = " and M_ProvinceName = '" . $a_loc[0] . "'"; } if (count($a_loc) == 2) { $filter_loc = " and M_CityName = '" . $a_loc[1] . "'"; } if (count($a_loc) == 3) { $filter_loc = " and M_DistrictName= '" . $a_loc[2] . "'"; } } $this->load->database("default"); $this->corss(); $sql = "select M_KelurahanID,M_KelurahanName, M_DistrictID, M_DistrictName, M_CityID, M_CityName, M_ProvinceID, M_ProvinceName from m_kelurahan join m_district on M_KelurahanName like ? and M_KelurahanIsActive='Y' and M_DistrictID = M_KelurahanM_DistrictID join m_city on M_CityID = M_DistrictM_CityID and M_CityIsActive = 'Y' join m_province on M_CityM_ProvinceID = M_ProvinceID and M_ProvinceIsActive = 'Y' $filter_loc limit 0,$max_result"; $qry = $this->db->query($sql, [$param["search"]]); if (!$qry) { echo json_encode(["status"=>"ERR","message"=>$this->db->error()["message"]]); exit; } $rows = $qry->result_array(); $result = []; foreach ($rows as $r) { $result[] = $r; $idx = count($result) - 1; $result[$idx]["tag"] = [ $r["M_ProvinceName"], $r["M_CityName"], $r["M_DistrictName"], $r["M_KelurahanName"], ]; $result[$idx]["level"] = 1; } if (count($rows) < $max_result) { $max_result = $max_result - count($rows); $sql = "select M_DistrictID, M_DistrictName, M_CityID, M_CityName, M_ProvinceID, M_ProvinceName from m_district join m_city on M_DistrictName like ? and M_DistrictIsActive ='Y' and M_DistrictM_CityID = M_CityID and M_CityIsActive = 'Y' join m_province on M_CityM_ProvinceID = M_ProvinceID and M_ProvinceIsActive = 'Y' $filter_loc limit 0,$max_result"; $qry = $this->db->query($sql, [$param["search"]]); if (!$qry) { echo json_encode(["status"=>"ERR","message"=>$this->db->error()["message"]]); exit; } $rows = $qry->result_array(); foreach ($rows as $r) { $result[] = $r; $idx = count($result) - 1; $result[$idx]["tag"] = [ $r["M_ProvinceName"], $r["M_CityName"], $r["M_DistrictName"], ]; $result[$idx]["level"] = 2; } if (count($rows) < $max_result) { $max_result = $max_result - count($rows); $x_loc = $filter_loc ; if(count($a_loc) > 2) $x_loc = ""; $sql = "select M_CityID, M_CityName, M_ProvinceID, M_ProvinceName from m_city join m_province on M_CityName like ? and M_CityIsActive = 'Y' and M_CityM_ProvinceID= M_ProvinceID and M_ProvinceIsActive= 'Y' $x_loc limit 0,$max_result"; $qry = $this->db->query($sql, [$param["search"]]); if (!$qry) { echo json_encode(["status"=>"ERR","message"=>$this->db->error()["message"]]); exit; } $rows = $qry->result_array(); foreach ($rows as $r) { $result[] = $r; $idx = count($result) - 1; $result[$idx]["tag"] = [ $r["M_ProvinceName"], $r["M_CityName"], ]; $result[$idx]["level"] = 3; } } } echo json_encode([ "status" => "OK", "rows" => $result ]); } function get_param() { $sbody = file_get_contents("php://input"); return json_decode($sbody, true); } function search_patient() { $this->corss(); $ch = curl_init( "http://devone.aplikasi.web.id/one-api/mockup/fo/registration_v11/patient/search" ); $param = $this->get_param(); $payload = json_encode([ "noreg" => "", "search" => $param["search"], "current_page" => 1, ]); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type:application/json"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $resp = curl_exec($ch); $error = curl_errno($ch); $error_msg = curl_error($ch); if ($error != 0) { echo json_encode(["status" => "ERR", "message" => $error_msg]); exit(); } echo $resp; } function lookup($param = "") { $this->corss(); $result = [ "status" => "OK", "data" => [ ["id" => 1, "name" => "Satu"], ["id" => 2, "name" => "Dua"], ["id" => 3, "name" => "Tiga"], ["id" => 4, "name" => "Empat"], ["id" => 5, "name" => "Lima"], ["id" => 6, "name" => "Enam"], ["id" => 7, "name" => "Tujuh"], ["id" => 8, "name" => "Delapan"], ["id" => 9, "name" => "Sembilan"], ], ]; if ($param != "") { $data = array_filter($result["data"], function ($r) use ($param) { return strpos($r["name"], $param) >= 0; }); $result["data"] = $data; } echo json_encode($result); } } ?>