feat(aptmt buttons) - 2 buttons added - v3

This commit is contained in:
2025-09-23 03:17:30 +05:30
parent cec65d6361
commit f3d8d25b59

View File

@@ -343,42 +343,57 @@ export default function InsuranceStatusPage() {
if (!cancelled && patient) { if (!cancelled && patient) {
setSelectedPatient(patient as Patient); setSelectedPatient(patient as Patient);
// derive values (use fetched patient as authoritative fallback) // populate the form state (so UI updates immediately)
const memberIdVal = (patient?.insuranceId ?? memberId ?? "") setMemberId(patient.insuranceId ?? "");
.toString() setFirstName(patient.firstName ?? "");
.trim(); setLastName(patient.lastName ?? "");
const firstNameVal = (patient?.firstName ?? firstName ?? "") const parsedDob =
.toString() patient?.dateOfBirth != null
.trim();
const dobVal =
dateOfBirth !== null
? dateOfBirth
: patient?.dateOfBirth
? typeof patient.dateOfBirth === "string" ? typeof patient.dateOfBirth === "string"
? parseLocalDate(patient.dateOfBirth) ? parseLocalDate(patient.dateOfBirth)
: patient.dateOfBirth : patient.dateOfBirth
: null; : null;
setDateOfBirth(parsedDob ?? null);
// --- determine presence/validity from *patient* object (authoritative here) ---
const memberIdVal =
patient.insuranceId !== undefined &&
patient.insuranceId !== null &&
String(patient.insuranceId).trim() !== ""
? String(patient.insuranceId).trim()
: "";
const firstNameVal =
patient.firstName !== undefined &&
patient.firstName !== null &&
String(patient.firstName).trim() !== ""
? String(patient.firstName).trim()
: "";
// DOB check: accept valid Date objects or parseable non-empty strings
let dobIsValid = false;
if (patient.dateOfBirth != null) {
if (typeof patient.dateOfBirth === "string") {
const d = parseLocalDate(patient.dateOfBirth);
dobIsValid = d instanceof Date && !isNaN(d.getTime());
} else if (patient.dateOfBirth instanceof Date) {
dobIsValid = !isNaN(patient.dateOfBirth.getTime());
} else {
// some other format — treat as invalid
dobIsValid = false;
}
}
// if any required field is missing, show toast and don't auto-run
const missing: string[] = []; const missing: string[] = [];
if (!memberIdVal) missing.push("Member ID"); if (!memberIdVal) missing.push("Member ID");
if (!firstNameVal) missing.push("First Name"); if (!firstNameVal) missing.push("First Name");
if (!dobVal) missing.push("Date of Birth"); if (!dobIsValid) missing.push("Date of Birth");
// populate the form state (keeps inputs consistent with patient)
setMemberId(patient.insuranceId ?? "");
setFirstName(patient.firstName ?? "");
setLastName(patient.lastName ?? "");
setDateOfBirth(
typeof patient.dateOfBirth === "string"
? parseLocalDate(patient.dateOfBirth)
: (patient.dateOfBirth ?? null)
);
if (missing.length > 0) { if (missing.length > 0) {
// show toast and DO NOT auto-run
if (!cancelled) { if (!cancelled) {
toast({ toast({
title: "Missing Fields", title: "Missing or invalid fields",
description: `Cannot auto-run. Please provide: ${missing.join(", ")}.`, description: `Cannot auto-run. Please provide: ${missing.join(", ")}.`,
variant: "destructive", variant: "destructive",
}); });