Initial commit: ICU Patient Display Management System

This commit is contained in:
Atharv1705
2026-10-23 14:59:37 +05:30
commit b7b29ee033
86 changed files with 22707 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
+9
View File
@@ -0,0 +1,9 @@
<!-- BEGIN:nextjs-agent-rules -->
# This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
<!-- END:nextjs-agent-rules -->
+1
View File
@@ -0,0 +1 @@
@AGENTS.md
+13
View File
@@ -0,0 +1,13 @@
FROM node:20-alpine
WORKDIR /app
RUN corepack enable pnpm
COPY package.json pnpm-lock.yaml* ./
RUN pnpm install
COPY . .
CMD ["pnpm", "dev"]
+36
View File
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
+25
View File
@@ -0,0 +1,25 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-nova",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/app/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"menuColor": "default",
"menuAccent": "subtle",
"registries": {}
}
+18
View File
@@ -0,0 +1,18 @@
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
const eslintConfig = defineConfig([
...nextVitals,
...nextTs,
// Override default ignores of eslint-config-next.
globalIgnores([
// Default ignores of eslint-config-next:
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
]),
]);
export default eslintConfig;
+16
View File
@@ -0,0 +1,16 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
// Allow other devices on the network to receive live updates
allowedDevOrigins: ["192.168.0.31"],
async rewrites() {
return [
{
source: '/api/:path*',
destination: 'http://127.0.0.1:8000/api/:path*', // Proxy to FastAPI backend
},
];
},
};
export default nextConfig;
+9875
View File
File diff suppressed because it is too large Load Diff
+35
View File
@@ -0,0 +1,35 @@
{
"name": "frontend_tmp",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
},
"dependencies": {
"@base-ui/react": "^1.7.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^1.31.0",
"next": "16.3.1",
"next-themes": "^0.4.6",
"react": "19.2.8",
"react-dom": "19.2.8",
"shadcn": "^4.17.0",
"tailwind-merge": "^3.6.0",
"tw-animate-css": "^1.4.0"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "20.19.43",
"@types/react": "19.3.0",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "16.3.1",
"tailwindcss": "^4",
"typescript": "5.9.3"
},
"packageManager": "pnpm@11.21.0"
}
+6067
View File
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
allowBuilds:
sharp: false
unrs-resolver: false
minimumReleaseAgeExclude:
- '@next/env@16.3.1'
- '@next/eslint-plugin-next@16.3.1'
- '@next/swc-darwin-arm64@16.3.1'
- '@next/swc-darwin-x64@16.3.1'
- '@next/swc-linux-arm64-gnu@16.3.1'
- '@next/swc-linux-arm64-musl@16.3.1'
- '@next/swc-linux-x64-gnu@16.3.1'
- '@next/swc-linux-x64-musl@16.3.1'
- '@next/swc-win32-arm64-msvc@16.3.1'
- '@next/swc-win32-x64-msvc@16.3.1'
- eslint-config-next@16.3.1
- next@16.3.1
+7
View File
@@ -0,0 +1,7 @@
const config = {
plugins: {
"@tailwindcss/postcss": {},
},
};
export default config;
+1
View File
@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

