feat(patients): surface the no-show count, and put the report filters in the URL

The no-show records existed and drove the risk tag, but the patient's file
never showed the number behind it — the operator saw a tag with no evidence.
GET /patient/{uuid}/no-shows returns the count, the policy threshold and the
window, and the banner shows it only when the count is above zero: "0 no-shows"
on every healthy patient's file is an accusation nobody made.

The badge does not block anything and the docs say so. Blocking is an
eligibility policy from task 09 built on the same tag; a clinic that wants to
see the risk but still take a deposit must not have to switch the count off.
A test pins that a tagged patient still books.

Both report pages kept their range and branch in local state, so going back
from a resource lost the report and a shared link opened someone else's
default. They use useUrlState now, like every other list in the panel.

Three tests that were owed:
- the service-level cancellation policy beats the tenant one with no blending,
  checked through the number that comes out rather than through the resolver
- a patient over the no-show threshold can still book
- occupied includes the waiting segment while active does not — if those two
  came back equal the whole utilization report would be pointless

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-01 13:59:58 +03:30
co-authored by Claude Opus 5
parent 824e7f83c6
commit 27c0b8f4f6
9 changed files with 309 additions and 7 deletions
+24 -2
View File
@@ -1,4 +1,4 @@
import { formatDate } from '../lib/utils';
import { formatDate, formatNumber } from '../lib/utils';
import BackButton from './ui/BackButton';
import {
ArrowLeftD, FilesServicePhone, FilesServiceCalendar,
@@ -44,7 +44,7 @@ const InfoLine = ({ icon, label, value }: { icon: React.ReactNode; label: string
* FileServicesHeader (name + status chip, file number, tags, contact/date,
* next appointment, یادداشت button).
*/
export default function PatientCaseBanner({ name, recordNumber, mobile, createdAt, tags, nextAppointment, hasDebt, onAddNote }: {
export default function PatientCaseBanner({ name, recordNumber, mobile, createdAt, tags, nextAppointment, hasDebt, noShows, onAddNote }: {
name: string;
recordNumber?: string | null;
mobile?: string | null;
@@ -52,6 +52,8 @@ export default function PatientCaseBanner({ name, recordNumber, mobile, createdA
tags?: Tag[];
nextAppointment?: number | null;
hasDebt?: boolean;
/** خلاصهٔ عدم حضور در پنجرهٔ سیاست — `null` یعنی هنوز نیامده. */
noShows?: { count: number; threshold: number; window_days: number; at_risk: boolean } | null;
onAddNote: () => void;
}) {
const complete = !hasDebt;
@@ -74,6 +76,26 @@ export default function PatientCaseBanner({ name, recordNumber, mobile, createdA
<span style={{ fontSize: 16, color: 'var(--text-2)' }}>برچسب ها:</span>
<TagDots tags={tags} />
</div>
{/* شمار عدم حضور فقط وقتی می‌آید که واقعاً اتفاقی افتاده باشد. «۰ غیبت» روی
پروندهٔ هر بیمار سالم، اتهام بی‌جاست. عبور از آستانه فقط رنگش را عوض می‌کند —
مسدودسازی کارِ قانون `eligibility` است، نه این نشان. */}
{noShows && noShows.count > 0 && (
<span
title={`در ${formatNumber(noShows.window_days)} روز گذشته · آستانهٔ سیاست: ${formatNumber(noShows.threshold)}`}
style={{
alignSelf: 'flex-start',
fontSize: 13,
borderRadius: 8,
padding: '4px 10px',
background: noShows.at_risk ? 'var(--danger-bg)' : 'var(--warning-bg)',
color: noShows.at_risk ? 'var(--danger)' : 'var(--warning)',
}}
>
{formatNumber(noShows.count)} بار عدم حضور
{noShows.at_risk && ' — پرریسک'}
</span>
)}
</div>
{/* middle — contact + file date */}
+14
View File
@@ -102,3 +102,17 @@ export function useWaitlist(status?: string) {
return { entries: query.data?.data ?? [], loading: query.isLoading, remove };
}
/** خلاصهٔ عدم حضور یک بیمار — نشان است نه مانع؛ مسدودسازی کارِ قانون `eligibility` است. */
export function usePatientNoShows(patientUuid: string | undefined) {
const query = useQuery({
queryKey: ['patient-no-shows', patientUuid],
queryFn: () =>
api.get<ApiResponse<{ count: number; threshold: number; window_days: number; at_risk: boolean }>>(
`/api/v1/patient/${patientUuid}/no-shows`,
),
enabled: !!patientUuid,
});
return { noShows: query.data?.data ?? null };
}
+4
View File
@@ -11,6 +11,7 @@ import {
import { PlusIcon } from '@heroicons/react/24/outline';
import { usePackages, usePatientPackages } from '../hooks/usePackages';
import { useCourseProtocols, usePatientCourses } from '../hooks/useCourses';
import { usePatientNoShows } from '../hooks/useCancellation';
import { toast } from 'sonner';
import { api } from '../lib/api';
import type { ApiResponse } from '../lib/api';
@@ -172,6 +173,8 @@ export default function PatientDetailPage() {
const sessions = sessionsQ.data?.data ?? [];
const hasDebt = sessions.some((s) => !s.is_paid);
const nowSec = Math.floor(Date.now() / 1000);
const { noShows } = usePatientNoShows(uuid);
const nextAppointment = (appointmentsQ.data?.data ?? [])
.filter((a: any) => (a.starts_at ?? 0) >= nowSec && !String(a.status).startsWith('cancelled'))
.sort((a: any, b: any) => a.starts_at - b.starts_at)[0]?.starts_at ?? null;
@@ -188,6 +191,7 @@ export default function PatientDetailPage() {
tags={(record as any)?.tags}
nextAppointment={nextAppointment}
hasDebt={hasDebt}
noShows={noShows}
onAddNote={() => setTab('notes')}
/>
+6 -2
View File
@@ -1,4 +1,5 @@
import React, { useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import { useUrlState } from '../hooks/useUrlState';
import PageHeader from '../components/ui/PageHeader';
import DataTable, { type Column } from '../components/ui/DataTable';
import SearchableSelect from '../components/ui/SearchableSelect';
@@ -25,7 +26,10 @@ const SEVERITY: Record<AccuracyRow['severity'], { label: string; className: stri
* کلینیک را بی‌صدا می‌خورد — این صفحه تنها جایی است که آن را نشان می‌دهد.
*/
export default function PlanAccuracyPage() {
const [days, setDays] = useState('30');
// بازه در URL: لینکِ گزارش باید همان بازه‌ای را باز کند که فرستنده دیده بود.
const [urlState, setUrlState] = useUrlState({ days: '30' });
const days = urlState.days;
const setDays = (v: string) => setUrlState({ days: v });
const range = useMemo(() => {
const to = Math.floor(Date.now() / 1000);
+10 -3
View File
@@ -1,4 +1,5 @@
import React, { useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import { useUrlState } from '../hooks/useUrlState';
import PageHeader from '../components/ui/PageHeader';
import DataTable, { type Column } from '../components/ui/DataTable';
import SearchableSelect from '../components/ui/SearchableSelect';
@@ -24,8 +25,14 @@ function percent(value: number | null): string {
*/
export default function ResourceUtilizationPage() {
const { branches } = useBranches();
const [branchUuid, setBranchUuid] = useState('');
const [days, setDays] = useState('7');
// بازه و شعبه در URL می‌نشینند نه در state: بازگشت از صفحهٔ منبع باید همان گزارش را
// برگرداند، و لینکِ گزارش باید همان چیزی را نشان بدهد که فرستنده دیده.
const [urlState, setUrlState] = useUrlState({ branch: '', days: '7' });
const branchUuid = urlState.branch;
const days = urlState.days;
const setBranchUuid = (v: string) => setUrlState({ branch: v });
const setDays = (v: string) => setUrlState({ days: v });
const range = useMemo(() => {
const to = Math.floor(Date.now() / 1000);