Compare commits

...

3 Commits

Author SHA1 Message Date
renaldybrada
fc9b4f5761 add action tindakan 2026-03-13 14:36:02 +07:00
renaldybrada
89e533aa44 create search dokter API + UI 2026-03-13 11:04:22 +07:00
renaldybrada
9745454134 add simrs supporting functions 2026-03-13 11:03:53 +07:00
4 changed files with 392 additions and 39 deletions
+94
View File
@@ -0,0 +1,94 @@
<?php
require_once "lib/PostgresDb.php";
header("Content-Type: application/json");
$db = new PostgresDb();
$action = $_GET['action'] ?? '';
$q = '';
if (isset($_GET['q'])) {
$q = $_GET['q'];
}
switch ($action) {
case "searchDPJP":
searchDPJP($db, $q);
break;
case "searchDokterAnestesi":
searchDokterAnestesi($db, $q);
break;
case "searchTindakan":
searchTindakan($db, $q);
break;
default :
echo json_encode([
"error" => "invalid action"
]);
}
function searchDPJP(PostgresDb $db, string $q) {
$query = "SELECT kddokter, namadokter, kdsmf, kode_dpjp FROM public.m_dokter WHERE kdsmf LIKE '%BEDAH%'";
if ($q != '') {
$query .= " AND (namadokter ILIKE '%$q%' OR kode_dpjp ILIKE '%$q%')";
}
$sql_dokter_bedah = $db->query($query);
$query .= " LIMIT 10";
$arr_dokter_bedah = array();
foreach ($sql_dokter_bedah->fetchAll() as $ds) {
array_push($arr_dokter_bedah, $ds);
}
echo json_encode([
"message" => "success get dokter",
"data" => $arr_dokter_bedah
]);
}
function searchDokterAnestesi(PostgresDb $db, string $q) {
$query = "SELECT kddokter, namadokter, kdsmf, kode_dpjp FROM public.m_dokter WHERE kdsmf LIKE '%ANESTHESI%'";
if ($q != '') {
$query .= " AND (namadokter ILIKE '%$q%' OR kode_dpjp ILIKE '%$q%')";
}
$query .= " LIMIT 10";
$sql_dokter_anestesi = $db->query($query);
$arr_dokter_anestesi = array();
foreach ($sql_dokter_anestesi->fetchAll() as $ds) {
array_push($arr_dokter_anestesi, $ds);
}
echo json_encode([
"message" => "success get dokter",
"data" => $arr_dokter_anestesi
]);
}
function searchTindakan(PostgresDb $db, string $q) {
$query = "SELECT kode as code, keterangan as str from icd_cm";
if ($q != '') {
$query .= " where kode ilike '$q%' OR keterangan ilike '%$q%'";
}
$query .= " LIMIT 10";
$sql_tindakan = $db->query($query);
$result = array();
foreach($sql_tindakan->fetchAll() as $t) {
array_push($result, $t);
}
echo json_encode([
"message" => "success get tindakan",
"data" => $result
]);
}
?>
+204 -39
View File
@@ -1,18 +1,5 @@
<?php
$riwayat = [
[
"tanggal" => "28/1/2026, 2:27:04 PM",
"operator" => "dr.SYAIFULLAH AMISRAGANI, Sp.OT",
"status" => "Tervalidasi"
],
[
"tanggal" => "29/1/2026, 10:13:29 AM",
"operator" => "dr.PRADANA NURHADI,Sp.U",
"status" => "Belum Validasi"
]
];
if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo "<pre>";
print_r($_POST);
@@ -57,13 +44,21 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
<div class="row">
<div class="col-md-4">
<div class="col-md-4 position-relative">
<label>DPJP Operator</label>
<select class="form-select" name="dpjp_operator" id="dpjp_operator">
<option>dr.SYAIFULLAH AMISRAGANI, Sp.OT</option>
<option>dr.AGUS, Sp.BO</option>
<option>dr.Koernia Kusuma Wardhana, Sp.B-TKV</option>
</select>
<input
type="text"
id="searchDPJP"
class="form-control"
placeholder="Cari dokter..."
autocomplete="off"
>
<input type="hidden" name="dpjp_operator" id="dpjp_operator">
<div
id="resultDPJP"
class="list-group position-absolute w-100"
style="z-index:1000"
></div>
</div>
<div class="col-md-4">
@@ -82,11 +77,19 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
<div class="col-md-4">
<label>DPJP Anastesi</label>
<select class="form-select" name="dpjp_anastesi">
<option>dr.FANNIYAH,Sp.An</option>
<option>dr.DEWI ARUM SAWITRI, Sp.AN-TI</option>
<option>dr.MUHAMAD AKBAR SIDIQ, Sp.AN-TI</option>
</select>
<input
type="text"
id="searchDokterAnestesi"
class="form-control"
placeholder="Cari dokter..."
autocomplete="off"
>
<input type="hidden" name="dpjp_anestesi" id="dpjp_anestesi">
<div
id="resultDokterAnestesi"
class="list-group position-absolute w-100"
style="z-index:1000"
></div>
</div>
<div class="col-md-4">
@@ -123,10 +126,18 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
<div id="tindakanContainer" class="container border pl-3">
<div class="row my-2 tindakanRow">
<div class="row my-2 tindakanRow position-relative">
<div class="col-md-6">
<input class="form-control" name="tindakan_operatif[]" placeholder="Cari Prosedur">
<input
type="text"
class="form-control tindakanSearch"
placeholder="Cari Prosedur"
autocomplete="off"
>
<input type="hidden" name="tindakan_operatif[]" class="tindakanValue">
<div class="list-group tindakanResult position-absolute w-100" style="z-index:1000"></div>
</div>
<div class="col-md-2">
@@ -660,6 +671,112 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
const BASEURL = "http://localhost:8080/dataLaporanOperasi.php";
/* SEARCH AND SHOW DPJP*/
const inputDokter = document.getElementById("searchDPJP")
const resultDokter = document.getElementById("resultDPJP")
const hiddenDokter = document.getElementById("dpjp_operator")
let timer = null
inputDokter.addEventListener("input", () => {
clearTimeout(timer)
let keyword = inputDokter.value
if (keyword.length < 2) {
resultDokter.innerHTML = ""
return
}
timer = setTimeout(() => {
fetch(`${BASEURL}?action=searchDPJP&q=${keyword}`)
.then(res => res.json())
.then(data => {
resultDokter.innerHTML = ""
// console.log(data)
data.data.forEach(d => {
let item = document.createElement("button")
item.type = "button"
item.className = "list-group-item list-group-item-action"
item.textContent = d.namadokter
item.onclick = () => {
inputDokter.value = d.namadokter
hiddenDokter.value = d.kddokter
resultDokter.innerHTML = ""
}
resultDokter.appendChild(item)
})
})
}, 300)
})
/* SEARCH AND SHOW Dokter Anestesi*/
const inputDokterAnestesi = document.getElementById("searchDokterAnestesi")
const resultDokterAnestesi = document.getElementById("resultDokterAnestesi")
const hiddenDokterAnestesi = document.getElementById("dpjp_anestesi")
inputDokterAnestesi.addEventListener("input", () => {
clearTimeout(timer)
let keyword = inputDokterAnestesi.value
if (keyword.length < 2) {
resultDokterAnestesi.innerHTML = ""
return
}
timer = setTimeout(() => {
fetch(`${BASEURL}?action=searchDokterAnestesi&q=${keyword}`)
.then(res => res.json())
.then(data => {
resultDokterAnestesi.innerHTML = ""
// console.log(data)
data.data.forEach(d => {
let item = document.createElement("button")
item.type = "button"
item.className = "list-group-item list-group-item-action"
item.textContent = d.namadokter
item.onclick = () => {
inputDokterAnestesi.value = d.namadokter
hiddenDokterAnestesi.value = d.kddokter
resultDokterAnestesi.innerHTML = ""
}
resultDokterAnestesi.appendChild(item)
})
})
}, 300)
})
/* kalkulasi waktu */
function calc(start, dur, end) {
@@ -689,25 +806,73 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
document.getElementById("lama_bius").oninput = () => calc("bius_mulai", "lama_bius", "bius_selesai")
/* dynamic tindakan */
let timerTindakan = null
document.addEventListener("click", e => {
document.addEventListener("input", function(e){
if (e.target.classList.contains("addTindakan")) {
let row = document.createElement("div")
row.classList.add("row", "my-2", "tindakanRow")
row.innerHTML = `
<div class="col-md-6">
<input class="form-control" name="tindakan_operatif[]" placeholder="Cari Prosedur">
</div>
if (!e.target.classList.contains("tindakanSearch")) return
<div class="col-md-2">
<button type="button" class="btn btn-success addTindakan">+</button>
</div>
`
document.getElementById("tindakanContainer").appendChild(row)
let input = e.target
let row = input.closest(".tindakanRow")
let result = row.querySelector(".tindakanResult")
clearTimeout(timerTindakan)
let keyword = input.value
if (keyword.length < 2) {
result.innerHTML = ""
return
}
timerTindakan = setTimeout(() => {
fetch(`http://localhost:8080/dataLaporanOperasi.php?action=searchTindakan&q=${keyword}`)
.then(res => res.json())
.then(data => {
result.innerHTML = ""
data.data.forEach(d => {
let item = document.createElement("button")
item.type = "button"
item.className = "list-group-item list-group-item-action"
item.textContent = d.str
item.onclick = () => {
input.value = d.str
row.querySelector(".tindakanValue").value = d.code
result.innerHTML = ""
}
result.appendChild(item)
})
})
}, 300)
})
document.addEventListener("click", function(e){
if (!e.target.classList.contains("addTindakan")) return
let row = document.querySelector(".tindakanRow")
let clone = row.cloneNode(true)
clone.querySelector(".tindakanSearch").value = ""
clone.querySelector(".tindakanValue").value = ""
clone.querySelector(".tindakanResult").innerHTML = ""
row.parentNode.appendChild(clone)
})
/* darah */
+57
View File
@@ -0,0 +1,57 @@
<?php
class PostgresDb
{
private $pdo;
public function __construct()
{
$host = "10.10.123.238";
$port = "5432";
$dbname = "simrs";
$user = "brawijaya";
$password = "ub*2025";
$dsn = "pgsql:host=$host;port=$port;dbname=$dbname";
try {
$this->pdo = new PDO($dsn, $user, $password, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
}
public function query($sql, $params = [])
{
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
return $stmt;
}
public function fetchAll($sql, $params = [])
{
return $this->query($sql, $params)->fetchAll();
}
public function fetch($sql, $params = [])
{
return $this->query($sql, $params)->fetch();
}
public function lastInsertId()
{
return $this->pdo->lastInsertId();
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
if (!function_exists('form_dropdown')) {
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '', $callback = null)
{
if (!is_array($selected)) {
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0) {
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name])) {
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' ' . $extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$form = '<select name="' . $name . '"' . $extra . $multiple . ">\n";
foreach ($options as $key => $val) {
$key = (string)$key;
if (is_array($val) && !empty($val)) {
$form .= '<optgroup label="' . $key . '">' . "\n";
foreach ($val as $optgroup_key => $optgroup_val) {
$sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="' . $optgroup_key . '"' . $sel . '>' . (string)$optgroup_val . "</option>\n";
}
$form .= '</optgroup>' . "\n";
} else {
$val = ($callback != '') ? $callback($val) : $val;
$sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
$form .= '<option value="' . $key . '"' . $sel . '>' . (string)$val . "</option>\n";
}
}
$form .= '</select>';
return $form;
}
}
?>