+111
View File
@@ -0,0 +1,111 @@
"use client";
import { useState, useEffect } from "react";
import { fetchApi } from "@/lib/api";
import { ArrowLeft, MonitorPlay } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
export default function AddDisplayPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [rooms, setRooms] = useState([]);
useEffect(() => {
fetchApi('/rooms').then(data => setRooms(data)).catch(() => {});
}, []);
const [formData, setFormData] = useState({
device_id: "",
device_secret: "",
name: "",
room_id: ""
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
const payload = {
...formData,
room_id: formData.room_id ? parseInt(formData.room_id) : null,
};
await fetchApi("/displays", {
method: "POST",
body: JSON.stringify(payload)
});
router.push("/displays");
} catch (err: any) {
setError(err?.message || "Failed to register display.");
setLoading(false);
}
};
return (
<div className="max-w-xl mx-auto space-y-6">
<div className="flex items-center gap-4">
<Link href="/displays" className="p-2 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:bg-zinc-800 rounded-lg transition-colors">
<ArrowLeft size={20} />
</Link>
<div>
<h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
Register New Display
</h1>
<p className="text-zinc-600 dark:text-zinc-400 mt-1 text-sm">Add a new ESP32 e-paper display to the system.</p>
</div>
</div>
{error && (
<div className="bg-red-950 border border-red-900 text-red-400 p-3 rounded-lg text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 space-y-5 sm:space-y-6 shadow-sm">
<div className="space-y-4">
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Hardware Device ID *</label>
<input required type="text" name="device_id" value={formData.device_id} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" placeholder="e.g. ESP32-MAC-123" />
<p className="text-[11px] sm:text-xs text-zinc-500 mt-1">This is usually the MAC address or unique ID hardcoded in the ESP32.</p>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Device Secret Key *</label>
<input required type="text" name="device_secret" value={formData.device_secret} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" placeholder="Secret Token for Authentication" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Display Custom Name (Optional)</label>
<input type="text" name="name" value={formData.name} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. Ward A - Main Display" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Assign to Room (Optional)</label>
<select name="room_id" value={formData.room_id} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="">-- Unassigned --</option>
{rooms.map((room: any) => (
<option key={room.id} value={room.id}>{room.room_number} ({room.ward})</option>
))}
</select>
</div>
</div>
<div className="pt-4 border-t border-zinc-200 dark:border-zinc-800 flex flex-col-reverse sm:flex-row justify-end gap-2.5 sm:gap-3">
<Link href="/displays" className="w-full sm:w-auto px-4 py-2.5 rounded-lg text-center text-sm text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors">
Cancel
</Link>
<button type="submit" disabled={loading} className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-6 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm disabled:opacity-50 shadow-sm">
{loading ? "Registering..." : <><MonitorPlay size={18} /> Register Device</>}
</button>
</div>
</form>
</div>
);
}
+90
View File
@@ -0,0 +1,90 @@
"use client";
import { useEffect, useState } from "react";
import { fetchApi } from "@/lib/api";
import { Monitor, Plus, Wifi, Battery, Search } from "lucide-react";
import Link from "next/link";
export default function DisplaysPage() {
const [displays, setDisplays] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchApi('/displays')
.then(data => {
setDisplays(data);
setLoading(false);
})
.catch(err => {
console.error(err);
setLoading(false);
});
}, []);
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 sm:gap-4 bg-white/75 dark:bg-zinc-900/75 backdrop-blur-md border border-zinc-200/60 dark:border-zinc-800/60 px-4 sm:px-5 py-3 sm:py-3.5 rounded-xl shadow-xs">
<div>
<h1 className="text-xl sm:text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
<Monitor className="text-red-500" /> Displays
</h1>
<p className="text-xs sm:text-sm text-zinc-600 dark:text-zinc-400 mt-0.5">Manage ESP32 e-paper displays in the ward.</p>
</div>
<Link href="/displays/new" className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-4 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm shadow-sm">
<Plus size={18} /> Register Display
</Link>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4 sm:gap-6">
{loading ? (
<div className="col-span-full h-40 flex items-center justify-center border border-zinc-200 dark:border-zinc-800 rounded-xl bg-zinc-50/70 dark:bg-zinc-900/30 text-zinc-500 text-sm">
Loading displays...
</div>
) : displays.length === 0 ? (
<div className="col-span-full h-40 flex items-center justify-center border border-zinc-200 dark:border-zinc-800 rounded-xl bg-zinc-50/70 dark:bg-zinc-900/30 text-zinc-500 text-sm">
No displays registered.
</div>
) : (
displays.map((display: any) => (
<div key={display.id} className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-5 hover:border-zinc-700/60 transition-colors shadow-sm">
<div className="flex justify-between items-start mb-3 sm:mb-4">
<div>
<h3 className="font-semibold text-zinc-800 dark:text-zinc-200 text-base sm:text-lg flex items-center gap-2">
{display.name || `Display ${display.device_id.substring(0,6)}`}
</h3>
<p className="text-zinc-500 text-xs font-mono mt-0.5 sm:mt-1">ID: {display.device_id}</p>
</div>
<div className="flex items-center gap-1.5">
<span className={`w-2.5 h-2.5 rounded-full ${display.online_status ? 'bg-emerald-500 animate-pulse' : 'bg-zinc-500'}`}></span>
<span className="text-[10px] text-zinc-500 capitalize">{display.online_status ? 'Online' : 'Offline'}</span>
</div>
</div>
<div className="space-y-2.5 sm:space-y-3 mb-4 sm:mb-5">
<div className="flex justify-between text-xs sm:text-sm">
<span className="text-zinc-500">Room Assigned:</span>
<span className="text-zinc-700 dark:text-zinc-300 font-medium">{display.room_id || 'None'}</span>
</div>
<div className="flex justify-between text-xs sm:text-sm">
<span className="text-zinc-500">IP Address:</span>
<span className="text-zinc-700 dark:text-zinc-300 font-mono text-xs">{display.ip_address || 'Offline'}</span>
</div>
</div>
<div className="flex gap-4 border-t border-zinc-200 dark:border-zinc-800/80 pt-3 sm:pt-4">
<div className="flex items-center gap-1.5 text-xs text-zinc-600 dark:text-zinc-400">
<Wifi size={14} className={display.wifi_rssi && display.wifi_rssi > -70 ? "text-emerald-500" : "text-amber-500"} />
{display.wifi_rssi ? `${display.wifi_rssi} dBm` : 'N/A'}
</div>
<div className="flex items-center gap-1.5 text-xs text-zinc-600 dark:text-zinc-400">
<Battery size={14} className={display.battery && display.battery > 20 ? "text-emerald-500" : "text-red-500"} />
{display.battery ? `${display.battery}%` : 'N/A'}
</div>
</div>
</div>
))
)}
</div>
</div>
);
}␍
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+130
View File
@@ -0,0 +1,130 @@
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@custom-variant dark (&:is(.dark *));
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-sans);
--font-mono: var(--font-geist-mono);
--font-heading: var(--font-sans);
--color-sidebar-ring: var(--sidebar-ring);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar: var(--sidebar);
--color-chart-5: var(--chart-5);
--color-chart-4: var(--chart-4);
--color-chart-3: var(--chart-3);
--color-chart-2: var(--chart-2);
--color-chart-1: var(--chart-1);
--color-ring: var(--ring);
--color-input: var(--input);
--color-border: var(--border);
--color-destructive: var(--destructive);
--color-accent-foreground: var(--accent-foreground);
--color-accent: var(--accent);
--color-muted-foreground: var(--muted-foreground);
--color-muted: var(--muted);
--color-secondary-foreground: var(--secondary-foreground);
--color-secondary: var(--secondary);
--color-primary-foreground: var(--primary-foreground);
--color-primary: var(--primary);
--color-popover-foreground: var(--popover-foreground);
--color-popover: var(--popover);
--color-card-foreground: var(--card-foreground);
--color-card: var(--card);
--radius-sm: calc(var(--radius) * 0.6);
--radius-md: calc(var(--radius) * 0.8);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) * 1.4);
--radius-2xl: calc(var(--radius) * 1.8);
--radius-3xl: calc(var(--radius) * 2.2);
--radius-4xl: calc(var(--radius) * 2.6);
}
:root {
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
--secondary: oklch(0.97 0 0);
--secondary-foreground: oklch(0.205 0 0);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
--chart-1: oklch(0.87 0 0);
--chart-2: oklch(0.556 0 0);
--chart-3: oklch(0.439 0 0);
--chart-4: oklch(0.371 0 0);
--chart-5: oklch(0.269 0 0);
--radius: 0.625rem;
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.205 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
--secondary: oklch(0.269 0 0);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.269 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.87 0 0);
--chart-2: oklch(0.556 0 0);
--chart-3: oklch(0.439 0 0);
--chart-4: oklch(0.371 0 0);
--chart-5: oklch(0.269 0 0);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.556 0 0);
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
html {
@apply font-sans;
}
}
+33
View File
@@ -0,0 +1,33 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import DashboardLayout from "@/components/DashboardLayout";
import { ThemeProvider } from "@/components/ThemeProvider";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "ICU Patient Display Management System",
description: "Dashboard for managing ICU e-Paper displays",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en" suppressHydrationWarning>
<body
className={`${inter.className} h-screen w-screen overflow-hidden text-zinc-900 dark:text-zinc-100 selection:bg-red-900 selection:text-red-100 bg-cover bg-center bg-no-repeat bg-fixed relative`}
style={{ backgroundImage: "url('/hospital-bg.png')" }}
>
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem={false}>
<DashboardLayout>
{children}
</DashboardLayout>
</ThemeProvider>
</body>
</html>
);
}
+102
View File
@@ -0,0 +1,102 @@
"use client";
import { useState } from "react";
import { fetchApi } from "@/lib/api";
import { Lock, Mail, ArrowRight } from "lucide-react";
export default function LoginPage() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
const formData = new URLSearchParams();
formData.append("username", email);
formData.append("password", password);
const res = await fetchApi("/auth/login", {
method: "POST",
body: formData, // Passing the URLSearchParams object directly allows fetch to set the correct Content-Type
});
if (res.access_token) {
localStorage.setItem("token", res.access_token);
// We'd typically redirect to / here, but we are keeping the dashboard open.
window.location.href = "/";
} else {
setError("Invalid response from server.");
}
} catch (err: any) {
setError(err?.message || "Failed to login. Check credentials.");
} finally {
setLoading(false);
}
};
return (
<div className="flex min-h-full w-full items-center justify-center bg-transparent p-4 sm:p-6">
<div className="relative z-10 w-full max-w-md bg-white/85 dark:bg-zinc-950/85 border border-zinc-200/80 dark:border-zinc-800/80 p-6 sm:p-8 rounded-2xl shadow-2xl backdrop-blur-md my-auto">
<div className="text-center mb-6 sm:mb-8">
<div className="flex justify-center mb-4 sm:mb-6">
<img src="/logo.png" alt="DMH Logo" className="h-12 sm:h-16 w-auto object-contain" />
</div>
<h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-100 tracking-tight">Staff Login</h1>
<p className="text-zinc-600 dark:text-zinc-400 mt-2 text-sm">Sign in to access the ICU management system</p>
</div>
{error && (
<div className="bg-red-950 border border-red-900 text-red-400 p-3 rounded-lg text-sm mb-6 text-center">
{error}
</div>
)}
<form onSubmit={handleLogin} className="space-y-5">
<div>
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Email Address</label>
<div className="relative">
<Mail className="absolute left-3 top-2.5 text-zinc-500 dark:text-zinc-500" size={18} />
<input
type="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg pl-10 pr-4 py-2 focus:outline-none focus:border-red-500 transition-colors"
placeholder="nurse@hospital.com"
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Password</label>
<div className="relative">
<Lock className="absolute left-3 top-2.5 text-zinc-500 dark:text-zinc-500" size={18} />
<input
type="password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg pl-10 pr-4 py-2 focus:outline-none focus:border-red-500 transition-colors"
placeholder="••••••••"
/>
</div>
</div>
<button
type="submit"
disabled={loading}
className="w-full bg-red-600 hover:bg-red-500 text-white font-medium py-2.5 rounded-lg transition-colors flex items-center justify-center gap-2 mt-2 disabled:opacity-50"
>
{loading ? "Authenticating..." : "Sign In"}
{!loading && <ArrowRight size={18} />}
</button>
</form>
</div>
</div>
);
}
+133
View File
@@ -0,0 +1,133 @@
"use client";
import { useEffect, useState } from "react";
import { fetchApi } from "@/lib/api";
import { HeartPulse, Activity, AlertCircle, MonitorPlay } from "lucide-react";
export default function Dashboard() {
const [stats, setStats] = useState({ patients: 0, displays: 0, critical: 0 });
const [recentPatients, setRecentPatients] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
// We fetch patients and displays to get basic counts.
// Real implementation would have a dedicated /stats endpoint.
Promise.all([
fetchApi('/patients').catch(() => []),
fetchApi('/displays').catch(() => [])
]).then(([patients, displays]) => {
const pList = patients || [];
const dList = displays || [];
setStats({
patients: pList.length,
displays: dList.length,
critical: pList.filter((p: any) => p.status === 'Critical').length
});
const sorted = [...pList].sort((a: any, b: any) => {
return new Date(b.last_updated).getTime() - new Date(a.last_updated).getTime();
});
setRecentPatients(sorted.slice(0, 5));
setLoading(false);
});
}, []);
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-end gap-2 bg-white/75 dark:bg-zinc-900/75 backdrop-blur-md border border-zinc-200/60 dark:border-zinc-800/60 px-4 sm:px-5 py-3 sm:py-3.5 rounded-xl shadow-xs">
<div>
<h1 className="text-xl sm:text-2xl font-bold text-zinc-900 dark:text-zinc-100 tracking-tight">ICU Overview</h1>
<p className="text-xs sm:text-sm text-zinc-600 dark:text-zinc-400 mt-0.5">Live status of patients and monitoring displays.</p>
</div>
</div>
{loading ? (
<div className="h-36 sm:h-40 flex items-center justify-center border border-zinc-200 dark:border-zinc-800 rounded-xl bg-zinc-50/70 dark:bg-zinc-900/30">
<Activity className="animate-pulse text-red-500" size={32} />
</div>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6">
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 p-5 sm:p-6 rounded-xl relative overflow-hidden group shadow-sm">
<div className="absolute top-0 right-0 p-4 sm:p-6 opacity-20 group-hover:scale-110 group-hover:opacity-30 transition-all duration-500">
<HeartPulse size={64} className="text-red-500 sm:w-20 sm:h-20" />
</div>
<div className="relative z-10">
<h3 className="text-zinc-500 dark:text-zinc-400 font-medium text-xs sm:text-sm">Total Patients</h3>
<p className="text-3xl sm:text-4xl font-bold text-zinc-900 dark:text-zinc-100 mt-1.5 sm:mt-2">{stats.patients}</p>
</div>
</div>
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 p-5 sm:p-6 rounded-xl relative overflow-hidden group shadow-sm">
<div className="absolute top-0 right-0 p-4 sm:p-6 opacity-20 group-hover:scale-110 group-hover:opacity-30 transition-all duration-500">
<MonitorPlay size={64} className="text-emerald-500 sm:w-20 sm:h-20" />
</div>
<div className="relative z-10">
<h3 className="text-zinc-500 dark:text-zinc-400 font-medium text-xs sm:text-sm">Active Displays</h3>
<p className="text-3xl sm:text-4xl font-bold text-zinc-900 dark:text-zinc-100 mt-1.5 sm:mt-2">{stats.displays}</p>
</div>
</div>
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 p-5 sm:p-6 rounded-xl relative overflow-hidden group shadow-sm sm:col-span-2 lg:col-span-1">
<div className="absolute top-0 right-0 p-4 sm:p-6 opacity-20 group-hover:scale-110 group-hover:opacity-30 transition-all duration-500">
<AlertCircle size={64} className="text-amber-500 sm:w-20 sm:h-20" />
</div>
<div className="relative z-10">
<h3 className="text-zinc-500 dark:text-zinc-400 font-medium text-xs sm:text-sm">Critical Patients</h3>
<p className="text-3xl sm:text-4xl font-bold text-red-600 dark:text-red-400 mt-1.5 sm:mt-2">{stats.critical}</p>
</div>
</div>
</div>
)}
{/* Recent Updates Table */}
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl overflow-hidden shadow-sm mt-6 sm:mt-8">
<div className="px-4 sm:px-6 py-3.5 sm:py-4 border-b border-zinc-200 dark:border-zinc-800 flex justify-between items-center">
<h2 className="text-base sm:text-lg font-medium text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
<Activity className="text-red-500 w-4 h-4 sm:w-5 sm:h-5" />
Recent Updates
</h2>
</div>
<div className="overflow-x-auto">
<table className="min-w-[520px] w-full text-left text-xs sm:text-sm text-zinc-700 dark:text-zinc-300">
<thead className="bg-white/80 dark:bg-zinc-950/50 text-zinc-600 dark:text-zinc-400 border-b border-zinc-200 dark:border-zinc-800 uppercase text-[10px] sm:text-xs font-semibold">
<tr>
<th className="px-4 sm:px-6 py-3">Time</th>
<th className="px-4 sm:px-6 py-3">Patient</th>
<th className="px-4 sm:px-6 py-3">Room</th>
<th className="px-4 sm:px-6 py-3">Status</th>
</tr>
</thead>
<tbody>
{recentPatients.length === 0 ? (
<tr>
<td colSpan={4} className="px-4 sm:px-6 py-6 text-center text-zinc-500">No recent updates found.</td>
</tr>
) : (
recentPatients.map((patient: any) => (
<tr key={patient.id} className="border-b border-zinc-200/50 dark:border-zinc-800/50 hover:bg-zinc-100 dark:hover:bg-zinc-800/20 transition-colors">
<td className="px-4 sm:px-6 py-3 text-zinc-500 whitespace-nowrap">{new Date(patient.last_updated).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</td>
<td className="px-4 sm:px-6 py-3 font-medium text-zinc-800 dark:text-zinc-200">
<span>{patient.patient_name}</span>
<span className="text-zinc-500 text-xs ml-1.5 font-normal">({patient.mrn})</span>
</td>
<td className="px-4 sm:px-6 py-3">{patient.room_id || 'Unassigned'}</td>
<td className="px-4 sm:px-6 py-3 whitespace-nowrap">
<span className={`px-2 py-0.5 rounded text-xs font-medium ${
patient.status === 'Critical' ? 'text-red-500 bg-red-500/10 dark:text-red-400 dark:bg-red-400/10' :
patient.status === 'Stable' ? 'text-emerald-600 bg-emerald-500/10 dark:text-emerald-400 dark:bg-emerald-400/10' :
'text-zinc-600 dark:text-zinc-400 bg-zinc-400/10'
}`}>
{patient.status}
</span>
</td>
</tr>
))
)}
</tbody>
</table>
</div>
</div>
</div>
);
}
+201
View File
@@ -0,0 +1,201 @@
"use client";
import { useState, useEffect } from "react";
import { fetchApi } from "@/lib/api";
import { ArrowLeft, Save } from "lucide-react";
import Link from "next/link";
import { useRouter, useParams } from "next/navigation";
export default function EditPatientPage() {
const router = useRouter();
const params = useParams();
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const [error, setError] = useState("");
const [rooms, setRooms] = useState<any[]>([]);
const [formData, setFormData] = useState({
mrn: "",
patient_name: "",
age: "",
gender: "",
blood_group: "",
diagnosis: "",
status: "",
doctor_name: "",
room_id: "",
notes: "",
food_instructions: "",
visiting_rules: "",
visiting_hours: "",
restrictions: ""
});
useEffect(() => {
fetchApi('/rooms').then(data => setRooms(data)).catch(() => {});
if (params.id) {
fetchApi(`/patients/${params.id}`)
.then(data => {
setFormData({
mrn: data.mrn || "",
patient_name: data.patient_name || "",
age: data.age?.toString() || "",
gender: data.gender || "",
blood_group: data.blood_group || "",
diagnosis: data.diagnosis || "",
status: data.status || "",
doctor_name: data.doctor_name || "",
room_id: data.room_id?.toString() || "",
notes: data.notes || "",
food_instructions: data.food_instructions || "No outside food allowed",
visiting_rules: data.visiting_rules || "2 times visits",
visiting_hours: data.visiting_hours || "9 - 11 AM, 4 - 6 PM",
restrictions: data.restrictions || "Dogs are not allowed"
});
setLoading(false);
})
.catch(err => {
setError("Failed to load patient data.");
setLoading(false);
});
}
}, [params.id]);
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setSaving(true);
setError("");
try {
const payload = {
...formData,
age: parseInt(formData.age),
room_id: formData.room_id ? parseInt(formData.room_id) : null,
};
await fetchApi(`/patients/${params.id}`, {
method: "PUT",
body: JSON.stringify(payload)
});
router.push("/patients");
} catch (err: any) {
setError(err.message || "Failed to update patient.");
setSaving(false);
}
};
if (loading) return <div className="p-8 text-center text-zinc-500 dark:text-zinc-500">Loading...</div>;
return (
<div className="max-w-3xl mx-auto space-y-6">
<div className="flex items-center gap-4">
<Link href="/patients" className="p-2 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:bg-zinc-800 rounded-lg transition-colors">
<ArrowLeft size={20} />
</Link>
<div>
<h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
Edit Patient
</h1>
<p className="text-zinc-600 dark:text-zinc-400 mt-1 text-sm">Update {formData.patient_name}'s records.</p>
</div>
</div>
{error && (
<div className="bg-red-950 border border-red-900 text-red-400 p-3 rounded-lg text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 space-y-5 sm:space-y-6 shadow-sm">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6">
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">MRN *</label>
<input required type="text" name="mrn" value={formData.mrn} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Full Name *</label>
<input required type="text" name="patient_name" value={formData.patient_name} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Age *</label>
<input required type="number" name="age" value={formData.age} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Gender *</label>
<select required name="gender" value={formData.gender} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Blood Group</label>
<input type="text" name="blood_group" value={formData.blood_group} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Primary Diagnosis</label>
<input type="text" name="diagnosis" value={formData.diagnosis} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Status *</label>
<select required name="status" value={formData.status} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="Stable">Stable</option>
<option value="Observation">Observation</option>
<option value="Critical">Critical</option>
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Attending Doctor</label>
<input type="text" name="doctor_name" value={formData.doctor_name} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" />
</div>
<div className="md:col-span-2">
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Assign to Room (Optional)</label>
<select name="room_id" value={formData.room_id} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="">-- Unassigned --</option>
{rooms.map((room: any) => (
<option key={room.id} value={room.id}>{room.room_number} ({room.ward})</option>
))}
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Food / Dietary Instructions</label>
<input type="text" name="food_instructions" value={formData.food_instructions} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. No outside food allowed" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Visiting Policy / Frequency</label>
<input type="text" name="visiting_rules" value={formData.visiting_rules} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. 2 times visits" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Visiting Hours</label>
<input type="text" name="visiting_hours" value={formData.visiting_hours} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. 9 - 11 AM, 4 - 6 PM" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Restrictions & Guidelines</label>
<input type="text" name="restrictions" value={formData.restrictions} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. Dogs are not allowed / Mask required" />
</div>
<div className="md:col-span-2">
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Additional Description / Notes</label>
<textarea name="notes" value={formData.notes} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm min-h-[100px]" placeholder="Enter any additional details, allergies, or notes..."></textarea>
</div>
</div>
<div className="pt-4 border-t border-zinc-200 dark:border-zinc-800 flex flex-col-reverse sm:flex-row justify-end gap-2.5 sm:gap-3">
<Link href="/patients" className="w-full sm:w-auto px-4 py-2.5 rounded-lg text-center text-sm text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors">
Cancel
</Link>
<button type="submit" disabled={saving} className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-6 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm disabled:opacity-50 shadow-sm">
{saving ? "Saving..." : <><Save size={18} /> Update Patient</>}
</button>
</div>
</form>
</div>
);
}
+177
View File
@@ -0,0 +1,177 @@
"use client";
import { useState, useEffect } from "react";
import { fetchApi } from "@/lib/api";
import { ArrowLeft, UserPlus } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
export default function AddPatientPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [rooms, setRooms] = useState<any[]>([]);
useEffect(() => {
fetchApi('/rooms').then(data => setRooms(data)).catch(() => {});
}, []);
const [formData, setFormData] = useState({
mrn: "",
patient_name: "",
age: "",
gender: "Male",
blood_group: "A+",
diagnosis: "",
status: "Stable",
doctor_name: "",
room_id: "",
notes: "",
food_instructions: "No outside food allowed",
visiting_rules: "2 times visits",
visiting_hours: "9 - 11 AM, 4 - 6 PM",
restrictions: "Dogs are not allowed"
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
const payload = {
...formData,
age: formData.age ? parseInt(formData.age) : null,
room_id: formData.room_id ? parseInt(formData.room_id) : null,
};
await fetchApi("/patients", {
method: "POST",
body: JSON.stringify(payload)
});
router.push("/patients");
} catch (err: any) {
setError(err?.message || "Failed to add patient.");
setLoading(false);
}
};
return (
<div className="max-w-2xl mx-auto space-y-6">
<div className="flex items-center gap-4">
<Link href="/patients" className="p-2 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:bg-zinc-800 rounded-lg transition-colors">
<ArrowLeft size={20} />
</Link>
<div>
<h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
Add New Patient
</h1>
<p className="text-zinc-600 dark:text-zinc-400 mt-1 text-sm">Enter the patient's admission details below.</p>
</div>
</div>
{error && (
<div className="bg-red-950 border border-red-900 text-red-400 p-3 rounded-lg text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 space-y-5 sm:space-y-6 shadow-sm">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6">
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Medical Record Number (MRN) *</label>
<input required type="text" name="mrn" value={formData.mrn} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" placeholder="e.g. MRN-10293" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Full Name *</label>
<input required type="text" name="patient_name" value={formData.patient_name} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="John Doe" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Age</label>
<input type="number" name="age" value={formData.age} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="45" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Gender</label>
<select name="gender" value={formData.gender} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Blood Group</label>
<select name="blood_group" value={formData.blood_group} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="A+">A+</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B-">B-</option>
<option value="O+">O+</option>
<option value="O-">O-</option>
<option value="AB+">AB+</option>
<option value="AB-">AB-</option>
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Current Status</label>
<select name="status" value={formData.status} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="Stable">Stable</option>
<option value="Critical">Critical</option>
<option value="Observation">Observation</option>
</select>
</div>
<div className="md:col-span-2">
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Diagnosis / Reason for Admission</label>
<input type="text" name="diagnosis" value={formData.diagnosis} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. Post-operative care" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Attending Doctor</label>
<input type="text" name="doctor_name" value={formData.doctor_name} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="Dr. Smith" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Assign to Room (Optional)</label>
<select name="room_id" value={formData.room_id} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm">
<option value="">-- Unassigned --</option>
{rooms.map((room: any) => (
<option key={room.id} value={room.id}>{room.room_number} ({room.ward})</option>
))}
</select>
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Food / Dietary Instructions</label>
<input type="text" name="food_instructions" value={formData.food_instructions} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. No outside food allowed" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Visiting Policy / Frequency</label>
<input type="text" name="visiting_rules" value={formData.visiting_rules} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. 2 times visits" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Visiting Hours</label>
<input type="text" name="visiting_hours" value={formData.visiting_hours} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. 9 - 11 AM, 4 - 6 PM" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Restrictions & Guidelines</label>
<input type="text" name="restrictions" value={formData.restrictions} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. Dogs are not allowed / Mask required" />
</div>
<div className="md:col-span-2">
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Additional Description / Notes</label>
<textarea name="notes" value={formData.notes} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm min-h-[100px]" placeholder="Enter any additional details, allergies, or notes..."></textarea>
</div>
</div>
<div className="pt-4 border-t border-zinc-200 dark:border-zinc-800 flex flex-col-reverse sm:flex-row justify-end gap-2.5 sm:gap-3">
<Link href="/patients" className="w-full sm:w-auto px-4 py-2.5 rounded-lg text-center text-sm text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors">
Cancel
</Link>
<button type="submit" disabled={loading} className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-6 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm disabled:opacity-50 shadow-sm">
{loading ? "Saving..." : <><UserPlus size={18} /> Save Patient</>}
</button>
</div>
</form>
</div>
);
}
+131
View File
@@ -0,0 +1,131 @@
"use client";
import { useEffect, useState } from "react";
import { fetchApi } from "@/lib/api";
import { Users, Plus, Edit2, Search, Trash2 } from "lucide-react";
import Link from "next/link";
export default function PatientsPage() {
const [patients, setPatients] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
const [search, setSearch] = useState("");
useEffect(() => {
fetchApi('/patients')
.then(data => {
setPatients(data || []);
setLoading(false);
})
.catch(err => {
console.error(err);
setLoading(false);
});
}, []);
const handleDelete = async (id: number) => {
if (!confirm("Are you sure you want to delete this patient?")) return;
try {
await fetchApi(`/patients/${id}`, { method: 'DELETE' });
setPatients(patients.filter((p: any) => p.id !== id));
} catch (err) {
alert("Failed to delete patient");
}
};
const filtered = patients.filter((p: any) =>
p.patient_name?.toLowerCase().includes(search.toLowerCase()) ||
p.mrn?.toLowerCase().includes(search.toLowerCase())
);
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 sm:gap-4 bg-white/75 dark:bg-zinc-900/75 backdrop-blur-md border border-zinc-200/60 dark:border-zinc-800/60 px-4 sm:px-5 py-3 sm:py-3.5 rounded-xl shadow-xs">
<div>
<h1 className="text-xl sm:text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
<Users className="text-red-500" /> Patients
</h1>
<p className="text-xs sm:text-sm text-zinc-600 dark:text-zinc-400 mt-0.5">Manage ICU patients, vitals, and records.</p>
</div>
<Link href="/patients/new" className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-4 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm shadow-sm">
<Plus size={18} /> Add Patient
</Link>
</div>
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl overflow-hidden shadow-sm">
<div className="p-3 sm:p-4 border-b border-zinc-200 dark:border-zinc-800 flex justify-between items-center bg-zinc-100/50 dark:bg-zinc-900/50">
<div className="flex items-center bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 rounded-lg px-3 py-2 w-full sm:w-72">
<Search className="text-zinc-400 mr-2 shrink-0" size={16} />
<input
type="text"
placeholder="Search MRN or Name..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="bg-transparent border-none outline-none text-zinc-700 dark:text-zinc-300 placeholder-zinc-500 text-xs sm:text-sm w-full"
/>
</div>
</div>
<div className="overflow-x-auto">
<table className="min-w-[640px] w-full text-left text-xs sm:text-sm text-zinc-700 dark:text-zinc-300">
<thead className="bg-white/80 dark:bg-zinc-950/50 text-zinc-600 dark:text-zinc-400 border-b border-zinc-200 dark:border-zinc-800 uppercase text-[10px] sm:text-xs font-semibold">
<tr>
<th className="px-4 sm:px-6 py-3.5">MRN</th>
<th className="px-4 sm:px-6 py-3.5">Name</th>
<th className="px-4 sm:px-6 py-3.5">Room</th>
<th className="px-4 sm:px-6 py-3.5">Status</th>
<th className="px-4 sm:px-6 py-3.5">Doctor</th>
<th className="px-4 sm:px-6 py-3.5 text-right">Actions</th>
</tr>
</thead>
<tbody>
{loading ? (
<tr>
<td colSpan={6} className="px-4 sm:px-6 py-8 text-center text-zinc-500">Loading patients...</td>
</tr>
) : filtered.length === 0 ? (
<tr>
<td colSpan={6} className="px-4 sm:px-6 py-8 text-center text-zinc-500">No patients found.</td>
</tr>
) : (
filtered.map((patient: any) => (
<tr key={patient.id} className="border-b border-zinc-200/50 dark:border-zinc-800/50 hover:bg-zinc-100 dark:hover:bg-zinc-800/20 transition-colors">
<td className="px-4 sm:px-6 py-3.5 font-mono text-zinc-500 whitespace-nowrap">{patient.mrn}</td>
<td className="px-4 sm:px-6 py-3.5 font-medium text-zinc-800 dark:text-zinc-200">
<div>{patient.patient_name}</div>
<div className="text-xs text-zinc-500 font-normal mt-0.5">
{patient.food_instructions && <span className="mr-2 text-amber-600 dark:text-amber-400 font-medium">{patient.food_instructions}</span>}
{patient.visiting_rules && <span className="text-zinc-400">Visits: {patient.visiting_rules}</span>}
</div>
</td>
<td className="px-4 sm:px-6 py-3.5 whitespace-nowrap">{patient.room_id || 'Unassigned'}</td>
<td className="px-4 sm:px-6 py-3.5 whitespace-nowrap">
<span className={`px-2 py-0.5 rounded text-xs font-medium ${
patient.status === 'Critical' ? 'text-red-500 bg-red-500/10 dark:text-red-400 dark:bg-red-400/10' :
patient.status === 'Stable' ? 'text-emerald-600 bg-emerald-500/10 dark:text-emerald-400 dark:bg-emerald-400/10' :
'text-zinc-600 dark:text-zinc-400 bg-zinc-400/10'
}`}>
{patient.status || 'Unknown'}
</span>
</td>
<td className="px-4 sm:px-6 py-3.5 whitespace-nowrap">{patient.doctor_name || 'N/A'}</td>
<td className="px-4 sm:px-6 py-3.5 text-right whitespace-nowrap">
<div className="flex items-center justify-end gap-2">
<Link href={`/patients/${patient.id}`} className="text-zinc-400 hover:text-emerald-500 transition-colors p-1" title="Edit Patient">
<Edit2 size={16} />
</Link>
<button onClick={() => handleDelete(patient.id)} className="text-zinc-400 hover:text-red-500 transition-colors p-1" title="Delete Patient">
<Trash2 size={16} />
</button>
</div>
</td>
</tr>
))
)}
</tbody>
</table>
</div>
</div>
</div>
);
}
+96
View File
@@ -0,0 +1,96 @@
"use client";
import { useState } from "react";
import { fetchApi } from "@/lib/api";
import { ArrowLeft, Save } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
export default function AddRoomPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [formData, setFormData] = useState({
room_number: "",
ward: "",
display_id: ""
});
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
const payload = {
...formData,
display_id: formData.display_id ? parseInt(formData.display_id) : null,
};
await fetchApi("/rooms", {
method: "POST",
body: JSON.stringify(payload)
});
router.push("/rooms");
} catch (err: any) {
setError(err?.message || "Failed to add room.");
setLoading(false);
}
};
return (
<div className="max-w-xl mx-auto space-y-6">
<div className="flex items-center gap-4">
<Link href="/rooms" className="p-2 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:bg-zinc-800 rounded-lg transition-colors">
<ArrowLeft size={20} />
</Link>
<div>
<h1 className="text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
Add New Room
</h1>
<p className="text-zinc-600 dark:text-zinc-400 mt-1 text-sm">Register a new ICU room to the system.</p>
</div>
</div>
{error && (
<div className="bg-red-950 border border-red-900 text-red-400 p-3 rounded-lg text-sm">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 space-y-5 sm:space-y-6 shadow-sm">
<div className="space-y-4">
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Room Number *</label>
<input required type="text" name="room_number" value={formData.room_number} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" placeholder="e.g. ICU-01" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Ward *</label>
<input required type="text" name="ward" value={formData.ward} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 font-mono text-sm" placeholder="e.g. Ward A" />
</div>
<div>
<label className="block text-xs sm:text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-1.5">Assign Display ID (Optional)</label>
<input type="number" name="display_id" value={formData.display_id} onChange={handleChange} className="w-full bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 text-zinc-900 dark:text-zinc-100 rounded-lg px-3.5 sm:px-4 py-2 focus:outline-none focus:border-red-500 text-sm" placeholder="e.g. 1" />
<p className="text-[11px] sm:text-xs text-zinc-500 mt-1">ID of the registered DisplayDevice assigned to this room.</p>
</div>
</div>
<div className="pt-4 border-t border-zinc-200 dark:border-zinc-800 flex flex-col-reverse sm:flex-row justify-end gap-2.5 sm:gap-3">
<Link href="/rooms" className="w-full sm:w-auto px-4 py-2.5 rounded-lg text-center text-sm text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors">
Cancel
</Link>
<button type="submit" disabled={loading} className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-6 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm disabled:opacity-50 shadow-sm">
{loading ? "Adding..." : <><Save size={18} /> Add Room</>}
</button>
</div>
</form>
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
"use client";
import { useEffect, useState } from "react";
import { fetchApi } from "@/lib/api";
import { Plus, Search } from "lucide-react";
import Link from "next/link";
export default function RoomsPage() {
const [rooms, setRooms] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
const [search, setSearch] = useState("");
useEffect(() => {
fetchApi('/rooms')
.then(data => {
setRooms(data);
setLoading(false);
})
.catch(err => {
console.error(err);
setLoading(false);
});
}, []);
const filtered = rooms.filter((r: any) =>
r.room_number?.toLowerCase().includes(search.toLowerCase()) ||
r.ward?.toLowerCase().includes(search.toLowerCase())
);
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 sm:gap-4 bg-white/75 dark:bg-zinc-900/75 backdrop-blur-md border border-zinc-200/60 dark:border-zinc-800/60 px-4 sm:px-5 py-3 sm:py-3.5 rounded-xl shadow-xs">
<div>
<h1 className="text-xl sm:text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
<svg className="text-red-500 w-5 h-5 sm:w-6 sm:h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" /></svg>
ICU Rooms
</h1>
<p className="text-xs sm:text-sm text-zinc-600 dark:text-zinc-400 mt-0.5">Manage hospital rooms and ward assignments.</p>
</div>
<Link href="/rooms/new" className="w-full sm:w-auto bg-red-600 hover:bg-red-500 text-white px-4 py-2.5 rounded-lg font-medium transition-colors flex items-center justify-center gap-2 text-sm shadow-sm">
<Plus size={18} /> Add Room
</Link>
</div>
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl overflow-hidden shadow-sm">
<div className="p-3 sm:p-4 border-b border-zinc-200 dark:border-zinc-800 flex justify-between items-center bg-zinc-100/50 dark:bg-zinc-900/50">
<div className="flex items-center bg-white dark:bg-zinc-950 border border-zinc-200 dark:border-zinc-800 rounded-lg px-3 py-2 w-full sm:w-72">
<Search className="text-zinc-400 mr-2 shrink-0" size={16} />
<input
type="text"
placeholder="Search Room Number or Ward..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="bg-transparent border-none outline-none text-zinc-700 dark:text-zinc-300 placeholder-zinc-500 text-xs sm:text-sm w-full"
/>
</div>
</div>
<div className="overflow-x-auto">
<table className="min-w-[500px] w-full text-left text-xs sm:text-sm text-zinc-700 dark:text-zinc-300">
<thead className="bg-white/80 dark:bg-zinc-950/50 text-zinc-600 dark:text-zinc-400 border-b border-zinc-200 dark:border-zinc-800 uppercase text-[10px] sm:text-xs font-semibold">
<tr>
<th className="px-4 sm:px-6 py-3.5">Room ID</th>
<th className="px-4 sm:px-6 py-3.5">Room Number</th>
<th className="px-4 sm:px-6 py-3.5">Ward</th>
<th className="px-4 sm:px-6 py-3.5">Assigned Display ID</th>
</tr>
</thead>
<tbody>
{loading ? (
<tr>
<td colSpan={4} className="px-4 sm:px-6 py-8 text-center text-zinc-500">Loading rooms...</td>
</tr>
) : filtered.length === 0 ? (
<tr>
<td colSpan={4} className="px-4 sm:px-6 py-8 text-center text-zinc-500">No rooms found.</td>
</tr>
) : (
filtered.map((room: any) => (
<tr key={room.id} className="border-b border-zinc-200/50 dark:border-zinc-800/50 hover:bg-zinc-100 dark:hover:bg-zinc-800/20 transition-colors">
<td className="px-4 sm:px-6 py-3.5 font-mono text-zinc-500 whitespace-nowrap">{room.id}</td>
<td className="px-4 sm:px-6 py-3.5 font-medium text-zinc-800 dark:text-zinc-200 whitespace-nowrap">{room.room_number}</td>
<td className="px-4 sm:px-6 py-3.5 whitespace-nowrap">{room.ward}</td>
<td className="px-4 sm:px-6 py-3.5 font-mono whitespace-nowrap">{room.display_id || 'None'}</td>
</tr>
))
)}
</tbody>
</table>
</div>
</div>
</div>
);
}
+112
View File
@@ -0,0 +1,112 @@
"use client";
import { useEffect, useState } from "react";
import { fetchApi } from "@/lib/api";
import { User, LogOut, Moon, BellRing } from "lucide-react";
import { useRouter } from "next/navigation";
import { useTheme } from "next-themes";
export default function SettingsPage() {
const router = useRouter();
const { theme, setTheme } = useTheme();
const [user, setUser] = useState<{name: string, email: string, role: string} | null>(null);
useEffect(() => {
const fetchUser = async () => {
try {
const data = await fetchApi("/auth/me");
setUser(data);
} catch (e) {
// Ignore
}
};
fetchUser();
}, []);
const handleLogout = () => {
localStorage.removeItem("token");
window.location.href = "/login"; // Force full reload to clear states
};
return (
<div className="max-w-4xl mx-auto space-y-6">
<div className="bg-white/75 dark:bg-zinc-900/75 backdrop-blur-md border border-zinc-200/60 dark:border-zinc-800/60 px-4 sm:px-5 py-3 sm:py-3.5 rounded-xl shadow-xs">
<h1 className="text-xl sm:text-2xl font-bold text-zinc-900 dark:text-zinc-100 flex items-center gap-2">
Settings
</h1>
<p className="text-xs sm:text-sm text-zinc-600 dark:text-zinc-400 mt-0.5">Manage your account and system preferences.</p>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4 sm:gap-6">
<div className="col-span-1 lg:col-span-2 space-y-4 sm:space-y-6">
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 shadow-sm">
<h2 className="text-base sm:text-lg font-bold text-zinc-900 dark:text-zinc-100 mb-4 flex items-center gap-2">
<User size={20} className="text-red-500" />
Profile Information
</h2>
{user ? (
<div className="space-y-3 sm:space-y-4">
<div>
<p className="text-xs text-zinc-500">Full Name</p>
<p className="text-sm sm:text-base text-zinc-900 dark:text-zinc-100 font-medium">{user.name}</p>
</div>
<div>
<p className="text-xs text-zinc-500">Email Address</p>
<p className="text-sm sm:text-base text-zinc-900 dark:text-zinc-100 font-medium break-all">{user.email}</p>
</div>
<div>
<p className="text-xs text-zinc-500">Role</p>
<p className="text-sm sm:text-base text-zinc-900 dark:text-zinc-100 font-medium capitalize">{user.role}</p>
</div>
</div>
) : (
<div className="text-xs sm:text-sm text-zinc-500">
You are currently browsing as a Guest.
<button onClick={() => router.push('/login')} className="text-red-500 ml-2 hover:underline">Log In</button>
</div>
)}
</div>
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 shadow-sm">
<h2 className="text-base sm:text-lg font-bold text-zinc-900 dark:text-zinc-100 mb-4 flex items-center gap-2">
<Moon size={20} className="text-red-500" />
Appearance
</h2>
<div className="flex items-center justify-between gap-4">
<div>
<p className="text-sm sm:text-base text-zinc-900 dark:text-zinc-100 font-medium">Dark Mode</p>
<p className="text-xs sm:text-sm text-zinc-500 mt-0.5">Toggle between light and dark theme across the dashboard.</p>
</div>
<button
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
className={`w-12 h-6 rounded-full relative transition-colors shrink-0 ${theme === "dark" ? "bg-red-600" : "bg-zinc-300"}`}
aria-label="Toggle theme"
>
<div className={`absolute top-1 w-4 h-4 bg-white rounded-full transition-all ${theme === "dark" ? "right-1" : "left-1"}`}></div>
</button>
</div>
</div>
</div>
<div className="col-span-1 space-y-4 sm:space-y-6">
<div className="bg-zinc-50/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-xl p-4 sm:p-6 shadow-sm">
<h2 className="text-base sm:text-lg font-bold text-zinc-900 dark:text-zinc-100 mb-4 flex items-center gap-2">
<BellRing size={20} className="text-red-500" />
Quick Actions
</h2>
<div className="space-y-3">
<button
onClick={handleLogout}
className="w-full flex items-center justify-center gap-2 bg-red-950/40 hover:bg-red-900/60 text-red-500 border border-red-900/60 py-2.5 rounded-lg transition-colors text-sm font-medium"
>
<LogOut size={18} />
Sign Out
</button>
</div>
</div>
</div>
</div>
</div>
);
}
@@ -0,0 +1,37 @@
"use client";
import { useState, useEffect } from "react";
import Sidebar from "./Sidebar";
import TopNav from "./TopNav";
import { usePathname } from "next/navigation";
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const isLogin = pathname === "/login";
const [sidebarOpen, setSidebarOpen] = useState(false);
// Auto-close mobile drawer on route transition
useEffect(() => {
setSidebarOpen(false);
}, [pathname]);
if (isLogin) {
return (
<main className="h-full w-full overflow-y-auto bg-transparent flex items-center justify-center p-4">
{children}
</main>
);
}
return (
<div className="flex h-full w-full overflow-hidden relative">
<Sidebar isOpen={sidebarOpen} onClose={() => setSidebarOpen(false)} />
<div className="flex-1 flex flex-col min-w-0 min-h-0 w-full overflow-hidden">
<TopNav onOpenSidebar={() => setSidebarOpen(true)} />
<main className="flex-1 overflow-y-auto min-h-0 bg-transparent p-4 sm:p-6 md:p-8">
{children}
</main>
</div>
</div>
);
}
+124
View File
@@ -0,0 +1,124 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Activity, Users, Monitor, Settings, X, DoorOpen } from "lucide-react";
interface SidebarProps {
isOpen: boolean;
onClose: () => void;
}
export default function Sidebar({ isOpen, onClose }: SidebarProps) {
const pathname = usePathname();
const navItems = [
{ href: "/", label: "Dashboard", icon: Activity },
{ href: "/patients", label: "Patients", icon: Users },
{ href: "/displays", label: "Displays", icon: Monitor },
{ href: "/rooms", label: "Rooms", icon: DoorOpen },
];
const isLinkActive = (href: string) => {
if (href === "/") return pathname === "/";
return pathname.startsWith(href);
};
return (
<>
{/* Mobile Backdrop Overlay */}
{isOpen && (
<div
onClick={onClose}
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-40 md:hidden transition-opacity duration-300"
aria-hidden="true"
/>
)}
{/* Sidebar Navigation */}
<aside
className={`
fixed inset-y-0 left-0 z-50 w-64 bg-white/95 dark:bg-zinc-950/95 backdrop-blur-md border-r border-zinc-200 dark:border-zinc-800
flex flex-col h-full transition-transform duration-300 ease-in-out shrink-0 select-none shadow-2xl md:shadow-none
md:static md:translate-x-0
${isOpen ? "translate-x-0" : "-translate-x-full md:translate-x-0"}
`}
>
{/* Header / Brand Logo */}
<div className="h-16 flex items-center justify-between px-6 border-b border-zinc-200 dark:border-zinc-800 shrink-0">
<Link href="/" onClick={onClose} className="flex items-center gap-3">
<img src="/logo.png" alt="DMH Logo" className="h-9 w-auto object-contain" />
<span className="text-zinc-900 dark:text-zinc-100 font-bold text-lg tracking-wide">
ICU Display
</span>
</Link>
{/* Close button for mobile */}
<button
onClick={onClose}
className="md:hidden p-1.5 text-zinc-400 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800 rounded-lg transition-colors"
aria-label="Close Sidebar"
>
<X size={20} />
</button>
</div>
{/* Navigation Links */}
<nav className="flex-1 py-6 px-4 space-y-1.5 overflow-y-auto">
{navItems.map((item) => {
const Icon = item.icon;
const active = isLinkActive(item.href);
return (
<Link
key={item.href}
href={item.href}
onClick={onClose}
className={`
flex items-center px-4 py-3 rounded-lg text-sm font-medium transition-all group
${active
? "text-red-500 bg-red-500/10 dark:bg-red-950/40 font-semibold"
: "text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100/80 dark:hover:bg-zinc-900/60"
}
`}
>
<Icon
size={20}
className={`mr-3 transition-colors ${
active ? "text-red-500" : "text-zinc-400 dark:text-zinc-500 group-hover:text-red-400"
}`}
/>
<span>{item.label}</span>
</Link>
);
})}
</nav>
{/* Bottom Settings Link */}
<div className="p-4 border-t border-zinc-200 dark:border-zinc-800 shrink-0">
<Link
href="/settings"
onClick={onClose}
className={`
flex items-center px-4 py-3 w-full rounded-lg text-sm font-medium transition-all group
${isLinkActive("/settings")
? "text-red-500 bg-red-500/10 dark:bg-red-950/40 font-semibold"
: "text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100/80 dark:hover:bg-zinc-900/60"
}
`}
>
<Settings
size={20}
className={`mr-3 transition-colors ${
isLinkActive("/settings")
? "text-red-500"
: "text-zinc-400 dark:text-zinc-500 group-hover:text-red-400"
}`}
/>
<span>Settings</span>
</Link>
</div>
</aside>
</>
);
}
+11
View File
@@ -0,0 +1,11 @@
"use client";
import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
export function ThemeProvider({
children,
...props
}: React.ComponentProps<typeof NextThemesProvider>) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}
+88
View File
@@ -0,0 +1,88 @@
"use client";
import { Bell, Search, User, Menu, Moon, Sun } from "lucide-react";
import Link from "next/link";
import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
interface TopNavProps {
onOpenSidebar: () => void;
}
export default function TopNav({ onOpenSidebar }: TopNavProps) {
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
return (
<header className="h-16 bg-white/70 dark:bg-zinc-950/70 backdrop-blur-md border-b border-zinc-200/60 dark:border-zinc-800/60 flex items-center justify-between px-3 sm:px-6 shrink-0 z-20 transition-colors">
{/* Left: Mobile Menu & Search */}
<div className="flex items-center gap-2 sm:gap-3 flex-1 min-w-0 mr-2 sm:mr-4">
{/* Mobile Hamburger Menu Button */}
<button
onClick={onOpenSidebar}
className="md:hidden p-2 -ml-1 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800/60 rounded-lg transition-colors shrink-0"
aria-label="Open Navigation Menu"
>
<Menu size={22} />
</button>
{/* Mobile brand icon when sidebar is collapsed */}
<Link href="/" className="flex items-center md:hidden shrink-0">
<img src="/logo.png" alt="DMH Logo" className="h-7 w-auto object-contain" />
</Link>
{/* Search Bar - Responsive */}
<div className="flex items-center bg-zinc-100/90 dark:bg-zinc-900/90 border border-zinc-200 dark:border-zinc-800 rounded-lg px-2.5 sm:px-3 py-1.5 w-full max-w-[170px] sm:max-w-xs md:max-w-sm">
<Search className="text-zinc-400 dark:text-zinc-500 mr-2 shrink-0" size={15} />
<input
type="text"
placeholder="Search..."
className="bg-transparent border-none outline-none text-zinc-800 dark:text-zinc-200 placeholder-zinc-400 dark:placeholder-zinc-500 text-xs sm:text-sm w-full min-w-0"
/>
</div>
</div>
{/* Right: Actions & User Info */}
<div className="flex items-center space-x-1.5 sm:space-x-3 shrink-0">
{/* Theme Toggle */}
{mounted && (
<button
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
className="p-2 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800/60 rounded-lg transition-colors"
aria-label="Toggle Theme"
>
{theme === "dark" ? <Sun size={18} /> : <Moon size={18} />}
</button>
)}
{/* Notifications */}
<button
className="relative p-2 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100 hover:bg-zinc-100 dark:hover:bg-zinc-800/60 rounded-lg transition-colors"
aria-label="Notifications"
>
<Bell size={18} />
<span className="absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full"></span>
</button>
{/* User Profile */}
<div className="flex items-center space-x-2.5 border-l border-zinc-200 dark:border-zinc-800 pl-2 sm:pl-3">
<div className="text-right hidden sm:block">
<p className="text-xs sm:text-sm font-medium text-zinc-800 dark:text-zinc-200 leading-tight">Admin User</p>
<p className="text-[10px] sm:text-xs text-zinc-500">ICU Ward A</p>
</div>
<Link
href="/settings"
className="w-8 h-8 sm:w-9 sm:h-9 rounded-full bg-red-900/80 hover:bg-red-800 flex items-center justify-center border border-red-700/60 shrink-0 transition-colors"
title="Profile & Settings"
>
<User className="text-red-300" size={16} />
</Link>
</div>
</div>
</header>
);
}
+47
View File
@@ -0,0 +1,47 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-red-600 text-white hover:bg-red-500",
destructive: "bg-red-700 text-white hover:bg-red-600",
outline: "border border-zinc-200 dark:border-zinc-800 bg-transparent hover:bg-zinc-100 dark:hover:bg-zinc-800",
secondary: "bg-zinc-100 dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 hover:bg-zinc-200 dark:hover:bg-zinc-700",
ghost: "hover:bg-zinc-100 dark:hover:bg-zinc-800",
link: "text-red-500 underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, ...props }, ref) => {
return (
<button
className={buttonVariants({ variant, size, className })}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = "Button"
export { Button, buttonVariants }
+16
View File
@@ -0,0 +1,16 @@
async function testLogin() {
const res = await fetch("http://127.0.0.1:8000/api/auth/login", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "username=nurse%40hospital.com&password=password123",
});
console.log(res.status);
console.log(await res.text());
}
testLogin();
+34
View File
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
}