MED-213: lifestyle
MED-213: lifestyle
This commit is contained in:
74
app/home/(user)/(dashboard)/life-style/page.tsx
Normal file
74
app/home/(user)/(dashboard)/life-style/page.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
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 { 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 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);
|
||||||
@@ -37,8 +37,8 @@ async function OrderAnalysisPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HomeLayoutPageHeader
|
<HomeLayoutPageHeader
|
||||||
title={<Trans i18nKey={'order-analysis:title'} />}
|
title={<Trans i18nKey="order-analysis:title" />}
|
||||||
description={<Trans i18nKey={'order-analysis:description'} />}
|
description={<Trans i18nKey="order-analysis:description" />}
|
||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<OrderAnalysesCards analyses={analyses} countryCode={countryCode} />
|
<OrderAnalysesCards analyses={analyses} countryCode={countryCode} />
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { Suspense } from 'react';
|
|
||||||
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { toTitleCase } from '@/lib/utils';
|
import { toTitleCase } from '@/lib/utils';
|
||||||
@@ -12,11 +10,9 @@ import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
import AIBlocks from '../_components/ai/ai-blocks';
|
||||||
import Dashboard from '../_components/dashboard';
|
import Dashboard from '../_components/dashboard';
|
||||||
import DashboardCards from '../_components/dashboard-cards';
|
import DashboardCards from '../_components/dashboard-cards';
|
||||||
import Recommendations from '../_components/recommendations';
|
|
||||||
import RecommendationsSkeleton from '../_components/recommendations-skeleton';
|
|
||||||
import { isValidOpenAiEnv } from '../_lib/server/is-valid-open-ai-env';
|
|
||||||
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
@@ -33,7 +29,10 @@ async function UserHomePage() {
|
|||||||
|
|
||||||
const { account } = await loadCurrentUserAccount();
|
const { account } = await loadCurrentUserAccount();
|
||||||
const api = createUserAnalysesApi(client);
|
const api = createUserAnalysesApi(client);
|
||||||
|
const userAnalysesApi = createUserAnalysesApi(client);
|
||||||
|
|
||||||
const bmiThresholds = await api.fetchBmiThresholds();
|
const bmiThresholds = await api.fetchBmiThresholds();
|
||||||
|
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
redirect('/');
|
redirect('/');
|
||||||
@@ -53,16 +52,13 @@ async function UserHomePage() {
|
|||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<Dashboard account={account} bmiThresholds={bmiThresholds} />
|
<Dashboard account={account} bmiThresholds={bmiThresholds} />
|
||||||
{(await isValidOpenAiEnv()) && (
|
|
||||||
<>
|
<h4>
|
||||||
<h4>
|
<Trans i18nKey="dashboard:recommendations.title" />
|
||||||
<Trans i18nKey="dashboard:recommendations.title" />
|
</h4>
|
||||||
</h4>
|
<div className="mt-4 grid gap-6 sm:grid-cols-3">
|
||||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
<AIBlocks account={account} analysisResponses={analysisResponses} />
|
||||||
<Recommendations account={account} />
|
</div>
|
||||||
</Suspense>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</PageBody>
|
</PageBody>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
49
app/home/(user)/_components/ai/ai-blocks.tsx
Normal file
49
app/home/(user)/_components/ai/ai-blocks.tsx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import React, { Suspense } from 'react';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
|
||||||
|
import { isValidOpenAiEnv } from '../../_lib/server/is-valid-open-ai-env';
|
||||||
|
import LifeStyleCard from './life-style-card';
|
||||||
|
import OrderAnalysesPackageCard from './order-analyses-package-card';
|
||||||
|
import Recommendations from './recommendations';
|
||||||
|
import RecommendationsSkeleton from './recommendations-skeleton';
|
||||||
|
import { AnalysisResponses } from './types';
|
||||||
|
|
||||||
|
const AIBlocks = async ({
|
||||||
|
account,
|
||||||
|
analysisResponses,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams;
|
||||||
|
analysisResponses?: AnalysisResponses;
|
||||||
|
}) => {
|
||||||
|
const isOpenAiAvailable = await isValidOpenAiEnv();
|
||||||
|
|
||||||
|
if (!isOpenAiAvailable) {
|
||||||
|
return <OrderAnalysesPackageCard />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (analysisResponses?.length === 0) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<OrderAnalysesPackageCard />
|
||||||
|
<Suspense fallback={<RecommendationsSkeleton amount={1} />}>
|
||||||
|
<LifeStyleCard
|
||||||
|
account={account}
|
||||||
|
analysisResponses={analysisResponses}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||||
|
<LifeStyleCard account={account} analysisResponses={analysisResponses} />
|
||||||
|
<Recommendations account={account} />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AIBlocks;
|
||||||
44
app/home/(user)/_components/ai/life-style-card.tsx
Normal file
44
app/home/(user)/_components/ai/life-style-card.tsx
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
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 { AnalysisResponses } from './types';
|
||||||
|
|
||||||
|
const LifeStyleCard = async ({
|
||||||
|
account,
|
||||||
|
analysisResponses,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams;
|
||||||
|
analysisResponses?: AnalysisResponses;
|
||||||
|
}) => {
|
||||||
|
const data = await loadLifeStyle(account, analysisResponses);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card variant="gradient-success" className="flex flex-col justify-between">
|
||||||
|
<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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LifeStyleCard;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@/packages/shared/src/config';
|
||||||
|
import { ChevronRight, HeartPulse } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Trans } from '@kit/ui/makerkit/trans';
|
||||||
|
import { Button } from '@kit/ui/shadcn/button';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardDescription,
|
||||||
|
CardFooter,
|
||||||
|
CardHeader,
|
||||||
|
} from '@kit/ui/shadcn/card';
|
||||||
|
|
||||||
|
const OrderAnalysesPackageCard = () => {
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
variant="gradient-success"
|
||||||
|
className="xs:w-1/2 flex w-full flex-col justify-between sm:w-auto"
|
||||||
|
>
|
||||||
|
<CardHeader className="flex-row sm:pb-0">
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
'bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<HeartPulse className="size-4 fill-green-500" />
|
||||||
|
</div>
|
||||||
|
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||||
|
<Link href={pathsConfig.app.orderAnalysisPackage}>
|
||||||
|
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||||
|
<ChevronRight className="size-4 stroke-2" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardFooter className="flex flex-col items-start gap-2">
|
||||||
|
<h5>
|
||||||
|
<Trans i18nKey="dashboard:heroCard.orderPackage.title" />
|
||||||
|
</h5>
|
||||||
|
<CardDescription className="text-primary">
|
||||||
|
<Trans i18nKey="dashboard:heroCard.orderPackage.description" />
|
||||||
|
</CardDescription>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OrderAnalysesPackageCard;
|
||||||
67
app/home/(user)/_components/ai/recommendations-skeleton.tsx
Normal file
67
app/home/(user)/_components/ai/recommendations-skeleton.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { InfoTooltip } from '@/packages/shared/src/components/ui/info-tooltip';
|
||||||
|
|
||||||
|
import { Button } from '@kit/ui/shadcn/button';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardDescription,
|
||||||
|
CardFooter,
|
||||||
|
CardHeader,
|
||||||
|
} from '@kit/ui/shadcn/card';
|
||||||
|
import { Skeleton } from '@kit/ui/skeleton';
|
||||||
|
|
||||||
|
const RecommendationsSkeleton = ({ amount = 2 }: { amount?: number }) => {
|
||||||
|
const emptyData = [
|
||||||
|
{
|
||||||
|
title: '1',
|
||||||
|
description: '',
|
||||||
|
subtitle: '',
|
||||||
|
variant: { id: '' },
|
||||||
|
price: 1,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return Array.from({ length: amount }, (_, index) => {
|
||||||
|
const { title, description, subtitle } = emptyData[0]!;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Skeleton key={title + index}>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex-row">
|
||||||
|
<div
|
||||||
|
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>
|
||||||
|
</CardHeader>
|
||||||
|
<CardFooter className="flex">
|
||||||
|
<div className="flex flex-1 flex-col items-start">
|
||||||
|
<h5>
|
||||||
|
{title}
|
||||||
|
{description && (
|
||||||
|
<>
|
||||||
|
{' '}
|
||||||
|
<InfoTooltip
|
||||||
|
content={
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<span>{description}</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</h5>
|
||||||
|
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</Skeleton>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RecommendationsSkeleton;
|
||||||
@@ -4,9 +4,9 @@ import React from 'react';
|
|||||||
|
|
||||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
|
||||||
import { loadAnalyses } from '../_lib/server/load-analyses';
|
import { loadAnalyses } from '../../_lib/server/load-analyses';
|
||||||
import { loadRecommendations } from '../_lib/server/load-recommendations';
|
import { loadRecommendations } from '../../_lib/server/load-recommendations';
|
||||||
import OrderAnalysesCards from './order-analyses-cards';
|
import OrderAnalysesCards from '../order-analyses-cards';
|
||||||
|
|
||||||
export default async function Recommendations({
|
export default async function Recommendations({
|
||||||
account,
|
account,
|
||||||
@@ -15,7 +15,7 @@ export default async function Recommendations({
|
|||||||
}) {
|
}) {
|
||||||
const { analyses, countryCode } = await loadAnalyses();
|
const { analyses, countryCode } = await loadAnalyses();
|
||||||
|
|
||||||
const analysisRecommendations = await loadRecommendations(analyses, account);
|
const analysisRecommendations = await loadRecommendations(account);
|
||||||
const orderAnalyses = analyses.filter((analysis) =>
|
const orderAnalyses = analyses.filter((analysis) =>
|
||||||
analysisRecommendations.includes(analysis.title),
|
analysisRecommendations.includes(analysis.title),
|
||||||
);
|
);
|
||||||
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'];
|
||||||
@@ -57,72 +57,64 @@ export default function OrderAnalysesCards({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return analyses.map(({ title, variant, description, subtitle, price }) => {
|
||||||
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
const formattedPrice =
|
||||||
{analyses.map(({ title, variant, description, subtitle, price }) => {
|
typeof price === 'number'
|
||||||
const formattedPrice =
|
? formatCurrency({
|
||||||
typeof price === 'number'
|
currencyCode: 'eur',
|
||||||
? formatCurrency({
|
locale: language,
|
||||||
currencyCode: 'eur',
|
value: price,
|
||||||
locale: language,
|
})
|
||||||
value: price,
|
: null;
|
||||||
})
|
return (
|
||||||
: null;
|
<Card
|
||||||
return (
|
key={title}
|
||||||
<Card
|
variant="gradient-success"
|
||||||
key={title}
|
className="flex flex-col justify-between"
|
||||||
variant="gradient-success"
|
>
|
||||||
className="flex flex-col justify-between"
|
<CardHeader className="flex-row">
|
||||||
>
|
<div className="bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||||
<CardHeader className="flex-row">
|
<HeartPulse className="size-4 fill-green-500" />
|
||||||
<div
|
</div>
|
||||||
className={
|
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||||
'bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white'
|
<Button
|
||||||
}
|
size="icon"
|
||||||
>
|
variant="outline"
|
||||||
<HeartPulse className="size-4 fill-green-500" />
|
className="px-2 text-black"
|
||||||
</div>
|
onClick={() => handleSelect(variant.id)}
|
||||||
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
>
|
||||||
<Button
|
{variantAddingToCart === variant.id ? (
|
||||||
size="icon"
|
<Loader2 className="size-4 animate-spin stroke-2" />
|
||||||
variant="outline"
|
) : (
|
||||||
className="px-2 text-black"
|
<ShoppingCart className="size-4 stroke-2" />
|
||||||
onClick={() => handleSelect(variant.id)}
|
)}
|
||||||
>
|
</Button>
|
||||||
{variantAddingToCart === variant.id ? (
|
</div>
|
||||||
<Loader2 className="size-4 animate-spin stroke-2" />
|
</CardHeader>
|
||||||
) : (
|
<CardFooter className="flex gap-2">
|
||||||
<ShoppingCart className="size-4 stroke-2" />
|
<div className="flex flex-1 flex-col items-start gap-2">
|
||||||
)}
|
<h5>
|
||||||
</Button>
|
{title}
|
||||||
</div>
|
{description && (
|
||||||
</CardHeader>
|
<>
|
||||||
<CardFooter className="flex gap-2">
|
<InfoTooltip
|
||||||
<div className="flex flex-1 flex-col items-start gap-2">
|
content={
|
||||||
<h5>
|
<div className="flex flex-col gap-2">
|
||||||
{title}
|
<span>{formattedPrice}</span>
|
||||||
{description && (
|
<span>{description}</span>
|
||||||
<>
|
</div>
|
||||||
<InfoTooltip
|
}
|
||||||
content={
|
/>
|
||||||
<div className="flex flex-col gap-2">
|
</>
|
||||||
<span>{formattedPrice}</span>
|
)}
|
||||||
<span>{description}</span>
|
</h5>
|
||||||
</div>
|
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||||
}
|
</div>
|
||||||
/>
|
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
||||||
</>
|
<span>{formattedPrice}</span>
|
||||||
)}
|
</div>
|
||||||
</h5>
|
</CardFooter>
|
||||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
</Card>
|
||||||
</div>
|
);
|
||||||
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
});
|
||||||
<span>{formattedPrice}</span>
|
|
||||||
</div>
|
|
||||||
</CardFooter>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { InfoTooltip } from '@/packages/shared/src/components/ui/info-tooltip';
|
|
||||||
|
|
||||||
import { Button } from '@kit/ui/shadcn/button';
|
|
||||||
import {
|
|
||||||
Card,
|
|
||||||
CardDescription,
|
|
||||||
CardFooter,
|
|
||||||
CardHeader,
|
|
||||||
} from '@kit/ui/shadcn/card';
|
|
||||||
import { Skeleton } from '@kit/ui/skeleton';
|
|
||||||
|
|
||||||
const RecommendationsSkeleton = () => {
|
|
||||||
const emptyData = [
|
|
||||||
{
|
|
||||||
title: '1',
|
|
||||||
description: '',
|
|
||||||
subtitle: '',
|
|
||||||
variant: { id: '' },
|
|
||||||
price: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '2',
|
|
||||||
description: '',
|
|
||||||
subtitle: '',
|
|
||||||
variant: { id: '' },
|
|
||||||
price: 1,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
return (
|
|
||||||
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
|
||||||
{emptyData.map(({ title, description, subtitle }) => (
|
|
||||||
<Skeleton key={title}>
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex-row">
|
|
||||||
<div
|
|
||||||
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>
|
|
||||||
</CardHeader>
|
|
||||||
<CardFooter className="flex">
|
|
||||||
<div className="flex flex-1 flex-col items-start">
|
|
||||||
<h5>
|
|
||||||
{title}
|
|
||||||
{description && (
|
|
||||||
<>
|
|
||||||
{' '}
|
|
||||||
<InfoTooltip
|
|
||||||
content={
|
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
<span>{description}</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</h5>
|
|
||||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
|
||||||
</CardFooter>
|
|
||||||
</Card>
|
|
||||||
</Skeleton>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RecommendationsSkeleton;
|
|
||||||
212
app/home/(user)/_lib/server/ai-actions.ts
Normal file
212
app/home/(user)/_lib/server/ai-actions.ts
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
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';
|
||||||
|
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
||||||
|
|
||||||
|
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,
|
||||||
|
analysisResponses,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams;
|
||||||
|
analysisResponses?: AnalysisResponses;
|
||||||
|
}): 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 { 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 cholesterol =
|
||||||
|
analysisResponses
|
||||||
|
?.find((ar) => ar.analysis_name_lab === 'Kolesterool')
|
||||||
|
?.response_value.toString() || 'unknown';
|
||||||
|
const ldl =
|
||||||
|
analysisResponses
|
||||||
|
?.find((ar) => ar.analysis_name_lab === 'LDL kolesterool')
|
||||||
|
?.response_value.toString() || 'unknown';
|
||||||
|
const hdl =
|
||||||
|
analysisResponses
|
||||||
|
?.find((ar) => ar.analysis_name_lab === 'HDL kolesterool')
|
||||||
|
?.response_value.toString() || 'unknown';
|
||||||
|
const vitamind =
|
||||||
|
analysisResponses
|
||||||
|
?.find((ar) => ar.analysis_name_lab === 'Vitamiin D (25-OH)')
|
||||||
|
?.response_value.toString() || 'unknown';
|
||||||
|
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateRecommendations({
|
||||||
|
analyses,
|
||||||
|
analysisResponses,
|
||||||
|
account,
|
||||||
|
}: {
|
||||||
|
analyses: OrderAnalysisCard[];
|
||||||
|
analysisResponses?: AnalysisResponses;
|
||||||
|
account: AccountWithParams;
|
||||||
|
}) {
|
||||||
|
const RECOMMENDATIONS_PROMPT_IT =
|
||||||
|
process.env.PROMPT_ID_ANALYSIS_RECOMMENDATIONS;
|
||||||
|
|
||||||
|
if (!RECOMMENDATIONS_PROMPT_IT || !account?.personal_code) {
|
||||||
|
console.error('No prompt ID for analysis recommendations');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const openAIClient = new OpenAI();
|
||||||
|
const supabaseClient = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
||||||
|
const weight = account.accountParams?.weight || 'unknown';
|
||||||
|
|
||||||
|
const formattedAnalysisResponses = analysisResponses?.map(
|
||||||
|
({
|
||||||
|
analysis_name_lab,
|
||||||
|
response_value,
|
||||||
|
norm_upper,
|
||||||
|
norm_lower,
|
||||||
|
norm_status,
|
||||||
|
}) => ({
|
||||||
|
name: analysis_name_lab,
|
||||||
|
value: response_value,
|
||||||
|
normUpper: norm_upper,
|
||||||
|
normLower: norm_lower,
|
||||||
|
normStatus: norm_status,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const formattedAnalyses = analyses.map(({ description, title }) => ({
|
||||||
|
description,
|
||||||
|
title,
|
||||||
|
}));
|
||||||
|
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: RECOMMENDATIONS_PROMPT_IT,
|
||||||
|
variables: {
|
||||||
|
analyses: JSON.stringify(formattedAnalyses),
|
||||||
|
results: JSON.stringify(formattedAnalysisResponses),
|
||||||
|
gender: gender.value,
|
||||||
|
age: age.toString(),
|
||||||
|
weight: weight.toString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await supabaseClient
|
||||||
|
.schema('medreport')
|
||||||
|
.from('ai_responses')
|
||||||
|
.insert({
|
||||||
|
account_id: account.id,
|
||||||
|
prompt_name: PROMPT_NAME.ANALYSIS_RECOMMENDATIONS,
|
||||||
|
prompt_id: RECOMMENDATIONS_PROMPT_IT,
|
||||||
|
input: JSON.stringify({
|
||||||
|
analyses: formattedAnalyses,
|
||||||
|
results: formattedAnalysisResponses,
|
||||||
|
gender,
|
||||||
|
age,
|
||||||
|
weight,
|
||||||
|
}),
|
||||||
|
latest_data_change: latestISO,
|
||||||
|
response: response.output_text,
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = JSON.parse(response.output_text);
|
||||||
|
|
||||||
|
return json.recommended;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting recommendations: ', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
48
app/home/(user)/_lib/server/load-life-style.ts
Normal file
48
app/home/(user)/_lib/server/load-life-style.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { cache } from 'react';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||||
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AnalysisResponses,
|
||||||
|
ILifeStyleResponse,
|
||||||
|
PROMPT_NAME,
|
||||||
|
} from '../../_components/ai/types';
|
||||||
|
import { updateLifeStyle } from './ai-actions';
|
||||||
|
|
||||||
|
const failedResponse = {
|
||||||
|
lifestyle: [],
|
||||||
|
summary: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
async function lifeStyleLoader(
|
||||||
|
account: AccountWithParams,
|
||||||
|
analysisResponses?: AnalysisResponses,
|
||||||
|
): Promise<ILifeStyleResponse> {
|
||||||
|
if (!account?.personal_code) {
|
||||||
|
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, analysisResponses });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const loadLifeStyle = cache(lifeStyleLoader);
|
||||||
@@ -1,140 +1,38 @@
|
|||||||
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 { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
|
||||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
import { Database } from '@/packages/supabase/src/database.types';
|
|
||||||
import OpenAI from 'openai';
|
|
||||||
|
|
||||||
import PersonalCode from '~/lib/utils';
|
import { PROMPT_NAME } from '../../_components/ai/types';
|
||||||
|
|
||||||
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
|
||||||
|
|
||||||
export const loadRecommendations = cache(recommendationsLoader);
|
export const loadRecommendations = cache(recommendationsLoader);
|
||||||
|
|
||||||
type AnalysisResponses =
|
|
||||||
Database['medreport']['Functions']['get_latest_analysis_response_elements_for_current_user']['Returns'];
|
|
||||||
|
|
||||||
const 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function recommendationsLoader(
|
async function recommendationsLoader(
|
||||||
analyses: OrderAnalysisCard[],
|
|
||||||
account: AccountWithParams | null,
|
account: AccountWithParams | null,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
if (!process.env.OPENAI_API_KEY) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (!account?.personal_code) {
|
if (!account?.personal_code) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const supabaseClient = getSupabaseServerClient();
|
const supabaseClient = getSupabaseServerClient();
|
||||||
const userAnalysesApi = createUserAnalysesApi(supabaseClient);
|
|
||||||
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
|
||||||
const analysesRecommendationsPromptId =
|
|
||||||
process.env.PROMPT_ID_ANALYSIS_RECOMMENDATIONS;
|
|
||||||
const latestResponseTime = getLatestResponseTime(analysisResponses);
|
|
||||||
const latestISO = latestResponseTime
|
|
||||||
? new Date(latestResponseTime).toISOString()
|
|
||||||
: new Date('2025').toISOString();
|
|
||||||
|
|
||||||
if (!analysesRecommendationsPromptId) {
|
const { data, error } = await supabaseClient
|
||||||
console.error('No prompt ID for analysis recommendations');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const previouslyRecommended = await supabaseClient
|
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('ai_responses')
|
.from('ai_responses')
|
||||||
.select('*')
|
.select('*')
|
||||||
.eq('account_id', account.id)
|
.eq('account_id', account.id)
|
||||||
.eq('prompt_id', analysesRecommendationsPromptId)
|
.eq('prompt_name', PROMPT_NAME.ANALYSIS_RECOMMENDATIONS)
|
||||||
.eq('latest_data_change', latestISO);
|
.order('latest_data_change', { ascending: false, nullsFirst: false })
|
||||||
|
.limit(1)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
if (previouslyRecommended.data?.[0]?.response) {
|
if (error) {
|
||||||
return JSON.parse(previouslyRecommended.data[0].response as string)
|
console.error('Error fetching AI response from DB: ', error);
|
||||||
.recommended;
|
|
||||||
}
|
|
||||||
|
|
||||||
const openAIClient = new OpenAI();
|
|
||||||
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
|
||||||
const weight = account.accountParams?.weight || 'unknown';
|
|
||||||
|
|
||||||
const formattedAnalysisResponses = analysisResponses.map(
|
|
||||||
({
|
|
||||||
analysis_name_lab,
|
|
||||||
response_value,
|
|
||||||
norm_upper,
|
|
||||||
norm_lower,
|
|
||||||
norm_status,
|
|
||||||
}) => ({
|
|
||||||
name: analysis_name_lab,
|
|
||||||
value: response_value,
|
|
||||||
normUpper: norm_upper,
|
|
||||||
normLower: norm_lower,
|
|
||||||
normStatus: norm_status,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const formattedAnalyses = analyses.map(({ description, title }) => ({
|
|
||||||
description,
|
|
||||||
title,
|
|
||||||
}));
|
|
||||||
|
|
||||||
let response;
|
|
||||||
|
|
||||||
try {
|
|
||||||
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(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error calling OpenAI: ', error);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = JSON.parse(response.output_text);
|
if (data?.response) {
|
||||||
|
return JSON.parse(data.response as string).recommended;
|
||||||
try {
|
} else {
|
||||||
await supabaseClient
|
return [];
|
||||||
.schema('medreport')
|
|
||||||
.from('ai_responses')
|
|
||||||
.insert({
|
|
||||||
account_id: account.id,
|
|
||||||
prompt_name: 'Analysis Recommendations',
|
|
||||||
prompt_id: analysesRecommendationsPromptId,
|
|
||||||
input: JSON.stringify({
|
|
||||||
analyses: formattedAnalyses,
|
|
||||||
results: formattedAnalysisResponses,
|
|
||||||
gender,
|
|
||||||
age,
|
|
||||||
weight,
|
|
||||||
}),
|
|
||||||
latest_data_change: latestISO,
|
|
||||||
response: response.output_text,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error saving AI response: ', error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.recommended;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,13 @@
|
|||||||
"benefits": {
|
"benefits": {
|
||||||
"title": "Sinu Medreport konto seis",
|
"title": "Sinu Medreport konto seis",
|
||||||
"validUntil": "Kehtiv kuni {{date}}"
|
"validUntil": "Kehtiv kuni {{date}}"
|
||||||
|
},
|
||||||
|
"orderPackage": {
|
||||||
|
"title": "Telli analüüside pakett",
|
||||||
|
"description": "Võrdle erinevate pakettide vahel ja vali endale sobiv"
|
||||||
|
},
|
||||||
|
"lifeStyle": {
|
||||||
|
"title": "Elustiili soovitused"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"recommendations": {
|
"recommendations": {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
drop function if exists medreport.get_latest_analysis_response_elements_for_current_user(uuid);
|
||||||
|
|
||||||
|
create or replace function medreport.get_latest_analysis_response_elements_for_current_user(p_user_id uuid)
|
||||||
|
returns table (
|
||||||
|
analysis_name medreport.analysis_response_elements.analysis_name%type,
|
||||||
|
response_time medreport.analysis_response_elements.response_time%type,
|
||||||
|
norm_upper medreport.analysis_response_elements.norm_upper%type,
|
||||||
|
norm_lower medreport.analysis_response_elements.norm_lower%type,
|
||||||
|
norm_status medreport.analysis_response_elements.norm_status%type,
|
||||||
|
response_value medreport.analysis_response_elements.response_value%type,
|
||||||
|
analysis_name_lab medreport.analysis_elements.analysis_name_lab%type
|
||||||
|
)
|
||||||
|
language sql
|
||||||
|
as $$
|
||||||
|
WITH ranked AS (
|
||||||
|
SELECT
|
||||||
|
are.analysis_name,
|
||||||
|
are.response_time,
|
||||||
|
are.norm_upper,
|
||||||
|
are.norm_lower,
|
||||||
|
are.norm_status,
|
||||||
|
are.response_value,
|
||||||
|
ae.analysis_name_lab,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY are.analysis_name
|
||||||
|
ORDER BY are.response_time DESC, are.id DESC
|
||||||
|
) AS rn
|
||||||
|
FROM medreport.analysis_responses ar
|
||||||
|
JOIN medreport.analysis_response_elements are
|
||||||
|
ON are.analysis_response_id = ar.id
|
||||||
|
JOIN medreport.analysis_elements ae
|
||||||
|
ON are.analysis_element_original_id = ae.analysis_id_original
|
||||||
|
WHERE ar.user_id = auth.uid()
|
||||||
|
AND ar.order_status IN ('COMPLETED', 'ON_HOLD')
|
||||||
|
)
|
||||||
|
SELECT analysis_name, response_time, norm_upper, norm_lower, norm_status, response_value, analysis_name_lab
|
||||||
|
FROM ranked
|
||||||
|
WHERE rn = 1
|
||||||
|
ORDER BY analysis_name;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
grant execute on function medreport.get_latest_analysis_response_elements_for_current_user(uuid) to authenticated, service_role;
|
||||||
Reference in New Issue
Block a user