MED-88: add doctor email notifications (#65)
* 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
This commit is contained in:
32
lib/services/doctor-jobs.service.ts
Normal file
32
lib/services/doctor-jobs.service.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
|
||||
async function getAssignedOrderIds() {
|
||||
const supabase = getSupabaseServerAdminClient();
|
||||
|
||||
const { data: assignedOrderIds } = await supabase
|
||||
.schema('medreport')
|
||||
.from('doctor_analysis_feedback')
|
||||
.select('analysis_order_id')
|
||||
.not('doctor_user_id', 'is', null)
|
||||
.throwOnError();
|
||||
|
||||
return assignedOrderIds?.map((f) => f.analysis_order_id) || [];
|
||||
}
|
||||
|
||||
export async function getOpenJobAnalysisResponseIds() {
|
||||
const supabase = getSupabaseServerAdminClient();
|
||||
const assignedIds = await getAssignedOrderIds();
|
||||
|
||||
let query = supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
.select('id, analysis_order_id')
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
if (assignedIds.length > 0) {
|
||||
query = query.not('analysis_order_id', 'in', `(${assignedIds.join(',')})`);
|
||||
}
|
||||
|
||||
const { data: analysisResponses } = await query.throwOnError();
|
||||
return analysisResponses?.map(({ id }) => id) || [];
|
||||
}
|
||||
Reference in New Issue
Block a user