save and claim button added
This commit is contained in:
@@ -36,7 +36,9 @@ interface AddPatientModalProps {
|
|||||||
// Define the ref type
|
// Define the ref type
|
||||||
export type AddPatientModalRef = {
|
export type AddPatientModalRef = {
|
||||||
shouldSchedule: boolean;
|
shouldSchedule: boolean;
|
||||||
|
shouldClaim: boolean;
|
||||||
navigateToSchedule: (patientId: number) => void;
|
navigateToSchedule: (patientId: number) => void;
|
||||||
|
navigateToClaim: (patientId: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AddPatientModal = forwardRef<
|
export const AddPatientModal = forwardRef<
|
||||||
@@ -51,6 +53,7 @@ export const AddPatientModal = forwardRef<
|
|||||||
const isEditing = !!patient;
|
const isEditing = !!patient;
|
||||||
const [, navigate] = useLocation();
|
const [, navigate] = useLocation();
|
||||||
const [saveAndSchedule, setSaveAndSchedule] = useState(false);
|
const [saveAndSchedule, setSaveAndSchedule] = useState(false);
|
||||||
|
const [saveAndClaim, setSaveAndClaim] = useState(false);
|
||||||
const patientFormRef = useRef<PatientFormRef>(null); // Ref for PatientForm
|
const patientFormRef = useRef<PatientFormRef>(null); // Ref for PatientForm
|
||||||
|
|
||||||
// Set up the imperativeHandle to expose functionality to the parent component
|
// Set up the imperativeHandle to expose functionality to the parent component
|
||||||
@@ -65,9 +68,14 @@ export const AddPatientModal = forwardRef<
|
|||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
shouldSchedule: saveAndSchedule,
|
shouldSchedule: saveAndSchedule,
|
||||||
|
shouldClaim: saveAndClaim, // ✅ NEW
|
||||||
navigateToSchedule: (patientId: number) => {
|
navigateToSchedule: (patientId: number) => {
|
||||||
navigate(`/appointments?newPatient=${patientId}`);
|
navigate(`/appointments?newPatient=${patientId}`);
|
||||||
},
|
},
|
||||||
|
navigateToClaim: (patientId: number) => {
|
||||||
|
// ✅ NEW
|
||||||
|
navigate(`/claims?newPatient=${patientId}`);
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleFormSubmit = (data: InsertPatient | UpdatePatient) => {
|
const handleFormSubmit = (data: InsertPatient | UpdatePatient) => {
|
||||||
@@ -79,10 +87,15 @@ export const AddPatientModal = forwardRef<
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveAndSchedule = () => {
|
const handleSaveAndSchedule = () => {
|
||||||
|
setSaveAndClaim(false); // ensure only one flag at a time
|
||||||
setSaveAndSchedule(true);
|
setSaveAndSchedule(true);
|
||||||
if (patientFormRef.current) {
|
patientFormRef.current?.submit();
|
||||||
patientFormRef.current.submit();
|
};
|
||||||
}
|
|
||||||
|
const handleSaveAndClaim = () => {
|
||||||
|
setSaveAndSchedule(false); // ensure only one flag at a time
|
||||||
|
setSaveAndClaim(true);
|
||||||
|
patientFormRef.current?.submit();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -120,6 +133,18 @@ export const AddPatientModal = forwardRef<
|
|||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{!isEditing && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="gap-1"
|
||||||
|
onClick={handleSaveAndClaim}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<Calendar className="h-4 w-4" />
|
||||||
|
Save & Claim
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
{!isEditing && (
|
{!isEditing && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -165,10 +165,11 @@ export default function ClaimsPage() {
|
|||||||
|
|
||||||
// workflow starts from there - this params are set by pdf extraction/patient page. then used in claim page here.
|
// workflow starts from there - this params are set by pdf extraction/patient page. then used in claim page here.
|
||||||
const [location] = useLocation();
|
const [location] = useLocation();
|
||||||
const { name, memberId, dob } = useMemo(() => {
|
const { name, memberId, dob, newPatient } = useMemo(() => {
|
||||||
const search = window.location.search;
|
const search = window.location.search;
|
||||||
const params = new URLSearchParams(search);
|
const params = new URLSearchParams(search);
|
||||||
return {
|
return {
|
||||||
|
newPatient: params.get("newPatient"),
|
||||||
name: params.get("name") || "",
|
name: params.get("name") || "",
|
||||||
memberId: params.get("memberId") || "",
|
memberId: params.get("memberId") || "",
|
||||||
dob: params.get("dob") || "",
|
dob: params.get("dob") || "",
|
||||||
@@ -179,7 +180,17 @@ export default function ClaimsPage() {
|
|||||||
setSelectedPatientId(patientId);
|
setSelectedPatientId(patientId);
|
||||||
setIsClaimFormOpen(true);
|
setIsClaimFormOpen(true);
|
||||||
};
|
};
|
||||||
|
// ✅ FIRST: if ?newPatient=<id> is present, open claim form directly
|
||||||
|
useEffect(() => {
|
||||||
|
if (newPatient) {
|
||||||
|
const id = Number(newPatient);
|
||||||
|
if (Number.isFinite(id) && id > 0) {
|
||||||
|
handleNewClaim(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [newPatient]);
|
||||||
|
|
||||||
|
// existing flow: only runs when there is no ?newPatient and we have memberId+dob
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (memberId && dob) {
|
if (memberId && dob) {
|
||||||
// if matching patient found then simply send its id to claim form,
|
// if matching patient found then simply send its id to claim form,
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ import { InsertPatient, Patient } from "@repo/db/types";
|
|||||||
// Type for the ref to access modal methods
|
// Type for the ref to access modal methods
|
||||||
type AddPatientModalRef = {
|
type AddPatientModalRef = {
|
||||||
shouldSchedule: boolean;
|
shouldSchedule: boolean;
|
||||||
|
shouldClaim: boolean;
|
||||||
navigateToSchedule: (patientId: number) => void;
|
navigateToSchedule: (patientId: number) => void;
|
||||||
|
navigateToClaim: (patientId: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PatientsPage() {
|
export default function PatientsPage() {
|
||||||
@@ -57,9 +59,14 @@ export default function PatientsPage() {
|
|||||||
variant: "default",
|
variant: "default",
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the add patient modal wants to proceed to scheduling, redirect to appointments page
|
// ✅ Check claim first, then schedule
|
||||||
|
if (addPatientModalRef.current?.shouldClaim) {
|
||||||
|
addPatientModalRef.current.navigateToClaim(newPatient.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (addPatientModalRef.current?.shouldSchedule) {
|
if (addPatientModalRef.current?.shouldSchedule) {
|
||||||
addPatientModalRef.current.navigateToSchedule(newPatient.id);
|
addPatientModalRef.current.navigateToSchedule(newPatient.id);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user