MED-202: fix doctor detail view
MED-202: fix doctor detail view
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
import ResultsTableWrapper from './results-table-wrapper';
|
import ResultsTableWrapper from './results-table-wrapper';
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function DoctorDashboard() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ResultsTableWrapper
|
<ResultsTableWrapper
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export function DoctorSidebar({
|
|||||||
<Sidebar collapsible="icon">
|
<Sidebar collapsible="icon">
|
||||||
<SidebarHeader className={'m-2'}>
|
<SidebarHeader className={'m-2'}>
|
||||||
<AppLogo
|
<AppLogo
|
||||||
href={pathsConfig.app.doctor}
|
href={pathsConfig.app.home}
|
||||||
className="max-w-full"
|
className="max-w-full"
|
||||||
compact={!open}
|
compact={!open}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ async function AnalysisPage({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader />
|
<PageHeader />
|
||||||
<PageBody>
|
<PageBody className="px-12">
|
||||||
<AnalysisView
|
<AnalysisView
|
||||||
patient={analysisResultDetails.patient}
|
patient={analysisResultDetails.patient}
|
||||||
order={analysisResultDetails.order}
|
order={analysisResultDetails.order}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ async function CompletedJobsPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader />
|
<PageHeader />
|
||||||
<PageBody>
|
<PageBody className="px-12">
|
||||||
<ResultsTableWrapper
|
<ResultsTableWrapper
|
||||||
titleKey="doctor:completedReviews"
|
titleKey="doctor:completedReviews"
|
||||||
action={getUserDoneResponsesAction}
|
action={getUserDoneResponsesAction}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ async function MyReviewsPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader />
|
<PageHeader />
|
||||||
<PageBody>
|
<PageBody className="px-12">
|
||||||
<ResultsTableWrapper
|
<ResultsTableWrapper
|
||||||
titleKey="doctor:myReviews"
|
titleKey="doctor:myReviews"
|
||||||
action={getUserInProgressResponsesAction}
|
action={getUserInProgressResponsesAction}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ async function OpenJobsPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader />
|
<PageHeader />
|
||||||
<PageBody>
|
<PageBody className="px-12">
|
||||||
<ResultsTableWrapper
|
<ResultsTableWrapper
|
||||||
titleKey="doctor:openReviews"
|
titleKey="doctor:openReviews"
|
||||||
action={getOpenResponsesAction}
|
action={getOpenResponsesAction}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
createDoctorPageViewLog,
|
createDoctorPageViewLog,
|
||||||
} from '~/lib/services/audit/doctorPageView.service';
|
} from '~/lib/services/audit/doctorPageView.service';
|
||||||
|
|
||||||
import Dashboard from './_components/doctor-dashboard';
|
import DoctorDashboard from './_components/doctor-dashboard';
|
||||||
import { DoctorGuard } from './_components/doctor-guard';
|
import { DoctorGuard } from './_components/doctor-guard';
|
||||||
|
|
||||||
async function DoctorPage() {
|
async function DoctorPage() {
|
||||||
@@ -16,8 +16,8 @@ async function DoctorPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader />
|
<PageHeader />
|
||||||
<PageBody>
|
<PageBody className="px-12">
|
||||||
<Dashboard />
|
<DoctorDashboard />
|
||||||
</PageBody>
|
</PageBody>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { GlobalLoader } from '@kit/ui/makerkit/global-loader';
|
|||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { AnalysisOrder } from '~/lib/types/analysis-order';
|
import { AnalysisOrder } from '~/lib/types/order';
|
||||||
|
|
||||||
function OrderConfirmedLoadingWrapper({
|
function OrderConfirmedLoadingWrapper({
|
||||||
medusaOrder: initialMedusaOrder,
|
medusaOrder: initialMedusaOrder,
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ export const selectJobAction = doctorAction(
|
|||||||
|
|
||||||
revalidateDoctorAnalysis();
|
revalidateDoctorAnalysis();
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
logger.error('Failed to select job', e);
|
logger.error({ error }, 'Failed to select job');
|
||||||
if (e instanceof Error) {
|
if (error instanceof Error) {
|
||||||
revalidateDoctorAnalysis();
|
revalidateDoctorAnalysis();
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
reason:
|
reason:
|
||||||
e['message'] === ErrorReason.JOB_ASSIGNED
|
error['message'] === ErrorReason.JOB_ASSIGNED
|
||||||
? ErrorReason.JOB_ASSIGNED
|
? ErrorReason.JOB_ASSIGNED
|
||||||
: ErrorReason.UNKNOWN,
|
: ErrorReason.UNKNOWN,
|
||||||
};
|
};
|
||||||
@@ -133,16 +133,16 @@ export const giveFeedbackAction = doctorAction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (e: any) {
|
} catch (error) {
|
||||||
if (isCompleted) {
|
if (isCompleted) {
|
||||||
await createNotificationLog({
|
await createNotificationLog({
|
||||||
action: NotificationAction.PATIENT_DOCTOR_FEEDBACK_RECEIVED,
|
action: NotificationAction.PATIENT_DOCTOR_FEEDBACK_RECEIVED,
|
||||||
status: 'FAIL',
|
status: 'FAIL',
|
||||||
comment: e?.message,
|
comment: error instanceof Error ? error.message : '',
|
||||||
relatedRecordId: analysisOrderId,
|
relatedRecordId: analysisOrderId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
logger.error('Failed to give feedback', e);
|
logger.error({ error }, 'Failed to give feedback');
|
||||||
return { success: false, reason: ErrorReason.UNKNOWN };
|
return { success: false, reason: ErrorReason.UNKNOWN };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export const getOpenResponsesAction = doctorAction(
|
|||||||
const data = await getOpenResponses({ page, pageSize });
|
const data = await getOpenResponses({ page, pageSize });
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error fetching open analysis response jobs`, error);
|
logger.error({ error }, `Error fetching open analysis response jobs`);
|
||||||
return { success: false, error: 'Failed to fetch data from the server.' };
|
return { success: false, error: 'Failed to fetch data from the server.' };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export type Patient = z.infer<typeof PatientSchema>;
|
|||||||
|
|
||||||
export const AnalysisResponsesSchema = z.object({
|
export const AnalysisResponsesSchema = z.object({
|
||||||
user_id: z.string(),
|
user_id: z.string(),
|
||||||
analysis_order_id: AnalysisOrderIdSchema,
|
analysis_order: AnalysisOrderIdSchema,
|
||||||
});
|
});
|
||||||
export type AnalysisResponses = z.infer<typeof AnalysisResponsesSchema>;
|
export type AnalysisResponses = z.infer<typeof AnalysisResponsesSchema>;
|
||||||
|
|
||||||
@@ -56,8 +56,8 @@ export const AnalysisResponseSchema = z.object({
|
|||||||
analysis_response_id: z.number(),
|
analysis_response_id: z.number(),
|
||||||
analysis_element_original_id: z.string(),
|
analysis_element_original_id: z.string(),
|
||||||
unit: z.string().nullable(),
|
unit: z.string().nullable(),
|
||||||
response_value: z.number(),
|
response_value: z.number().nullable(),
|
||||||
response_time: z.string(),
|
response_time: z.string().nullable(),
|
||||||
norm_upper: z.number().nullable(),
|
norm_upper: z.number().nullable(),
|
||||||
norm_upper_included: z.boolean().nullable(),
|
norm_upper_included: z.boolean().nullable(),
|
||||||
norm_lower: z.number().nullable(),
|
norm_lower: z.number().nullable(),
|
||||||
@@ -74,8 +74,8 @@ export const AnalysisResponseSchema = z.object({
|
|||||||
analysis_response_id: z.number(),
|
analysis_response_id: z.number(),
|
||||||
analysis_element_original_id: z.string(),
|
analysis_element_original_id: z.string(),
|
||||||
unit: z.string().nullable(),
|
unit: z.string().nullable(),
|
||||||
response_value: z.number(),
|
response_value: z.number().nullable(),
|
||||||
response_time: z.string(),
|
response_time: z.string().nullable(),
|
||||||
norm_upper: z.number().nullable(),
|
norm_upper: z.number().nullable(),
|
||||||
norm_upper_included: z.boolean().nullable(),
|
norm_upper_included: z.boolean().nullable(),
|
||||||
norm_lower: z.number().nullable(),
|
norm_lower: z.number().nullable(),
|
||||||
@@ -92,7 +92,7 @@ export const AnalysisResponseSchema = z.object({
|
|||||||
export type AnalysisResponse = z.infer<typeof AnalysisResponseSchema>;
|
export type AnalysisResponse = z.infer<typeof AnalysisResponseSchema>;
|
||||||
|
|
||||||
export const AnalysisResultDetailsSchema = z.object({
|
export const AnalysisResultDetailsSchema = z.object({
|
||||||
analysisResponse: z.array(AnalysisResponseSchema),
|
analysisResponse: z.array(AnalysisResponseSchema).nullable(),
|
||||||
order: OrderSchema,
|
order: OrderSchema,
|
||||||
doctorFeedback: DoctorFeedbackSchema,
|
doctorFeedback: DoctorFeedbackSchema,
|
||||||
patient: PatientSchema,
|
patient: PatientSchema,
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ export const ElementSchema = z.object({
|
|||||||
analysis_response_id: z.number(),
|
analysis_response_id: z.number(),
|
||||||
analysis_element_original_id: z.string(),
|
analysis_element_original_id: z.string(),
|
||||||
unit: z.string().nullable(),
|
unit: z.string().nullable(),
|
||||||
response_value: z.number(),
|
response_value: z.number().nullable(),
|
||||||
response_time: z.string(),
|
response_time: z.string().nullable(),
|
||||||
norm_upper: z.number().nullable(),
|
norm_upper: z.number().nullable(),
|
||||||
norm_upper_included: z.boolean().nullable(),
|
norm_upper_included: z.boolean().nullable(),
|
||||||
norm_lower: z.number().nullable(),
|
norm_lower: z.number().nullable(),
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'server-only';
|
import 'server-only';
|
||||||
|
|
||||||
|
import { listOrdersByIds, retrieveOrder } from '@lib/data/orders';
|
||||||
import { isBefore } from 'date-fns';
|
import { isBefore } from 'date-fns';
|
||||||
|
|
||||||
import { renderDoctorSummaryReceivedEmail } from '@kit/email-templates';
|
import { renderDoctorSummaryReceivedEmail } from '@kit/email-templates';
|
||||||
|
import { getLogger } from '@kit/shared/logger';
|
||||||
import { getFullName } from '@kit/shared/utils';
|
import { getFullName } from '@kit/shared/utils';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
||||||
@@ -31,7 +33,7 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
|
|
||||||
const [
|
const [
|
||||||
{ data: doctorFeedbackItems },
|
{ data: doctorFeedbackItems },
|
||||||
{ data: medusaOrderItems },
|
medusaOrders,
|
||||||
{ data: analysisResponseElements },
|
{ data: analysisResponseElements },
|
||||||
{ data: accounts },
|
{ data: accounts },
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
@@ -43,11 +45,7 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
'analysis_order_id',
|
'analysis_order_id',
|
||||||
analysisResponses.map((r) => r.analysis_order_id.id),
|
analysisResponses.map((r) => r.analysis_order_id.id),
|
||||||
),
|
),
|
||||||
supabase
|
listOrdersByIds(medusaOrderIds),
|
||||||
.schema('public')
|
|
||||||
.from('order_item')
|
|
||||||
.select('order_id, item_id(product_title, product_type)')
|
|
||||||
.in('order_id', medusaOrderIds),
|
|
||||||
supabase
|
supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('analysis_response_elements')
|
.from('analysis_response_elements')
|
||||||
@@ -56,7 +54,7 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
supabase
|
supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('name, last_name, id, primary_owner_user_id, preferred_locale')
|
.select('name,last_name,id,primary_owner_user_id,preferred_locale,slug')
|
||||||
.in('primary_owner_user_id', userIds),
|
.in('primary_owner_user_id', userIds),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -69,7 +67,7 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
? await supabase
|
? await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('name, last_name, id, primary_owner_user_id, preferred_locale')
|
.select('name,last_name,id,primary_owner_user_id,preferred_locale,slug')
|
||||||
.in('primary_owner_user_id', doctorUserIds)
|
.in('primary_owner_user_id', doctorUserIds)
|
||||||
: { data: [] };
|
: { data: [] };
|
||||||
|
|
||||||
@@ -82,21 +80,26 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
) || [];
|
) || [];
|
||||||
|
|
||||||
const firstSampleGivenAt = responseElements.length
|
const firstSampleGivenAt = responseElements.length
|
||||||
? responseElements.reduce((earliest, current) =>
|
? responseElements.reduce((earliest, current) => {
|
||||||
new Date(current.response_time) < new Date(earliest.response_time)
|
if (current.response_time && earliest.response_time) {
|
||||||
? current
|
if (
|
||||||
: earliest,
|
new Date(current.response_time) < new Date(earliest.response_time)
|
||||||
)?.response_time
|
) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
return earliest;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}).response_time
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const medusaOrder = medusaOrderItems?.find(
|
const medusaOrder = medusaOrders?.find(
|
||||||
({ order_id }) =>
|
({ id }) => id === analysisResponse.analysis_order_id.medusa_order_id,
|
||||||
order_id === analysisResponse.analysis_order_id.medusa_order_id,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const patientAccount = allAccounts?.find(
|
const patientAccount = allAccounts?.find(
|
||||||
({ primary_owner_user_id }) =>
|
({ primary_owner_user_id, slug }) =>
|
||||||
analysisResponse.user_id === primary_owner_user_id,
|
analysisResponse.user_id === primary_owner_user_id && !slug,
|
||||||
);
|
);
|
||||||
|
|
||||||
const feedback = doctorFeedbackItems?.find(
|
const feedback = doctorFeedbackItems?.find(
|
||||||
@@ -110,9 +113,10 @@ async function enrichAnalysisData(analysisResponses?: AnalysisResponseBase[]) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const order = {
|
const order = {
|
||||||
title: medusaOrder?.item_id.product_title,
|
title: medusaOrder?.items?.[0]?.product_title,
|
||||||
isPackage:
|
isPackage:
|
||||||
medusaOrder?.item_id.product_type?.toLowerCase() === 'analysis package',
|
medusaOrder?.items?.[0]?.product_type?.toLowerCase() ===
|
||||||
|
'analysis package',
|
||||||
analysisOrderId: analysisResponse.analysis_order_id.id,
|
analysisOrderId: analysisResponse.analysis_order_id.id,
|
||||||
status: analysisResponse.order_status,
|
status: analysisResponse.order_status,
|
||||||
};
|
};
|
||||||
@@ -177,6 +181,7 @@ export async function getUserInProgressResponses({
|
|||||||
`,
|
`,
|
||||||
{ count: 'exact' },
|
{ count: 'exact' },
|
||||||
)
|
)
|
||||||
|
.neq('status', 'ON_HOLD')
|
||||||
.in('analysis_order_id', analysisOrderIds)
|
.in('analysis_order_id', analysisOrderIds)
|
||||||
.range(offset, offset + pageSize - 1)
|
.range(offset, offset + pageSize - 1)
|
||||||
.order('created_at', { ascending: false });
|
.order('created_at', { ascending: false });
|
||||||
@@ -280,6 +285,7 @@ export async function getOpenResponses({
|
|||||||
`,
|
`,
|
||||||
{ count: 'exact' },
|
{ count: 'exact' },
|
||||||
)
|
)
|
||||||
|
.neq('order_status', 'ON_HOLD')
|
||||||
.order('created_at', { ascending: false });
|
.order('created_at', { ascending: false });
|
||||||
|
|
||||||
if (assignedIds.length > 0) {
|
if (assignedIds.length > 0) {
|
||||||
@@ -365,47 +371,50 @@ export async function getOtherResponses({
|
|||||||
export async function getAnalysisResultsForDoctor(
|
export async function getAnalysisResultsForDoctor(
|
||||||
analysisResponseId: number,
|
analysisResponseId: number,
|
||||||
): Promise<AnalysisResultDetails> {
|
): Promise<AnalysisResultDetails> {
|
||||||
|
const logger = await getLogger();
|
||||||
|
const ctx = {
|
||||||
|
action: 'get-analysis-results-for-doctor',
|
||||||
|
analysisResponseId,
|
||||||
|
};
|
||||||
const supabase = getSupabaseServerClient();
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
const { data: analysisResponseElements, error } = await supabase
|
const { data: analysisResponsesData, error: analysisResponsesError } =
|
||||||
.schema('medreport')
|
await supabase
|
||||||
.from(`analysis_response_elements`)
|
.schema('medreport')
|
||||||
.select(
|
.from(`analysis_response_elements`)
|
||||||
`*,
|
.select(
|
||||||
analysis_responses(user_id, analysis_order_id(id,medusa_order_id, analysis_element_ids))`,
|
`*,
|
||||||
)
|
analysis_responses(user_id, analysis_order:analysis_order_id(id,medusa_order_id, analysis_element_ids))`,
|
||||||
.eq('analysis_response_id', analysisResponseId);
|
)
|
||||||
|
.eq('analysis_response_id', analysisResponseId);
|
||||||
|
|
||||||
if (error) {
|
if (analysisResponsesError) {
|
||||||
throw new Error('Something went wrong.');
|
logger.error(
|
||||||
|
{ ...ctx, analysisResponsesError },
|
||||||
|
'No order response for this analysis response id',
|
||||||
|
);
|
||||||
|
throw new Error('No order for this analysis id');
|
||||||
}
|
}
|
||||||
|
const firstAnalysisResponse = analysisResponsesData?.[0];
|
||||||
const firstAnalysisResponse = analysisResponseElements?.[0];
|
|
||||||
const userId = firstAnalysisResponse?.analysis_responses.user_id;
|
const userId = firstAnalysisResponse?.analysis_responses.user_id;
|
||||||
const medusaOrderId =
|
const medusaOrderId =
|
||||||
firstAnalysisResponse?.analysis_responses?.analysis_order_id
|
firstAnalysisResponse?.analysis_responses?.analysis_order?.medusa_order_id;
|
||||||
?.medusa_order_id;
|
|
||||||
|
|
||||||
if (!analysisResponseElements?.length || !userId || !medusaOrderId) {
|
if (!analysisResponsesData?.length || !userId || !medusaOrderId) {
|
||||||
throw new Error('Failed to retrieve full analysis data.');
|
throw new Error('Failed to retrieve full analysis data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseElementAnalysisElementOriginalIds =
|
const responseElementAnalysisElementOriginalIds = analysisResponsesData.map(
|
||||||
analysisResponseElements.map(
|
({ analysis_element_original_id }) => analysis_element_original_id,
|
||||||
({ analysis_element_original_id }) => analysis_element_original_id,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
const [
|
const [
|
||||||
{ data: medusaOrderItems, error: medusaOrderError },
|
medusaOrder,
|
||||||
{ data: accountWithParams, error: accountError },
|
{ data: accountWithParams, error: accountError },
|
||||||
{ data: doctorFeedback, error: feedbackError },
|
{ data: doctorFeedback, error: feedbackError },
|
||||||
{ data: previousAnalyses, error: previousAnalysesError },
|
{ data: previousAnalyses, error: previousAnalysesError },
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
supabase
|
retrieveOrder(medusaOrderId, true, '*items'),
|
||||||
.schema('public')
|
|
||||||
.from('order_item')
|
|
||||||
.select(`order_id, item_id(product_title, product_type)`)
|
|
||||||
.eq('order_id', medusaOrderId),
|
|
||||||
supabase
|
supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
@@ -422,7 +431,7 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
.select(`*`)
|
.select(`*`)
|
||||||
.eq(
|
.eq(
|
||||||
'analysis_order_id',
|
'analysis_order_id',
|
||||||
firstAnalysisResponse.analysis_responses.analysis_order_id.id,
|
firstAnalysisResponse.analysis_responses.analysis_order.id,
|
||||||
)
|
)
|
||||||
.limit(1),
|
.limit(1),
|
||||||
supabase
|
supabase
|
||||||
@@ -452,12 +461,7 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
.order('response_time'),
|
.order('response_time'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (
|
if (!medusaOrder || accountError || feedbackError || previousAnalysesError) {
|
||||||
medusaOrderError ||
|
|
||||||
accountError ||
|
|
||||||
feedbackError ||
|
|
||||||
previousAnalysesError
|
|
||||||
) {
|
|
||||||
throw new Error('Something went wrong.');
|
throw new Error('Something went wrong.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,15 +482,20 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
} = accountWithParams[0];
|
} = accountWithParams[0];
|
||||||
|
|
||||||
const analysisResponseElementsWithPreviousData = [];
|
const analysisResponseElementsWithPreviousData = [];
|
||||||
for (const analysisResponseElement of analysisResponseElements) {
|
for (const analysisResponseElement of analysisResponsesData) {
|
||||||
const latestPreviousAnalysis = previousAnalyses.find(
|
const latestPreviousAnalysis = previousAnalyses.find(
|
||||||
({ analysis_element_original_id, response_time }) =>
|
({ analysis_element_original_id, response_time }) => {
|
||||||
analysis_element_original_id ===
|
if (response_time && analysisResponseElement.response_time) {
|
||||||
analysisResponseElement.analysis_element_original_id &&
|
return (
|
||||||
isBefore(
|
analysis_element_original_id ===
|
||||||
new Date(response_time),
|
analysisResponseElement.analysis_element_original_id &&
|
||||||
new Date(analysisResponseElement.response_time),
|
isBefore(
|
||||||
),
|
new Date(response_time),
|
||||||
|
new Date(analysisResponseElement.response_time),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
analysisResponseElementsWithPreviousData.push({
|
analysisResponseElementsWithPreviousData.push({
|
||||||
...analysisResponseElement,
|
...analysisResponseElement,
|
||||||
@@ -497,12 +506,12 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
return {
|
return {
|
||||||
analysisResponse: analysisResponseElementsWithPreviousData,
|
analysisResponse: analysisResponseElementsWithPreviousData,
|
||||||
order: {
|
order: {
|
||||||
title: medusaOrderItems?.[0]?.item_id.product_title ?? '-',
|
title: medusaOrder.items?.[0]?.product_title ?? '-',
|
||||||
isPackage:
|
isPackage:
|
||||||
medusaOrderItems?.[0]?.item_id.product_type?.toLowerCase() ===
|
medusaOrder.items?.[0]?.product_type?.toLowerCase() ===
|
||||||
'analysis package',
|
'analysis package',
|
||||||
analysisOrderId:
|
analysisOrderId:
|
||||||
firstAnalysisResponse.analysis_responses.analysis_order_id.id,
|
firstAnalysisResponse.analysis_responses.analysis_order.id,
|
||||||
},
|
},
|
||||||
doctorFeedback: doctorFeedback?.[0],
|
doctorFeedback: doctorFeedback?.[0],
|
||||||
patient: {
|
patient: {
|
||||||
@@ -525,8 +534,15 @@ export async function selectJob(analysisOrderId: number, userId: string) {
|
|||||||
const {
|
const {
|
||||||
data: { user },
|
data: { user },
|
||||||
} = await supabase.auth.getUser();
|
} = await supabase.auth.getUser();
|
||||||
|
const logger = await getLogger();
|
||||||
|
const ctx = {
|
||||||
|
action: 'select-job',
|
||||||
|
patientUserId: userId,
|
||||||
|
currentUserId: user?.id,
|
||||||
|
};
|
||||||
|
|
||||||
if (!user?.id) {
|
if (!user?.id) {
|
||||||
|
logger.error(ctx, 'No user logged in');
|
||||||
throw new Error('No user logged in.');
|
throw new Error('No user logged in.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,6 +557,7 @@ export async function selectJob(analysisOrderId: number, userId: string) {
|
|||||||
const jobAssignedToUserId = existingFeedback?.[0]?.doctor_user_id;
|
const jobAssignedToUserId = existingFeedback?.[0]?.doctor_user_id;
|
||||||
|
|
||||||
if (!!jobAssignedToUserId && jobAssignedToUserId !== user.id) {
|
if (!!jobAssignedToUserId && jobAssignedToUserId !== user.id) {
|
||||||
|
logger.error(ctx, 'Job assigned to a different user');
|
||||||
throw new Error(ErrorReason.JOB_ASSIGNED);
|
throw new Error(ErrorReason.JOB_ASSIGNED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +574,10 @@ export async function selectJob(analysisOrderId: number, userId: string) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (error || existingFeedbackError) {
|
if (error || existingFeedbackError) {
|
||||||
|
logger.error(
|
||||||
|
{ ...ctx, error, existingFeedbackError },
|
||||||
|
'Failed updating doctor feedback',
|
||||||
|
);
|
||||||
throw new Error('Something went wrong');
|
throw new Error('Something went wrong');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"extends": "@kit/tsconfig/base.json",
|
"extends": "../../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import { HttpTypes } from '@medusajs/types';
|
|||||||
|
|
||||||
import { getAuthHeaders, getCacheOptions } from './cookies';
|
import { getAuthHeaders, getCacheOptions } from './cookies';
|
||||||
|
|
||||||
export const retrieveOrder = async (id: string, allowCache = true) => {
|
export const retrieveOrder = async (
|
||||||
|
id: string,
|
||||||
|
allowCache = true,
|
||||||
|
fields = '*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',
|
||||||
|
) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
...(await getAuthHeaders()),
|
...(await getAuthHeaders()),
|
||||||
};
|
};
|
||||||
@@ -19,8 +23,7 @@ export const retrieveOrder = async (id: string, allowCache = true) => {
|
|||||||
.fetch<HttpTypes.StoreOrderResponse>(`/store/orders/${id}`, {
|
.fetch<HttpTypes.StoreOrderResponse>(`/store/orders/${id}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
query: {
|
query: {
|
||||||
fields:
|
fields,
|
||||||
'*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',
|
|
||||||
},
|
},
|
||||||
headers,
|
headers,
|
||||||
next,
|
next,
|
||||||
@@ -62,6 +65,14 @@ export const listOrders = async (
|
|||||||
.catch((err) => medusaError(err));
|
.catch((err) => medusaError(err));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const listOrdersByIds = async (ids: string[]) => {
|
||||||
|
try {
|
||||||
|
return Promise.all(ids.map((id) => retrieveOrder(id)));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('response Error', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createTransferRequest = async (
|
export const createTransferRequest = async (
|
||||||
formData: FormData,
|
formData: FormData,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function useNotificationsStream(params: {
|
|||||||
'postgres_changes',
|
'postgres_changes',
|
||||||
{
|
{
|
||||||
event: 'INSERT',
|
event: 'INSERT',
|
||||||
schema: 'public',
|
schema: 'medreport',
|
||||||
filter: `account_id=in.(${params.accountIds.join(', ')})`,
|
filter: `account_id=in.(${params.accountIds.join(', ')})`,
|
||||||
table: 'notifications',
|
table: 'notifications',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user