feat(aptmt buttons) - 2 buttons added
This commit is contained in:
@@ -651,8 +651,17 @@ export default function AppointmentsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------
|
// -------------------
|
||||||
|
// appointment page — update these handlers
|
||||||
const handleCheckEligibility = (appointmentId: number) => {
|
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) => {
|
const handleClaimsPreAuth = (appointmentId: number) => {
|
||||||
@@ -732,7 +741,17 @@ export default function AppointmentsPage() {
|
|||||||
>
|
>
|
||||||
<span className="flex items-center gap-2">
|
<span className="flex items-center gap-2">
|
||||||
<Shield className="h-4 w-4" />
|
<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>
|
</span>
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
|
|||||||
@@ -308,18 +308,19 @@ export default function InsuranceStatusPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const appointmentId = params.get("appointmentId");
|
const appointmentId = params.get("appointmentId");
|
||||||
|
const action = params.get("action"); // 'eligibility' | 'claim'
|
||||||
if (!appointmentId) return;
|
if (!appointmentId) return;
|
||||||
|
|
||||||
const id = Number(appointmentId);
|
const id = Number(appointmentId);
|
||||||
if (Number.isNaN(id) || id <= 0) return;
|
if (Number.isNaN(id) || id <= 0) return;
|
||||||
|
if (!action || (action !== "eligibility" && action !== "claim")) return;
|
||||||
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
const inFlight = { running: false }; // local guard to avoid concurrent calls
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await apiRequest("GET", `/api/appointments/${id}/patient`);
|
const res = await apiRequest("GET", `/api/appointments/${id}/patient`);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// try to read body for a helpful error message, otherwise show generic
|
|
||||||
let body: any = null;
|
let body: any = null;
|
||||||
try {
|
try {
|
||||||
body = await res.json();
|
body = await res.json();
|
||||||
@@ -338,9 +339,52 @@ export default function InsuranceStatusPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
// endpoint may return either { patient } or patient object directly
|
|
||||||
const patient = data?.patient ?? data;
|
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) {
|
} catch (err: any) {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
console.error("Error fetching patient for appointment:", err);
|
console.error("Error fetching patient for appointment:", err);
|
||||||
@@ -357,7 +401,7 @@ export default function InsuranceStatusPage() {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [location]); // re-run when wouter location changes
|
}, [location]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user