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:
@@ -41,3 +41,43 @@ export async function getAccountAdmin({
|
||||
|
||||
return data as unknown as AccountWithMemberships;
|
||||
}
|
||||
|
||||
export async function getDoctorAccounts() {
|
||||
const { data } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('id, email, name, last_name, preferred_locale')
|
||||
.eq('is_personal_account', true)
|
||||
.eq('application_role', 'doctor')
|
||||
.throwOnError();
|
||||
|
||||
return data?.map(({ id, email, name, last_name, preferred_locale }) => ({
|
||||
id,
|
||||
email,
|
||||
name,
|
||||
lastName: last_name,
|
||||
preferredLocale: preferred_locale,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getAssignedDoctorAccount(analysisOrderId: number) {
|
||||
const { data: doctorUser } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('doctor_analysis_feedback')
|
||||
.select('doctor_user_id')
|
||||
.eq('analysis_order_id', analysisOrderId)
|
||||
.throwOnError();
|
||||
|
||||
const doctorData = doctorUser[0];
|
||||
if (!doctorData || !doctorData.doctor_user_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('email')
|
||||
.eq('primary_owner_user_id', doctorData.doctor_user_id);
|
||||
|
||||
return { email: data?.[0]?.email };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user