fix: remove auto appointment creation from claim submission

Claims no longer auto-create a schedule appointment when submitted — appointmentId is now optional.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-17 22:54:17 -04:00
parent 8e011c5a29
commit 7f19e38fc1
4 changed files with 26 additions and 218 deletions

View File

@@ -39,12 +39,10 @@ import {
ClaimFormData,
ClaimPreAuthData,
InputServiceLine,
InsertAppointment,
MissingTeethStatus,
NpiProvider,
Patient,
Staff,
UpdateAppointment,
UpdatePatient,
} from "@repo/db/types";
import { Decimal } from "decimal.js";
@@ -89,9 +87,6 @@ interface ClaimFormProps {
/** When true: form saves to AppointmentProcedure (Select Procedures flow), shows only Save button */
proceduresOnly?: boolean;
onSubmit: (data: ClaimFormData) => Promise<Claim>;
onHandleAppointmentSubmit: (
appointmentData: InsertAppointment | UpdateAppointment,
) => Promise<number | { id: number }>;
onHandleUpdatePatient: (patient: UpdatePatient & { id: number }) => void;
onHandleForMHSeleniumClaim: (data: ClaimFormData) => void;
onHandleForMHSeleniumClaimPreAuth: (data: ClaimPreAuthData) => void;
@@ -114,7 +109,6 @@ export function ClaimForm({
initialTab,
autoSubmitPreauth,
proceduresOnly = false,
onHandleAppointmentSubmit,
onHandleUpdatePatient,
onHandleForMHSeleniumClaim,
onHandleForMHSeleniumClaimPreAuth,
@@ -952,28 +946,7 @@ export function ClaimForm({
return;
}
// 1. Create or update appointment
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const appointmentData = {
patientId: patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
};
const created = await onHandleAppointmentSubmit(appointmentData);
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
// 3. Create Claim(if not)
// Filter out empty service lines (empty procedureCode)
@@ -999,7 +972,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId: patientId,
insuranceProvider: "MassHealth",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
@@ -1013,7 +986,7 @@ export function ClaimForm({
npiProvider: f.npiProvider,
patientId: patientId,
insuranceProvider: "Mass Health",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
insuranceSiteKey: "MH",
claimId: createdClaim.id,
});
@@ -1112,25 +1085,7 @@ export function ClaimForm({
return;
}
// Create appointment if needed
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f;
const claimFilesMeta: ClaimFileMeta[] = (uploadedFiles || []).map((file) => ({
@@ -1149,7 +1104,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "CCA",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
@@ -1161,7 +1116,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "CCA",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
insuranceSiteKey: "CCA",
claimId: createdClaim.id,
});
@@ -1197,24 +1152,7 @@ export function ClaimForm({
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f;
@@ -1233,7 +1171,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "Delta Dental MA",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
@@ -1244,7 +1182,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "Delta Dental MA",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
insuranceSiteKey: "DDMA",
claimId: createdClaim.id,
claimFiles: claimFilesMeta,
@@ -1281,24 +1219,7 @@ export function ClaimForm({
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f;
@@ -1316,7 +1237,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "United/DentalHub",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
@@ -1327,7 +1248,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "United/DentalHub",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
insuranceSiteKey: "UNITED_SCO",
claimId: createdClaim.id,
claimFiles: claimFilesMeta,
@@ -1364,24 +1285,7 @@ export function ClaimForm({
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f;
@@ -1401,7 +1305,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "Tufts SCO",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
@@ -1420,7 +1324,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "Tufts SCO",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
insuranceSiteKey: "TuftsSCO",
claimId: createdClaim.id,
claimFiles: claimFilesMeta,
@@ -1650,26 +1554,7 @@ export function ClaimForm({
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const appointmentData = {
patientId: patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
};
const created = await onHandleAppointmentSubmit(appointmentData);
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToSave } = form;
@@ -1689,7 +1574,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId: patientId,
insuranceProvider: "MassHealth",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
isDraft: true,
@@ -1806,24 +1691,7 @@ export function ClaimForm({
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId: patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id ?? 1,
title: serviceDate,
startTime: "09:00",
endTime: "09:30",
type: "recall",
status: "scheduled",
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const appointmentIdToUse = appointmentId;
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = form;
@@ -1842,7 +1710,7 @@ export function ClaimForm({
staffId: appointmentStaffId ?? Number(staff?.id),
patientId: patientId,
insuranceProvider: patient?.insuranceProvider || "MassHealth",
appointmentId: appointmentIdToUse!,
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});

View File

@@ -26,8 +26,6 @@ import { QK_APPOINTMENTS_BASE } from "@/pages/appointments-page";
import ClaimsOfPatientModal from "@/components/claims/claims-of-patient-table";
import {
Claim,
InsertAppointment,
UpdateAppointment,
UpdatePatient,
} from "@repo/db/types";
import ClaimDocumentsUploadMultiple from "@/components/claims/claim-document-upload-modal";
@@ -112,36 +110,6 @@ export default function ClaimsPage() {
},
});
// Create/upsert appointment mutation
const createAppointmentMutation = useMutation({
mutationFn: async (appointment: InsertAppointment) => {
const res = await apiRequest(
"POST",
"/api/appointments/upsert",
appointment
);
const data = await res.json();
if (!res.ok) {
throw new Error(data?.message || "Failed to create appointment");
}
return data;
},
onSuccess: (appointment) => {
queryClient.invalidateQueries({ queryKey: QK_APPOINTMENTS_BASE });
toast({
title: "Appointment Scheduled",
description: appointment.message || "Appointment created successfully.",
});
},
onError: (error: Error) => {
toast({
title: "Error",
description: `Failed to create appointment: ${error.message}`,
variant: "destructive",
});
},
});
// create claim mutation
const createClaimMutation = useMutation({
mutationFn: async (claimData: any) => {
@@ -347,38 +315,6 @@ export default function ClaimsPage() {
};
}, [location, search, newPatient]);
// 1. upsert appointment.
const handleAppointmentSubmit = async (
appointmentData: InsertAppointment | UpdateAppointment
): Promise<number> => {
return new Promise<number>((resolve, reject) => {
createAppointmentMutation.mutate(
{
date: appointmentData.date,
startTime: "09:00",
endTime: "09:30",
staffId: appointmentData.staffId,
patientId: appointmentData.patientId,
userId: user?.id,
title: "Scheduled Appointment",
type: "checkup",
},
{
onSuccess: (appointment) => {
if (!appointment?.id) {
reject(new Error("Appointment was created but returned no ID"));
return;
}
resolve(appointment.id);
},
onError: (error) => {
reject(error);
},
}
);
});
};
// 2. Update Patient ( for insuranceId and Insurance Provider)
const handleUpdatePatient = (patient: UpdatePatient & { id?: number }) => {
if (patient) {
@@ -1097,7 +1033,6 @@ export default function ClaimsPage() {
proceduresOnly={mode === "procedures"}
onClose={closeClaim}
onSubmit={handleClaimSubmit}
onHandleAppointmentSubmit={handleAppointmentSubmit}
onHandleUpdatePatient={handleUpdatePatient}
onHandleForMHSeleniumClaim={handleMHClaimSubmitSelenium}
onHandleForMHSeleniumClaimPreAuth={handleMHClaimPreAuthSubmitSelenium}

View File

@@ -79,11 +79,16 @@ export type ClaimWithServiceLines = Claim & {
}[];
staff?: Staff | null;
claimFiles?: ClaimFileMeta[] | null;
npiProvider?: {
id: number;
npiNumber: string;
providerName: string;
} | null;
};
export type MissingTeethStatus = "No_missing" | "endentulous" | "Yes_missing";
export interface ClaimFormData {
patientId: number;
appointmentId: number;
appointmentId?: number | null;
userId: number;
staffId: number;
patientName: string;

View File

@@ -93,7 +93,7 @@ export type MissingTeethStatus = "No_missing" | "endentulous" | "Yes_missing";
export interface ClaimFormData {
patientId: number;
appointmentId: number;
appointmentId?: number | null;
userId: number;
staffId: number;
patientName: string;