* MED-88: add doctor email notifications * add logging, send open jobs notification on partial analysis response * update permissions * fix import, permissions * casing, let email be null * unused import
38 lines
975 B
TypeScript
38 lines
975 B
TypeScript
import { Database } from '@kit/supabase/database';
|
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
|
|
|
export enum NotificationAction {
|
|
DOCTOR_FEEDBACK_RECEIVED = 'DOCTOR_FEEDBACK_RECEIVED',
|
|
NEW_JOBS_ALERT = 'NEW_JOBS_ALERT',
|
|
PATIENT_RESULTS_RECEIVED_ALERT = 'PATIENT_RESULTS_RECEIVED_ALERT',
|
|
}
|
|
|
|
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);
|
|
}
|
|
};
|