@@ -9,11 +9,7 @@ import { AnalysisElement, createAnalysisElement, getAnalysisElements } from '~/l
|
||||
import { createCodes } from '~/lib/services/codes.service';
|
||||
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
|
||||
import type { ICode } from '~/lib/types/code';
|
||||
|
||||
function toArray<T>(input?: T | T[] | null): T[] {
|
||||
if (!input) return [];
|
||||
return Array.isArray(input) ? input : [input];
|
||||
}
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
|
||||
const WRITE_XML_TO_FILE = false as boolean;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
@@ -53,47 +54,44 @@ export default async function AnalysisResultsPage({
|
||||
}
|
||||
|
||||
const orderedAnalysisElements = analysisResponse.orderedAnalysisElements;
|
||||
const hasOrderedAnalysisElements = orderedAnalysisElements.length > 0;
|
||||
const isPartialStatus = analysisResponse.order.status === 'PARTIAL_ANALYSIS_RESPONSE';
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="gap-4">
|
||||
<div className="mt-8 flex flex-col justify-between gap-4 sm:flex-row sm:items-center sm:gap-0">
|
||||
<div>
|
||||
<h4>
|
||||
<Trans i18nKey="analysis-results:pageTitle" />
|
||||
</h4>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{analysisResponse?.elements &&
|
||||
analysisResponse.elements?.length > 0 ? (
|
||||
<Trans i18nKey="analysis-results:description" />
|
||||
) : (
|
||||
<Trans i18nKey="analysis-results:descriptionEmpty" />
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<PageHeader
|
||||
title={<Trans i18nKey="analysis-results:pageTitle" />}
|
||||
description={hasOrderedAnalysisElements ? (
|
||||
isPartialStatus
|
||||
? <Trans i18nKey="analysis-results:descriptionPartial" />
|
||||
: <Trans i18nKey="analysis-results:description" />
|
||||
) : (
|
||||
<Trans i18nKey="analysis-results:descriptionEmpty" />
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
<Button asChild>
|
||||
<Link href={pathsConfig.app.orderAnalysisPackage}>
|
||||
<Trans i18nKey="analysis-results:orderNewAnalysis" />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</PageHeader>
|
||||
<PageBody className="gap-4 pt-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
<h4>
|
||||
<h5 className="break-all">
|
||||
<Trans
|
||||
i18nKey="analysis-results:orderTitle"
|
||||
values={{ orderNumber: analysisResponse.order.medusaOrderId }}
|
||||
/>
|
||||
</h4>
|
||||
<h5>
|
||||
<Trans
|
||||
i18nKey={`orders:status.${analysisResponse.order.status}`}
|
||||
/>
|
||||
</h5>
|
||||
<h6>
|
||||
<Trans i18nKey={`orders:status.${analysisResponse.order.status}`} />
|
||||
<ButtonTooltip
|
||||
content={`${analysisResponse.order.createdAt ? new Date(analysisResponse?.order?.createdAt).toLocaleString() : ''}`}
|
||||
className="ml-6"
|
||||
/>
|
||||
</h5>
|
||||
</h6>
|
||||
</div>
|
||||
{analysisResponse?.summary?.value && (
|
||||
<div>
|
||||
@@ -106,7 +104,16 @@ export default async function AnalysisResultsPage({
|
||||
<div className="flex flex-col gap-2">
|
||||
{orderedAnalysisElements ? (
|
||||
orderedAnalysisElements.map((element, index) => (
|
||||
<Analysis key={index} element={element} />
|
||||
<React.Fragment key={element.analysisIdOriginal}>
|
||||
<Analysis element={element} />
|
||||
{element.results?.nestedElements?.map((nestedElement, nestedIndex) => (
|
||||
<Analysis
|
||||
key={`nested-${nestedElement.analysisElementOriginalId}-${nestedIndex}`}
|
||||
nestedElement={nestedElement}
|
||||
isNestedElement
|
||||
/>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))
|
||||
) : (
|
||||
<div className="text-muted-foreground text-sm">
|
||||
|
||||
@@ -3,13 +3,10 @@ import { useMemo } from 'react';
|
||||
import { ArrowDown } from 'lucide-react';
|
||||
|
||||
import { cn } from '@kit/ui/utils';
|
||||
import { AnalysisResultDetailsElementResults } from '@/packages/features/accounts/src/types/analysis-results';
|
||||
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
|
||||
export enum AnalysisResultLevel {
|
||||
NORMAL = 0,
|
||||
WARNING = 1,
|
||||
CRITICAL = 2,
|
||||
}
|
||||
type AnalysisResultLevelBarResults = Pick<AnalysisResultDetailsElementResults, 'normLower' | 'normUpper' | 'responseValue'>;
|
||||
|
||||
const Level = ({
|
||||
isActive = false,
|
||||
@@ -50,7 +47,7 @@ const Level = ({
|
||||
)}
|
||||
|
||||
{color === 'success' && typeof normRangeText === 'string' && (
|
||||
<p className={cn("absolute bottom-[-18px] left-3/8 text-xs text-muted-foreground font-bold", {
|
||||
<p className={cn("absolute bottom-[-18px] left-3/8 text-xs text-muted-foreground font-bold whitespace-nowrap", {
|
||||
'opacity-60': isActive,
|
||||
})}>
|
||||
{normRangeText}
|
||||
@@ -60,28 +57,19 @@ const Level = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const AnalysisLevelBarSkeleton = () => {
|
||||
return (
|
||||
<div className="mt-4 flex h-3 w-[60%] sm:w-[35%] max-w-[360px] gap-1 sm:mt-0">
|
||||
<Level color="gray-200" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const AnalysisLevelBar = ({
|
||||
level,
|
||||
results,
|
||||
results: {
|
||||
normLower: lower,
|
||||
normUpper: upper,
|
||||
responseValue: value,
|
||||
},
|
||||
normRangeText,
|
||||
}: {
|
||||
level: AnalysisResultLevel;
|
||||
results: AnalysisResultDetailsElementResults;
|
||||
results: AnalysisResultLevelBarResults;
|
||||
normRangeText: string | null;
|
||||
}) => {
|
||||
|
||||
const { normLower: lower, normUpper: upper, responseValue: value, normStatus } = results;
|
||||
const normLowerIncluded = results?.normLowerIncluded || false;
|
||||
const normUpperIncluded = results?.normUpperIncluded || false;
|
||||
|
||||
// Calculate arrow position based on value within normal range
|
||||
const arrowLocation = useMemo(() => {
|
||||
// If no response value, center the arrow
|
||||
@@ -147,8 +135,6 @@ const AnalysisLevelBar = ({
|
||||
|
||||
// Show appropriate levels based on available norm bounds
|
||||
const hasLowerBound = lower !== null;
|
||||
const isLowerBoundZero = hasLowerBound && lower === 0;
|
||||
console.info('isLowerBoundZero', results.analysisElementOriginalId, { isLowerBoundZero, hasLowerBound, lower });
|
||||
const hasUpperBound = upper !== null;
|
||||
|
||||
// Determine which section the value falls into
|
||||
@@ -157,34 +143,10 @@ const AnalysisLevelBar = ({
|
||||
const isValueInNormalRange = !isValueBelowLower && !isValueAboveUpper;
|
||||
|
||||
const [first, second, third] = useMemo(() => {
|
||||
if (!hasLowerBound) {
|
||||
return [
|
||||
{
|
||||
isActive: isNormal,
|
||||
color: "success",
|
||||
isFirst: true,
|
||||
normRangeText,
|
||||
...(isNormal ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isWarning,
|
||||
color: "warning",
|
||||
...(isWarning ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isCritical,
|
||||
color: "destructive",
|
||||
isLast: true,
|
||||
...(isCritical ? { arrowLocation } : {}),
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
|
||||
return [
|
||||
const [warning, normal, critical] = [
|
||||
{
|
||||
isActive: isWarning,
|
||||
color: "warning",
|
||||
isFirst: true,
|
||||
...(isWarning ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
@@ -200,10 +162,30 @@ const AnalysisLevelBar = ({
|
||||
...(isCritical ? { arrowLocation } : {}),
|
||||
},
|
||||
] as const;
|
||||
|
||||
if (!hasLowerBound) {
|
||||
return [
|
||||
{ ...normal, isFirst: true },
|
||||
warning,
|
||||
critical,
|
||||
] as const;
|
||||
}
|
||||
|
||||
return [
|
||||
{ ...warning, isFirst: true },
|
||||
normal,
|
||||
{ ...critical, isLast: true },
|
||||
] as const;
|
||||
}, [isValueBelowLower, isValueAboveUpper, isValueInNormalRange, arrowLocation, normRangeText, isNormal, isWarning, isCritical]);
|
||||
|
||||
return (
|
||||
<div className="mt-4 flex h-3 w-[60%] sm:w-[35%] max-w-[360px] gap-1 sm:mt-0">
|
||||
<div className={cn(
|
||||
"flex h-3 gap-1",
|
||||
"mt-4 sm:mt-0",
|
||||
"w-[60%] sm:w-[35%]",
|
||||
"min-w-[50vw] sm:min-w-auto",
|
||||
"max-w-[360px]",
|
||||
)}>
|
||||
<Level {...first} />
|
||||
<Level {...second} />
|
||||
<Level {...third} />
|
||||
|
||||
@@ -2,33 +2,59 @@
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AnalysisResultDetailsElement } from '@/packages/features/accounts/src/types/analysis-results';
|
||||
import { format } from 'date-fns';
|
||||
import { Info } from 'lucide-react';
|
||||
|
||||
import type {
|
||||
AnalysisResultDetailsElement,
|
||||
AnalysisResultsDetailsElementNested,
|
||||
} from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { cn } from '@kit/ui/utils';
|
||||
|
||||
import AnalysisLevelBar, {
|
||||
AnalysisResultLevel,
|
||||
} from './analysis-level-bar';
|
||||
|
||||
export enum AnalysisStatus {
|
||||
NORMAL = 0,
|
||||
MEDIUM = 1,
|
||||
HIGH = 2,
|
||||
}
|
||||
import AnalysisLevelBar from './analysis-level-bar';
|
||||
|
||||
const Analysis = ({
|
||||
element,
|
||||
element: elementOriginal,
|
||||
nestedElement,
|
||||
isNestedElement = false,
|
||||
}: {
|
||||
element: AnalysisResultDetailsElement;
|
||||
element?: AnalysisResultDetailsElement;
|
||||
nestedElement?: AnalysisResultsDetailsElementNested;
|
||||
isNestedElement?: boolean;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const element = (() => {
|
||||
if (isNestedElement) {
|
||||
return nestedElement!;
|
||||
}
|
||||
return elementOriginal!;
|
||||
})();
|
||||
const results: AnalysisResultDetailsElement['results'] = useMemo(() => {
|
||||
if (isNestedElement) {
|
||||
const nestedElement = element as AnalysisResultsDetailsElementNested;
|
||||
return {
|
||||
analysisElementOriginalId: nestedElement.analysisElementOriginalId,
|
||||
normLower: nestedElement.normLower,
|
||||
normUpper: nestedElement.normUpper,
|
||||
normStatus: nestedElement.normStatus,
|
||||
responseTime: nestedElement.responseTime,
|
||||
responseValue: nestedElement.responseValue,
|
||||
responseValueIsNegative: nestedElement.responseValueIsNegative,
|
||||
responseValueIsWithinNorm: nestedElement.responseValueIsWithinNorm,
|
||||
normLowerIncluded: nestedElement.normLowerIncluded,
|
||||
normUpperIncluded: nestedElement.normUpperIncluded,
|
||||
unit: nestedElement.unit,
|
||||
status: nestedElement.status,
|
||||
nestedElements: [],
|
||||
};
|
||||
}
|
||||
return (element as AnalysisResultDetailsElement).results;
|
||||
}, [element, isNestedElement]);
|
||||
|
||||
const name = element.analysisName || '';
|
||||
const results = element.results;
|
||||
|
||||
const hasIsWithinNorm = results?.responseValueIsWithinNorm !== null;
|
||||
const hasIsNegative = results?.responseValueIsNegative !== null;
|
||||
@@ -58,8 +84,8 @@ const Analysis = ({
|
||||
return responseValue;
|
||||
})();
|
||||
const unit = results?.unit || '';
|
||||
const normLower = results?.normLower;
|
||||
const normUpper = results?.normUpper;
|
||||
const normLower = results?.normLower ?? null;
|
||||
const normUpper = results?.normUpper ?? null;
|
||||
const normStatus = results?.normStatus ?? null;
|
||||
|
||||
const [showTooltip, setShowTooltip] = useState(false);
|
||||
@@ -80,15 +106,21 @@ const Analysis = ({
|
||||
}, [normStatus]);
|
||||
|
||||
const isCancelled = Number(results?.status) === 5;
|
||||
const hasNestedElements = results?.nestedElements.length > 0;
|
||||
const nestedElements = results?.nestedElements ?? null;
|
||||
const hasNestedElements = Array.isArray(nestedElements) && nestedElements.length > 0;
|
||||
|
||||
const normRangeText = normLower !== null ? `${normLower} - ${normUpper || ''}` : null;
|
||||
const normRangeText = (() => {
|
||||
if (normLower === null && normUpper === null) {
|
||||
return null;
|
||||
}
|
||||
return `${normLower ?? '...'} - ${normUpper ?? '...'}`;
|
||||
})();
|
||||
const hasTextualResponse = hasIsNegative || hasIsWithinNorm;
|
||||
|
||||
return (
|
||||
<div className="border-border rounded-lg border px-5">
|
||||
<div className={cn("border-border rounded-lg border px-5", { 'ml-8': isNestedElement })}>
|
||||
<div className="flex flex-col items-center justify-between gap-2 pt-3 pb-6 sm:py-3 sm:h-[65px] sm:flex-row sm:gap-0">
|
||||
<div className="flex items-center gap-2 font-semibold">
|
||||
<div className={cn("flex items-center gap-2 font-semibold", { 'font-bold': isNestedElement })}>
|
||||
{name}
|
||||
{results?.responseTime && (
|
||||
<div
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AnalysisResultDetailsMapped } from "@/packages/features/accounts/src/types/analysis-results";
|
||||
import type { AnalysisResultDetailsMapped } from "@/packages/features/user-analyses/src/types/analysis-results";
|
||||
|
||||
type AnalysisTestResponse = Omit<AnalysisResultDetailsMapped, 'order' | 'orderedAnalysisElementIds' | 'summary' | 'elements'>;
|
||||
|
||||
@@ -26,7 +26,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "1744-2"
|
||||
}
|
||||
},
|
||||
@@ -46,7 +46,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "1920-8"
|
||||
}
|
||||
},
|
||||
@@ -66,7 +66,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "1988-5"
|
||||
}
|
||||
},
|
||||
@@ -86,7 +86,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "57747-8"
|
||||
}
|
||||
},
|
||||
@@ -106,7 +106,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "2276-4"
|
||||
}
|
||||
},
|
||||
@@ -126,7 +126,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14771-0"
|
||||
}
|
||||
},
|
||||
@@ -146,7 +146,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": false,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "59156-0"
|
||||
}
|
||||
},
|
||||
@@ -166,7 +166,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": true,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "59156-0"
|
||||
}
|
||||
},
|
||||
@@ -186,7 +186,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "13955-0"
|
||||
}
|
||||
},
|
||||
@@ -206,7 +206,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14646-4"
|
||||
}
|
||||
},
|
||||
@@ -226,7 +226,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "2000-8"
|
||||
}
|
||||
},
|
||||
@@ -246,7 +246,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "59158-6"
|
||||
}
|
||||
},
|
||||
@@ -266,7 +266,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14647-2"
|
||||
}
|
||||
},
|
||||
@@ -286,7 +286,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14682-9"
|
||||
}
|
||||
},
|
||||
@@ -306,7 +306,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "22748-8"
|
||||
}
|
||||
},
|
||||
@@ -326,7 +326,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "58805-3"
|
||||
}
|
||||
},
|
||||
@@ -346,7 +346,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "2601-3"
|
||||
}
|
||||
},
|
||||
@@ -367,7 +367,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "70204-3"
|
||||
}
|
||||
},
|
||||
@@ -387,7 +387,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14798-3"
|
||||
}
|
||||
},
|
||||
@@ -408,7 +408,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "14927-8"
|
||||
}
|
||||
},
|
||||
@@ -428,7 +428,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "3016-3"
|
||||
}
|
||||
},
|
||||
@@ -448,7 +448,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "22664-7"
|
||||
}
|
||||
},
|
||||
@@ -468,7 +468,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "50561-0"
|
||||
}
|
||||
},
|
||||
@@ -489,7 +489,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "60493-4"
|
||||
}
|
||||
},
|
||||
@@ -509,7 +509,7 @@ const big1: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": true,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "60025-4"
|
||||
},
|
||||
}
|
||||
@@ -535,7 +535,7 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValueIsWithinNorm": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "1988-5"
|
||||
}
|
||||
},
|
||||
@@ -555,6 +555,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 150,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "718-7"
|
||||
},
|
||||
{
|
||||
@@ -567,6 +569,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 45,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "4544-3"
|
||||
},
|
||||
{
|
||||
@@ -579,6 +583,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 5,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "6690-2"
|
||||
},
|
||||
{
|
||||
@@ -591,6 +597,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 5,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "789-8"
|
||||
},
|
||||
{
|
||||
@@ -603,6 +611,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 85,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "787-2"
|
||||
},
|
||||
{
|
||||
@@ -615,6 +625,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 30,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "785-6"
|
||||
},
|
||||
{
|
||||
@@ -627,6 +639,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 355,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "786-4"
|
||||
},
|
||||
{
|
||||
@@ -639,6 +653,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 15,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "788-0"
|
||||
},
|
||||
{
|
||||
@@ -651,6 +667,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 255,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "777-3"
|
||||
},
|
||||
{
|
||||
@@ -663,6 +681,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0.2,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "51637-7"
|
||||
},
|
||||
{
|
||||
@@ -675,6 +695,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 10,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "32623-1"
|
||||
},
|
||||
{
|
||||
@@ -687,6 +709,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 15,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "32207-3"
|
||||
},
|
||||
{
|
||||
@@ -699,6 +723,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0.05,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "704-7"
|
||||
},
|
||||
{
|
||||
@@ -711,6 +737,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0.05,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "711-2"
|
||||
},
|
||||
{
|
||||
@@ -723,6 +751,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 5,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "751-8"
|
||||
},
|
||||
{
|
||||
@@ -735,6 +765,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0.5,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "742-7"
|
||||
},
|
||||
{
|
||||
@@ -747,6 +779,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 1.5,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "731-0"
|
||||
},
|
||||
{
|
||||
@@ -759,6 +793,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "51584-1"
|
||||
},
|
||||
{
|
||||
@@ -771,6 +807,8 @@ const big2: AnalysisTestResponse = {
|
||||
"responseValue": 0,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "38518-7"
|
||||
},
|
||||
{
|
||||
@@ -779,8 +817,12 @@ const big2: AnalysisTestResponse = {
|
||||
"normStatus": 0,
|
||||
"responseTime": "2025-09-12 14:02:04",
|
||||
"responseValue": 0,
|
||||
"normUpper": null,
|
||||
"normLower": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "771-6"
|
||||
},
|
||||
{
|
||||
@@ -789,8 +831,12 @@ const big2: AnalysisTestResponse = {
|
||||
"normStatus": 0,
|
||||
"responseTime": "2025-09-12 14:02:04",
|
||||
"responseValue": 0,
|
||||
"normUpper": null,
|
||||
"normLower": null,
|
||||
"normLowerIncluded": false,
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"analysisElementOriginalId": "58413-6"
|
||||
}
|
||||
],
|
||||
@@ -804,7 +850,7 @@ const big2: AnalysisTestResponse = {
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": false,
|
||||
"responseValueIsWithinNorm": false,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "57021-8"
|
||||
}
|
||||
},
|
||||
@@ -825,7 +871,7 @@ const big2: AnalysisTestResponse = {
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": false,
|
||||
"responseValueIsWithinNorm": false,
|
||||
"status": "5",
|
||||
"status": 5,
|
||||
"analysisElementOriginalId": "43583-4"
|
||||
}
|
||||
},
|
||||
@@ -846,7 +892,7 @@ const big2: AnalysisTestResponse = {
|
||||
"normUpperIncluded": false,
|
||||
"responseValueIsNegative": null,
|
||||
"responseValueIsWithinNorm": null,
|
||||
"status": "4",
|
||||
"status": 4,
|
||||
"analysisElementOriginalId": "60493-4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,8 +163,9 @@ async function sendAnalysisPackageOrderEmail({
|
||||
partnerLocationName,
|
||||
language,
|
||||
});
|
||||
console.info(`Successfully sent analysis package order email to ${email}`);
|
||||
} catch (error) {
|
||||
console.error("Failed to send email", error);
|
||||
console.error(`Failed to send analysis package order email to ${email}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { AnalysisResultDetailsMapped } from '@kit/accounts/types/analysis-results';
|
||||
import type { AnalysisResultDetailsMapped } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
'use server';
|
||||
|
||||
import { toArray } from '@/lib/utils';
|
||||
|
||||
import { getMailer } from '@kit/mailers';
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
|
||||
import { emailSchema } from '~/lib/validations/email.schema';
|
||||
|
||||
|
||||
@@ -49,27 +49,30 @@ export async function upsertMedipostActionLog({
|
||||
medipostExternalOrderId?: string | null;
|
||||
medipostPrivateMessageId?: string | null;
|
||||
}) {
|
||||
const { data } = await getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('medipost_actions')
|
||||
.upsert(
|
||||
{
|
||||
action,
|
||||
xml,
|
||||
has_analysis_results: hasAnalysisResults,
|
||||
medusa_order_id: medusaOrderId,
|
||||
response_xml: responseXml,
|
||||
has_error: hasError,
|
||||
medipost_external_order_id: medipostExternalOrderId,
|
||||
medipost_private_message_id: medipostPrivateMessageId,
|
||||
},
|
||||
{
|
||||
onConflict: 'medipost_private_message_id',
|
||||
ignoreDuplicates: false
|
||||
}
|
||||
)
|
||||
.select('id')
|
||||
.throwOnError();
|
||||
const recordData = {
|
||||
action,
|
||||
xml,
|
||||
has_analysis_results: hasAnalysisResults,
|
||||
medusa_order_id: medusaOrderId,
|
||||
response_xml: responseXml,
|
||||
has_error: hasError,
|
||||
medipost_external_order_id: medipostExternalOrderId,
|
||||
medipost_private_message_id: medipostPrivateMessageId,
|
||||
};
|
||||
|
||||
const query = getSupabaseServerAdminClient().schema('medreport').from('medipost_actions');
|
||||
const { data } = medipostPrivateMessageId
|
||||
? await query
|
||||
.upsert(recordData, {
|
||||
onConflict: 'medipost_private_message_id',
|
||||
ignoreDuplicates: false
|
||||
})
|
||||
.select('id')
|
||||
.throwOnError()
|
||||
: await query
|
||||
.insert(recordData)
|
||||
.select('id')
|
||||
.throwOnError();
|
||||
|
||||
const medipostActionId = data?.[0]?.id;
|
||||
if (!medipostActionId) {
|
||||
|
||||
@@ -13,9 +13,10 @@ import type {
|
||||
MedipostOrderResponse,
|
||||
UuringElement,
|
||||
} from '@/packages/shared/src/types/medipost-analysis';
|
||||
import { toArray } from '@/lib/utils';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import type { AnalysisResponseElement } from '~/lib/types/analysis-response-element';
|
||||
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
||||
@@ -138,28 +139,25 @@ export async function getAnalysisResponseElementsForGroup({
|
||||
continue;
|
||||
}
|
||||
|
||||
const responseValueIsNumeric = responseValue !== null;
|
||||
const responseValueIsNegative = vastuseVaartus === 'Negatiivne';
|
||||
const responseValueIsWithinNorm = vastuseVaartus === 'Normi piires';
|
||||
const mappedResponse = createUserAnalysesApi(getSupabaseServerAdminClient())
|
||||
.mapUuringVastus({ uuringVastus: response });
|
||||
|
||||
results.push({
|
||||
analysis_element_original_id: analysisElementOriginalId,
|
||||
norm_lower: response.NormAlum?.['#text'] ?? null,
|
||||
norm_lower_included:
|
||||
response.NormAlum?.['@_kaasaarvatud'].toLowerCase() === 'jah',
|
||||
norm_status: response.NormiStaatus,
|
||||
norm_upper: response.NormYlem?.['#text'] ?? null,
|
||||
norm_upper_included:
|
||||
response.NormYlem?.['@_kaasaarvatud'].toLowerCase() === 'jah',
|
||||
response_time: response.VastuseAeg ?? null,
|
||||
response_value: responseValue,
|
||||
norm_lower: mappedResponse.normLower,
|
||||
norm_lower_included: mappedResponse.normLowerIncluded,
|
||||
norm_status: mappedResponse.normStatus,
|
||||
norm_upper: mappedResponse.normUpper,
|
||||
norm_upper_included: mappedResponse.normUpperIncluded,
|
||||
response_time: mappedResponse.responseTime,
|
||||
response_value: mappedResponse.responseValue,
|
||||
unit: groupUuringElement.Mootyhik ?? null,
|
||||
original_response_element: groupUuringElement,
|
||||
analysis_name: groupUuringElement.UuringNimi || groupUuringElement.KNimetus,
|
||||
comment: groupUuringElement.UuringuKommentaar ?? null,
|
||||
status: status.toString(),
|
||||
response_value_is_within_norm: responseValueIsNumeric ? null : responseValueIsWithinNorm,
|
||||
response_value_is_negative: responseValueIsNumeric ? null : responseValueIsNegative,
|
||||
response_value_is_within_norm: mappedResponse.responseValueIsWithinNorm,
|
||||
response_value_is_negative: mappedResponse.responseValueIsNegative,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -198,7 +196,7 @@ async function hasAllAnalysisResponseElements({
|
||||
}) {
|
||||
const allOrderResponseElements = await getExistingAnalysisResponseElements({ analysisResponseId });
|
||||
const expectedOrderResponseElements = order.analysis_element_ids?.length ?? 0;
|
||||
return allOrderResponseElements.length === expectedOrderResponseElements;
|
||||
return allOrderResponseElements.length >= expectedOrderResponseElements;
|
||||
}
|
||||
|
||||
export async function syncPrivateMessage({
|
||||
@@ -305,6 +303,7 @@ export async function readPrivateMessageResponse({
|
||||
const hasInvalidOrderId = isNaN(analysisOrderId);
|
||||
|
||||
if (hasInvalidOrderId || !messageResponse || !patientPersonalCode) {
|
||||
console.error(`Invalid order id or message response or patient personal code, medipostExternalOrderId=${medipostExternalOrderId}, privateMessageId=${privateMessageId}`);
|
||||
await upsertMedipostActionLog({
|
||||
action: 'sync_analysis_results_from_medipost',
|
||||
xml: privateMessageXml,
|
||||
@@ -342,6 +341,7 @@ export async function readPrivateMessageResponse({
|
||||
|
||||
const status = await syncPrivateMessage({ messageResponse, order: analysisOrder });
|
||||
|
||||
console.info(`Successfully synced analysis results from Medipost message privateMessageId=${privateMessageId}`);
|
||||
await upsertMedipostActionLog({
|
||||
action: 'sync_analysis_results_from_medipost',
|
||||
xml: privateMessageXml,
|
||||
@@ -475,6 +475,7 @@ export async function sendOrderToMedipost({
|
||||
isMedipostError,
|
||||
errorMessage: e.response,
|
||||
});
|
||||
console.error(`Failed to send order to Medipost, medusaOrderId=${medusaOrderId}, error=${e.response}`);
|
||||
await upsertMedipostActionLog({
|
||||
action: 'send_order_to_medipost',
|
||||
xml: orderXml,
|
||||
@@ -484,6 +485,7 @@ export async function sendOrderToMedipost({
|
||||
hasError: true,
|
||||
});
|
||||
} else {
|
||||
console.error(`Failed to send order to Medipost, medusaOrderId=${medusaOrderId}, error=${e}`);
|
||||
await logMedipostDispatch({
|
||||
medusaOrderId,
|
||||
isSuccess: false,
|
||||
@@ -500,6 +502,7 @@ export async function sendOrderToMedipost({
|
||||
|
||||
throw e;
|
||||
}
|
||||
console.info(`Successfully sent order to Medipost, medusaOrderId=${medusaOrderId}`);
|
||||
await logMedipostDispatch({
|
||||
medusaOrderId,
|
||||
isSuccess: true,
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import {
|
||||
MaterjalideGrupp,
|
||||
} from '@/lib/types/medipost';
|
||||
import { toArray } from '@/lib/utils';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import { uniqBy } from 'lodash';
|
||||
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
@@ -9,8 +9,6 @@ import { z } from 'zod';
|
||||
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
|
||||
|
||||
const env = () =>
|
||||
z
|
||||
.object({
|
||||
|
||||
@@ -9,11 +9,6 @@ export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export function toArray<T>(input?: T | T[] | null): T[] {
|
||||
if (!input) return [];
|
||||
return Array.isArray(input) ? input : [input];
|
||||
}
|
||||
|
||||
export function toTitleCase(str?: string) {
|
||||
return (
|
||||
str
|
||||
|
||||
@@ -4,6 +4,9 @@ const noop = (event: string) => {
|
||||
// do nothing - this is to prevent errors when the analytics service is not initialized
|
||||
|
||||
return async (...args: unknown[]) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
console.debug(
|
||||
`Noop analytics service called with event: ${event}`,
|
||||
...args.filter(Boolean),
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
|
||||
export type AnalysisOrder = Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||
@@ -1,139 +0,0 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
export type UserAnalysisElement =
|
||||
Database['medreport']['Tables']['analysis_response_elements']['Row'];
|
||||
export type UserAnalysisResponse =
|
||||
Database['medreport']['Tables']['analysis_responses']['Row'] & {
|
||||
elements: UserAnalysisElement[];
|
||||
};
|
||||
export type UserAnalysis = UserAnalysisResponse[];
|
||||
|
||||
const ElementSchema = z.object({
|
||||
unit: z.string(),
|
||||
norm_lower: z.number(),
|
||||
norm_upper: z.number(),
|
||||
norm_status: z.number(),
|
||||
analysis_name: z.string(),
|
||||
response_time: z.string(),
|
||||
response_value: z.number(),
|
||||
response_value_is_negative: z.boolean(),
|
||||
norm_lower_included: z.boolean(),
|
||||
norm_upper_included: z.boolean(),
|
||||
status: z.string(),
|
||||
analysis_element_original_id: z.string(),
|
||||
original_response_element: z.object({
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
const OrderSchema = z.object({
|
||||
status: z.string(),
|
||||
medusa_order_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
});
|
||||
|
||||
const DoctorAnalysisFeedbackSchema = z.object({
|
||||
id: z.number(),
|
||||
status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
created_by: z.string(),
|
||||
});
|
||||
|
||||
const SummarySchema = z.object({
|
||||
id: z.number(),
|
||||
value: z.string(),
|
||||
status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
created_by: z.string(),
|
||||
updated_at: z.coerce.date().nullable(),
|
||||
updated_by: z.string(),
|
||||
doctor_user_id: z.string().nullable(),
|
||||
analysis_order_id: z.number(),
|
||||
doctor_analysis_feedback: z.array(DoctorAnalysisFeedbackSchema),
|
||||
});
|
||||
|
||||
export const AnalysisResultDetailsSchema = z.object({
|
||||
id: z.number(),
|
||||
analysis_order_id: z.number(),
|
||||
order_number: z.string(),
|
||||
order_status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
updated_at: z.coerce.date().nullable(),
|
||||
elements: z.array(ElementSchema),
|
||||
order: OrderSchema,
|
||||
summary: SummarySchema.nullable(),
|
||||
});
|
||||
export type AnalysisResultDetails = z.infer<typeof AnalysisResultDetailsSchema>;
|
||||
|
||||
export type AnalysisResultDetailsElementResults = {
|
||||
unit: string | null;
|
||||
normLower: number | null;
|
||||
normUpper: number | null;
|
||||
normStatus: number | null;
|
||||
responseTime: string | null;
|
||||
responseValue: number | null;
|
||||
responseValueIsNegative: boolean | null;
|
||||
responseValueIsWithinNorm: boolean | null;
|
||||
normLowerIncluded: boolean;
|
||||
normUpperIncluded: boolean;
|
||||
status: string;
|
||||
analysisElementOriginalId: string;
|
||||
nestedElements: {
|
||||
analysisElementOriginalId: string;
|
||||
normLower?: number | null;
|
||||
normLowerIncluded: boolean;
|
||||
normStatus: number;
|
||||
normUpper?: number | null;
|
||||
normUpperIncluded: boolean;
|
||||
responseTime: string;
|
||||
responseValue: number;
|
||||
status: number;
|
||||
unit: string;
|
||||
}[];
|
||||
labComment?: string | null;
|
||||
};
|
||||
|
||||
export type AnalysisResultDetailsElement = {
|
||||
analysisIdOriginal: string;
|
||||
isWaitingForResults: boolean;
|
||||
analysisName: string;
|
||||
results: AnalysisResultDetailsElementResults;
|
||||
};
|
||||
|
||||
export type AnalysisResultDetailsMapped = {
|
||||
id: number;
|
||||
order: {
|
||||
status: string;
|
||||
medusaOrderId: string;
|
||||
createdAt: Date | string;
|
||||
};
|
||||
elements: {
|
||||
id: string;
|
||||
unit: string;
|
||||
norm_lower: number;
|
||||
norm_upper: number;
|
||||
norm_status: number;
|
||||
analysis_name: string;
|
||||
response_time: string;
|
||||
response_value: number;
|
||||
norm_lower_included: boolean;
|
||||
norm_upper_included: boolean;
|
||||
status: string;
|
||||
analysis_element_original_id: string;
|
||||
}[];
|
||||
orderedAnalysisElementIds: number[];
|
||||
orderedAnalysisElements: AnalysisResultDetailsElement[];
|
||||
summary: {
|
||||
id: number;
|
||||
status: string;
|
||||
user_id: string;
|
||||
created_at: Date;
|
||||
created_by: string;
|
||||
value?: string;
|
||||
} | null;
|
||||
};
|
||||
@@ -330,7 +330,7 @@ export async function medusaLoginOrRegister(credentials: {
|
||||
await medusaRegister({ email, password, name, lastName });
|
||||
return await medusaLogin(email, password);
|
||||
} catch (registerError) {
|
||||
console.error("Failed to create Medusa account for user with email=${email}", registerError);
|
||||
console.error(`Failed to create Medusa account for user with email=${email}`, registerError);
|
||||
throw medusaError(registerError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import type { UuringElement, UuringuVastus } from '@kit/shared/types/medipost-analysis';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import type { UuringuVastus } from '@kit/shared/types/medipost-analysis';
|
||||
|
||||
import type { AnalysisResultDetails, AnalysisResultDetailsMapped, UserAnalysis } from '../types/analysis-results';
|
||||
import type { AnalysisResultsQuery, AnalysisResultDetailsElement, AnalysisResultDetailsMapped, AnalysisResultLevel, AnalysisResultsDetailsElementNested, AnalysisStatus, UserAnalysis } from '../types/analysis-results';
|
||||
import type { AnalysisOrder } from '../types/analysis-orders';
|
||||
|
||||
/**
|
||||
@@ -43,31 +44,13 @@ class UserAnalysesApi {
|
||||
async getUserAnalysis(
|
||||
analysisOrderId: number,
|
||||
): Promise<AnalysisResultDetailsMapped | null> {
|
||||
const authUser = await this.client.auth.getUser();
|
||||
const { data, error: userError } = authUser;
|
||||
|
||||
if (userError) {
|
||||
console.error('Failed to get user', userError);
|
||||
throw userError;
|
||||
}
|
||||
|
||||
const { user } = data;
|
||||
|
||||
const analysisOrder = await this.getAnalysisOrder({ analysisOrderId });
|
||||
const orderedAnalysisElementIds = analysisOrder.analysis_element_ids ?? [];
|
||||
if (orderedAnalysisElementIds.length === 0) {
|
||||
console.error('No ordered analysis element ids found for analysis order id=', analysisOrderId);
|
||||
return null;
|
||||
}
|
||||
const { data: orderedAnalysisElements, error: orderedAnalysisElementsError } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.select('analysis_id_original,analysis_name_lab')
|
||||
.in('id', orderedAnalysisElementIds);
|
||||
if (orderedAnalysisElementsError) {
|
||||
console.error('Failed to get ordered analysis elements for analysis order id=', analysisOrderId, orderedAnalysisElementsError);
|
||||
throw orderedAnalysisElementsError;
|
||||
}
|
||||
const orderedAnalysisElements = await this.getOrderedAnalysisElements({ analysisOrderId, orderedAnalysisElementIds });
|
||||
|
||||
const orderedAnalysisElementOriginalIds = orderedAnalysisElements.map(({ analysis_id_original }) => analysis_id_original);
|
||||
if (orderedAnalysisElementOriginalIds.length === 0) {
|
||||
@@ -75,6 +58,43 @@ class UserAnalysesApi {
|
||||
return null;
|
||||
}
|
||||
|
||||
const responseWithElements = await this.getAnalysisResponseWithElements({ analysisOrderId });
|
||||
if (!responseWithElements) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const mappedOrderedAnalysisElements = await this.getMappedOrderedAnalysisElements({
|
||||
analysisResponseElements: responseWithElements.elements,
|
||||
orderedAnalysisElements,
|
||||
});
|
||||
|
||||
const feedback = responseWithElements.summary?.doctor_analysis_feedback?.[0];
|
||||
return {
|
||||
id: analysisOrderId,
|
||||
order: {
|
||||
status: analysisOrder.status,
|
||||
medusaOrderId: analysisOrder.medusa_order_id,
|
||||
createdAt: analysisOrder.created_at,
|
||||
},
|
||||
orderedAnalysisElements: mappedOrderedAnalysisElements,
|
||||
summary:
|
||||
feedback?.status === 'COMPLETED'
|
||||
? (responseWithElements.summary?.doctor_analysis_feedback?.[0] ?? null)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
async getAnalysisResponseWithElements({
|
||||
analysisOrderId,
|
||||
}: {
|
||||
analysisOrderId: number;
|
||||
}) {
|
||||
const { data, error: userError } = await this.client.auth.getUser();
|
||||
if (userError) {
|
||||
throw userError;
|
||||
}
|
||||
const { user } = data;
|
||||
|
||||
const { data: analysisResponse } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
@@ -87,29 +107,52 @@ class UserAnalysesApi {
|
||||
.eq('analysis_order_id', analysisOrderId)
|
||||
.throwOnError();
|
||||
|
||||
const responseWithElements = analysisResponse?.[0] as AnalysisResultDetails | null;
|
||||
if (!responseWithElements) {
|
||||
return null;
|
||||
return analysisResponse?.[0] as AnalysisResultsQuery | null;
|
||||
}
|
||||
|
||||
async getOrderedAnalysisElements({
|
||||
analysisOrderId,
|
||||
orderedAnalysisElementIds,
|
||||
}: {
|
||||
analysisOrderId: number;
|
||||
orderedAnalysisElementIds: number[];
|
||||
}) {
|
||||
const { data: orderedAnalysisElements, error: orderedAnalysisElementsError } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.select('analysis_id_original,analysis_name_lab')
|
||||
.in('id', orderedAnalysisElementIds);
|
||||
if (orderedAnalysisElementsError) {
|
||||
console.error(`Failed to get ordered analysis elements for analysis order id=${analysisOrderId}`, orderedAnalysisElementsError);
|
||||
throw orderedAnalysisElementsError;
|
||||
}
|
||||
return orderedAnalysisElements;
|
||||
}
|
||||
|
||||
const analysisResponseElements = responseWithElements.elements;
|
||||
|
||||
const feedback = responseWithElements.summary?.doctor_analysis_feedback?.[0];
|
||||
|
||||
async getMappedOrderedAnalysisElements({
|
||||
analysisResponseElements,
|
||||
orderedAnalysisElements,
|
||||
}: {
|
||||
analysisResponseElements: AnalysisResultsQuery['elements'];
|
||||
orderedAnalysisElements: { analysis_id_original: string; analysis_name_lab: string }[];
|
||||
}): Promise<AnalysisResultDetailsElement[]> {
|
||||
const mappedOrderedAnalysisElements = orderedAnalysisElements.map(({ analysis_id_original, analysis_name_lab }) => {
|
||||
return this.getOrderedAnalysisElements({
|
||||
return this.getOrderedAnalysisElement({
|
||||
analysisIdOriginal: analysis_id_original,
|
||||
analysisNameLab: analysis_name_lab,
|
||||
analysisResponseElements,
|
||||
});
|
||||
}).sort((a, b) => a.analysisName.localeCompare(b.analysisName));
|
||||
const nestedAnalysisElementIds = mappedOrderedAnalysisElements.map(({ results }) => results?.nestedElements.map(({ analysisElementOriginalId }) => analysisElementOriginalId)).flat().filter(Boolean);
|
||||
|
||||
const nestedAnalysisElementIds = mappedOrderedAnalysisElements
|
||||
.map(({ results }) => results?.nestedElements.map(({ analysisElementOriginalId }) => analysisElementOriginalId))
|
||||
.flat().filter(Boolean);
|
||||
if (nestedAnalysisElementIds.length > 0) {
|
||||
const { data: nestedAnalysisElements, error: nestedAnalysisElementsError } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_elements')
|
||||
.select('*')
|
||||
.in('id', nestedAnalysisElementIds);
|
||||
.in('analysis_id_original', nestedAnalysisElementIds);
|
||||
if (!nestedAnalysisElementsError && nestedAnalysisElements) {
|
||||
for (const mappedOrderedAnalysisElement of mappedOrderedAnalysisElements) {
|
||||
const { results } = mappedOrderedAnalysisElement;
|
||||
@@ -118,58 +161,33 @@ class UserAnalysesApi {
|
||||
}
|
||||
for (const nestedElement of results.nestedElements) {
|
||||
const { analysisElementOriginalId } = nestedElement;
|
||||
const nestedAnalysisElement = nestedAnalysisElements.find(({ id }) => id === analysisElementOriginalId);
|
||||
const nestedAnalysisElement = nestedAnalysisElements.find(({ analysis_id_original }) => analysis_id_original === analysisElementOriginalId);
|
||||
if (!nestedAnalysisElement) {
|
||||
continue;
|
||||
}
|
||||
results.nestedElements.push({
|
||||
...nestedAnalysisElement,
|
||||
analysisElementOriginalId,
|
||||
analysisName: nestedAnalysisElement.analysis_name_lab,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
mappedOrderedAnalysisElements.forEach(({ results }) => {
|
||||
results?.nestedElements.forEach(({ analysisElementOriginalId }) => {
|
||||
const nestedAnalysisElement = nestedAnalysisElements.find(({ id }) => id === analysisElementOriginalId);
|
||||
if (nestedAnalysisElement) {
|
||||
results?.nestedElements.push({
|
||||
...nestedAnalysisElement,
|
||||
analysisElementOriginalId,
|
||||
analysisName: nestedAnalysisElement.analysis_name_lab,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
nestedElement.analysisElementOriginalId = analysisElementOriginalId;
|
||||
nestedElement.analysisName = nestedAnalysisElement.analysis_name_lab as string | undefined;
|
||||
}
|
||||
results.nestedElements = results.nestedElements.sort((a, b) => a.analysisName?.localeCompare(b.analysisName ?? '') ?? 0);
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to get nested analysis elements by ids=', nestedAnalysisElementIds, nestedAnalysisElementsError);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: analysisOrderId,
|
||||
order: {
|
||||
status: analysisOrder.status,
|
||||
medusaOrderId: analysisOrder.medusa_order_id,
|
||||
createdAt: new Date(analysisOrder.created_at),
|
||||
},
|
||||
orderedAnalysisElementIds,
|
||||
orderedAnalysisElements: mappedOrderedAnalysisElements,
|
||||
summary:
|
||||
feedback?.status === 'COMPLETED'
|
||||
? (responseWithElements.summary?.doctor_analysis_feedback?.[0] ?? null)
|
||||
: null,
|
||||
};
|
||||
return mappedOrderedAnalysisElements;
|
||||
}
|
||||
|
||||
getOrderedAnalysisElements({
|
||||
getOrderedAnalysisElement({
|
||||
analysisIdOriginal,
|
||||
analysisNameLab,
|
||||
analysisResponseElements,
|
||||
}: {
|
||||
analysisIdOriginal: string;
|
||||
analysisNameLab: string;
|
||||
analysisResponseElements: AnalysisResultDetails['elements'];
|
||||
}) {
|
||||
analysisResponseElements: AnalysisResultsQuery['elements'];
|
||||
}): AnalysisResultDetailsElement {
|
||||
const elementResponse = analysisResponseElements.find((element) => element.analysis_element_original_id === analysisIdOriginal);
|
||||
if (!elementResponse) {
|
||||
return {
|
||||
@@ -184,51 +202,74 @@ class UserAnalysesApi {
|
||||
isWaitingForResults: false,
|
||||
analysisName: analysisNameLab,
|
||||
results: {
|
||||
nestedElements: (() => {
|
||||
const nestedElements = elementResponse.original_response_element?.UuringuElement as UuringElement[] | undefined;
|
||||
if (!nestedElements) {
|
||||
return [];
|
||||
}
|
||||
return nestedElements.map((element) => {
|
||||
const elementVastus = element.UuringuVastus as UuringuVastus | undefined;
|
||||
const responseValue = elementVastus?.VastuseVaartus;
|
||||
const responseValueIsNumeric = !isNaN(Number(responseValue));
|
||||
const responseValueIsNegative = responseValue === 'Negatiivne';
|
||||
const responseValueIsWithinNorm = responseValue === 'Normi piires';
|
||||
nestedElements: ((): AnalysisResultsDetailsElementNested[] => {
|
||||
const nestedElements = toArray(elementResponse.original_response_element?.UuringuElement)
|
||||
return nestedElements.map<AnalysisResultsDetailsElementNested>((element) => {
|
||||
const mappedResponse = this.mapUuringVastus({
|
||||
uuringVastus: element.UuringuVastus as UuringuVastus | undefined,
|
||||
});
|
||||
return {
|
||||
status: element.UuringOlek,
|
||||
unit: element.Mootyhik,
|
||||
normLower: elementVastus?.NormAlum?.['#text'],
|
||||
normUpper: elementVastus?.NormYlem?.['#text'],
|
||||
normStatus: elementVastus?.NormiStaatus,
|
||||
responseTime: elementVastus?.VastuseAeg,
|
||||
response_value: responseValueIsNegative || !responseValueIsNumeric ? null : (responseValue ?? null),
|
||||
response_value_is_negative: responseValueIsNumeric ? null : responseValueIsNegative,
|
||||
response_value_is_within_norm: responseValueIsNumeric ? null : responseValueIsWithinNorm,
|
||||
normLowerIncluded: elementVastus?.NormAlum?.['@_kaasaarvatud'] === 'JAH',
|
||||
normUpperIncluded: elementVastus?.NormYlem?.['@_kaasaarvatud'] === 'JAH',
|
||||
unit: element.Mootyhik ?? null,
|
||||
normLower: mappedResponse.normLower,
|
||||
normUpper: mappedResponse.normUpper,
|
||||
normStatus: mappedResponse.normStatus,
|
||||
responseTime: mappedResponse.responseTime,
|
||||
responseValue: mappedResponse.responseValue,
|
||||
responseValueIsNegative: mappedResponse.responseValueIsNegative,
|
||||
responseValueIsWithinNorm: mappedResponse.responseValueIsWithinNorm,
|
||||
normLowerIncluded: mappedResponse.normLowerIncluded,
|
||||
normUpperIncluded: mappedResponse.normUpperIncluded,
|
||||
analysisElementOriginalId: element.UuringId,
|
||||
status: Number(elementResponse.status) as AnalysisStatus,
|
||||
analysisName: undefined,
|
||||
};
|
||||
});
|
||||
})(),
|
||||
labComment,
|
||||
//originalResponseElement: elementResponse.original_response_element ?? null,
|
||||
unit: elementResponse.unit,
|
||||
normLower: elementResponse.norm_lower,
|
||||
normUpper: elementResponse.norm_upper,
|
||||
normStatus: elementResponse.norm_status,
|
||||
responseTime: elementResponse.response_time,
|
||||
responseValue: elementResponse.response_value,
|
||||
responseValueIsNegative: elementResponse.response_value_is_negative === true,
|
||||
responseValueIsWithinNorm: elementResponse.response_value_is_within_norm === true,
|
||||
responseValueIsNegative: elementResponse.response_value_is_negative === null ? null : elementResponse.response_value_is_negative === true,
|
||||
responseValueIsWithinNorm: elementResponse.response_value_is_within_norm === null ? null : elementResponse.response_value_is_within_norm === true,
|
||||
normLowerIncluded: elementResponse.norm_lower_included,
|
||||
normUpperIncluded: elementResponse.norm_upper_included,
|
||||
status: elementResponse.status,
|
||||
status: Number(elementResponse.status) as AnalysisStatus,
|
||||
analysisElementOriginalId: elementResponse.analysis_element_original_id,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mapUuringVastus({ uuringVastus }: { uuringVastus?: UuringuVastus }) {
|
||||
const vastuseVaartus = uuringVastus?.VastuseVaartus;
|
||||
const responseValue = (() => {
|
||||
const valueAsNumber = Number(vastuseVaartus);
|
||||
if (isNaN(valueAsNumber)) {
|
||||
return null;
|
||||
}
|
||||
return valueAsNumber;
|
||||
})();
|
||||
const responseValueNumber = Number(responseValue);
|
||||
const responseValueIsNumeric = !isNaN(responseValueNumber);
|
||||
const responseValueIsNegative = vastuseVaartus === 'Negatiivne';
|
||||
const responseValueIsWithinNorm = vastuseVaartus === 'Normi piires';
|
||||
return {
|
||||
normLower: uuringVastus?.NormAlum?.['#text'] ?? null,
|
||||
normUpper: uuringVastus?.NormYlem?.['#text'] ?? null,
|
||||
normStatus: (uuringVastus?.NormiStaatus ?? null) as AnalysisResultLevel | null,
|
||||
responseTime: uuringVastus?.VastuseAeg ?? null,
|
||||
responseValue: responseValueIsNegative || !responseValueIsNumeric ? null : (responseValueNumber ?? null),
|
||||
responseValueIsNegative: responseValueIsNumeric ? null : responseValueIsNegative,
|
||||
responseValueIsWithinNorm: responseValueIsNumeric ? null : responseValueIsWithinNorm,
|
||||
normLowerIncluded:
|
||||
uuringVastus?.NormAlum?.['@_kaasaarvatud'].toLowerCase() === 'jah',
|
||||
normUpperIncluded:
|
||||
uuringVastus?.NormYlem?.['@_kaasaarvatud'].toLowerCase() === 'jah',
|
||||
};
|
||||
}
|
||||
|
||||
// @TODO unused currently
|
||||
async getUserAnalyses(): Promise<UserAnalysis | null> {
|
||||
const authUser = await this.client.auth.getUser();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as z from 'zod';
|
||||
import type { Database } from '@kit/supabase/database';
|
||||
import type { AnalysisOrderStatus, NormStatus } from '@kit/shared/types/medipost-analysis';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import type { AnalysisOrder } from './analysis-orders';
|
||||
|
||||
export type UserAnalysisElement =
|
||||
Database['medreport']['Tables']['analysis_response_elements']['Row'];
|
||||
@@ -10,92 +11,131 @@ export type UserAnalysisResponse =
|
||||
};
|
||||
export type UserAnalysis = UserAnalysisResponse[];
|
||||
|
||||
const ElementSchema = z.object({
|
||||
unit: z.string(),
|
||||
norm_lower: z.number(),
|
||||
norm_upper: z.number(),
|
||||
norm_status: z.number(),
|
||||
analysis_name: z.string(),
|
||||
response_time: z.string(),
|
||||
response_value: z.number(),
|
||||
response_value_is_negative: z.boolean(),
|
||||
response_value_is_within_norm: z.boolean(),
|
||||
norm_lower_included: z.boolean(),
|
||||
norm_upper_included: z.boolean(),
|
||||
status: z.string(),
|
||||
analysis_element_original_id: z.string(),
|
||||
original_response_element: z.object({
|
||||
export type AnalysisResultsQuery = {
|
||||
id: number,
|
||||
analysis_order_id: number,
|
||||
order_number: string,
|
||||
order_status: string,
|
||||
user_id: string,
|
||||
created_at: string,
|
||||
updated_at: string | null,
|
||||
elements: {
|
||||
unit: string,
|
||||
norm_lower: number,
|
||||
norm_upper: number,
|
||||
norm_status: number,
|
||||
analysis_name: string,
|
||||
response_time: string,
|
||||
response_value: number,
|
||||
response_value_is_negative: boolean,
|
||||
response_value_is_within_norm: boolean,
|
||||
norm_lower_included: boolean,
|
||||
norm_upper_included: boolean,
|
||||
status: string,
|
||||
analysis_element_original_id: string,
|
||||
original_response_element: {
|
||||
UuringuElement: {
|
||||
UuringIdOID: string,
|
||||
UuringId: string,
|
||||
TLyhend: string,
|
||||
KNimetus: string,
|
||||
UuringNimi: string,
|
||||
UuringuKommentaar: string | null,
|
||||
TellijaUuringId: number,
|
||||
TeostajaUuringId: string,
|
||||
UuringOlek: keyof typeof AnalysisOrderStatus,
|
||||
Mootyhik: string | null,
|
||||
Kood: {
|
||||
HkKood: number,
|
||||
HkKoodiKordaja: number,
|
||||
Koefitsient: number,
|
||||
Hind: number,
|
||||
},
|
||||
UuringuVastus: {
|
||||
VastuseVaartus: string,
|
||||
VastuseAeg: string,
|
||||
NormiStaatus: keyof typeof NormStatus,
|
||||
ProoviJarjenumber: number,
|
||||
},
|
||||
UuringuTaitjaAsutuseJnr: number,
|
||||
},
|
||||
UuringuKommentaar: string | null,
|
||||
},
|
||||
}[],
|
||||
order: {
|
||||
status: string,
|
||||
medusa_order_id: string,
|
||||
created_at: string,
|
||||
},
|
||||
summary: {
|
||||
id: number,
|
||||
value: string,
|
||||
status: string,
|
||||
user_id: string,
|
||||
created_at: string,
|
||||
created_by: string,
|
||||
updated_at: string | null,
|
||||
updated_by: string,
|
||||
doctor_user_id: string | null,
|
||||
analysis_order_id: number,
|
||||
doctor_analysis_feedback: {
|
||||
id: number,
|
||||
status: string,
|
||||
user_id: string,
|
||||
created_at: string,
|
||||
created_by: string,
|
||||
}[],
|
||||
} | null,
|
||||
};
|
||||
|
||||
}),
|
||||
});
|
||||
export type AnalysisResultsDetailsElementNested = {
|
||||
analysisElementOriginalId: string;
|
||||
analysisName?: string;
|
||||
} & Pick<
|
||||
AnalysisResultDetailsElementResults,
|
||||
'unit' |
|
||||
'normLower' |
|
||||
'normUpper' |
|
||||
'normStatus' |
|
||||
'responseTime' |
|
||||
'responseValue' |
|
||||
'responseValueIsNegative' |
|
||||
'responseValueIsWithinNorm' |
|
||||
'normLowerIncluded' |
|
||||
'normUpperIncluded' |
|
||||
'status' |
|
||||
'analysisElementOriginalId'
|
||||
>;
|
||||
|
||||
const OrderSchema = z.object({
|
||||
status: z.string(),
|
||||
medusa_order_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
});
|
||||
export enum AnalysisResultLevel {
|
||||
NORMAL = 0,
|
||||
WARNING = 1,
|
||||
CRITICAL = 2,
|
||||
}
|
||||
|
||||
const DoctorAnalysisFeedbackSchema = z.object({
|
||||
id: z.number(),
|
||||
status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
created_by: z.string(),
|
||||
});
|
||||
|
||||
const SummarySchema = z.object({
|
||||
id: z.number(),
|
||||
value: z.string(),
|
||||
status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
created_by: z.string(),
|
||||
updated_at: z.coerce.date().nullable(),
|
||||
updated_by: z.string(),
|
||||
doctor_user_id: z.string().nullable(),
|
||||
analysis_order_id: z.number(),
|
||||
doctor_analysis_feedback: z.array(DoctorAnalysisFeedbackSchema),
|
||||
});
|
||||
|
||||
export const AnalysisResultDetailsSchema = z.object({
|
||||
id: z.number(),
|
||||
analysis_order_id: z.number(),
|
||||
order_number: z.string(),
|
||||
order_status: z.string(),
|
||||
user_id: z.string(),
|
||||
created_at: z.coerce.date(),
|
||||
updated_at: z.coerce.date().nullable(),
|
||||
elements: z.array(ElementSchema),
|
||||
order: OrderSchema,
|
||||
summary: SummarySchema.nullable(),
|
||||
});
|
||||
export type AnalysisResultDetails = z.infer<typeof AnalysisResultDetailsSchema>;
|
||||
export enum AnalysisStatus {
|
||||
QUEUED = 1,
|
||||
PENDING = 2,
|
||||
ONGOING = 3,
|
||||
COMPLETED = 4,
|
||||
REFUSED = 5,
|
||||
CANCELLED = 6,
|
||||
}
|
||||
|
||||
export type AnalysisResultDetailsElementResults = {
|
||||
unit: string | null;
|
||||
normLower: number | null;
|
||||
normUpper: number | null;
|
||||
normStatus: number | null;
|
||||
normStatus: AnalysisResultLevel | null;
|
||||
responseTime: string | null;
|
||||
responseValue: number | null;
|
||||
responseValueIsNegative: boolean | null;
|
||||
responseValueIsWithinNorm: boolean | null;
|
||||
normLowerIncluded: boolean;
|
||||
normUpperIncluded: boolean;
|
||||
status: string;
|
||||
status: AnalysisStatus;
|
||||
analysisElementOriginalId: string;
|
||||
nestedElements: {
|
||||
analysisElementOriginalId: string;
|
||||
normLower?: number | null;
|
||||
normLowerIncluded: boolean;
|
||||
normStatus: number;
|
||||
normUpper?: number | null;
|
||||
normUpperIncluded: boolean;
|
||||
responseTime: string;
|
||||
responseValue: number;
|
||||
status: number;
|
||||
unit: string;
|
||||
}[];
|
||||
nestedElements: AnalysisResultsDetailsElementNested[];
|
||||
labComment?: string | null;
|
||||
};
|
||||
|
||||
@@ -103,37 +143,21 @@ export type AnalysisResultDetailsElement = {
|
||||
analysisIdOriginal: string;
|
||||
isWaitingForResults: boolean;
|
||||
analysisName: string;
|
||||
results: AnalysisResultDetailsElementResults;
|
||||
results?: AnalysisResultDetailsElementResults;
|
||||
};
|
||||
|
||||
export type AnalysisResultDetailsMapped = {
|
||||
id: number;
|
||||
order: {
|
||||
status: string;
|
||||
medusaOrderId: string;
|
||||
createdAt: Date | string;
|
||||
};
|
||||
elements: {
|
||||
id: string;
|
||||
unit: string;
|
||||
norm_lower: number;
|
||||
norm_upper: number;
|
||||
norm_status: number;
|
||||
analysis_name: string;
|
||||
response_time: string;
|
||||
response_value: number;
|
||||
norm_lower_included: boolean;
|
||||
norm_upper_included: boolean;
|
||||
status: string;
|
||||
analysis_element_original_id: string;
|
||||
}[];
|
||||
orderedAnalysisElementIds: number[];
|
||||
createdAt: string;
|
||||
} & Pick<AnalysisOrder, 'status'>;
|
||||
orderedAnalysisElements: AnalysisResultDetailsElement[];
|
||||
summary: {
|
||||
id: number;
|
||||
status: string;
|
||||
user_id: string;
|
||||
created_at: Date;
|
||||
created_at: string;
|
||||
created_by: string;
|
||||
value?: string;
|
||||
} | null;
|
||||
|
||||
@@ -2,6 +2,9 @@ import { MonitoringService } from '@kit/monitoring-core';
|
||||
|
||||
export class ConsoleMonitoringService implements MonitoringService {
|
||||
identifyUser(data: { id: string }) {
|
||||
if (typeof window !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
console.log(`[Console Monitoring] Identified user`, data);
|
||||
}
|
||||
|
||||
@@ -12,6 +15,9 @@ export class ConsoleMonitoringService implements MonitoringService {
|
||||
}
|
||||
|
||||
captureEvent(event: string) {
|
||||
if (typeof window !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
console.log(`[Console Monitoring] Captured event: ${event}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,3 +57,8 @@ export const getPersonParameters = (personalCode: string) => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export function toArray<T>(input?: T | T[] | null): T[] {
|
||||
if (!input) return [];
|
||||
return Array.isArray(input) ? input : [input];
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ export type Database = {
|
||||
norm_upper: number | null
|
||||
norm_upper_included: boolean | null
|
||||
original_response_element: Json
|
||||
response_time: string
|
||||
response_time: string | null
|
||||
response_value: number | null
|
||||
response_value_is_negative?: boolean | null
|
||||
response_value_is_within_norm?: boolean | null
|
||||
@@ -706,7 +706,7 @@ export type Database = {
|
||||
norm_upper?: number | null
|
||||
norm_upper_included?: boolean | null
|
||||
original_response_element: Json
|
||||
response_time: string
|
||||
response_time: string | null
|
||||
response_value: number | null
|
||||
response_value_is_negative?: boolean | null
|
||||
response_value_is_within_norm?: boolean | null
|
||||
@@ -727,7 +727,7 @@ export type Database = {
|
||||
norm_upper?: number | null
|
||||
norm_upper_included?: boolean | null
|
||||
original_response_element?: Json
|
||||
response_time?: string
|
||||
response_time?: string | null
|
||||
response_value?: number | null
|
||||
response_value_is_negative?: boolean | null
|
||||
response_value_is_within_norm?: boolean | null
|
||||
|
||||
@@ -158,11 +158,11 @@ export function PageHeader({
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-between py-5',
|
||||
'flex py-5 flex-col sm:flex-row items-start sm:items-center sm:justify-between',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className={'flex flex-col gap-y-2'}>
|
||||
<div className={'flex flex-col gap-y-4 sm:gap-y-2'}>
|
||||
<If condition={title}>
|
||||
<PageTitle>{title}</PageTitle>
|
||||
</If>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"pageTitle": "My analysis results",
|
||||
"description": "All analysis results will appear here within 1-3 business days after they have been done.",
|
||||
"description": "",
|
||||
"descriptionPartial": "All analysis results will appear here within 1-3 business days after they have been done.",
|
||||
"descriptionEmpty": "If you've already done your analysis, your results will appear here soon.",
|
||||
"orderNewAnalysis": "Order new analyses",
|
||||
"waitingForResults": "Waiting for results",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"pageTitle": "Minu analüüside vastused",
|
||||
"description": "Kõikide analüüside tulemused ilmuvad 1-3 tööpäeva jooksul peale nende andmist.",
|
||||
"description": "",
|
||||
"descriptionPartial": "Kõikide analüüside tulemused ilmuvad 1-3 tööpäeva jooksul peale nende andmist.",
|
||||
"descriptionEmpty": "Kui oled juba käinud analüüse andmas, siis varsti jõuavad siia sinu analüüside vastused.",
|
||||
"orderNewAnalysis": "Telli uued analüüsid",
|
||||
"waitingForResults": "Tulemuse ootel",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"pageTitle": "Мои результаты анализов",
|
||||
"description": "Все результаты анализов появляются в течение 1-3 рабочих дней после их сдачи.",
|
||||
"description": "",
|
||||
"descriptionPartial": "Все результаты анализов появляются в течение 1-3 рабочих дней после их сдачи.",
|
||||
"descriptionEmpty": "Если вы уже сдали анализы, то вскоре здесь появятся ваши результаты.",
|
||||
"orderNewAnalysis": "Заказать новые анализы",
|
||||
"waitingForResults": "Ожидание результатов",
|
||||
|
||||
@@ -75,11 +75,11 @@
|
||||
}
|
||||
|
||||
h5 {
|
||||
@apply text-base;
|
||||
@apply text-lg;
|
||||
}
|
||||
|
||||
h6 {
|
||||
@apply text-lg;
|
||||
@apply text-base;
|
||||
}
|
||||
|
||||
.lucide {
|
||||
|
||||
10
supabase/migrations/20250920154900_ai_tables.sql
Normal file
10
supabase/migrations/20250920154900_ai_tables.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
create table if not exists medreport.ai_responses (
|
||||
id uuid unique not null default extensions.uuid_generate_v4 (),
|
||||
account_id uuid references medreport.accounts(id) on delete cascade not null,
|
||||
prompt_name varchar(50) not null,
|
||||
prompt_id varchar(50) not null,
|
||||
input jsonb not null,
|
||||
response jsonb not null,
|
||||
created_at timestamp with time zone not null default now(),
|
||||
latest_data_change timestamp with time zone not null
|
||||
);
|
||||
Reference in New Issue
Block a user