* MED-82: add patient notification emails * remove console.log * clean up * remove extra paragraph from email
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { Database } from '@kit/supabase/database';
|
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
|
|
|
export enum NotificationAction {
|
|
DOCTOR_NEW_JOBS = 'DOCTOR_NEW_JOBS',
|
|
DOCTOR_PATIENT_RESULTS_RECEIVED = 'DOCTOR_PATIENT_RESULTS_RECEIVED',
|
|
PATIENT_DOCTOR_FEEDBACK_RECEIVED = 'PATIENT_DOCTOR_FEEDBACK_RECEIVED',
|
|
PATIENT_ORDER_PROCESSING = 'PATIENT_ORDER_PROCESSING',
|
|
PATIENT_FIRST_RESULTS_RECEIVED = 'PATIENT_FIRST_RESULTS_RECEIVED',
|
|
PATIENT_FULL_RESULTS_RECEIVED = 'PATIENT_FULL_RESULTS_RECEIVED',
|
|
}
|
|
|
|
export const createNotificationLog = async ({
|
|
action,
|
|
status,
|
|
comment,
|
|
relatedRecordId,
|
|
}: {
|
|
action: NotificationAction;
|
|
status: Database['audit']['Enums']['action_status'];
|
|
comment?: string;
|
|
relatedRecordId?: string | number;
|
|
}) => {
|
|
try {
|
|
const supabase = getSupabaseServerAdminClient();
|
|
|
|
await supabase
|
|
.schema('audit')
|
|
.from('notification_entries')
|
|
.insert({
|
|
action,
|
|
status,
|
|
comment,
|
|
related_record_key: relatedRecordId?.toString(),
|
|
})
|
|
.throwOnError();
|
|
} catch (error) {
|
|
console.error('Failed to insert doctor notification log', error);
|
|
}
|
|
};
|