feat(aptmt buttons) - 2 buttons added

This commit is contained in:
2025-09-23 01:46:45 +05:30
parent 460b3b53ac
commit ae0b61b326
2 changed files with 70 additions and 7 deletions

View File

@@ -651,8 +651,17 @@ export default function AppointmentsPage() {
}
// -------------------
// appointment page — update these handlers
const handleCheckEligibility = (appointmentId: number) => {
setLocation(`/insurance-status?appointmentId=${appointmentId}`);
setLocation(
`/insurance-status?appointmentId=${appointmentId}&action=eligibility`
);
};
const handleCheckClaimStatus = (appointmentId: number) => {
setLocation(
`/insurance-status?appointmentId=${appointmentId}&action=claim`
);
};
const handleClaimsPreAuth = (appointmentId: number) => {
@@ -732,7 +741,17 @@ export default function AppointmentsPage() {
>
<span className="flex items-center gap-2">
<Shield className="h-4 w-4" />
Check Eligibility
Eligibility Status
</span>
</Item>
{/* Check Eligibility */}
<Item
onClick={({ props }) => handleCheckClaimStatus(props.appointmentId)}
>
<span className="flex items-center gap-2">
<Shield className="h-4 w-4" />
Claim Status
</span>
</Item>

View File

@@ -308,18 +308,19 @@ export default function InsuranceStatusPage() {
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const appointmentId = params.get("appointmentId");
const action = params.get("action"); // 'eligibility' | 'claim'
if (!appointmentId) return;
const id = Number(appointmentId);
if (Number.isNaN(id) || id <= 0) return;
if (!action || (action !== "eligibility" && action !== "claim")) return;
let cancelled = false;
const inFlight = { running: false }; // local guard to avoid concurrent calls
(async () => {
try {
const res = await apiRequest("GET", `/api/appointments/${id}/patient`);
if (!res.ok) {
// try to read body for a helpful error message, otherwise show generic
let body: any = null;
try {
body = await res.json();
@@ -338,9 +339,52 @@ export default function InsuranceStatusPage() {
}
const data = await res.json();
// endpoint may return either { patient } or patient object directly
const patient = data?.patient ?? data;
if (!cancelled && patient) setSelectedPatient(patient as Patient);
if (!cancelled && patient) {
setSelectedPatient(patient as Patient);
// Give the selectedPatient -> form fields effect a brief moment to run
setTimeout(() => {
if (cancelled) return;
const tryInvoke = async () => {
if (cancelled) return;
// prevent overlapping concurrent handler calls
if (inFlight.running) return;
const ready =
(memberId?.trim() ?? "") !== "" &&
(firstName?.trim() ?? "") !== "" &&
dateOfBirth !== null;
if (!ready) return;
inFlight.running = true;
try {
if (action === "eligibility") {
await handleMHEligibilityButton();
} else {
await handleMHStatusButton();
}
} catch (err) {
console.error("Auto MH action failed:", err);
} finally {
inFlight.running = false;
}
};
// single-shot attempt, plus one quick retry if fields weren't populated yet
(async () => {
await tryInvoke();
if (!cancelled && !inFlight.running) {
// if not ready previously, try again shortly (single retry)
setTimeout(async () => {
await tryInvoke();
}, 150);
}
})();
}, 100); // small delay to let form state populate
}
} catch (err: any) {
if (!cancelled) {
console.error("Error fetching patient for appointment:", err);
@@ -357,7 +401,7 @@ export default function InsuranceStatusPage() {
return () => {
cancelled = true;
};
}, [location]); // re-run when wouter location changes
}, [location]);
return (
<div>