fix - autorun selenium from aptmnt page - deleted this
This commit is contained in:
@@ -34,7 +34,7 @@ export default function InsuranceStatusPage() {
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { status, message, show } = useAppSelector(
|
const { status, message, show } = useAppSelector(
|
||||||
(state) => state.seleniumEligibilityCheckTask
|
(state) => state.seleniumEligibilityCheckTask,
|
||||||
);
|
);
|
||||||
const [selectedPatient, setSelectedPatient] = useState<Patient | null>(null);
|
const [selectedPatient, setSelectedPatient] = useState<Patient | null>(null);
|
||||||
const [location] = useLocation();
|
const [location] = useLocation();
|
||||||
@@ -56,12 +56,6 @@ export default function InsuranceStatusPage() {
|
|||||||
string | null
|
string | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
// 1) state to remember we should auto-run once patient arrives
|
|
||||||
const [pendingAutoAction, setPendingAutoAction] = useState<{
|
|
||||||
appointmentId: number;
|
|
||||||
action: "eligibility" | "claim";
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
// Populate fields from selected patient
|
// Populate fields from selected patient
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedPatient) {
|
if (selectedPatient) {
|
||||||
@@ -129,12 +123,12 @@ export default function InsuranceStatusPage() {
|
|||||||
setTaskStatus({
|
setTaskStatus({
|
||||||
status: "pending",
|
status: "pending",
|
||||||
message: "Sending Data to Selenium...",
|
message: "Sending Data to Selenium...",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
const response = await apiRequest(
|
const response = await apiRequest(
|
||||||
"POST",
|
"POST",
|
||||||
"/api/insurance-status/eligibility-check",
|
"/api/insurance-status/eligibility-check",
|
||||||
{ data: JSON.stringify(data) }
|
{ data: JSON.stringify(data) },
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.error) throw new Error(result.error);
|
if (result.error) throw new Error(result.error);
|
||||||
@@ -144,7 +138,7 @@ export default function InsuranceStatusPage() {
|
|||||||
status: "success",
|
status: "success",
|
||||||
message:
|
message:
|
||||||
"Patient status is updated, and its eligibility pdf is uploaded at Document Page.",
|
"Patient status is updated, and its eligibility pdf is uploaded at Document Page.",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -161,7 +155,7 @@ export default function InsuranceStatusPage() {
|
|||||||
setPreviewPdfId(Number(result.pdfFileId));
|
setPreviewPdfId(Number(result.pdfFileId));
|
||||||
// optional fallback name while header is parsed
|
// optional fallback name while header is parsed
|
||||||
setPreviewFallbackFilename(
|
setPreviewFallbackFilename(
|
||||||
result.pdfFilename ?? `eligibility_${memberId}.pdf`
|
result.pdfFilename ?? `eligibility_${memberId}.pdf`,
|
||||||
);
|
);
|
||||||
setPreviewOpen(true);
|
setPreviewOpen(true);
|
||||||
}
|
}
|
||||||
@@ -170,7 +164,7 @@ export default function InsuranceStatusPage() {
|
|||||||
setTaskStatus({
|
setTaskStatus({
|
||||||
status: "error",
|
status: "error",
|
||||||
message: error.message || "Selenium submission failed",
|
message: error.message || "Selenium submission failed",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
toast({
|
toast({
|
||||||
title: "Selenium service error",
|
title: "Selenium service error",
|
||||||
@@ -194,12 +188,12 @@ export default function InsuranceStatusPage() {
|
|||||||
setTaskStatus({
|
setTaskStatus({
|
||||||
status: "pending",
|
status: "pending",
|
||||||
message: "Sending Data to Selenium...",
|
message: "Sending Data to Selenium...",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
const response = await apiRequest(
|
const response = await apiRequest(
|
||||||
"POST",
|
"POST",
|
||||||
"/api/insurance-status/claim-status-check",
|
"/api/insurance-status/claim-status-check",
|
||||||
{ data: JSON.stringify(data) }
|
{ data: JSON.stringify(data) },
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.error) throw new Error(result.error);
|
if (result.error) throw new Error(result.error);
|
||||||
@@ -209,7 +203,7 @@ export default function InsuranceStatusPage() {
|
|||||||
status: "success",
|
status: "success",
|
||||||
message:
|
message:
|
||||||
"Claim status is updated, and its pdf is uploaded at Document Page.",
|
"Claim status is updated, and its pdf is uploaded at Document Page.",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -226,7 +220,7 @@ export default function InsuranceStatusPage() {
|
|||||||
setPreviewPdfId(Number(result.pdfFileId));
|
setPreviewPdfId(Number(result.pdfFileId));
|
||||||
// optional fallback name while header is parsed
|
// optional fallback name while header is parsed
|
||||||
setPreviewFallbackFilename(
|
setPreviewFallbackFilename(
|
||||||
result.pdfFilename ?? `eligibility_${memberId}.pdf`
|
result.pdfFilename ?? `eligibility_${memberId}.pdf`,
|
||||||
);
|
);
|
||||||
setPreviewOpen(true);
|
setPreviewOpen(true);
|
||||||
}
|
}
|
||||||
@@ -235,7 +229,7 @@ export default function InsuranceStatusPage() {
|
|||||||
setTaskStatus({
|
setTaskStatus({
|
||||||
status: "error",
|
status: "error",
|
||||||
message: error.message || "Selenium submission failed",
|
message: error.message || "Selenium submission failed",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
toast({
|
toast({
|
||||||
title: "Selenium service error",
|
title: "Selenium service error",
|
||||||
@@ -369,7 +363,6 @@ export default function InsuranceStatusPage() {
|
|||||||
// set selectedPatient as before
|
// set selectedPatient as before
|
||||||
setSelectedPatient(patient as Patient);
|
setSelectedPatient(patient as Patient);
|
||||||
|
|
||||||
setPendingAutoAction({ appointmentId: id, action: action as any });
|
|
||||||
clearUrlParams(["appointmentId", "action"]);
|
clearUrlParams(["appointmentId", "action"]);
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -390,82 +383,41 @@ export default function InsuranceStatusPage() {
|
|||||||
};
|
};
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
// ---------- same case1: runs when selectedPatient AND form fields are ready ----------
|
// handling case-1, when redirect happens from appointment page:
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pendingAutoAction) return;
|
const params = new URLSearchParams(window.location.search);
|
||||||
if (!selectedPatient) return; // wait until fetch effect set it
|
const appointmentId = params.get("appointmentId");
|
||||||
|
if (!appointmentId) return;
|
||||||
|
|
||||||
if (
|
const id = Number(appointmentId);
|
||||||
selectedPatient &&
|
if (Number.isNaN(id) || id <= 0) return;
|
||||||
memberId === "" &&
|
|
||||||
firstName === "" &&
|
|
||||||
dateOfBirth === null
|
|
||||||
) {
|
|
||||||
// form hasn't been populated yet; do nothing and wait for the next re-render
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
let inFlight = false;
|
|
||||||
|
|
||||||
// helper: determine final values using both selectedPatient and current form state
|
|
||||||
const finalMemberId =
|
|
||||||
(selectedPatient?.insuranceId
|
|
||||||
? String(selectedPatient.insuranceId).trim()
|
|
||||||
: "") || (memberId ? memberId.trim() : "");
|
|
||||||
|
|
||||||
const finalFirstName =
|
|
||||||
(selectedPatient?.firstName
|
|
||||||
? String(selectedPatient.firstName).trim()
|
|
||||||
: "") || (firstName ? firstName.trim() : "");
|
|
||||||
|
|
||||||
// DOB: try component state first (user may have typed), else patient fallback
|
|
||||||
const parsedDobFromPatient =
|
|
||||||
selectedPatient?.dateOfBirth != null
|
|
||||||
? typeof selectedPatient.dateOfBirth === "string"
|
|
||||||
? parseLocalDate(selectedPatient.dateOfBirth)
|
|
||||||
: selectedPatient.dateOfBirth
|
|
||||||
: null;
|
|
||||||
const finalDob = dateOfBirth ?? parsedDobFromPatient ?? null;
|
|
||||||
|
|
||||||
const missing: string[] = [];
|
|
||||||
if (!finalMemberId) missing.push("Member ID");
|
|
||||||
if (!finalFirstName) missing.push("First Name");
|
|
||||||
if (!finalDob) missing.push("Date of Birth");
|
|
||||||
|
|
||||||
if (missing.length > 0) {
|
|
||||||
toast({
|
|
||||||
title: "Missing Fields",
|
|
||||||
description: `Cannot auto-run. Missing: ${missing.join(", ")}.`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If ready, call the requested handler once. Clear pendingAutoAction afterwards.
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (cancelled) return;
|
|
||||||
if (inFlight) return;
|
|
||||||
inFlight = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (pendingAutoAction.action === "eligibility") {
|
const res = await apiRequest("GET", `/api/appointments/${id}/patient`);
|
||||||
await handleMHEligibilityButton();
|
if (!res.ok) return;
|
||||||
} else {
|
|
||||||
await handleMHStatusButton();
|
const data = await res.json();
|
||||||
|
const patient = data?.patient ?? data;
|
||||||
|
|
||||||
|
if (!cancelled && patient) {
|
||||||
|
// ✅ ONLY prefill patient
|
||||||
|
setSelectedPatient(patient as Patient);
|
||||||
|
|
||||||
|
// ✅ clean URL (no auto selenium)
|
||||||
|
clearUrlParams(["appointmentId", "action"]);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Auto MH action failed:", err);
|
console.error("Failed to fetch patient from appointment", err);
|
||||||
} finally {
|
|
||||||
inFlight = false;
|
|
||||||
if (!cancelled) setPendingAutoAction(null); // clear so it doesn't run again
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [pendingAutoAction, selectedPatient, memberId, firstName, dateOfBirth]);
|
}, [location]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -589,7 +541,7 @@ export default function InsuranceStatusPage() {
|
|||||||
onPdfReady={(pdfId, fallbackFilename) => {
|
onPdfReady={(pdfId, fallbackFilename) => {
|
||||||
setPreviewPdfId(pdfId);
|
setPreviewPdfId(pdfId);
|
||||||
setPreviewFallbackFilename(
|
setPreviewFallbackFilename(
|
||||||
fallbackFilename ?? `eligibility_ddma_${memberId}.pdf`
|
fallbackFilename ?? `eligibility_ddma_${memberId}.pdf`,
|
||||||
);
|
);
|
||||||
setPreviewOpen(true);
|
setPreviewOpen(true);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user