Compare commits
3 Commits
5ef7f58f5d
...
f7fbbd2352
| Author | SHA1 | Date | |
|---|---|---|---|
| f7fbbd2352 | |||
| a77e2a7f70 | |||
| b216f7b211 |
12
lib/services/analysis-response.service.ts
Normal file
12
lib/services/analysis-response.service.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
|
||||
export async function getAnalysisResponseAdmin(analysisOrderId: number) {
|
||||
const { data } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
.select('*')
|
||||
.eq('analysis_order_id', analysisOrderId)
|
||||
.single()
|
||||
.throwOnError();
|
||||
return data;
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import { createBillingEventHandlerService } from './billing-event-handler.servic
|
||||
type ClientProvider = () => SupabaseClient<Database>;
|
||||
|
||||
// the billing provider from the database
|
||||
type BillingProvider = Enums<'billing_provider'>;
|
||||
type BillingProvider = Enums<{ schema: 'medreport' }, 'billing_provider'>;
|
||||
|
||||
/**
|
||||
* @name getBillingEventHandlerService
|
||||
|
||||
@@ -19,10 +19,10 @@ import { initializeEmailI18n } from '../lib/i18n';
|
||||
|
||||
export async function renderAllResultsReceivedEmail({
|
||||
language,
|
||||
analysisOrderId,
|
||||
analysisResponseId,
|
||||
}: {
|
||||
language: string;
|
||||
analysisOrderId: number;
|
||||
analysisResponseId: number;
|
||||
}) {
|
||||
const namespace = 'all-results-received-email';
|
||||
|
||||
@@ -57,13 +57,13 @@ export async function renderAllResultsReceivedEmail({
|
||||
{t(`${namespace}:openOrdersHeading`)}
|
||||
</Text>
|
||||
<EmailButton
|
||||
href={`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisOrderId}`}
|
||||
href={`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisResponseId}`}
|
||||
>
|
||||
{t(`${namespace}:linkText`)}
|
||||
</EmailButton>
|
||||
<Text>
|
||||
{t(`${namespace}:ifLinksDisabled`)}{' '}
|
||||
{`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisOrderId}`}
|
||||
{`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisResponseId}`}
|
||||
</Text>
|
||||
<CommonFooter t={t} />
|
||||
</EmailContent>
|
||||
|
||||
@@ -19,10 +19,10 @@ import { initializeEmailI18n } from '../lib/i18n';
|
||||
|
||||
export async function renderFirstResultsReceivedEmail({
|
||||
language,
|
||||
analysisOrderId,
|
||||
analysisResponseId,
|
||||
}: {
|
||||
language: string;
|
||||
analysisOrderId: number;
|
||||
analysisResponseId: number;
|
||||
}) {
|
||||
const namespace = 'first-results-received-email';
|
||||
|
||||
@@ -61,14 +61,14 @@ export async function renderFirstResultsReceivedEmail({
|
||||
</Text>
|
||||
|
||||
<EmailButton
|
||||
href={`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisOrderId}`}
|
||||
href={`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisResponseId}`}
|
||||
>
|
||||
{t(`${namespace}:linkText`)}
|
||||
</EmailButton>
|
||||
|
||||
<Text>
|
||||
{t(`${namespace}:ifLinksDisabled`)}{' '}
|
||||
{`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisOrderId}`}
|
||||
{`${process.env.NEXT_PUBLIC_SITE_URL}/doctor/analysis/${analysisResponseId}`}
|
||||
</Text>
|
||||
<CommonFooter t={t} />
|
||||
</EmailContent>
|
||||
|
||||
@@ -404,8 +404,14 @@ export async function getAnalysisResultsForDoctor(
|
||||
const medusaOrderId =
|
||||
firstAnalysisResponse?.analysis_responses?.analysis_order?.medusa_order_id;
|
||||
|
||||
if (!analysisResponsesData?.length || !userId || !medusaOrderId) {
|
||||
throw new Error('Failed to retrieve full analysis data.');
|
||||
if (!analysisResponsesData?.length) {
|
||||
throw new Error('No analysis responses data found.');
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('No user id found.');
|
||||
}
|
||||
if (!medusaOrderId) {
|
||||
throw new Error('No medusa order id found.');
|
||||
}
|
||||
|
||||
const responseElementAnalysisElementOriginalIds = analysisResponsesData.map(
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
getDoctorAccounts,
|
||||
getUserContactAdmin,
|
||||
} from '~/lib/services/account.service';
|
||||
import { getAnalysisResponseAdmin } from '~/lib/services/analysis-response.service';
|
||||
import {
|
||||
NotificationAction,
|
||||
createNotificationLog,
|
||||
@@ -74,14 +75,14 @@ class OrderWebhooksService {
|
||||
}
|
||||
|
||||
logger.info(ctx, 'Status change processed. No notifications to send.');
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
if (actions.length)
|
||||
await Promise.all(
|
||||
actions.map((action) =>
|
||||
createNotificationLog({
|
||||
action,
|
||||
status: 'FAIL',
|
||||
comment: e?.message,
|
||||
comment: e instanceof Error ? e.message : 'Unknown error',
|
||||
relatedRecordId: analysisOrder.id,
|
||||
}),
|
||||
),
|
||||
@@ -201,11 +202,11 @@ class OrderWebhooksService {
|
||||
status: 'SUCCESS',
|
||||
relatedRecordId: orderCart.order_id,
|
||||
});
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
createNotificationLog({
|
||||
action: NotificationAction.TTO_ORDER_CONFIRMATION,
|
||||
status: 'FAIL',
|
||||
comment: e?.message,
|
||||
comment: e instanceof Error ? e.message : 'Unknown error',
|
||||
relatedRecordId: ttoReservation.id,
|
||||
});
|
||||
logger.error(
|
||||
@@ -345,10 +346,12 @@ class OrderWebhooksService {
|
||||
.map(({ email }) => email)
|
||||
.filter((email): email is string => !!email);
|
||||
|
||||
|
||||
const analysisResponse = await getAnalysisResponseAdmin(analysisOrder.id);
|
||||
await sendEmailFromTemplate(
|
||||
renderFirstResultsReceivedEmail,
|
||||
{
|
||||
analysisOrderId: analysisOrder.id,
|
||||
analysisResponseId: analysisResponse.id,
|
||||
language: 'et',
|
||||
},
|
||||
doctorEmails,
|
||||
@@ -380,10 +383,12 @@ class OrderWebhooksService {
|
||||
return;
|
||||
}
|
||||
|
||||
const analysisResponse = await getAnalysisResponseAdmin(analysisOrder.id);
|
||||
|
||||
await sendEmailFromTemplate(
|
||||
renderAllResultsReceivedEmail,
|
||||
{
|
||||
analysisOrderId: analysisOrder.id,
|
||||
analysisResponseId: analysisResponse.id,
|
||||
language: 'et',
|
||||
},
|
||||
assignedDoctorEmail,
|
||||
|
||||
Reference in New Issue
Block a user