Compare commits

..

No commits in common. "ai-dev" and "master" have entirely different histories.

6 changed files with 158 additions and 403 deletions

View File

@ -1,63 +0,0 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/../db/db_setup.php';
$response = ['status' => 'error', 'message' => 'Invalid request'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = json_decode(file_get_contents('php://input'), true);
if (json_last_error() !== JSON_ERROR_NONE) {
$response['message'] = 'Invalid JSON received.';
echo json_encode($response);
exit;
}
// Basic validation
if (empty($input['first_name']) || empty($input['last_name']) || empty($input['date_of_birth']) || empty($input['gender']) || empty($input['contact_number'])) {
$response['message'] = 'All fields are required.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO patients (first_name, last_name, date_of_birth, gender, contact_number) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([
htmlspecialchars($input['first_name']),
htmlspecialchars($input['last_name']),
$input['date_of_birth'],
htmlspecialchars($input['gender']),
htmlspecialchars($input['contact_number'])
]);
$patientId = $pdo->lastInsertId();
$response = [
'status' => 'success',
'message' => 'Patient registered successfully.',
'patient' => [
'id' => $patientId,
'first_name' => htmlspecialchars($input['first_name']),
'last_name' => htmlspecialchars($input['last_name']),
'date_of_birth' => $input['date_of_birth'],
'gender' => htmlspecialchars($input['gender']),
'contact_number' => htmlspecialchars($input['contact_number']),
'created_at' => date('Y-m-d H:i:s')
]
];
} catch (PDOException $e) {
// In a real app, log this error. Don't expose it to the user.
$response['message'] = 'Database error: ' . $e->getMessage();
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, first_name, last_name, date_of_birth, gender, contact_number, DATE_FORMAT(created_at, '%Y-%m-%d') as registration_date FROM patients ORDER BY created_at DESC LIMIT 20");
$patients = $stmt->fetchAll();
$response = ['status' => 'success', 'patients' => $patients];
} catch (PDOException $e) {
$response['message'] = 'Database error: ' . $e->getMessage();
}
}
echo json_encode($response);

View File

@ -1,66 +0,0 @@
/* General Body Styles */
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #f8f9fa;
color: #212529;
}
/* Main container */
.container {
max-width: 1200px;
}
/* Header */
.header-title {
font-weight: 700;
color: #343a40;
}
/* Main card for content */
.card {
border: none;
border-radius: 0.5rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}
/* Table styles */
.table {
margin-bottom: 0;
}
.table thead th {
border-bottom-width: 1px;
font-weight: 600;
text-transform: uppercase;
font-size: 0.8rem;
letter-spacing: 0.5px;
color: #495057;
}
.table tbody tr:hover {
background-color: #f1f3f5;
}
/* Modal styles */
.modal-header {
border-bottom: none;
}
.modal-content {
border-radius: 0.5rem;
}
/* Toast notifications */
.toast {
border-radius: 0.375rem;
}
/* Button styles */
.btn-primary {
transition: all 0.2s ease-in-out;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

View File

@ -1,98 +0,0 @@
document.addEventListener('DOMContentLoaded', function () {
const registrationForm = document.getElementById('registrationForm');
const patientTableBody = document.getElementById('patientTableBody');
const toastContainer = document.getElementById('toastContainer');
// --- Function to show a toast notification ---
function showToast(message, type = 'success') {
const toastId = 'toast-' + Date.now();
const toastHTML = `
<div id="${toastId}" class="toast align-items-center text-white bg-${type === 'success' ? 'primary' : 'danger'} border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
${message}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
`;
toastContainer.innerHTML += toastHTML;
const toastElement = document.getElementById(toastId);
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
toast.show();
toastElement.addEventListener('hidden.bs.toast', () => toastElement.remove());
}
// --- Function to add a patient to the table ---
function addPatientToTable(patient) {
const row = document.createElement('tr');
row.innerHTML = `
<td>${patient.id}</td>
<td>${patient.first_name} ${patient.last_name}</td>
<td>${patient.date_of_birth}</td>
<td>${patient.gender}</td>
<td>${patient.contact_number}</td>
<td>${patient.registration_date || new Date().toISOString().split('T')[0]}</td>
`;
patientTableBody.prepend(row);
}
// --- Fetch and display initial patients ---
async function loadInitialPatients() {
try {
const response = await fetch('api/patients.php');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
if (data.status === 'success' && data.patients) {
patientTableBody.innerHTML = ''; // Clear existing rows
data.patients.forEach(addPatientToTable);
} else {
showToast(data.message || 'Could not load patients.', 'danger');
}
} catch (error) {
console.error('Fetch error:', error);
showToast('An error occurred while fetching patient data.', 'danger');
}
}
// --- Handle form submission ---
if (registrationForm) {
registrationForm.addEventListener('submit', async function (e) {
e.preventDefault();
const formData = new FormData(registrationForm);
const patientData = Object.fromEntries(formData.entries());
try {
const response = await fetch('api/patients.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(patientData)
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const result = await response.json();
if (result.status === 'success') {
showToast('Patient registered successfully!');
addPatientToTable(result.patient);
registrationForm.reset();
const modal = bootstrap.Modal.getInstance(document.getElementById('registerPatientModal'));
modal.hide();
} else {
showToast(result.message || 'Registration failed.', 'danger');
}
} catch (error) {
console.error('Submit error:', error);
showToast('An error occurred during registration.', 'danger');
}
});
}
// --- Initial load ---
loadInitialPatients();
});

View File

@ -1,42 +1,17 @@
<?php <?php
// Generated by setup_mariadb_project.sh — edit as needed.
define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'app_35776');
define('DB_USER', 'app_35776');
define('DB_PASS', 'd11073e7-b00a-4db1-8298-81fe6862c5a6');
// Database configuration function db() {
define('DB_HOST', getenv('DB_HOST') ?: '127.0.0.1'); static $pdo;
define('DB_PORT', getenv('DB_PORT') ?: '3306'); if (!$pdo) {
define('DB_NAME', getenv('DB_NAME') ?: 'main'); $pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
define('DB_USER', getenv('DB_USER') ?: 'admin'); PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
define('DB_PASS', getenv('DB_PASS') ?: 'admin'); PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
if (!function_exists('db')) { }
/** return $pdo;
* Establishes a PDO database connection.
*
* @return PDO The PDO database connection object.
* @throws PDOException If the connection fails.
*/
function db(): PDO
{
static $pdo = null;
if ($pdo === null) {
$dsn = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME . ';charset=utf8mb4';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
} catch (PDOException $e) {
// In a real app, you would log this error and show a generic error page.
// For development, it's okay to show the error.
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
}
return $pdo;
}
} }

