lifestyle development
This commit is contained in:
84
app/home/(user)/(dashboard)/life-style/page.tsx
Normal file
84
app/home/(user)/(dashboard)/life-style/page.tsx
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||||
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
|
import { Circle } from 'lucide-react';
|
||||||
|
|
||||||
|
import { cn } from '@kit/ui/lib/utils';
|
||||||
|
import { PageBody } from '@kit/ui/makerkit/page';
|
||||||
|
import { Trans } from '@kit/ui/makerkit/trans';
|
||||||
|
import { Skeleton } from '@kit/ui/shadcn/skeleton';
|
||||||
|
|
||||||
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import {
|
||||||
|
PageViewAction,
|
||||||
|
createPageViewLog,
|
||||||
|
} from '~/lib/services/audit/pageView.service';
|
||||||
|
|
||||||
|
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||||
|
import { loadLifeStyle } from '../../_lib/server/load-life-style';
|
||||||
|
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||||
|
|
||||||
|
export async function generateMetadata() {
|
||||||
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: t('common:lifeStyle.title'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function LifeStylePage() {
|
||||||
|
const supabaseClient = getSupabaseServerClient();
|
||||||
|
const userAnalysesApi = createUserAnalysesApi(supabaseClient);
|
||||||
|
|
||||||
|
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
||||||
|
console.log('analysisResponses', analysisResponses);
|
||||||
|
const { account } = await loadCurrentUserAccount();
|
||||||
|
if (!account) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const data = await loadLifeStyle(account);
|
||||||
|
|
||||||
|
await createPageViewLog({
|
||||||
|
accountId: account.id,
|
||||||
|
action: PageViewAction.VIEW_LIFE_STYLE,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data.lifestyle) {
|
||||||
|
return <Skeleton className="mt-10 h-10 w-full" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<HomeLayoutPageHeader
|
||||||
|
title={<Trans i18nKey={'common:lifeStyle.title'} />}
|
||||||
|
description=""
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PageBody>
|
||||||
|
<div className="mt-8">
|
||||||
|
{data.lifestyle.map(({ title, description, score }, index) => (
|
||||||
|
<React.Fragment key={`${index}-${title}`}>
|
||||||
|
<div
|
||||||
|
key={`${index}-${title}`}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<h3>{title}</h3>
|
||||||
|
<Circle
|
||||||
|
className={cn('text-success fill-success size-6', {
|
||||||
|
'text-warning fill-warning': score === 1,
|
||||||
|
'text-destructive fill-destructive': score === 2,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p className="font-regular py-4">{description}</p>
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</PageBody>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withI18n(LifeStylePage);
|
||||||
@@ -18,14 +18,14 @@ const AIBlocks = async ({ account }: { account: AccountWithParams }) => {
|
|||||||
return <OrderAnalysesPackageCard />;
|
return <OrderAnalysesPackageCard />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { analyses, countryCode } = await loadAnalyses();
|
const { analyses } = await loadAnalyses();
|
||||||
|
|
||||||
if (analyses.length === 0) {
|
if (analyses.length === 0) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<OrderAnalysesPackageCard />
|
<OrderAnalysesPackageCard />
|
||||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
<Suspense fallback={<RecommendationsSkeleton amount={1} />}>
|
||||||
<LifeStyleCard />
|
<LifeStyleCard account={account} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -33,7 +33,7 @@ const AIBlocks = async ({ account }: { account: AccountWithParams }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||||
<LifeStyleCard />
|
<LifeStyleCard account={account} />
|
||||||
<Recommendations account={account} />
|
<Recommendations account={account} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,16 +2,34 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Card } from '@kit/ui/shadcn/card';
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
import { pathsConfig } from '@/packages/shared/src/config';
|
||||||
|
import { ChevronRight } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Trans } from '@kit/ui/makerkit/trans';
|
||||||
|
import { Button } from '@kit/ui/shadcn/button';
|
||||||
|
import { Card, CardHeader } from '@kit/ui/shadcn/card';
|
||||||
|
|
||||||
import { loadLifeStyle } from '../../_lib/server/load-life-style';
|
import { loadLifeStyle } from '../../_lib/server/load-life-style';
|
||||||
|
|
||||||
const LifeStyleCard = async () => {
|
const LifeStyleCard = async ({ account }: { account: AccountWithParams }) => {
|
||||||
const data = await loadLifeStyle();
|
const data = await loadLifeStyle(account);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card variant="gradient-success" className="flex flex-col justify-between">
|
<Card variant="gradient-success" className="flex flex-col justify-between">
|
||||||
Test
|
<CardHeader className="flex-row justify-between">
|
||||||
|
<h5>
|
||||||
|
<Trans i18nKey="dashboard:heroCard.lifeStyle.title" />
|
||||||
|
</h5>
|
||||||
|
<Link href={pathsConfig.app.lifeStyle}>
|
||||||
|
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||||
|
<ChevronRight className="size-4 stroke-2" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</CardHeader>
|
||||||
|
<span className="text-primary p-4 text-sm">{data.summary}</span>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@kit/ui/shadcn/card';
|
} from '@kit/ui/shadcn/card';
|
||||||
import { Skeleton } from '@kit/ui/skeleton';
|
import { Skeleton } from '@kit/ui/skeleton';
|
||||||
|
|
||||||
const RecommendationsSkeleton = () => {
|
const RecommendationsSkeleton = ({ amount = 2 }: { amount?: number }) => {
|
||||||
const emptyData = [
|
const emptyData = [
|
||||||
{
|
{
|
||||||
title: '1',
|
title: '1',
|
||||||
@@ -20,55 +20,48 @@ const RecommendationsSkeleton = () => {
|
|||||||
variant: { id: '' },
|
variant: { id: '' },
|
||||||
price: 1,
|
price: 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '2',
|
|
||||||
description: '',
|
|
||||||
subtitle: '',
|
|
||||||
variant: { id: '' },
|
|
||||||
price: 1,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
return (
|
return Array.from({ length: amount }, (_, index) => {
|
||||||
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
const { title, description, subtitle } = emptyData[0]!;
|
||||||
{emptyData.map(({ title, description, subtitle }) => (
|
|
||||||
<Skeleton key={title}>
|
return (
|
||||||
<Card>
|
<Skeleton key={title + index}>
|
||||||
<CardHeader className="flex-row">
|
<Card>
|
||||||
<div
|
<CardHeader className="flex-row">
|
||||||
className={
|
<div
|
||||||
'mb-6 flex size-8 items-center-safe justify-center-safe'
|
className={
|
||||||
}
|
'mb-6 flex size-8 items-center-safe justify-center-safe'
|
||||||
/>
|
}
|
||||||
<div className="ml-auto flex size-8 items-center-safe justify-center-safe">
|
/>
|
||||||
<Button size="icon" className="px-2" />
|
<div className="ml-auto flex size-8 items-center-safe justify-center-safe">
|
||||||
</div>
|
<Button size="icon" className="px-2" />
|
||||||
</CardHeader>
|
</div>
|
||||||
<CardFooter className="flex">
|
</CardHeader>
|
||||||
<div className="flex flex-1 flex-col items-start">
|
<CardFooter className="flex">
|
||||||
<h5>
|
<div className="flex flex-1 flex-col items-start">
|
||||||
{title}
|
<h5>
|
||||||
{description && (
|
{title}
|
||||||
<>
|
{description && (
|
||||||
{' '}
|
<>
|
||||||
<InfoTooltip
|
{' '}
|
||||||
content={
|
<InfoTooltip
|
||||||
<div className="flex flex-col gap-2">
|
content={
|
||||||
<span>{description}</span>
|
<div className="flex flex-col gap-2">
|
||||||
</div>
|
<span>{description}</span>
|
||||||
}
|
</div>
|
||||||
/>
|
}
|
||||||
</>
|
/>
|
||||||
)}
|
</>
|
||||||
</h5>
|
)}
|
||||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
</h5>
|
||||||
</div>
|
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||||
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
</div>
|
||||||
</CardFooter>
|
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
||||||
</Card>
|
</CardFooter>
|
||||||
</Skeleton>
|
</Card>
|
||||||
))}
|
</Skeleton>
|
||||||
</div>
|
);
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RecommendationsSkeleton;
|
export default RecommendationsSkeleton;
|
||||||
|
|||||||
18
app/home/(user)/_components/ai/types.ts
Normal file
18
app/home/(user)/_components/ai/types.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Database } from '@/packages/supabase/src/database.types';
|
||||||
|
|
||||||
|
export interface ILifeStyleResponse {
|
||||||
|
lifestyle: {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
score: 0 | 1 | 2;
|
||||||
|
}[];
|
||||||
|
summary: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PROMPT_NAME {
|
||||||
|
LIFE_STYLE = 'Life Style',
|
||||||
|
ANALYSIS_RECOMMENDATIONS = 'Analysis Recommendations',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AnalysisResponses =
|
||||||
|
Database['medreport']['Functions']['get_latest_analysis_response_elements_for_current_user']['Returns'];
|
||||||
@@ -63,55 +63,53 @@ export default function OrderItemsTable({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Table className="border-separate rounded-lg border p-2 sm:hidden">
|
<Table className="border-separate rounded-lg border p-2 sm:hidden">
|
||||||
<TableBody>
|
{items
|
||||||
{items
|
.sort((a, b) =>
|
||||||
.sort((a, b) =>
|
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
)
|
||||||
)
|
.map((orderItem) => (
|
||||||
.map((orderItem) => (
|
<TableBody key={`${orderItem.id}-mobile`}>
|
||||||
<div key={`${orderItem.id}-mobile`}>
|
<MobileTableRow
|
||||||
|
titleKey={title}
|
||||||
|
value={orderItem.product_title || ''}
|
||||||
|
/>
|
||||||
|
<MobileTableRow
|
||||||
|
titleKey="orders:table.createdAt"
|
||||||
|
value={formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||||
|
/>
|
||||||
|
{order.location && (
|
||||||
<MobileTableRow
|
<MobileTableRow
|
||||||
titleKey={title}
|
titleKey="orders:table.location"
|
||||||
value={orderItem.product_title || ''}
|
value={order.location}
|
||||||
/>
|
/>
|
||||||
<MobileTableRow
|
)}
|
||||||
titleKey="orders:table.createdAt"
|
<MobileTableRow
|
||||||
value={formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
titleKey="orders:table.status"
|
||||||
/>
|
value={
|
||||||
{order.location && (
|
isPackage
|
||||||
<MobileTableRow
|
? `orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`
|
||||||
titleKey="orders:table.location"
|
: `orders:status.${type}.${order?.status ?? 'CONFIRMED'}`
|
||||||
value={order.location}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
<TableRow>
|
||||||
<MobileTableRow
|
<TableCell />
|
||||||
titleKey="orders:table.status"
|
<TableCell className="flex w-full items-center justify-end p-0 pt-2">
|
||||||
value={
|
<Button size="sm" onClick={openDetailedView}>
|
||||||
isPackage
|
<Trans i18nKey="analysis-results:view" />
|
||||||
? `orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`
|
</Button>
|
||||||
: `orders:status.${type}.${order?.status ?? 'CONFIRMED'}`
|
{isTtoservice && order.bookingCode && (
|
||||||
}
|
<Button
|
||||||
/>
|
size="sm"
|
||||||
<TableRow>
|
className="bg-warning/90 hover:bg-warning"
|
||||||
<TableCell />
|
onClick={() => setIsConfirmOpen(true)}
|
||||||
<TableCell className="flex w-full items-center justify-end p-0 pt-2">
|
>
|
||||||
<Button size="sm" onClick={openDetailedView}>
|
<Trans i18nKey="analysis-results:cancel" />
|
||||||
<Trans i18nKey="analysis-results:view" />
|
|
||||||
</Button>
|
</Button>
|
||||||
{isTtoservice && order.bookingCode && (
|
)}
|
||||||
<Button
|
</TableCell>
|
||||||
size="sm"
|
</TableRow>
|
||||||
className="bg-warning/90 hover:bg-warning"
|
</TableBody>
|
||||||
onClick={() => setIsConfirmOpen(true)}
|
))}
|
||||||
>
|
|
||||||
<Trans i18nKey="analysis-results:cancel" />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<Table className="hidden border-separate rounded-lg border sm:block">
|
<Table className="hidden border-separate rounded-lg border sm:block">
|
||||||
|
|||||||
108
app/home/(user)/_lib/server/ai-actions.ts
Normal file
108
app/home/(user)/_lib/server/ai-actions.ts
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||||
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
|
import OpenAI from 'openai';
|
||||||
|
|
||||||
|
import PersonalCode from '~/lib/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AnalysisResponses,
|
||||||
|
ILifeStyleResponse,
|
||||||
|
PROMPT_NAME,
|
||||||
|
} from '../../_components/ai/types';
|
||||||
|
|
||||||
|
async function getLatestResponseTime(items: AnalysisResponses) {
|
||||||
|
if (!items?.length) return null;
|
||||||
|
|
||||||
|
let latest = null;
|
||||||
|
for (const it of items) {
|
||||||
|
const d = new Date(it.response_time);
|
||||||
|
const t = d.getTime();
|
||||||
|
if (!Number.isNaN(t) && (latest === null || t > latest.getTime())) {
|
||||||
|
latest = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateLifeStyle({
|
||||||
|
account,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams;
|
||||||
|
}): Promise<ILifeStyleResponse> {
|
||||||
|
const LIFE_STYLE_PROMPT_ID = process.env.PROMPT_ID_LIFE_STYLE;
|
||||||
|
if (!LIFE_STYLE_PROMPT_ID || !account?.personal_code) {
|
||||||
|
return {
|
||||||
|
lifestyle: [],
|
||||||
|
summary: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const openAIClient = new OpenAI();
|
||||||
|
const supabaseClient = getSupabaseServerClient();
|
||||||
|
const userAnalysesApi = createUserAnalysesApi(supabaseClient);
|
||||||
|
|
||||||
|
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
||||||
|
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
||||||
|
const weight = account.accountParams?.weight || 'unknown';
|
||||||
|
const height = account.accountParams?.height || 'unknown';
|
||||||
|
const isSmoker = !!account.accountParams?.isSmoker;
|
||||||
|
|
||||||
|
const latestResponseTime = await getLatestResponseTime(analysisResponses);
|
||||||
|
const latestISO = latestResponseTime
|
||||||
|
? new Date(latestResponseTime).toISOString()
|
||||||
|
: new Date('2025').toISOString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await openAIClient.responses.create({
|
||||||
|
store: false,
|
||||||
|
prompt: {
|
||||||
|
id: LIFE_STYLE_PROMPT_ID,
|
||||||
|
variables: {
|
||||||
|
gender: gender.value,
|
||||||
|
age: age.toString(),
|
||||||
|
weight: weight.toString(),
|
||||||
|
height: height.toString(),
|
||||||
|
cholesterol: '',
|
||||||
|
ldl: '',
|
||||||
|
hdl: '',
|
||||||
|
vitamind: '',
|
||||||
|
is_smoker: isSmoker.toString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await supabaseClient
|
||||||
|
.schema('medreport')
|
||||||
|
.from('ai_responses')
|
||||||
|
.insert({
|
||||||
|
account_id: account.id,
|
||||||
|
prompt_name: PROMPT_NAME.LIFE_STYLE,
|
||||||
|
prompt_id: LIFE_STYLE_PROMPT_ID,
|
||||||
|
input: JSON.stringify({
|
||||||
|
gender: gender.value,
|
||||||
|
age: age.toString(),
|
||||||
|
weight: weight.toString(),
|
||||||
|
cholesterol: '',
|
||||||
|
ldl: '',
|
||||||
|
hdl: '',
|
||||||
|
vitamind: '',
|
||||||
|
is_smoker: isSmoker.toString(),
|
||||||
|
}),
|
||||||
|
latest_data_change: latestISO,
|
||||||
|
response: response.output_text,
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = JSON.parse(response.output_text);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error calling OpenAI: ', error);
|
||||||
|
return {
|
||||||
|
lifestyle: [],
|
||||||
|
summary: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +1,49 @@
|
|||||||
import { cache } from 'react';
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
import OpenAI from 'openai';
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
|
|
||||||
import PersonalCode from '~/lib/utils';
|
import { ILifeStyleResponse, PROMPT_NAME } from '../../_components/ai/types';
|
||||||
|
import { updateLifeStyle } from './ai-actions';
|
||||||
|
|
||||||
const failedResponse = {
|
const failedResponse = {
|
||||||
lifeStyle: null,
|
lifestyle: [],
|
||||||
summary: null,
|
summary: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function lifeStyleLoader(account: AccountWithParams) {
|
async function lifeStyleLoader(
|
||||||
|
account: AccountWithParams,
|
||||||
|
): Promise<ILifeStyleResponse> {
|
||||||
if (!account?.personal_code) {
|
if (!account?.personal_code) {
|
||||||
return failedResponse;
|
return failedResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
const openAIClient = new OpenAI();
|
const lifeStylePromptId = process.env.PROMPT_ID_LIFE_STYLE;
|
||||||
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
|
||||||
try {
|
|
||||||
const response = await openAIClient.responses.create({
|
|
||||||
store: false,
|
|
||||||
prompt: {
|
|
||||||
id: analysesRecommendationsPromptId,
|
|
||||||
variables: {
|
|
||||||
analyses: JSON.stringify(formattedAnalyses),
|
|
||||||
results: JSON.stringify(formattedAnalysisResponses),
|
|
||||||
gender: gender.value,
|
|
||||||
age: age.toString(),
|
|
||||||
weight: weight.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
if (!lifeStylePromptId) {
|
||||||
} catch (error) {
|
|
||||||
console.error('Error calling OpenAI: ', error);
|
|
||||||
return failedResponse;
|
return failedResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const supabaseClient = getSupabaseServerClient();
|
||||||
|
const { data, error } = await supabaseClient
|
||||||
|
.schema('medreport')
|
||||||
|
.from('ai_responses')
|
||||||
|
.select('response')
|
||||||
|
.eq('account_id', account.id)
|
||||||
|
.eq('prompt_name', PROMPT_NAME.LIFE_STYLE)
|
||||||
|
.order('latest_data_change', { ascending: false, nullsFirst: false })
|
||||||
|
.limit(1)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching AI response from DB: ', error);
|
||||||
|
return failedResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data?.response) {
|
||||||
|
return JSON.parse(data.response as string);
|
||||||
|
} else {
|
||||||
|
return await updateLifeStyle({ account });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export const loadLifeStyle = cache(lifeStyleLoader);
|
export const loadLifeStyle = cache(lifeStyleLoader);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import OpenAI from 'openai';
|
|||||||
|
|
||||||
import PersonalCode from '~/lib/utils';
|
import PersonalCode from '~/lib/utils';
|
||||||
|
|
||||||
|
import { PROMPT_NAME } from '../../_components/ai/types';
|
||||||
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
||||||
|
|
||||||
export const loadRecommendations = cache(recommendationsLoader);
|
export const loadRecommendations = cache(recommendationsLoader);
|
||||||
@@ -120,7 +121,7 @@ async function recommendationsLoader(
|
|||||||
.from('ai_responses')
|
.from('ai_responses')
|
||||||
.insert({
|
.insert({
|
||||||
account_id: account.id,
|
account_id: account.id,
|
||||||
prompt_name: 'Analysis Recommendations',
|
prompt_name: PROMPT_NAME.ANALYSIS_RECOMMENDATIONS,
|
||||||
prompt_id: analysesRecommendationsPromptId,
|
prompt_id: analysesRecommendationsPromptId,
|
||||||
input: JSON.stringify({
|
input: JSON.stringify({
|
||||||
analyses: formattedAnalyses,
|
analyses: formattedAnalyses,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export enum PageViewAction {
|
|||||||
VIEW_ORDER_ANALYSIS = 'VIEW_ORDER_ANALYSIS',
|
VIEW_ORDER_ANALYSIS = 'VIEW_ORDER_ANALYSIS',
|
||||||
VIEW_TEAM_ACCOUNT_DASHBOARD = 'VIEW_TEAM_ACCOUNT_DASHBOARD',
|
VIEW_TEAM_ACCOUNT_DASHBOARD = 'VIEW_TEAM_ACCOUNT_DASHBOARD',
|
||||||
VIEW_TTO_SERVICE_BOOKING = 'VIEW_TTO_SERVICE_BOOKING',
|
VIEW_TTO_SERVICE_BOOKING = 'VIEW_TTO_SERVICE_BOOKING',
|
||||||
|
VIEW_LIFE_STYLE = 'VIEW_LIFE_STYLE',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createPageViewLog = async ({
|
export const createPageViewLog = async ({
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const PathsSchema = z.object({
|
|||||||
completedJobs: z.string().min(1),
|
completedJobs: z.string().min(1),
|
||||||
openJobs: z.string().min(1),
|
openJobs: z.string().min(1),
|
||||||
analysisDetails: z.string().min(1),
|
analysisDetails: z.string().min(1),
|
||||||
|
lifeStyle: z.string().min(1),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ const pathsConfig = PathsSchema.parse({
|
|||||||
completedJobs: '/doctor/completed-jobs',
|
completedJobs: '/doctor/completed-jobs',
|
||||||
openJobs: '/doctor/open-jobs',
|
openJobs: '/doctor/open-jobs',
|
||||||
analysisDetails: 'doctor/analysis',
|
analysisDetails: 'doctor/analysis',
|
||||||
|
lifeStyle: '/home/life-style',
|
||||||
},
|
},
|
||||||
} satisfies z.infer<typeof PathsSchema>);
|
} satisfies z.infer<typeof PathsSchema>);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Bike,
|
||||||
FileLineChart,
|
FileLineChart,
|
||||||
HeartPulse,
|
HeartPulse,
|
||||||
LineChart,
|
LineChart,
|
||||||
@@ -53,6 +54,12 @@ const routes = [
|
|||||||
Icon: <Stethoscope className={iconClasses} />,
|
Icon: <Stethoscope className={iconClasses} />,
|
||||||
end: true,
|
end: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'common:routes.lifeStyle',
|
||||||
|
path: pathsConfig.app.lifeStyle,
|
||||||
|
Icon: <Bike className={iconClasses} />,
|
||||||
|
end: true,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
] satisfies z.infer<typeof NavigationConfigSchema>['routes'];
|
] satisfies z.infer<typeof NavigationConfigSchema>['routes'];
|
||||||
|
|||||||
@@ -84,7 +84,8 @@
|
|||||||
"preferences": "Eelistused",
|
"preferences": "Eelistused",
|
||||||
"security": "Turvalisus",
|
"security": "Turvalisus",
|
||||||
"admin": "Admin",
|
"admin": "Admin",
|
||||||
"accounts": "Kontod"
|
"accounts": "Kontod",
|
||||||
|
"lifeStyle": "Elustiil"
|
||||||
},
|
},
|
||||||
"roles": {
|
"roles": {
|
||||||
"owner": {
|
"owner": {
|
||||||
@@ -150,5 +151,8 @@
|
|||||||
"no": "Ei",
|
"no": "Ei",
|
||||||
"preferNotToAnswer": "Eelistan mitte vastata",
|
"preferNotToAnswer": "Eelistan mitte vastata",
|
||||||
"book": "Broneeri",
|
"book": "Broneeri",
|
||||||
"change": "Muuda"
|
"change": "Muuda",
|
||||||
|
"lifeStyle": {
|
||||||
|
"title": "Elustiili soovitused"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
"orderPackage": {
|
"orderPackage": {
|
||||||
"title": "Telli analüüside pakett",
|
"title": "Telli analüüside pakett",
|
||||||
"description": "Võrdle erinevate pakettide vahel ja vali endale sobiv"
|
"description": "Võrdle erinevate pakettide vahel ja vali endale sobiv"
|
||||||
|
},
|
||||||
|
"lifeStyle": {
|
||||||
|
"title": "Elustiili soovitused"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"recommendations": {
|
"recommendations": {
|
||||||
|
|||||||
Reference in New Issue
Block a user