Finished! refactored app.tsx into components

This commit is contained in:
2026-03-30 13:56:06 -05:00
parent 31d65b6d18
commit 516f43308f
20 changed files with 1234 additions and 276 deletions

View File

@@ -1,184 +1,591 @@
.counter {
font-size: 16px;
padding: 5px 10px;
border-radius: 5px;
color: var(--accent);
background: var(--accent-bg);
border: 2px solid transparent;
transition: border-color 0.3s;
:root {
--surface: #f4f4f6;
--surface-hover: #ededf0;
--danger-bg: #fff5f5;
--danger-border: #fecaca;
--danger-header: #fee2e2;
--danger-text: #991b1b;
--warning-bg: #fffbeb;
--warning-border: #fde68a;
--warning-header: #fef3c7;
--warning-text: #92400e;
--info-bg: #f0f9ff;
--info-border: #bae6fd;
--info-header: #e0f2fe;
--info-text: #075985;
--badge-low-bg: #dcfce7;
--badge-low-text: #166534;
--badge-medium-bg: #fef9c3;
--badge-medium-text: #854d0e;
--badge-high-bg: #fee2e2;
--badge-high-text: #991b1b;
}
@media (prefers-color-scheme: dark) {
:root {
--surface: #1e1f27;
--surface-hover: #25262f;
--danger-bg: #1f1315;
--danger-border: #5b2128;
--danger-header: #2d1517;
--danger-text: #fca5a5;
--warning-bg: #1c1509;
--warning-border: #5c3d10;
--warning-header: #271c0a;
--warning-text: #fcd34d;
--info-bg: #091520;
--info-border: #0c3a54;
--info-header: #0d1f2e;
--info-text: #7dd3fc;
--badge-low-bg: rgba(34, 197, 94, 0.15);
--badge-low-text: #86efac;
--badge-medium-bg: rgba(234, 179, 8, 0.15);
--badge-medium-text: #fde047;
--badge-high-bg: rgba(239, 68, 68, 0.15);
--badge-high-text: #fca5a5;
}
}
/* ── Layout ───────────────────────────────────────────────────────────────── */
.app {
max-width: 1300px;
margin: 0 auto;
padding: 24px 20px 48px;
}
.app-header {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 24px;
&:hover {
border-color: var(--accent-border);
}
&:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
h1 {
margin: 0;
font-size: 1.6rem;
letter-spacing: -0.5px;
color: var(--text-h);
}
}
.hero {
position: relative;
.fetching-badge {
font-size: 0.75rem;
color: var(--text);
background: var(--surface);
border: 1px solid var(--border);
padding: 2px 10px;
border-radius: 12px;
}
.base,
.framework,
.vite {
inset-inline: 0;
margin: 0 auto;
}
/* ── Alert cards ──────────────────────────────────────────────────────────── */
.base {
width: 170px;
position: relative;
z-index: 0;
}
.alerts-panel {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
margin-bottom: 28px;
.framework,
.vite {
position: absolute;
}
.framework {
z-index: 1;
top: 34px;
height: 28px;
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
scale(1.4);
}
.vite {
z-index: 0;
top: 107px;
height: 26px;
width: auto;
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
scale(0.8);
@media (max-width: 768px) {
grid-template-columns: 1fr;
}
}
#center {
.alert-card {
border-radius: 10px;
border: 1px solid;
overflow: hidden;
}
.alert-card--danger {
background: var(--danger-bg);
border-color: var(--danger-border);
}
.alert-card--warning {
background: var(--warning-bg);
border-color: var(--warning-border);
}
.alert-card--info {
background: var(--info-bg);
border-color: var(--info-border);
}
.alert-card__header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 14px;
font-weight: 600;
font-size: 0.82rem;
letter-spacing: 0.02em;
text-transform: uppercase;
.alert-card--danger & {
background: var(--danger-header);
color: var(--danger-text);
border-bottom: 1px solid var(--danger-border);
}
.alert-card--warning & {
background: var(--warning-header);
color: var(--warning-text);
border-bottom: 1px solid var(--warning-border);
}
.alert-card--info & {
background: var(--info-header);
color: var(--info-text);
border-bottom: 1px solid var(--info-border);
}
}
.alert-card__count {
background: rgba(0 0 0 / 0.1);
border-radius: 10px;
padding: 1px 8px;
font-size: 0.8rem;
font-weight: 700;
text-transform: none;
letter-spacing: 0;
}
@media (prefers-color-scheme: dark) {
.alert-card__count {
background: rgba(255 255 255 / 0.1);
}
}
.alert-card__list {
list-style: none;
margin: 0;
padding: 10px 14px 12px;
display: flex;
flex-wrap: wrap;
gap: 6px;
li {
font-size: 0.8rem;
font-family: var(--mono);
padding: 2px 8px;
border-radius: 4px;
.alert-card--danger & {
background: var(--danger-header);
color: var(--danger-text);
}
.alert-card--warning & {
background: var(--warning-header);
color: var(--warning-text);
}
.alert-card--info & {
background: var(--info-header);
color: var(--info-text);
}
}
}
.alert-card__empty {
margin: 0;
padding: 10px 14px 12px;
font-size: 0.85rem;
color: var(--text);
&--error {
color: var(--danger-text);
}
}
/* ── State messages ───────────────────────────────────────────────────────── */
.state-message {
text-align: center;
padding: 48px;
color: var(--text);
&.error {
color: var(--danger-text);
button {
margin-top: 12px;
padding: 6px 16px;
border-radius: 6px;
border: 1px solid var(--danger-border);
background: var(--danger-bg);
color: var(--danger-text);
cursor: pointer;
&:hover {
background: var(--danger-header);
}
}
}
}
/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrapper {
overflow-x: auto;
border: 1px solid var(--border);
border-radius: 10px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.875rem;
th {
background: var(--surface);
color: var(--text);
text-align: left;
padding: 10px 14px;
font-weight: 600;
font-size: 0.78rem;
letter-spacing: 0.05em;
text-transform: uppercase;
border-bottom: 1px solid var(--border);
white-space: nowrap;
}
td {
padding: 10px 14px;
color: var(--text-h);
border-bottom: 1px solid var(--border);
vertical-align: middle;
}
tbody tr:last-child td {
border-bottom: none;
}
tbody tr:hover td {
background: var(--surface);
}
}
.missing {
color: var(--border);
}
/* ── Risk badge ───────────────────────────────────────────────────────────── */
.risk-badge {
display: inline-block;
min-width: 24px;
text-align: center;
font-weight: 700;
font-size: 0.78rem;
padding: 2px 8px;
border-radius: 12px;
}
.risk-badge--low {
background: var(--badge-low-bg);
color: var(--badge-low-text);
}
.risk-badge--medium {
background: var(--badge-medium-bg);
color: var(--badge-medium-text);
}
.risk-badge--high {
background: var(--badge-high-bg);
color: var(--badge-high-text);
}
.data-issue-flag {
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: 6px;
font-size: 0.7rem;
font-weight: 800;
color: var(--warning-text);
background: var(--warning-header);
border: 1px solid var(--warning-border);
border-radius: 50%;
width: 16px;
height: 16px;
cursor: default;
vertical-align: middle;
}
/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
margin-top: 20px;
span {
font-size: 0.875rem;
color: var(--text);
}
button {
padding: 6px 18px;
border-radius: 6px;
border: 1px solid var(--accent-border);
background: var(--accent-bg);
color: var(--accent);
cursor: pointer;
font-size: 0.875rem;
font-weight: 500;
transition: background 0.15s, border-color 0.15s;
&:hover:not(:disabled) {
background: var(--accent-bg);
border-color: var(--accent);
filter: brightness(1.1);
}
&:disabled {
opacity: 0.35;
cursor: not-allowed;
}
}
}
/* ── Submission panel ─────────────────────────────────────────────────────── */
.submission-panel {
margin-top: 40px;
border: 1px solid var(--border);
border-radius: 10px;
overflow: hidden;
}
.submission-panel__header {
padding: 18px 20px 14px;
border-bottom: 1px solid var(--border);
background: var(--surface);
h2 {
margin: 0 0 4px;
font-size: 1.1rem;
color: var(--text-h);
}
}
.submission-panel__note {
font-size: 0.85rem;
color: var(--text);
margin: 0;
}
/* ── Payload preview ─────────────────────────────────────────────────── */
.payload-preview {
display: flex;
flex-direction: column;
gap: 25px;
place-content: center;
place-items: center;
flex-grow: 1;
}
@media (max-width: 1024px) {
padding: 32px 20px 24px;
gap: 18px;
.payload-row {
display: grid;
grid-template-columns: 280px 1fr;
align-items: start;
gap: 12px;
padding: 12px 20px;
border-bottom: 1px solid var(--border);
&:last-child {
border-bottom: none;
}
@media (max-width: 640px) {
grid-template-columns: 1fr;
}
}
#next-steps {
display: flex;
border-top: 1px solid var(--border);
text-align: left;
& > div {
flex: 1 1 0;
padding: 32px;
@media (max-width: 1024px) {
padding: 24px 20px;
}
}
.icon {
margin-bottom: 16px;
width: 22px;
height: 22px;
}
@media (max-width: 1024px) {
flex-direction: column;
text-align: center;
}
}
#docs {
border-right: 1px solid var(--border);
@media (max-width: 1024px) {
border-right: none;
border-bottom: 1px solid var(--border);
}
}
#next-steps ul {
list-style: none;
padding: 0;
.payload-row--danger { background: var(--danger-bg); }
.payload-row--warning { background: var(--warning-bg); }
.payload-row--info { background: var(--info-bg); }
.payload-row__label {
display: flex;
align-items: center;
gap: 8px;
margin: 32px 0 0;
padding-top: 2px;
.logo {
height: 18px;
}
code {
font-size: 0.8rem;
background: transparent;
padding: 0;
a {
color: var(--text-h);
font-size: 16px;
border-radius: 6px;
background: var(--social-bg);
display: flex;
padding: 6px 12px;
align-items: center;
gap: 8px;
text-decoration: none;
transition: box-shadow 0.3s;
&:hover {
box-shadow: var(--shadow);
}
.button-icon {
height: 18px;
width: 18px;
}
}
@media (max-width: 1024px) {
margin-top: 20px;
flex-wrap: wrap;
justify-content: center;
li {
flex: 1 1 calc(50% - 8px);
}
a {
width: 100%;
justify-content: center;
box-sizing: border-box;
}
.payload-row--danger & { color: var(--danger-text); }
.payload-row--warning & { color: var(--warning-text); }
.payload-row--info & { color: var(--info-text); }
}
}
#spacer {
height: 88px;
.payload-row__count {
font-size: 0.75rem;
font-weight: 700;
border-radius: 10px;
padding: 1px 7px;
.payload-row--danger & { background: var(--danger-header); color: var(--danger-text); }
.payload-row--warning & { background: var(--warning-header); color: var(--warning-text); }
.payload-row--info & { background: var(--info-header); color: var(--info-text); }
}
.payload-row__ids {
display: flex;
flex-wrap: wrap;
gap: 6px;
min-height: 24px;
}
.payload-row__empty {
font-size: 0.8rem;
font-family: var(--mono);
color: var(--text);
opacity: 0.5;
}
.payload-id {
font-size: 0.8rem;
font-family: var(--mono);
padding: 2px 8px;
border-radius: 4px;
.payload-row--danger & { background: var(--danger-header); color: var(--danger-text); }
.payload-row--warning & { background: var(--warning-header); color: var(--warning-text); }
.payload-row--info & { background: var(--info-header); color: var(--info-text); }
}
/* ── Submit button & error ────────────────────────────────────────────── */
.submission-panel__actions {
padding: 16px 20px;
border-top: 1px solid var(--border);
@media (max-width: 1024px) {
height: 48px;
background: var(--surface);
display: flex;
align-items: center;
gap: 16px;
}
.submit-btn {
padding: 10px 28px;
border-radius: 7px;
border: none;
background: var(--accent);
color: #fff;
font-size: 0.95rem;
font-weight: 600;
cursor: pointer;
transition: opacity 0.15s, filter 0.15s;
&:hover:not(:disabled) {
filter: brightness(1.1);
}
&:disabled {
opacity: 0.45;
cursor: not-allowed;
}
}
.ticks {
position: relative;
.submit-error {
margin: 0;
font-size: 0.875rem;
color: var(--danger-text);
}
/* ── Submission result ────────────────────────────────────────────────── */
.submission-result {
margin: 0;
border-top: 1px solid var(--border);
}
.submission-result__header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 16px 20px;
flex-wrap: wrap;
}
.submission-result--pass .submission-result__header { background: var(--badge-low-bg); }
.submission-result--fail .submission-result__header { background: var(--danger-bg); }
.submission-result__score {
display: flex;
align-items: center;
gap: 12px;
}
.submission-result__pct {
font-size: 2rem;
font-weight: 800;
color: var(--text-h);
line-height: 1;
}
.submission-result__status {
font-size: 0.85rem;
font-weight: 700;
padding: 3px 12px;
border-radius: 12px;
}
.status--pass {
background: var(--badge-low-bg);
color: var(--badge-low-text);
}
.status--fail {
background: var(--badge-high-bg);
color: var(--badge-high-text);
}
.submission-result__meta {
display: flex;
gap: 16px;
font-size: 0.82rem;
color: var(--text);
flex-wrap: wrap;
}
.personal-best {
color: var(--accent);
font-weight: 600;
}
.breakdown-table {
width: 100%;
border-radius: 0;
border-top: 1px solid var(--border);
&::before,
&::after {
content: '';
position: absolute;
top: -4.5px;
border: 5px solid transparent;
}
th, td {
text-align: right;
padding: 9px 20px;
&::before {
left: 0;
border-left-color: var(--border);
}
&::after {
right: 0;
border-right-color: var(--border);
&:first-child {
text-align: left;
}
}
}
.feedback-list {
margin: 0;
padding: 12px 20px;
list-style: none;
display: flex;
flex-direction: column;
gap: 6px;
border-top: 1px solid var(--border);
font-size: 0.875rem;
li { color: var(--text-h); }
&--strengths { background: var(--badge-low-bg); }
&--issues { background: var(--warning-bg); }
}

View File

@@ -1,121 +1,62 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from './assets/vite.svg'
import heroImg from './assets/hero.png'
import './App.css'
import { useState } from 'react';
import { AlertsPanel, PatientTable, SubmissionPanel } from './components'
import { useAllPatients, usePatientRiskAnalysis } from './hooks';
import './App.css';
function App() {
const [count, setCount] = useState(0)
const PAGE_SIZE = 10;
const App = () => {
const [page, setPage] = useState(1);
const {
data: allPatients,
isLoading,
isFetching,
isError,
error,
refetch,
} = useAllPatients();
const riskAnalysis = usePatientRiskAnalysis();
const totalPatients = allPatients?.length ?? 0;
const totalPages = Math.max(1, Math.ceil(totalPatients / PAGE_SIZE));
const pagePatients = allPatients?.slice(
(page - 1) * PAGE_SIZE, page * PAGE_SIZE
) ?? [];
return (
<>
<section id="center">
<div className="hero">
<img src={heroImg} className="base" width="170" height="179" alt="" />
<img src={reactLogo} className="framework" alt="React logo" />
<img src={viteLogo} className="vite" alt="Vite logo" />
</div>
<div>
<h1>Get started</h1>
<p>
Edit <code>src/App.tsx</code> and save to test <code>HMR</code>
</p>
</div>
<button
className="counter"
onClick={() => setCount((count) => count + 1)}
>
Count is {count}
</button>
</section>
<div className="ticks"></div>
<section id="next-steps">
<div id="docs">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#documentation-icon"></use>
</svg>
<h2>Documentation</h2>
<p>Your questions, answered</p>
<ul>
<li>
<a href="https://vite.dev/" target="_blank">
<img className="logo" src={viteLogo} alt="" />
Explore Vite
</a>
</li>
<li>
<a href="https://react.dev/" target="_blank">
<img className="button-icon" src={reactLogo} alt="" />
Learn more
</a>
</li>
</ul>
</div>
<div id="social">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#social-icon"></use>
</svg>
<h2>Connect with us</h2>
<p>Join the Vite community</p>
<ul>
<li>
<a href="https://github.com/vitejs/vite" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#github-icon"></use>
</svg>
GitHub
</a>
</li>
<li>
<a href="https://chat.vite.dev/" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#discord-icon"></use>
</svg>
Discord
</a>
</li>
<li>
<a href="https://x.com/vite_js" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#x-icon"></use>
</svg>
X.com
</a>
</li>
<li>
<a href="https://bsky.app/profile/vite.dev" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#bluesky-icon"></use>
</svg>
Bluesky
</a>
</li>
</ul>
</div>
</section>
<div className="ticks"></div>
<section id="spacer"></section>
</>
)
<div className='app'>
<header className='app-header'>
<h1>Patient Records</h1>
{isFetching && !isLoading && <span className='fetching-badge'>Updating...</span>}
</header>
<AlertsPanel
alerts={riskAnalysis.submissionPayload}
loading={riskAnalysis.isLoading}
error={riskAnalysis.error}
/>
<main>
{isLoading && <div className='state-message'>Loading patients...</div>}
{isError && (
<div className='state-message error'>
<p>{error.message}</p>
<button onClick={() => refetch()}>Retry</button>
</div>
)}
{allPatients && (
<PatientTable
patients={pagePatients}
page={page}
totalPages={totalPages}
totalPatients={totalPatients}
onPageChange={setPage}
/>
)}
</main>
<SubmissionPanel
payload={riskAnalysis.submissionPayload}
loading={riskAnalysis.isLoading}
/>
</div>
);
}
export default App

116
src/api/patients.ts Normal file
View File

@@ -0,0 +1,116 @@
const BASE_URL = import.meta.env.VITE_BASE_URL as string;
const API_KEY = import.meta.env.VITE_API_KEY as string;
export interface Patient {
patient_id: string,
name: string,
age: number | null,
gender: string,
blood_pressure: string
temperature: number | null,
visit_date: string
diagnosis: string
medications: string
};
export interface Pagination {
page: number
limit: number
total: number
totalPages: number
hasNext: boolean
hasPrevious: boolean
};
export interface PatientsResponse {
data: Patient[]
pagination: Pagination
};
export class ApiError extends Error {
readonly status: number
constructor(status: number, message: string) {
super(message)
this.name = 'ApiError'
this.status = status
};
};
const normalizePatient = (raw: Record<string, unknown>): Patient => {
return {
patient_id: String(raw.patient_id ?? raw.id ?? ''),
name: String(raw.name ?? raw.patient_name ?? 'Unknown'),
age: raw.age != null ? Number(raw.age): null,
gender: String(raw.gender ?? raw.sex ?? ''),
blood_pressure: String(raw.blood_pressure ?? raw.bp ?? ''),
temperature: raw.temperature != null ? Number(raw.temperature) : null,
visit_date: String(raw.visit_date ?? raw.date ?? ''),
diagnosis: String(raw.diagnosis ?? raw.condition ?? ''),
medications: String(raw.medications ?? raw.meds ?? ''),
};
};
const normalizePagination = (
raw: Record<string, unknown>,
page: number,
limit: number,
): Pagination => {
return {
page: Number(raw.page ?? page),
limit: Number(raw.limit ?? raw.per_page ?? limit),
total: Number(raw.total ?? raw.totalCount ?? raw.total_count ?? 0),
totalPages: Number(raw.totalPages ?? raw.total_pages ?? raw.pages ?? 1),
hasNext: Boolean(raw.hasNext ?? raw.has_next ?? false),
hasPrevious: Boolean(raw.hasPrevious ?? raw.has_previous ?? false),
};
};
const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
const fetchPageWithRetry = async (
page: number,
limit: number,
attempt= 0,
): Promise<PatientsResponse> => {
try {
return await fetchPatients(page, limit);
} catch (error) {
if (error instanceof ApiError && error.status === 429 && attempt < 5) {
await delay(Math.min(1500 * 2 ** attempt, 20_000));
return fetchPageWithRetry(page, limit, attempt + 1);
}
throw error;
}
};
export const fetchAllPatients = async (): Promise<Patient[]> => {
const all: Patient[] = [];
let page = 1;
while (true) {
const result = await fetchPageWithRetry(page, 10);
all.push(...result.data);
if (!result.pagination.hasNext) break
page++;
await delay(500);
}
return all;
};
export const fetchPatients = async (
page = 1,
limit = 10,
): Promise<PatientsResponse> => {
const url = `${BASE_URL}/api/patients?page=${page}&limit=${limit}`;
const res = await fetch(url, {
headers: { 'x-api-key': API_KEY }
});
if (!res.ok)
throw new ApiError(res.status, `API error ${res.status}: ${res.statusText}`)
const json = await res.json();
const rawData = json.data ?? json.patients ?? json.results ?? [];
const rawPagination = json.pagination ?? json.meta ?? json.paging ?? {};
return {
data: Array.isArray(rawData) ? rawData.map(normalizePatient) : [],
pagination: normalizePagination(rawPagination, page, limit),
};
};

52
src/api/submit.ts Normal file
View File

@@ -0,0 +1,52 @@
import { ApiError } from './patients'
import type { SubmissionPayload } from '../lib/scoring'
const BASE_URL = import.meta.env.VITE_BASE_URL as string
const API_KEY = import.meta.env.VITE_API_KEY as string
interface BreakdownCategory {
score: number;
max: number;
correct: number;
submitted: number;
matches: number;
};
export interface SubmissionResponse {
success: boolean;
message: string;
results: {
score: number;
percentage: number;
status: string;
breakdown: {
high_risk: BreakdownCategory
fever: BreakdownCategory
data_quality: BreakdownCategory
};
feedback: {
strengths: string[];
issues: string[];
};
attempt_number: number;
remaining_attempts: number;
is_personal_best: boolean;
can_resubmit: boolean;
};
};
export const submitAssessment = async (
payload: SubmissionPayload
): Promise<SubmissionResponse> => {
const res = await fetch(`${BASE_URL}/api/submit-assessment`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
body: JSON.stringify(payload),
});
if (!res.ok)
throw new ApiError(res.status, `Submission failed: ${res.status} ${res.statusText}`)
return res.json() as Promise<SubmissionResponse>
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

Before

Width:  |  Height:  |  Size: 4.0 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1,73 @@
import type { SubmissionPayload } from '../lib/scoring';
const AlertCard = ({
title,
ids,
variant,
loading,
error,
}: {
title: string;
ids: string[];
variant: 'danger' | 'warning' | 'info';
loading: boolean;
error?: Error | null;
}) => {
return (
<div className={`alert-card alert-card--${variant}`}>
<div className='alert-card__header'>
<span className='alert-card__title'>{title}</span>
{!loading && !error && <span className='alert-card__count'>{ids.length}</span>}
</div>
{ loading ? (
<p className='alert-card__empty'>Loading...</p>
): error ? (
<p className="alert-card__empty alert-card__empty--error">{error.message}</p>
): ids.length === 0 ? (
<p className='alert-card__empty'>None</p>
): (
<ul className='alert-cards__list'>
{ids.map((id) => (
<li key={id}>{id}</li>
))}
</ul>
)}
</div>
);
};
export const AlertsPanel = ({
alerts,
loading,
error,
}: {
alerts: SubmissionPayload;
loading: boolean;
error?: Error | null;
}) => {
return (
<div className='alerts-panel'>
<AlertCard
title='High Risk Patients (score >= 4)'
ids={alerts.high_risk_patients}
variant='danger'
loading={loading}
error={error}
/>
<AlertCard
title='Fever Patients (temp >= 99.6 F)'
ids={alerts.fever_patients}
variant='warning'
loading={loading}
error={error}
/>
<AlertCard
title='Data Quality Issue Patients'
ids={alerts.data_quality_issues}
variant='info'
loading={loading}
error={error}
/>
</div>
);
};

View File

@@ -0,0 +1,85 @@
import type { Patient } from '../api/patients'
import { scorePatient } from '../lib/scoring'
const RiskBadge = ({ score }: { score: number}) => {
const level = score >= 4 ? 'high' : score >= 2 ? 'medium' : 'low';
return <span className={`risk-badge risk-badge--${level}`}>{score}</span>
};
export const PatientTable = ({
patients,
page,
totalPages,
totalPatients,
onPageChange,
}: {
patients: Patient[];
page: number;
totalPages: number;
totalPatients: number;
onPageChange: (page: number) => void;
}) => {
return (
<>
<div className='table-wrapper'>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Blood Pressure</th>
<th>Temp</th>
<th>Visited</th>
<th>Diagnosis</th>
<th>Medications</th>
<th>Risk</th>
</tr>
</thead>
<tbody>
{patients.map((patient) => {
const score = scorePatient(patient);
return (
<tr key={patient.patient_id}>
<td>{patient.patient_id}</td>
<td>{patient.name}</td>
<td>{patient.age ?? <span className='missing'>-</span>}</td>
<td>{patient.gender}</td>
<td>{patient.blood_pressure}</td>
<td>{patient.temperature}</td>
<td>{patient.visit_date}</td>
<td>{patient.diagnosis}</td>
<td>{patient.medications}</td>
<td>
<RiskBadge score={score.totalScore} />
{score.hasDataIssue && (
<span className='data-issue-flag' title='Missing or invalid data'>!</span>
)}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
<div className='pagination'>
<button
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
Previous
</button>
<span>
Page {page} of {totalPages}&nbsp;({totalPatients} total)
</span>
<button
disabled={page >= totalPages}
onClick={() => onPageChange(page + 1)}
>
Next
</button>
</div>
</>
);
};

View File

@@ -0,0 +1,130 @@
import { useSubmitAssessment } from '../hooks'
import type { SubmissionPayload } from '../lib/scoring'
import type { SubmissionResponse } from '../api/submit'
const PayloadPreview = ({ payload }: { payload: SubmissionPayload }) => {
const rows: { label: string; key: keyof SubmissionPayload; variant: string }[] = [
{ label: 'High Risk Patients', key: 'high_risk_patients', variant: 'danger'},
{ label: 'Fever Patients', key: 'fever_patients', variant: 'warning'},
{ label: 'Data Quality Issue Patients', key: 'data_quality_issues', variant: 'info'},
];
return (
<div className='payload-preview'>
{rows.map(({ label, key, variant }) => (
<div key={key} className={`payload-row payload-row--${variant}`}>
<div className='payload-row__label'>
<code>{label}</code>
<span className='payload-row__count'>{payload[key].length}</span>
</div>
<div className='payload-row__ids'>
{payload[key].length === 0 ? (
<span className='payload-row__empty'>[]</span>
): (
payload[key].map((id) => <span key={id} className='payload-id'>{id}</span>)
)}
</div>
</div>
))}
</div>
);
};
const SubmissionResult = ({ result }: { result: SubmissionResponse }) => {
const { results } = result;
const isPassing = results.status === 'PASS';
return (
<div className={`submission-result ${isPassing ? 'submission-result--pass' : 'submission-result--fail'}`}>
<div className='submission-result__header'>
<div className='submission-result__score'>
<span className='submission-result__pct'>{results.percentage}%</span>
<span className={`submission-result__status ${isPassing ? 'status--pass' : 'status--fail'}`}>
{results.status}
</span>
</div>
<div className='submission-result__meta'>
<span>Attempt {results.attempt_number}</span>
<span>
{results.remaining_attempts} attempt{results.remaining_attempts === 1 ? 's': ''} remaining
</span>
</div>
</div>
<table className='breakdown-table'>
<thead>
<tr>
<th>Category</th>
<th>Score</th>
<th>Correct</th>
<th>Submitted</th>
<th>Matches</th>
</tr>
</thead>
<tbody>
{(
[
['High Risk', results.breakdown.high_risk],
['Fever', results.breakdown.fever],
['Data Quality', results.breakdown.data_quality],
] as const
).map(([label, cat]) => (
<tr key={label}>
<td>{label}</td>
<td>{cat.score} / {cat.max}</td>
<td>{cat.correct}</td>
<td>{cat.submitted}</td>
<td>{cat.matches}</td>
</tr>
))}
</tbody>
</table>
</div>
);
};
export const SubmissionPanel = ({
payload,
loading: analysisLoading,
}: {
payload: SubmissionPayload;
loading: boolean;
}) => {
const {
mutate,
isPending,
isSuccess,
isError,
error,
data,
} = useSubmitAssessment();
const totalItems =
payload.high_risk_patients.length +
payload.fever_patients.length +
payload.data_quality_issues.length
return (
<section className='submission-panel'>
<div className='submission-panel__header'>
<h2>Submit Assessment</h2>
<p className='submission-panel__note'>
Review payload before submitting.
</p>
</div>
{analysisLoading ? (
<p className='state-message'>Loading patient data...</p>
): (
<PayloadPreview payload={payload} />
)}
<div className='submission-panel__actions'>
<button
className='submit-btn'
disabled={isPending || analysisLoading || totalItems === 0}
onClick={() => mutate(payload)}
>
{isPending ? 'Submitting...' : 'Submit Assessment'}
</button>
{isError && (
<p className='submit-error'>{(error as Error).message}</p>
)}
</div>
{isSuccess && data && <SubmissionResult result={data} />}
</section>
);
};

3
src/components/index.tsx Normal file
View File

@@ -0,0 +1,3 @@
export { AlertsPanel } from './AlertsPanel';
export { PatientTable } from './PatientTable';
export { SubmissionPanel } from './SubmissionPanel';

4
src/hooks/index.ts Normal file
View File

@@ -0,0 +1,4 @@
export { useAllPatients } from './useAllPatients';
export { usePatientRiskAnalysis } from './usePatientRiskAnalysis';
export { usePatients } from './usePatients';
export { useSubmitAssessment } from './useSubmitAssessment';

View File

@@ -0,0 +1,11 @@
import { useQuery } from '@tanstack/react-query'
import { fetchAllPatients } from '../api/patients'
import { apiRetryConfig } from '../lib/queryConfig'
export const useAllPatients = () => useQuery({
queryKey: ['patients', 'all'],
queryFn: fetchAllPatients,
staleTime: 5 * 60_000,
gcTime: 10 * 60_000,
...apiRetryConfig,
});

View File

@@ -0,0 +1,15 @@
import { useAllPatients } from './useAllPatients'
import { scorePatient, computeSubmissionPayload } from '../lib/scoring'
export const usePatientRiskAnalysis = () => {
const { data, isLoading, isError, error } = useAllPatients();
const patients = data ?? [];
const submissionPayload = computeSubmissionPayload(patients);
return {
isLoading,
isError,
error,
scores: patients.map(scorePatient),
submissionPayload,
};
};

11
src/hooks/usePatients.ts Normal file
View File

@@ -0,0 +1,11 @@
import { useQuery, keepPreviousData } from '@tanstack/react-query';
import { fetchPatients } from '../api/patients';
import { apiRetryConfig } from '../lib/queryConfig';
export const usePatients = (page = 1, limit = 10) => useQuery({
queryKey: ['patients', page, limit],
queryFn: () => fetchPatients(page, limit),
placeholderData: keepPreviousData,
staleTime: 30_000,
...apiRetryConfig,
});

View File

@@ -0,0 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { submitAssessment } from '../api/submit';
export const useSubmitAssessment = () => useMutation({ mutationFn: submitAssessment });

View File

@@ -51,14 +51,8 @@
}
#root {
width: 1126px;
max-width: 100%;
margin: 0 auto;
text-align: center;
border-inline: 1px solid var(--border);
width: 100%;
min-height: 100svh;
display: flex;
flex-direction: column;
box-sizing: border-box;
}

15
src/lib/queryConfig.ts Normal file
View File

@@ -0,0 +1,15 @@
import { ApiError } from '../api/patients'
export const apiRetryConfig = {
retry: (failureCount: number, error: Error) => {
if (error instanceof ApiError && error.status === 429) return failureCount < 5
if (error instanceof ApiError && error.status >= 400 && error.status < 500) return false
return failureCount < 3
},
retryDelay: (attemptIndex: number, error: Error) => {
if (error instanceof ApiError && error.status === 429) {
return Math.min(2000 * 2 ** attemptIndex, 30_000)
}
return Math.min(1000 * 2 ** attemptIndex, 10_000)
},
};

94
src/lib/scoring.ts Normal file
View File

@@ -0,0 +1,94 @@
import type { Patient } from '../api/patients';
export interface PatientRiskScore {
patient_id: string;
bpScore: number;
tempScore: number;
ageScore: number;
totalScore: number;
bpValid: boolean;
tempValid: boolean;
ageValid: boolean;
hasDataIssue: boolean;
};
export interface SubmissionPayload {
high_risk_patients: string[];
fever_patients: string[];
data_quality_issues: string[];
};
const scoreSystolic = (value: number): number => {
if (value < 120) return 0;
if (value < 130) return 1;
if (value < 140) return 2;
return 3;
};
const scoreDiastolic = (value: number): number => {
if (value < 80) return 0;
if (value < 90) return 2;
return 3;
};
export const scoreBP = (bp: string | null | undefined): { score: number; valid: boolean } => {
if (!bp) return { score: 0, valid: false };
const parts = bp.split('/');
if (parts.length !== 2) return { score: 0, valid: false };
const [sysStr, diaStr] = parts;
if (!sysStr.trim() || !diaStr.trim()) return { score: 0, valid: false };
const sys = Number(sysStr.trim()), dia = Number(diaStr.trim());
if (!Number.isFinite(sys) || !Number.isFinite(dia)) return { score: 0, valid: false };
return { score: Math.max(scoreSystolic(sys), scoreDiastolic(dia)), valid: true };
};
export const scoreTemp = (temp: number | null | undefined): { score: number; valid: boolean } => {
if (temp == null || !Number.isFinite(temp)) return { score: 0, valid: false };
if (temp <= 99.5) return { score: 0, valid: true };
if (temp <= 100.9) return { score: 1, valid: true };
return { score: 2, valid: true };
};
export const scoreAge = (age: number | null | undefined): { score: number; valid: boolean } => {
if (age == null || !Number.isFinite(age)) return { score: 0, valid: false };
if (age < 40) return { score: 0, valid: true };
if (age <= 65) return { score: 1, valid: true };
return { score: 2, valid: true };
};
export const scorePatient = (patient: Patient): PatientRiskScore => {
const patient_id = patient.patient_id;
const { score: bpScore, valid: bpValid } = scoreBP(patient.blood_pressure);
const { score: tempScore, valid: tempValid } = scoreTemp(patient.temperature);
const { score: ageScore, valid: ageValid } = scoreAge(patient.age);
const totalScore = bpScore + tempScore + ageScore;
const hasDataIssue = !bpValid || !tempValid || !ageValid;
return {
patient_id,
bpScore,
tempScore,
ageScore,
totalScore,
bpValid,
tempValid,
ageValid,
hasDataIssue
};
};
export const computeSubmissionPayload = (patients: Patient[]): SubmissionPayload => {
const high_risk_patients: string[] = [];
const fever_patients: string[] = [];
const data_quality_issues: string[] = [];
for (const patient of patients) {
const score = scorePatient(patient);
if (score.totalScore >= 4)
high_risk_patients.push(patient.patient_id)
if (score.tempValid && patient.temperature != null && patient.temperature >= 99.6)
fever_patients.push(patient.patient_id)
if (score.hasDataIssue)
data_quality_issues.push(patient.patient_id);
}
return { high_risk_patients, fever_patients, data_quality_issues };
};

View File

@@ -1,10 +1,15 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import './index.css'
import App from './App.tsx'
const queryClient = new QueryClient();
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</StrictMode>,
)