View File

@ -1,22 +0,0 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
$sql = "
CREATE TABLE IF NOT EXISTS patients (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
date_of_birth DATE NOT NULL,
gender VARCHAR(10) NOT NULL,
contact_number VARCHAR(20) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);";
$pdo->exec($sql);
// You can add a success message here if running from CLI
// echo "Table 'patients' created successfully (if it didn't exist).";
} catch (PDOException $e) {
// In a real app, you'd log this error, not display it
die("DB ERROR: " . $e->getMessage());
}

259
index.php
View File

@ -1,121 +1,150 @@
<!DOCTYPE html> <?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en"> <html lang="en">
<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" />
<title>HIMS - Hospital Information Management System</title> <title>New Style</title>
<meta name="description" content="A comprehensive Hospital Information Management System built with Flatlogic Generator."> <?php
<meta name="keywords" content="hims, hospital management, patient registration, medical records, healthcare, flatlogic"> // Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
<!-- Social Media Meta Tags --> $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
<meta property="og:title" content="HIMS - Hospital Information Management System"> ?>
<meta property="og:description" content="A comprehensive Hospital Information Management System built with Flatlogic Generator."> <?php if ($projectDescription): ?>
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>"> <!-- Meta description -->
<meta name="twitter:card" content="summary_large_image"> <meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>"> <!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Bootstrap CSS --> <!-- Twitter meta tags -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> <?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Custom Fonts & CSS --> <!-- Open Graph image -->
<link rel="preconnect" href="https://fonts.googleapis.com"> <meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <!-- Twitter image -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> <meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>"> <?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head> </head>
<body> <body>
<main>
<main class="container mt-4"> <div class="card">
<header class="d-flex justify-content-between align-items-center mb-4"> <h1>Analyzing your requirements and generating your website…</h1>
<h1 class="header-title">Hospital Information Management System</h1> <div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<button class="btn btn-primary btn-lg" data-bs-toggle="modal" data-bs-target="#registerPatientModal"> <span class="sr-only">Loading…</span>
<i class="bi bi-person-plus-fill me-2"></i> Register New Patient </div>
</button> <p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
</header> <p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
<div class="card">
<div class="card-header bg-white">
<h5 class="card-title mb-0">Recently Registered Patients</h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-light">
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Date of Birth</th>
<th scope="col">Gender</th>
<th scope="col">Contact</th>
<th scope="col">Registration Date</th>
</tr>
</thead>
<tbody id="patientTableBody">
<!-- Patient rows will be injected here by JavaScript -->
<tr><td colspan="6" class="text-center p-4">Loading patient data...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</main>
<!-- Registration Modal -->
<div class="modal fade" id="registerPatientModal" tabindex="-1" aria-labelledby="registerPatientModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="registerPatientModalLabel">New Patient Registration</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="registrationForm">
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName" class="form-label">First Name</label>
<input type="text" class="form-control" id="firstName" name="first_name" required>
</div>
<div class="col-md-6 mb-3">
<label for="lastName" class="form-label">Last Name</label>
<input type="text" class="form-control" id="lastName" name="last_name" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="dob" class="form-label">Date of Birth</label>
<input type="date" class="form-control" id="dob" name="date_of_birth" required>
</div>
<div class="col-md-6 mb-3">
<label for="gender" class="form-label">Gender</label>
<select class="form-select" id="gender" name="gender" required>
<option value="" disabled selected>Select gender...</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="mb-3">
<label for="contactNumber" class="form-label">Contact Number</label>
<input type="tel" class="form-control" id="contactNumber" name="contact_number" required>
</div>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-secondary me-2" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Register Patient</button>
</div>
</form>
</div>
</div>
</div>
</div> </div>
</main>
<!-- Toast Container --> <footer>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11" id="toastContainer"></div> Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body> </body>
</html> </html>