version 2
This commit is contained in:
parent
f0947adeb2
commit
c8d83e1d5c
43
add_prescription.php
Normal file
43
add_prescription.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('doctor');
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$response = ['success' => false, 'message' => 'An unknown error occurred.'];
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$visit_id = $_POST['visit_id'] ?? null;
|
||||||
|
$patient_id = $_POST['patient_id'] ?? null;
|
||||||
|
$medication = $_POST['medication'] ?? null;
|
||||||
|
$dosage = $_POST['dosage'] ?? null;
|
||||||
|
$frequency = $_POST['frequency'] ?? null;
|
||||||
|
$notes = $_POST['notes'] ?? '';
|
||||||
|
$doctor_id = $_SESSION['user_id'] ?? null;
|
||||||
|
|
||||||
|
if ($visit_id && $patient_id && $doctor_id && $medication && $dosage && $frequency) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
"INSERT INTO prescriptions (visit_id, patient_id, doctor_id, medication, dosage, frequency, notes)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||||
|
);
|
||||||
|
$stmt->execute([$visit_id, $patient_id, $doctor_id, $medication, $dosage, $frequency, $notes]);
|
||||||
|
|
||||||
|
$response['success'] = true;
|
||||||
|
$response['message'] = 'Prescription saved successfully.';
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// In a real app, log this error instead of echoing it.
|
||||||
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Invalid or missing data provided.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Invalid request method.';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
?>
|
||||||
12
alter_visits_table.php
Normal file
12
alter_visits_table.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "ALTER TABLE `patient_visits` CHANGE `id` `visit_id` INT(11) NOT NULL AUTO_INCREMENT;";
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Table 'patient_visits' altered successfully. Column 'id' renamed to 'visit_id'.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Database error: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
?>
|
||||||
54
billing.php
54
billing.php
@ -5,13 +5,12 @@ require_once 'db/config.php';
|
|||||||
|
|
||||||
// Handle status update
|
// Handle status update
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mark_paid') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mark_paid') {
|
||||||
$patient_id_to_update = $_POST['patient_id'] ?? null;
|
$visit_id_to_update = $_POST['visit_id'] ?? null;
|
||||||
if ($patient_id_to_update) {
|
if ($visit_id_to_update) {
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$stmt = $pdo->prepare("UPDATE patients SET payment_status = 'paid' WHERE id = ?");
|
$stmt = $pdo->prepare("UPDATE patient_visits SET payment_status = 'paid' WHERE visit_id = ?");
|
||||||
$stmt->execute([$patient_id_to_update]);
|
$stmt->execute([$visit_id_to_update]);
|
||||||
// Redirect to avoid form resubmission
|
|
||||||
header("Location: billing.php");
|
header("Location: billing.php");
|
||||||
exit;
|
exit;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
@ -20,15 +19,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch unpaid patients
|
// Fetch unpaid visits and calculate total cost
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$stmt = $pdo->prepare("SELECT p.*, u.username as doctor_name FROM patients p JOIN users u ON p.doctor_id = u.id WHERE p.status = 'Completed' AND p.payment_status = 'unpaid' ORDER BY p.updated_at DESC");
|
$stmt = $pdo->prepare(
|
||||||
|
"SELECT
|
||||||
|
pv.visit_id,
|
||||||
|
pv.cost as consultation_fee,
|
||||||
|
p.patient_name,
|
||||||
|
p.id as patient_id,
|
||||||
|
u.username as doctor_name,
|
||||||
|
pv.service_rendered,
|
||||||
|
COALESCE((SELECT SUM(lt.cost) FROM ordered_tests ot JOIN lab_tests lt ON ot.test_id = lt.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'lab'), 0) as lab_tests_cost,
|
||||||
|
COALESCE((SELECT SUM(it.cost) FROM ordered_tests ot JOIN imaging_tests it ON ot.test_id = it.test_id WHERE ot.visit_id = pv.visit_id AND ot.test_type = 'imaging'), 0) as imaging_tests_cost
|
||||||
|
FROM patient_visits pv
|
||||||
|
JOIN patients p ON pv.patient_id = p.id
|
||||||
|
JOIN users u ON pv.doctor_id = u.id
|
||||||
|
WHERE pv.status = 'Completed' AND pv.payment_status = 'unpaid'
|
||||||
|
ORDER BY pv.visit_time DESC"
|
||||||
|
);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$unpaid_patients = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$unpaid_visits = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$unpaid_patients = [];
|
$unpaid_visits = [];
|
||||||
// Log error
|
// You should log the error in a real application
|
||||||
|
// error_log($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -101,26 +116,27 @@ try {
|
|||||||
<th>Patient Name</th>
|
<th>Patient Name</th>
|
||||||
<th>Doctor</th>
|
<th>Doctor</th>
|
||||||
<th>Service Rendered</th>
|
<th>Service Rendered</th>
|
||||||
<th>Cost</th>
|
<th>Total Bill</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if (!empty($unpaid_patients)):
|
<?php if (!empty($unpaid_visits)):
|
||||||
foreach ($unpaid_patients as $patient):
|
foreach ($unpaid_visits as $visit):
|
||||||
|
$total_bill = $visit['consultation_fee'] + $visit['lab_tests_cost'] + $visit['imaging_tests_cost'];
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="patient_profile.php?id=<?php echo $patient['id']; ?>"><?php echo htmlspecialchars($patient['patient_name']); ?></a></td>
|
<td><a href="patient_profile.php?id=<?php echo $visit['patient_id']; ?>"><?php echo htmlspecialchars($visit['patient_name']); ?></a></td>
|
||||||
<td>Dr. <?php echo htmlspecialchars($patient['doctor_name']); ?></td>
|
<td>Dr. <?php echo htmlspecialchars($visit['doctor_name']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($patient['service_rendered']); ?></td>
|
<td><?php echo htmlspecialchars($visit['service_rendered']); ?></td>
|
||||||
<td>$<?php echo htmlspecialchars(number_format($patient['cost'], 2)); ?></td>
|
<td>$<?php echo htmlspecialchars(number_format($total_bill, 2)); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<form method="POST" action="billing.php" style="display:inline;">
|
<form method="POST" action="billing.php" style="display:inline;">
|
||||||
<input type="hidden" name="patient_id" value="<?php echo $patient['id']; ?>">
|
<input type="hidden" name="visit_id" value="<?php echo $visit['visit_id']; ?>">
|
||||||
<input type="hidden" name="action" value="mark_paid">
|
<input type="hidden" name="action" value="mark_paid">
|
||||||
<button type="submit" class="btn btn-sm btn-success"><i class="bi bi-check-lg"></i> Mark as Paid</button>
|
<button type="submit" class="btn btn-sm btn-success"><i class="bi bi-check-lg"></i> Mark as Paid</button>
|
||||||
</form>
|
</form>
|
||||||
<a href="invoice.php?id=<?php echo $patient['id']; ?>" class="btn btn-sm btn-info" target="_blank"><i class="bi bi-printer"></i> Invoice</a>
|
<a href="invoice.php?visit_id=<?php echo $visit['visit_id']; ?>" class="btn btn-sm btn-info" target="_blank"><i class="bi bi-printer"></i> Invoice</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
34
dispense.php
Normal file
34
dispense.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('receptionist'); // Or a new 'pharmacist' role
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
$response = ['success' => false, 'message' => 'Invalid request.'];
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$prescription_id = $_POST['prescription_id'] ?? null;
|
||||||
|
$user_id = $_SESSION['user_id'] ?? null;
|
||||||
|
|
||||||
|
if ($prescription_id && $user_id) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
"UPDATE prescriptions SET status = 'Dispensed', dispensed_at = CURRENT_TIMESTAMP, dispensed_by = ? WHERE id = ?"
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($stmt->execute([$user_id, $prescription_id])) {
|
||||||
|
$response = ['success' => true, 'message' => 'Prescription marked as dispensed.'];
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Failed to update prescription status.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Missing prescription ID or user not logged in.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
?>
|
||||||
@ -4,17 +4,28 @@ require_role('doctor');
|
|||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
|
|
||||||
// Get doctor ID from session
|
// Get doctor ID from session
|
||||||
$doctor_id = $_SESSION['user_id'] ?? 0; // Default to 0 if not set
|
$doctor_id = $_SESSION['user_id'] ?? 0;
|
||||||
|
|
||||||
// Fetch patients assigned to the doctor
|
// Fetch today's visits for the logged-in doctor
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
// Corrected to fetch patients for the logged-in doctor based on the user_id which corresponds to the doctor's ID in the `doctors` table
|
$stmt = $pdo->prepare(
|
||||||
$stmt = $pdo->prepare("SELECT p.* FROM patients p JOIN users u ON p.doctor_id = u.id WHERE u.id = ? AND DATE(p.created_at) = CURDATE() ORDER BY p.created_at DESC");
|
"SELECT
|
||||||
|
pv.id as visit_id,
|
||||||
|
pv.status,
|
||||||
|
pv.notes,
|
||||||
|
p.id as patient_id,
|
||||||
|
p.patient_id as patient_system_id,
|
||||||
|
p.patient_name
|
||||||
|
FROM patient_visits pv
|
||||||
|
JOIN patients p ON pv.patient_id = p.id
|
||||||
|
WHERE pv.doctor_id = ? AND DATE(pv.visit_time) = CURDATE()
|
||||||
|
ORDER BY pv.visit_time DESC"
|
||||||
|
);
|
||||||
$stmt->execute([$doctor_id]);
|
$stmt->execute([$doctor_id]);
|
||||||
$patients = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$visits = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$patients = [];
|
$visits = [];
|
||||||
// In a real app, you'd want to log this error
|
// In a real app, you'd want to log this error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +71,14 @@ try {
|
|||||||
<i class="bi bi-person-fill"></i>
|
<i class="bi bi-person-fill"></i>
|
||||||
<span>Doctor</span>
|
<span>Doctor</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="lab_reports.php" class="nav-link">
|
||||||
|
<i class="bi bi-file-earmark-medical"></i>
|
||||||
|
<span>Lab Reports</span>
|
||||||
|
</a>
|
||||||
|
<a href="pharmacy.php" class="nav-link">
|
||||||
|
<i class="bi bi-capsule-pill"></i>
|
||||||
|
<span>Pharmacy</span>
|
||||||
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="sidebar-footer">
|
<div class="sidebar-footer">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
@ -99,34 +118,34 @@ try {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if (!empty($patients)):
|
<?php if (!empty($visits)):
|
||||||
foreach ($patients as $patient):
|
foreach ($visits as $visit):
|
||||||
?>
|
?>
|
||||||
<tr id="patient-row-<?php echo $patient['id']; ?>">
|
<tr id="patient-row-<?php echo $visit['visit_id']; ?>">
|
||||||
<td><?php echo htmlspecialchars($patient['patient_id']); ?></td>
|
<td><?php echo htmlspecialchars($visit['patient_system_id']); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="patient_profile.php?id=<?php echo $patient['id']; ?>"><?php echo htmlspecialchars($patient['patient_name']); ?></a>
|
<a href="patient_profile.php?id=<?php echo $visit['patient_id']; ?>"><?php echo htmlspecialchars($visit['patient_name']); ?></a>
|
||||||
</td>
|
</td>
|
||||||
<td><span class="badge bg-<?php echo get_status_badge_class($patient['status']); ?>-soft" id="status-<?php echo $patient['id']; ?>"><?php echo htmlspecialchars($patient['status']); ?></span></td>
|
<td><span class="badge bg-<?php echo get_status_badge_class($visit['status']); ?>-soft" id="status-<?php echo $visit['visit_id']; ?>"><?php echo htmlspecialchars($visit['status']); ?></span></td>
|
||||||
<td id="action-cell-<?php echo $patient['id']; ?>">
|
<td id="action-cell-<?php echo $visit['visit_id']; ?>">
|
||||||
<?php echo get_action_buttons($patient); ?>
|
<?php echo get_action_buttons($visit); ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="notes-row" id="notes-row-<?php echo $patient['id']; ?>" style="<?php echo $patient['status'] !== 'In Progress' ? 'display: none;' : ''; ?>">
|
<tr class="notes-row" id="notes-row-<?php echo $visit['visit_id']; ?>" style="<?php echo $visit['status'] !== 'In Progress' ? 'display: none;' : ''; ?>">
|
||||||
<td colspan="4">
|
<td colspan="4">
|
||||||
<form class="notes-form" data-patient-id="<?php echo $patient['id']; ?>">
|
<form class="notes-form" data-visit-id="<?php echo $visit['visit_id']; ?>">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="notes-<?php echo $patient['id']; ?>" class="form-label">Consultation Notes</label>
|
<label for="notes-<?php echo $visit['visit_id']; ?>" class="form-label">Consultation Notes</label>
|
||||||
<textarea class="form-control" id="notes-<?php echo $patient['id']; ?>" rows="3"><?php echo htmlspecialchars($patient['notes'] ?? ''); ?></textarea>
|
<textarea class="form-control" id="notes-<?php echo $visit['visit_id']; ?>" rows="3"><?php echo htmlspecialchars($visit['notes'] ?? ''); ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8 mb-3">
|
<div class="col-md-8 mb-3">
|
||||||
<label for="service-<?php echo $patient['id']; ?>" class="form-label">Service Rendered</label>
|
<label for="service-<?php echo $visit['visit_id']; ?>" class="form-label">Service Rendered</label>
|
||||||
<input type="text" class="form-control" id="service-<?php echo $patient['id']; ?>" placeholder="e.g., General Consultation">
|
<input type="text" class="form-control" id="service-<?php echo $visit['visit_id']; ?>" placeholder="e.g., General Consultation">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="cost-<?php echo $patient['id']; ?>" class="form-label">Cost ($)</label>
|
<label for="cost-<?php echo $visit['visit_id']; ?>" class="form-label">Cost ($)</label>
|
||||||
<input type="number" class="form-control" id="cost-<?php echo $patient['id']; ?>" placeholder="e.g., 75.00" step="0.01">
|
<input type="number" class="form-control" id="cost-<?php echo $visit['visit_id']; ?>" placeholder="e.g., 75.00" step="0.01">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-sm btn-success">
|
<button type="submit" class="btn btn-sm btn-success">
|
||||||
@ -151,29 +170,193 @@ try {
|
|||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Prescription Modal -->
|
||||||
|
<div class="modal fade" id="prescriptionModal" tabindex="-1" aria-labelledby="prescriptionModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="prescriptionModalLabel">Add Prescription</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="prescriptionForm">
|
||||||
|
<input type="hidden" id="prescriptionVisitId" name="visit_id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="medication" class="form-label">Medication</label>
|
||||||
|
<input type="text" class="form-control" id="medication" name="medication" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="dosage" class="form-label">Dosage</label>
|
||||||
|
<input type="text" class="form-control" id="dosage" name="dosage" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="frequency" class="form-label">Frequency</label>
|
||||||
|
<input type="text" class="form-control" id="frequency" name="frequency" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="prescriptionNotes" class="form-label">Notes</label>
|
||||||
|
<textarea class="form-control" id="prescriptionNotes" name="notes" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Prescription</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Order Tests Modal -->
|
||||||
|
<div class="modal fade" id="orderTestsModal" tabindex="-1" aria-labelledby="orderTestsModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="orderTestsModalLabel">Order Tests</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="orderTestsForm">
|
||||||
|
<input type="hidden" id="orderVisitId" name="visit_id">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h5>Lab Tests</h5>
|
||||||
|
<div id="lab-tests-list" class="list-group" style="max-height: 300px; overflow-y: auto;">
|
||||||
|
<!-- JS will populate this -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h5>Imaging Tests</h5>
|
||||||
|
<div id="imaging-tests-list" class="list-group" style="max-height: 300px; overflow-y: auto;">
|
||||||
|
<!-- JS will populate this -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3">
|
||||||
|
<button type="submit" class="btn btn-primary">Order Selected Tests</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
if (e.target.matches('.start-consultation-btn')) {
|
if (e.target.matches('.start-consultation-btn')) {
|
||||||
const patientId = e.target.dataset.patientId;
|
const visitId = e.target.dataset.visitId;
|
||||||
updatePatientStatus(patientId, 'In Progress');
|
updatePatientStatus(visitId, 'In Progress');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.target.matches('.prescribe-btn')) {
|
||||||
|
const visitId = e.target.dataset.visitId;
|
||||||
|
document.getElementById('prescriptionVisitId').value = visitId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.target.matches('.order-tests-btn')) {
|
||||||
|
const visitId = e.target.dataset.visitId;
|
||||||
|
document.getElementById('orderVisitId').value = visitId;
|
||||||
|
loadTestsForModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('submit', function(e) {
|
document.addEventListener('submit', function(e) {
|
||||||
if (e.target.matches('.notes-form')) {
|
if (e.target.matches('.notes-form')) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const patientId = e.target.dataset.patientId;
|
const visitId = e.target.dataset.visitId;
|
||||||
const notes = document.getElementById('notes-' + patientId).value;
|
const notes = document.getElementById('notes-' + visitId).value;
|
||||||
const service = document.getElementById('service-' + patientId).value;
|
const service = document.getElementById('service-' + visitId).value;
|
||||||
const cost = document.getElementById('cost-' + patientId).value;
|
const cost = document.getElementById('cost-' + visitId).value;
|
||||||
updatePatientStatus(patientId, 'Completed', notes, service, cost);
|
updatePatientStatus(visitId, 'Completed', notes, service, cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.target.matches('#prescriptionForm')) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(e.target);
|
||||||
|
|
||||||
|
fetch('add_prescription.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Prescription saved successfully!');
|
||||||
|
const modal = bootstrap.Modal.getInstance(document.getElementById('prescriptionModal'));
|
||||||
|
modal.hide();
|
||||||
|
e.target.reset();
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('An unexpected error occurred while saving the prescription.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.target.matches('#orderTestsForm')) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(e.target);
|
||||||
|
|
||||||
|
fetch('order_tests.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Tests ordered successfully!');
|
||||||
|
const modal = bootstrap.Modal.getInstance(document.getElementById('orderTestsModal'));
|
||||||
|
modal.hide();
|
||||||
|
e.target.reset();
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('An unexpected error occurred while ordering tests.');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function updatePatientStatus(patientId, status, notes = null, service = null, cost = null) {
|
function loadTestsForModal() {
|
||||||
|
fetch('get_tests.php')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
const labList = document.getElementById('lab-tests-list');
|
||||||
|
const imagingList = document.getElementById('imaging-tests-list');
|
||||||
|
labList.innerHTML = '';
|
||||||
|
imagingList.innerHTML = '';
|
||||||
|
|
||||||
|
data.lab_tests.forEach(test => {
|
||||||
|
labList.innerHTML += `
|
||||||
|
<label class="list-group-item">
|
||||||
|
<input class="form-check-input me-1" type="checkbox" name="lab_tests[]" value="${test.test_id}">
|
||||||
|
${test.test_name}
|
||||||
|
</label>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
data.imaging_tests.forEach(test => {
|
||||||
|
imagingList.innerHTML += `
|
||||||
|
<label class="list-group-item">
|
||||||
|
<input class="form-check-input me-1" type="checkbox" name="imaging_tests[]" value="${test.test_id}">
|
||||||
|
${test.test_name}
|
||||||
|
</label>`;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
alert('Could not load tests: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error loading tests:', error);
|
||||||
|
alert('An error occurred while fetching tests.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePatientStatus(visitId, status, notes = null, service = null, cost = null) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('patient_id', patientId);
|
formData.append('visit_id', visitId);
|
||||||
formData.append('status', status);
|
formData.append('status', status);
|
||||||
if (notes !== null) {
|
if (notes !== null) {
|
||||||
formData.append('notes', notes);
|
formData.append('notes', notes);
|
||||||
@ -193,18 +376,18 @@ function updatePatientStatus(patientId, status, notes = null, service = null, co
|
|||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
// Update status badge
|
// Update status badge
|
||||||
const statusBadge = document.getElementById('status-' + patientId);
|
const statusBadge = document.getElementById('status-' + visitId);
|
||||||
statusBadge.textContent = status;
|
statusBadge.textContent = status;
|
||||||
statusBadge.className = 'badge bg-' + data.status_class + '-soft';
|
statusBadge.className = 'badge bg-' + data.status_class + '-soft';
|
||||||
|
|
||||||
// Update action buttons/form
|
// Update action buttons/form
|
||||||
const actionCell = document.getElementById('action-cell-' + patientId);
|
const actionCell = document.getElementById('action-cell-' + visitId);
|
||||||
const notesRow = document.getElementById('notes-row-' + patientId);
|
const notesRow = document.getElementById('notes-row-' + visitId);
|
||||||
if (status === 'In Progress') {
|
if (status === 'In Progress') {
|
||||||
actionCell.innerHTML = '';
|
actionCell.innerHTML = get_action_buttons({ status: 'In Progress', visit_id: visitId });
|
||||||
notesRow.style.display = 'table-row';
|
notesRow.style.display = 'table-row';
|
||||||
} else if (status === 'Completed') {
|
} else if (status === 'Completed') {
|
||||||
actionCell.innerHTML = '<span class="text-success"><i class="bi bi-check-circle-fill me-1"></i>Completed</span>';
|
actionCell.innerHTML = get_action_buttons({ status: 'Completed', visit_id: visitId });
|
||||||
notesRow.style.display = 'none';
|
notesRow.style.display = 'none';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -233,16 +416,30 @@ function get_status_badge_class($status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_action_buttons($patient) {
|
function get_action_buttons($visit) {
|
||||||
switch ($patient['status']) {
|
$status = $visit['status'];
|
||||||
|
$visit_id = $visit['visit_id'];
|
||||||
|
$patient_id = $visit['patient_id'] ?? 0;
|
||||||
|
|
||||||
|
$buttons = '';
|
||||||
|
|
||||||
|
switch ($status) {
|
||||||
case 'Pending':
|
case 'Pending':
|
||||||
return '<button class="btn btn-sm btn-primary start-consultation-btn" data-patient-id="' . $patient['id'] . '"><i class="bi bi-play-circle me-1"></i>Start Consultation</button>';
|
$buttons .= '<button class="btn btn-sm btn-primary start-consultation-btn" data-visit-id="' . $visit_id . '"><i class="bi bi-play-circle me-1"></i>Start Consultation</button>';
|
||||||
|
break;
|
||||||
case 'In Progress':
|
case 'In Progress':
|
||||||
return ''; // Form is shown in a separate row
|
// The form is shown, but we can add a prescribe button here too
|
||||||
|
$buttons .= '<button class="btn btn-sm btn-info prescribe-btn" data-bs-toggle="modal" data-bs-target="#prescriptionModal" data-visit-id="' . $visit_id . '" data-patient-id="' . $patient_id . '"><i class="bi bi-pen me-1"></i>Prescribe</button>';
|
||||||
|
$buttons .= ' <button class="btn btn-sm btn-secondary order-tests-btn" data-bs-toggle="modal" data-bs-target="#orderTestsModal" data-visit-id="' . $visit_id . '"><i class="bi bi-eyedropper me-1"></i>Order Tests</button>';
|
||||||
|
break;
|
||||||
case 'Completed':
|
case 'Completed':
|
||||||
return '<span class="text-success"><i class="bi bi-check-circle-fill me-1"></i>Completed</span>';
|
$buttons .= '<span class="text-success"><i class="bi bi-check-circle-fill me-1"></i>Completed</span>';
|
||||||
|
$buttons .= ' <button class="btn btn-sm btn-outline-primary prescribe-btn" data-bs-toggle="modal" data-bs-target="#prescriptionModal" data-visit-id="' . $visit_id . '" data-patient-id="' . $patient_id . '"><i class="bi bi-pen me-1"></i>Add/View Prescription</button>';
|
||||||
|
$buttons .= ' <button class="btn btn-sm btn-outline-secondary order-tests-btn" data-bs-toggle="modal" data-bs-target="#orderTestsModal" data-visit-id="' . $visit_id . '"><i class="bi bi-eyedropper me-1"></i>Order/View Tests</button>';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return '';
|
break;
|
||||||
}
|
}
|
||||||
|
return $buttons;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
32
enter_results.php
Normal file
32
enter_results.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('receptionist'); // Or a new 'lab_technician' role
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
$response = ['success' => false, 'message' => 'Invalid request.'];
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$order_id = $_POST['order_id'] ?? null;
|
||||||
|
$results = $_POST['results'] ?? null;
|
||||||
|
|
||||||
|
if ($order_id && $results) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("UPDATE ordered_tests SET results = ?, status = 'Completed' WHERE order_id = ?");
|
||||||
|
|
||||||
|
if ($stmt->execute([$results, $order_id])) {
|
||||||
|
$response = ['success' => true, 'message' => 'Results submitted successfully.'];
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Failed to submit results.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Missing order ID or results.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
?>
|
||||||
18
get_tests.php
Normal file
18
get_tests.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$lab_tests = $pdo->query("SELECT test_id, test_name FROM lab_tests ORDER BY test_name ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$imaging_tests = $pdo->query("SELECT test_id, test_name FROM imaging_tests ORDER BY test_name ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'lab_tests' => $lab_tests,
|
||||||
|
'imaging_tests' => $imaging_tests
|
||||||
|
]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
93
invoice.php
93
invoice.php
@ -2,33 +2,64 @@
|
|||||||
require_once 'auth.php';
|
require_once 'auth.php';
|
||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
|
|
||||||
$patient_id = $_GET['id'] ?? null;
|
$visit_id = $_GET['visit_id'] ?? null;
|
||||||
|
|
||||||
if (!$patient_id) {
|
if (!$visit_id) {
|
||||||
die("Patient ID is required.");
|
die("Visit ID is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch patient and latest completed visit details
|
// Fetch visit details
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
// This query fetches the most recent completed visit for the patient
|
$stmt = $pdo->prepare(
|
||||||
$stmt = $pdo->prepare("
|
"SELECT
|
||||||
SELECT p.*, u.username as doctor_name
|
pv.*,
|
||||||
FROM patients p
|
p.patient_name,
|
||||||
JOIN users u ON p.doctor_id = u.id
|
p.address,
|
||||||
WHERE p.id = ? AND p.status = 'Completed'
|
p.phone_number,
|
||||||
ORDER BY p.updated_at DESC
|
u.username as doctor_name
|
||||||
LIMIT 1
|
FROM patient_visits pv
|
||||||
");
|
JOIN patients p ON pv.patient_id = p.id
|
||||||
$stmt->execute([$patient_id]);
|
JOIN users u ON pv.doctor_id = u.id
|
||||||
|
WHERE pv.visit_id = ?"
|
||||||
|
);
|
||||||
|
$stmt->execute([$visit_id]);
|
||||||
$visit = $stmt->fetch(PDO::FETCH_ASSOC);
|
$visit = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Fetch ordered tests for the visit
|
||||||
|
$tests_stmt = $pdo->prepare(
|
||||||
|
"SELECT
|
||||||
|
ot.test_type,
|
||||||
|
CASE
|
||||||
|
WHEN ot.test_type = 'lab' THEN lt.test_name
|
||||||
|
WHEN ot.test_type = 'imaging' THEN it.test_name
|
||||||
|
END as test_name,
|
||||||
|
CASE
|
||||||
|
WHEN ot.test_type = 'lab' THEN lt.cost
|
||||||
|
WHEN ot.test_type = 'imaging' THEN it.cost
|
||||||
|
END as cost
|
||||||
|
FROM ordered_tests ot
|
||||||
|
LEFT JOIN lab_tests lt ON ot.test_type = 'lab' AND ot.test_id = lt.test_id
|
||||||
|
LEFT JOIN imaging_tests it ON ot.test_type = 'imaging' AND ot.test_id = it.test_id
|
||||||
|
WHERE ot.visit_id = ?"
|
||||||
|
);
|
||||||
|
$tests_stmt->execute([$visit_id]);
|
||||||
|
$ordered_tests = $tests_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$visit = null;
|
$visit = null;
|
||||||
// Log error
|
$ordered_tests = [];
|
||||||
|
// In a real app, you would log this error
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$visit) {
|
if (!$visit) {
|
||||||
die("No completed visit found for this patient or an error occurred.");
|
die("No completed visit found for this ID or an error occurred.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate total bill
|
||||||
|
$total_bill = $visit['cost'];
|
||||||
|
foreach ($ordered_tests as $test) {
|
||||||
|
$total_bill += $test['cost'];
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -37,7 +68,7 @@ if (!$visit) {
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Invoice - <?php echo htmlspecialchars($visit['patient_id']); ?></title>
|
<title>Invoice - Visit #<?php echo htmlspecialchars($visit['visit_id']); ?></title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
@ -73,11 +104,11 @@ if (!$visit) {
|
|||||||
<h5>Billed To:</h5>
|
<h5>Billed To:</h5>
|
||||||
<p><strong><?php echo htmlspecialchars($visit['patient_name']); ?></strong></p>
|
<p><strong><?php echo htmlspecialchars($visit['patient_name']); ?></strong></p>
|
||||||
<p><?php echo htmlspecialchars($visit['address']); ?></p>
|
<p><?php echo htmlspecialchars($visit['address']); ?></p>
|
||||||
<p><?php echo htmlspecialchars($visit['phone']); ?></p>
|
<p><?php echo htmlspecialchars($visit['phone_number']); ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-5 text-md-end">
|
<div class="col-md-5 text-md-end">
|
||||||
<p><strong>Invoice #:</strong> INV-<?php echo htmlspecialchars($visit['id']); ?></p>
|
<p><strong>Invoice #:</strong> INV-<?php echo htmlspecialchars($visit['visit_id']); ?></p>
|
||||||
<p><strong>Date:</strong> <?php echo date("F j, Y", strtotime($visit['updated_at'])); ?></p>
|
<p><strong>Date:</strong> <?php echo date("F j, Y", strtotime($visit['visit_time'])); ?></p>
|
||||||
<p><strong>Status:</strong> <span class="badge bg-<?php echo $visit['payment_status'] === 'paid' ? 'success' : 'danger'; ?>"><?php echo ucfirst(htmlspecialchars($visit['payment_status'])); ?></span></p>
|
<p><strong>Status:</strong> <span class="badge bg-<?php echo $visit['payment_status'] === 'paid' ? 'success' : 'danger'; ?>"><?php echo ucfirst(htmlspecialchars($visit['payment_status'])); ?></span></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -88,24 +119,32 @@ if (!$visit) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
<thead>
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Service Rendered</th>
|
<th>Item</th>
|
||||||
<th class="text-end">Cost</th>
|
<th class="text-end">Cost</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars($visit['service_rendered']); ?></td>
|
<td><?php echo htmlspecialchars($visit['service_rendered']); ?> (Consultation)</td>
|
||||||
<td class="text-end">$<?php echo htmlspecialchars(number_format($visit['cost'], 2)); ?></td>
|
<td class="text-end">$<?php echo htmlspecialchars(number_format($visit['cost'], 2)); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<?php foreach ($ordered_tests as $test): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($test['test_name']); ?> (<?php echo ucfirst(htmlspecialchars($test['test_type'])); ?> Test)</td>
|
||||||
|
<td class="text-end">$<?php echo htmlspecialchars(number_format($test['cost'], 2)); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr class="fw-bold">
|
||||||
|
<td class="text-end">Total:</td>
|
||||||
|
<td class="text-end">$<?php echo htmlspecialchars(number_format($total_bill, 2)); ?></td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="total-section">
|
|
||||||
<h4>Total: $<?php echo htmlspecialchars(number_format($visit['cost'], 2)); ?></h4>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button onclick="window.print();" class="btn btn-primary print-btn"><i class="bi bi-printer"></i> Print Invoice</button>
|
<button onclick="window.print();" class="btn btn-primary print-btn"><i class="bi bi-printer"></i> Print Invoice</button>
|
||||||
<a href="billing.php" class="btn btn-secondary btn-back d-print-none" style="display: block; width: 150px; margin: 10px auto 0;">Back to Billing</a>
|
<a href="billing.php" class="btn btn-secondary btn-back d-print-none" style="display: block; width: 150px; margin: 10px auto 0;">Back to Billing</a>
|
||||||
|
|
||||||
|
|||||||
151
lab_imaging_config.php
Normal file
151
lab_imaging_config.php
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'auth.php';
|
||||||
|
|
||||||
|
// Ensure user is authenticated
|
||||||
|
check_login();
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
// Handle POST requests to add tests
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if (isset($_POST['add_lab_test'])) {
|
||||||
|
$test_name = trim($_POST['test_name']);
|
||||||
|
$cost = trim($_POST['cost']);
|
||||||
|
if (!empty($test_name) && is_numeric($cost)) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO lab_tests (test_name, cost) VALUES (?, ?)");
|
||||||
|
$stmt->execute([$test_name, $cost]);
|
||||||
|
$message = '<div class="alert alert-success">Lab test added successfully!</div>';
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-danger">Invalid input for lab test.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['add_imaging_test'])) {
|
||||||
|
$test_name = trim($_POST['test_name']);
|
||||||
|
$cost = trim($_POST['cost']);
|
||||||
|
if (!empty($test_name) && is_numeric($cost)) {
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO imaging_tests (test_name, cost) VALUES (?, ?)");
|
||||||
|
$stmt->execute([$test_name, $cost]);
|
||||||
|
$message = '<div class="alert alert-success">Imaging test added successfully!</div>';
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-danger">Invalid input for imaging test.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all tests
|
||||||
|
$lab_tests = $pdo->query("SELECT * FROM lab_tests ORDER BY test_name ASC")->fetchAll();
|
||||||
|
$imaging_tests = $pdo->query("SELECT * FROM imaging_tests ORDER BY test_name ASC")->fetchAll();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Lab & Imaging Test Configuration</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1>Test Configuration</h1>
|
||||||
|
<div>
|
||||||
|
<a href="reception.php" class="btn btn-outline-secondary">Back to Reception</a>
|
||||||
|
<a href="doctor_dashboard.php" class="btn btn-outline-primary">Back to Dashboard</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php echo $message; ?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<!-- Lab Tests Column -->
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3>Lab Tests</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form method="POST" action="">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col">
|
||||||
|
<input type="text" name="test_name" class="form-control" placeholder="Test Name" required>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<input type="number" step="0.01" name="cost" class="form-control" placeholder="Cost" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="submit" name="add_lab_test" class="btn btn-primary">Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Test Name</th>
|
||||||
|
<th>Cost</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($lab_tests as $test): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($test['test_name']); ?></td>
|
||||||
|
<td>$<?php echo htmlspecialchars(number_format($test['cost'], 2)); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Imaging Tests Column -->
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3>Imaging Tests</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form method="POST" action="">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col">
|
||||||
|
<input type="text" name="test_name" class="form-control" placeholder="Test Name" required>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<input type="number" step="0.01" name="cost" class="form-control" placeholder="Cost" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="submit" name="add_imaging_test" class="btn btn-success">Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Test Name</th>
|
||||||
|
<th>Cost</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($imaging_tests as $test): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($test['test_name']); ?></td>
|
||||||
|
<td>$<?php echo htmlspecialchars(number_format($test['cost'], 2)); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
199
lab_reports.php
Normal file
199
lab_reports.php
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('receptionist'); // For now, accessible by receptionists
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Fetch all ordered tests that are not yet completed
|
||||||
|
$pending_tests_stmt = $pdo->prepare(
|
||||||
|
"SELECT
|
||||||
|
ot.order_id,
|
||||||
|
ot.ordered_at,
|
||||||
|
ot.test_type,
|
||||||
|
ot.status,
|
||||||
|
p.patient_name,
|
||||||
|
p.id as patient_id,
|
||||||
|
CASE
|
||||||
|
WHEN ot.test_type = 'lab' THEN lt.test_name
|
||||||
|
WHEN ot.test_type = 'imaging' THEN it.test_name
|
||||||
|
END as test_name,
|
||||||
|
u.username as doctor_name
|
||||||
|
FROM ordered_tests ot
|
||||||
|
JOIN patient_visits pv ON ot.visit_id = pv.visit_id
|
||||||
|
JOIN patients p ON pv.patient_id = p.id
|
||||||
|
JOIN users u ON pv.doctor_id = u.id
|
||||||
|
LEFT JOIN lab_tests lt ON ot.test_type = 'lab' AND ot.test_id = lt.test_id
|
||||||
|
LEFT JOIN imaging_tests it ON ot.test_type = 'imaging' AND ot.test_id = it.test_id
|
||||||
|
WHERE ot.status = 'Ordered'
|
||||||
|
ORDER BY ot.ordered_at ASC"
|
||||||
|
);
|
||||||
|
$pending_tests_stmt->execute();
|
||||||
|
$pending_tests = $pending_tests_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Lab & Imaging Reports</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="page-wrapper">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<aside class="sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<a href="index.php" class="sidebar-brand">
|
||||||
|
<i class="bi bi-heart-pulse-fill"></i>
|
||||||
|
<span>ClinicFlow</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar-nav">
|
||||||
|
<a href="reception.php" class="nav-link">
|
||||||
|
<i class="bi bi-people-fill"></i>
|
||||||
|
<span>Reception</span>
|
||||||
|
</a>
|
||||||
|
<a href="doctor_dashboard.php" class="nav-link">
|
||||||
|
<i class="bi bi-person-fill"></i>
|
||||||
|
<span>Doctor</span>
|
||||||
|
</a>
|
||||||
|
<a href="lab_reports.php" class="nav-link active">
|
||||||
|
<i class="bi bi-file-earmark-medical"></i>
|
||||||
|
<span>Lab Reports</span>
|
||||||
|
</a>
|
||||||
|
<a href="pharmacy.php" class="nav-link">
|
||||||
|
<i class="bi bi-capsule-pill"></i>
|
||||||
|
<span>Pharmacy</span>
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
<div class="sidebar-footer">
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<i class="bi bi-person-circle me-2"></i>
|
||||||
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
||||||
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<main class="main-content">
|
||||||
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="h3 mb-0 text-gray-800">Pending Lab & Imaging Reports</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Date Ordered</th>
|
||||||
|
<th>Patient</th>
|
||||||
|
<th>Test Name</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Ordered By</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($pending_tests)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No pending tests found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($pending_tests as $test): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= date("d M, Y", strtotime($test['ordered_at'])) ?></td>
|
||||||
|
<td><a href="patient_profile.php?id=<?= $test['patient_id'] ?>"><?= htmlspecialchars($test['patient_name']) ?></a></td>
|
||||||
|
<td><?= htmlspecialchars($test['test_name']) ?></td>
|
||||||
|
<td><?= htmlspecialchars(ucfirst($test['test_type'])) ?></td>
|
||||||
|
<td>Dr. <?= htmlspecialchars($test['doctor_name'] ?? 'N/A') ?></td>
|
||||||
|
<td><span class="badge bg-warning-soft"><?= htmlspecialchars($test['status']) ?></span></td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-primary enter-results-btn" data-bs-toggle="modal" data-bs-target="#resultsModal" data-order-id="<?= $test['order_id'] ?>">Enter Results</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Enter Results Modal -->
|
||||||
|
<div class="modal fade" id="resultsModal" tabindex="-1" aria-labelledby="resultsModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="resultsModalLabel">Enter Test Results</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="resultsForm">
|
||||||
|
<input type="hidden" id="orderId" name="order_id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="resultsText" class="form-label">Results</label>
|
||||||
|
<textarea class="form-control" id="resultsText" name="results" rows="5" required></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Results & Complete</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (e.target.matches('.enter-results-btn')) {
|
||||||
|
const orderId = e.target.dataset.orderId;
|
||||||
|
document.getElementById('orderId').value = orderId;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('submit', function(e) {
|
||||||
|
if (e.target.matches('#resultsForm')) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(e.target);
|
||||||
|
const orderId = formData.get('order_id');
|
||||||
|
|
||||||
|
fetch('enter_results.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Results submitted successfully!');
|
||||||
|
const modal = bootstrap.Modal.getInstance(document.getElementById('resultsModal'));
|
||||||
|
modal.hide();
|
||||||
|
e.target.reset();
|
||||||
|
// Remove the row from the table
|
||||||
|
document.querySelector(`[data-order-id="${orderId}"]`).closest('tr').remove();
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('An unexpected error occurred while submitting the results.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
42
order_tests.php
Normal file
42
order_tests.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('doctor');
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
$response = ['success' => false, 'message' => 'Invalid request.'];
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$visit_id = $_POST['visit_id'] ?? null;
|
||||||
|
$lab_tests = $_POST['lab_tests'] ?? [];
|
||||||
|
$imaging_tests = $_POST['imaging_tests'] ?? [];
|
||||||
|
|
||||||
|
if ($visit_id && (!empty($lab_tests) || !empty($imaging_tests))) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO ordered_tests (visit_id, test_type, test_id) VALUES (?, ?, ?)");
|
||||||
|
|
||||||
|
foreach ($lab_tests as $test_id) {
|
||||||
|
$stmt->execute([$visit_id, 'lab', $test_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($imaging_tests as $test_id) {
|
||||||
|
$stmt->execute([$visit_id, 'imaging', $test_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo->commit();
|
||||||
|
$response = ['success' => true, 'message' => 'Tests ordered successfully.'];
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$pdo->rollBack();
|
||||||
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['message'] = 'Missing visit ID or no tests selected.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
?>
|
||||||
@ -19,16 +19,50 @@ if (!$patient) {
|
|||||||
die("Patient not found.");
|
die("Patient not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, fetch all visits for this patient using their patient_id
|
// Fetch all visits for this patient
|
||||||
$history_stmt = db()->prepare(
|
$visit_history_stmt = db()->prepare(
|
||||||
"SELECT p.*, d.username as doctor_name
|
"SELECT pv.*, u.username as doctor_name
|
||||||
FROM patients p
|
FROM patient_visits pv
|
||||||
LEFT JOIN users d ON p.doctor_id = d.id
|
LEFT JOIN users u ON pv.doctor_id = u.id
|
||||||
WHERE p.patient_id = ?
|
WHERE pv.patient_id = ?
|
||||||
ORDER BY p.created_at DESC"
|
ORDER BY pv.visit_time DESC"
|
||||||
);
|
);
|
||||||
$history_stmt->execute([$patient['patient_id']]);
|
$visit_history_stmt->execute([$patient_id]);
|
||||||
$visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
$visit_history = $visit_history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Fetch all prescriptions for this patient
|
||||||
|
$prescriptions_stmt = db()->prepare(
|
||||||
|
"SELECT pr.*, u.username as doctor_name
|
||||||
|
FROM prescriptions pr
|
||||||
|
LEFT JOIN users u ON pr.doctor_id = u.id
|
||||||
|
WHERE pr.patient_id = ?
|
||||||
|
ORDER BY pr.prescription_date DESC"
|
||||||
|
);
|
||||||
|
$prescriptions_stmt->execute([$patient_id]);
|
||||||
|
$prescriptions = $prescriptions_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Fetch all ordered tests for this patient
|
||||||
|
$ordered_tests_stmt = db()->prepare(
|
||||||
|
"SELECT
|
||||||
|
ot.ordered_at,
|
||||||
|
ot.test_type,
|
||||||
|
ot.status,
|
||||||
|
ot.results,
|
||||||
|
CASE
|
||||||
|
WHEN ot.test_type = 'lab' THEN lt.test_name
|
||||||
|
WHEN ot.test_type = 'imaging' THEN it.test_name
|
||||||
|
END as test_name,
|
||||||
|
u.username as doctor_name
|
||||||
|
FROM ordered_tests ot
|
||||||
|
JOIN patient_visits pv ON ot.visit_id = pv.visit_id
|
||||||
|
JOIN users u ON pv.doctor_id = u.id
|
||||||
|
LEFT JOIN lab_tests lt ON ot.test_type = 'lab' AND ot.test_id = lt.test_id
|
||||||
|
LEFT JOIN imaging_tests it ON ot.test_type = 'imaging' AND ot.test_id = it.test_id
|
||||||
|
WHERE pv.patient_id = ?
|
||||||
|
ORDER BY ot.ordered_at DESC"
|
||||||
|
);
|
||||||
|
$ordered_tests_stmt->execute([$patient_id]);
|
||||||
|
$ordered_tests = $ordered_tests_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -44,23 +78,26 @@ $visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="d-flex">
|
<div class="page-wrapper">
|
||||||
<!-- Sidebar -->
|
<!-- Sidebar -->
|
||||||
<div class="sidebar vh-100 d-flex flex-column p-3">
|
<aside class="sidebar">
|
||||||
<a href="reception.php" class="sidebar-brand d-flex align-items-center mb-4">
|
<div class="sidebar-header">
|
||||||
<i class="bi bi-heart-pulse-fill me-2"></i>
|
<a href="index.php" class="sidebar-brand">
|
||||||
<span class="fs-5 fw-bold">ClinicSystem</span>
|
<i class="bi bi-heart-pulse-fill"></i>
|
||||||
|
<span>ClinicFlow</span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="nav flex-column mb-auto">
|
</div>
|
||||||
<li class="nav-item">
|
<nav class="sidebar-nav">
|
||||||
<a href="reception.php" class="nav-link active">
|
<a href="reception.php" class="nav-link active">
|
||||||
<i class="bi bi-person-circle me-2"></i>
|
<i class="bi bi-people-fill"></i>
|
||||||
<span>Patients</span>
|
<span>Reception</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
<a href="doctor_dashboard.php" class="nav-link">
|
||||||
<!-- Add other nav items here -->
|
<i class="bi bi-person-fill"></i>
|
||||||
</ul>
|
<span>Doctor</span>
|
||||||
<hr>
|
</a>
|
||||||
|
</nav>
|
||||||
|
<div class="sidebar-footer">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="bi bi-person-circle me-2"></i>
|
<i class="bi bi-person-circle me-2"></i>
|
||||||
@ -71,9 +108,10 @@ $visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
<!-- Main Content -->
|
<!-- Main Content -->
|
||||||
<div class="main-content flex-grow-1 p-4">
|
<main class="main-content">
|
||||||
<header class="d-flex justify-content-between align-items-center mb-4">
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<h1 class="h3 mb-0 text-gray-800">Patient Profile</h1>
|
<h1 class="h3 mb-0 text-gray-800">Patient Profile</h1>
|
||||||
<a href="reception.php" class="btn btn-sm btn-outline-primary">
|
<a href="reception.php" class="btn btn-sm btn-outline-primary">
|
||||||
@ -91,16 +129,123 @@ $visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-4">
|
||||||
|
<p><strong>Patient ID:</strong> <?= htmlspecialchars($patient['patient_id']) ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
<p><strong>Phone:</strong> <?= htmlspecialchars($patient['phone_number']) ?></p>
|
<p><strong>Phone:</strong> <?= htmlspecialchars($patient['phone_number']) ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-4">
|
||||||
<p><strong>Address:</strong> <?= htmlspecialchars($patient['address']) ?></p>
|
<p><strong>Address:</strong> <?= htmlspecialchars($patient['address']) ?></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Prescription History -->
|
||||||
|
<div class="card shadow-sm mb-4">
|
||||||
|
<div class="card-header py-3">
|
||||||
|
<h6 class="m-0 font-weight-bold text-primary">
|
||||||
|
<i class="bi bi-file-earmark-medical me-2"></i>
|
||||||
|
Prescription History
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Doctor</th>
|
||||||
|
<th>Medication</th>
|
||||||
|
<th>Dosage</th>
|
||||||
|
<th>Frequency</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($prescriptions)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No prescription history found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($prescriptions as $prescription): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= date("d M, Y", strtotime($prescription['prescription_date'])) ?></td>
|
||||||
|
<td>Dr. <?= htmlspecialchars($prescription['doctor_name'] ?? 'N/A') ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['medication']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['dosage']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['frequency']) ?></td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $prescription['status'] === 'Dispensed' ? 'success' : 'warning'; ?>-soft"><?= htmlspecialchars($prescription['status']) ?></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="prescription_view.php?id=<?= $prescription['id'] ?>" class="btn btn-sm btn-outline-primary" target="_blank">
|
||||||
|
<i class="bi bi-printer me-1"></i> View/Print
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ordered Tests History -->
|
||||||
|
<div class="card shadow-sm mb-4">
|
||||||
|
<div class="card-header py-3">
|
||||||
|
<h6 class="m-0 font-weight-bold text-primary">
|
||||||
|
<i class="bi bi-eyedropper me-2"></i>
|
||||||
|
Ordered Tests History
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Date Ordered</th>
|
||||||
|
<th>Test Name</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Ordered By</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Results</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($ordered_tests)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="text-center">No tests have been ordered for this patient.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($ordered_tests as $index => $test): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= date("d M, Y", strtotime($test['ordered_at'])) ?></td>
|
||||||
|
<td><?= htmlspecialchars($test['test_name']) ?></td>
|
||||||
|
<td><?= htmlspecialchars(ucfirst($test['test_type'])) ?></td>
|
||||||
|
<td>Dr. <?= htmlspecialchars($test['doctor_name'] ?? 'N/A') ?></td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $test['status'] === 'Completed' ? 'success' : 'info'; ?>-soft"><?= htmlspecialchars($test['status']) ?></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php if ($test['status'] === 'Completed' && !empty($test['results'])): ?>
|
||||||
|
<button class="btn btn-sm btn-outline-secondary view-results-btn" data-bs-toggle="modal" data-bs-target="#viewResultsModal" data-results="<?= htmlspecialchars($test['results']) ?>">View Results</button>
|
||||||
|
<?php else: ?>
|
||||||
|
<span class="text-muted">N/A</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Visit History -->
|
<!-- Visit History -->
|
||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
<div class="card-header py-3">
|
<div class="card-header py-3">
|
||||||
@ -128,21 +273,10 @@ $visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php foreach ($visit_history as $visit): ?>
|
<?php foreach ($visit_history as $visit): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= date("d M, Y h:i A", strtotime($visit['created_at'])) ?></td>
|
<td><?= date("d M, Y h:i A", strtotime($visit['visit_time'])) ?></td>
|
||||||
<td><?= htmlspecialchars($visit['doctor_name'] ?? 'N/A') ?></td>
|
<td>Dr. <?= htmlspecialchars($visit['doctor_name'] ?? 'N/A') ?></td>
|
||||||
<td>
|
<td>
|
||||||
<?php
|
<span class="badge bg-primary-soft"><?= htmlspecialchars($visit['status']) ?></span>
|
||||||
$status = htmlspecialchars($visit['status']);
|
|
||||||
$badge_class = 'bg-secondary';
|
|
||||||
if ($status == 'Pending') {
|
|
||||||
$badge_class = 'bg-warning text-dark';
|
|
||||||
} elseif ($status == 'In Progress') {
|
|
||||||
$badge_class = 'bg-info text-dark';
|
|
||||||
} elseif ($status == 'Completed') {
|
|
||||||
$badge_class = 'bg-success';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<span class="badge <?= $badge_class ?>"><?= $status ?></span>
|
|
||||||
</td>
|
</td>
|
||||||
<td><?= nl2br(htmlspecialchars($visit['notes'] ?? 'No notes added.')) ?></td>
|
<td><?= nl2br(htmlspecialchars($visit['notes'] ?? 'No notes added.')) ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -154,9 +288,33 @@ $visit_history = $history_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
|
<!-- View Results Modal -->
|
||||||
|
<div class="modal fade" id="viewResultsModal" tabindex="-1" aria-labelledby="viewResultsModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-scrollable">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="viewResultsModalLabel">Test Results</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="resultsModalBody">
|
||||||
|
<!-- Results will be injected here by JS -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (e.target.matches('.view-results-btn')) {
|
||||||
|
const results = e.target.dataset.results;
|
||||||
|
document.getElementById('resultsModalBody').innerText = results;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
165
pharmacy.php
Normal file
165
pharmacy.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('receptionist'); // For now, accessible by receptionists/pharmacists
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Fetch all prescriptions that have not been dispensed
|
||||||
|
$pending_prescriptions_stmt = $pdo->prepare(
|
||||||
|
"SELECT
|
||||||
|
pr.id as prescription_id,
|
||||||
|
pr.prescription_date,
|
||||||
|
pr.medication,
|
||||||
|
pr.dosage,
|
||||||
|
pr.frequency,
|
||||||
|
p.patient_name,
|
||||||
|
p.id as patient_id,
|
||||||
|
u.username as doctor_name
|
||||||
|
FROM prescriptions pr
|
||||||
|
JOIN patients p ON pr.patient_id = p.id
|
||||||
|
JOIN users u ON pr.doctor_id = u.id
|
||||||
|
WHERE pr.status = 'Prescribed'
|
||||||
|
ORDER BY pr.prescription_date ASC"
|
||||||
|
);
|
||||||
|
$pending_prescriptions_stmt->execute();
|
||||||
|
$pending_prescriptions = $pending_prescriptions_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Pharmacy Dashboard</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="page-wrapper">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<aside class="sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<a href="index.php" class="sidebar-brand">
|
||||||
|
<i class="bi bi-heart-pulse-fill"></i>
|
||||||
|
<span>ClinicFlow</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar-nav">
|
||||||
|
<a href="reception.php" class="nav-link">
|
||||||
|
<i class="bi bi-people-fill"></i>
|
||||||
|
<span>Reception</span>
|
||||||
|
</a>
|
||||||
|
<a href="doctor_dashboard.php" class="nav-link">
|
||||||
|
<i class="bi bi-person-fill"></i>
|
||||||
|
<span>Doctor</span>
|
||||||
|
</a>
|
||||||
|
<a href="lab_reports.php" class="nav-link">
|
||||||
|
<i class="bi bi-file-earmark-medical"></i>
|
||||||
|
<span>Lab Reports</span>
|
||||||
|
</a>
|
||||||
|
<a href="pharmacy.php" class="nav-link active">
|
||||||
|
<i class="bi bi-capsule-pill"></i>
|
||||||
|
<span>Pharmacy</span>
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
<div class="sidebar-footer">
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<i class="bi bi-person-circle me-2"></i>
|
||||||
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
||||||
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<main class="main-content">
|
||||||
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h1 class="h3 mb-0 text-gray-800">Pharmacy - Pending Prescriptions</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Date Prescribed</th>
|
||||||
|
<th>Patient</th>
|
||||||
|
<th>Doctor</th>
|
||||||
|
<th>Medication</th>
|
||||||
|
<th>Dosage</th>
|
||||||
|
<th>Frequency</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($pending_prescriptions)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No pending prescriptions found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($pending_prescriptions as $prescription): ?>
|
||||||
|
<tr id="prescription-row-<?= $prescription['prescription_id'] ?>">
|
||||||
|
<td><?= date("d M, Y", strtotime($prescription['prescription_date'])) ?></td>
|
||||||
|
<td><a href="patient_profile.php?id=<?= $prescription['patient_id'] ?>"><?= htmlspecialchars($prescription['patient_name']) ?></a></td>
|
||||||
|
<td>Dr. <?= htmlspecialchars($prescription['doctor_name']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['medication']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['dosage']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['frequency']) ?></td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-success dispense-btn" data-prescription-id="<?= $prescription['prescription_id'] ?>">Dispense</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (e.target.matches('.dispense-btn')) {
|
||||||
|
if (!confirm('Are you sure you want to mark this prescription as dispensed?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prescriptionId = e.target.dataset.prescriptionId;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('prescription_id', prescriptionId);
|
||||||
|
|
||||||
|
fetch('dispense.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Prescription dispensed successfully!');
|
||||||
|
// Remove the row from the table
|
||||||
|
document.getElementById('prescription-row-' + prescriptionId).remove();
|
||||||
|
} else {
|
||||||
|
alert('Error: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('An unexpected error occurred.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
134
prescription_view.php
Normal file
134
prescription_view.php
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
if (!isset($_GET['id'])) {
|
||||||
|
die("No prescription ID provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$prescription_id = $_GET['id'];
|
||||||
|
|
||||||
|
// Fetch prescription details along with patient and doctor info
|
||||||
|
$stmt = db()->prepare(
|
||||||
|
"SELECT
|
||||||
|
pr.*,
|
||||||
|
p.patient_name, p.patient_id as patient_system_id, p.address, p.phone_number,
|
||||||
|
u.username as doctor_name
|
||||||
|
FROM prescriptions pr
|
||||||
|
JOIN patients p ON pr.patient_id = p.id
|
||||||
|
JOIN users u ON pr.doctor_id = u.id
|
||||||
|
WHERE pr.id = ?"
|
||||||
|
);
|
||||||
|
$stmt->execute([$prescription_id]);
|
||||||
|
$prescription = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$prescription) {
|
||||||
|
die("Prescription not found.");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Prescription for <?= htmlspecialchars($prescription['patient_name']) ?></title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body { background-color: #f8f9fa; }
|
||||||
|
.prescription-container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 40px auto;
|
||||||
|
padding: 30px;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.05);
|
||||||
|
}
|
||||||
|
.prescription-header, .prescription-footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
.prescription-header h2 { font-weight: 600; }
|
||||||
|
.patient-details, .doctor-details {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding: 15px;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
.medication-details { margin-top: 30px; }
|
||||||
|
@media print {
|
||||||
|
body { background-color: #fff; }
|
||||||
|
.prescription-container {
|
||||||
|
margin: 0;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.no-print { display: none; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="prescription-container">
|
||||||
|
<div class="prescription-header">
|
||||||
|
<h2>Prescription</h2>
|
||||||
|
<p class="text-muted">Date: <?= date("F j, Y", strtotime($prescription['prescription_date'])) ?></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-6">
|
||||||
|
<h5>Patient Details</h5>
|
||||||
|
<div class="patient-details">
|
||||||
|
<strong>Name:</strong> <?= htmlspecialchars($prescription['patient_name']) ?><br>
|
||||||
|
<strong>Patient ID:</strong> <?= htmlspecialchars($prescription['patient_system_id']) ?><br>
|
||||||
|
<strong>Address:</strong> <?= htmlspecialchars($prescription['address']) ?><br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<h5>Prescribing Doctor</h5>
|
||||||
|
<div class="doctor-details">
|
||||||
|
<strong>Dr. <?= htmlspecialchars($prescription['doctor_name']) ?></strong><br>
|
||||||
|
ClinicFlow Medical Center<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="medication-details">
|
||||||
|
<h4><i class="bi bi-file-medical"></i> Rx</h4>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Medication</th>
|
||||||
|
<th>Dosage</th>
|
||||||
|
<th>Frequency</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><strong><?= htmlspecialchars($prescription['medication']) ?></strong></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['dosage']) ?></td>
|
||||||
|
<td><?= htmlspecialchars($prescription['frequency']) ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php if (!empty($prescription['notes'])) : ?>
|
||||||
|
<div class="mt-3">
|
||||||
|
<strong>Notes:</strong>
|
||||||
|
<p class="text-muted"><?= nl2br(htmlspecialchars($prescription['notes'])) ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="prescription-footer mt-5">
|
||||||
|
<p class="text-muted small">This is a computer-generated prescription and does not require a physical signature.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center mt-4 no-print">
|
||||||
|
<button onclick="window.print();" class="btn btn-primary">Print Prescription</button>
|
||||||
|
<a href="patient_profile.php?id=<?= $prescription['patient_id'] ?>" class="btn btn-secondary">Back to Profile</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -43,6 +43,18 @@ $total_revenue = $pdo->query("SELECT SUM(total_fee) FROM patients WHERE status =
|
|||||||
<i class="bi bi-receipt"></i>
|
<i class="bi bi-receipt"></i>
|
||||||
<span>Billing</span>
|
<span>Billing</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="lab_imaging_config.php" class="nav-link">
|
||||||
|
<i class="bi bi-gear-fill"></i>
|
||||||
|
<span>Test Config</span>
|
||||||
|
</a>
|
||||||
|
<a href="lab_reports.php" class="nav-link">
|
||||||
|
<i class="bi bi-file-earmark-medical"></i>
|
||||||
|
<span>Lab Reports</span>
|
||||||
|
</a>
|
||||||
|
<a href="pharmacy.php" class="nav-link">
|
||||||
|
<i class="bi bi-capsule-pill"></i>
|
||||||
|
<span>Pharmacy</span>
|
||||||
|
</a>
|
||||||
<a href="doctor_dashboard.php" class="nav-link">
|
<a href="doctor_dashboard.php" class="nav-link">
|
||||||
<i class="bi bi-person-fill"></i>
|
<i class="bi bi-person-fill"></i>
|
||||||
<span>Doctor</span>
|
<span>Doctor</span>
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once 'auth.php';
|
||||||
|
require_role('doctor');
|
||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
@ -6,16 +8,17 @@ header('Content-Type: application/json');
|
|||||||
$response = ['success' => false, 'message' => 'Invalid request'];
|
$response = ['success' => false, 'message' => 'Invalid request'];
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$patient_id = $_POST['patient_id'] ?? null;
|
$visit_id = $_POST['visit_id'] ?? null;
|
||||||
$status = $_POST['status'] ?? null;
|
$status = $_POST['status'] ?? null;
|
||||||
$notes = $_POST['notes'] ?? null;
|
$notes = $_POST['notes'] ?? null;
|
||||||
$service_rendered = $_POST['service_rendered'] ?? null;
|
$service_rendered = $_POST['service_rendered'] ?? null;
|
||||||
$cost = $_POST['cost'] ?? null;
|
$cost = $_POST['cost'] ?? null;
|
||||||
|
|
||||||
if ($patient_id && $status) {
|
if ($visit_id && $status) {
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$sql = "UPDATE patients SET status = ?";
|
// All updates now go to the patient_visits table
|
||||||
|
$sql = "UPDATE patient_visits SET status = ?";
|
||||||
$params = [$status];
|
$params = [$status];
|
||||||
|
|
||||||
if ($notes !== null) {
|
if ($notes !== null) {
|
||||||
@ -33,28 +36,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$params[] = $cost;
|
$params[] = $cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When completing, set payment_status to unpaid
|
// When completing, set payment_status to unpaid for this specific visit
|
||||||
if ($status === 'Completed') {
|
if ($status === 'Completed') {
|
||||||
$sql .= ", payment_status = 'unpaid'";
|
$sql .= ", payment_status = 'unpaid'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= " WHERE id = ?";
|
$sql .= " WHERE visit_id = ?";
|
||||||
$params[] = $patient_id;
|
$params[] = $visit_id;
|
||||||
|
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
|
|
||||||
if ($stmt->execute($params)) {
|
if ($stmt->execute($params)) {
|
||||||
$response['success'] = true;
|
$response['success'] = true;
|
||||||
$response['message'] = 'Patient status updated successfully.';
|
$response['message'] = 'Visit status updated successfully.';
|
||||||
$response['status_class'] = get_status_badge_class($status);
|
$response['status_class'] = get_status_badge_class($status);
|
||||||
} else {
|
} else {
|
||||||
$response['message'] = 'Failed to update patient status.';
|
$response['message'] = 'Failed to update visit status.';
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$response['message'] = 'Database error: ' . $e->getMessage();
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$response['message'] = 'Missing patient ID or status.';
|
$response['message'] = 'Missing visit ID or status.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user