75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$response = ['success' => false, 'message' => 'Invalid request'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$patient_id = $_POST['patient_id'] ?? null;
|
|
$status = $_POST['status'] ?? null;
|
|
$notes = $_POST['notes'] ?? null;
|
|
$service_rendered = $_POST['service_rendered'] ?? null;
|
|
$cost = $_POST['cost'] ?? null;
|
|
|
|
if ($patient_id && $status) {
|
|
try {
|
|
$pdo = db();
|
|
$sql = "UPDATE patients SET status = ?";
|
|
$params = [$status];
|
|
|
|
if ($notes !== null) {
|
|
$sql .= ", notes = ?";
|
|
$params[] = $notes;
|
|
}
|
|
|
|
if ($service_rendered !== null) {
|
|
$sql .= ", service_rendered = ?";
|
|
$params[] = $service_rendered;
|
|
}
|
|
|
|
if ($cost !== null) {
|
|
$sql .= ", cost = ?";
|
|
$params[] = $cost;
|
|
}
|
|
|
|
// When completing, set payment_status to unpaid
|
|
if ($status === 'Completed') {
|
|
$sql .= ", payment_status = 'unpaid'";
|
|
}
|
|
|
|
$sql .= " WHERE id = ?";
|
|
$params[] = $patient_id;
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
if ($stmt->execute($params)) {
|
|
$response['success'] = true;
|
|
$response['message'] = 'Patient status updated successfully.';
|
|
$response['status_class'] = get_status_badge_class($status);
|
|
} else {
|
|
$response['message'] = 'Failed to update patient status.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
} else {
|
|
$response['message'] = 'Missing patient ID or status.';
|
|
}
|
|
}
|
|
|
|
echo json_encode($response);
|
|
|
|
function get_status_badge_class($status) {
|
|
switch ($status) {
|
|
case 'Pending':
|
|
return 'warning';
|
|
case 'In Progress':
|
|
return 'info';
|
|
case 'Completed':
|
|
return 'success';
|
|
default:
|
|
return 'secondary';
|
|
}
|
|
}
|
|
?>
|