feat(MED-168): clean up types
This commit is contained in:
@@ -4,12 +4,7 @@ import { ArrowDown } from 'lucide-react';
|
||||
|
||||
import { cn } from '@kit/ui/utils';
|
||||
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
|
||||
export enum AnalysisResultLevel {
|
||||
NORMAL = 0,
|
||||
WARNING = 1,
|
||||
CRITICAL = 2,
|
||||
}
|
||||
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||
|
||||
type AnalysisResultLevelBarResults = Pick<AnalysisResultDetailsElementResults, 'normLower' | 'normUpper' | 'responseValue'>;
|
||||
|
||||
@@ -148,20 +143,18 @@ const AnalysisLevelBar = ({
|
||||
const isValueInNormalRange = !isValueBelowLower && !isValueAboveUpper;
|
||||
|
||||
const [first, second, third] = useMemo(() => {
|
||||
if (!hasLowerBound) {
|
||||
return [
|
||||
{
|
||||
isActive: isNormal,
|
||||
color: "success",
|
||||
isFirst: true,
|
||||
normRangeText,
|
||||
...(isNormal ? { arrowLocation } : {}),
|
||||
},
|
||||
const [warning, normal, critical] = [
|
||||
{
|
||||
isActive: isWarning,
|
||||
color: "warning",
|
||||
...(isWarning ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isNormal,
|
||||
color: "success",
|
||||
normRangeText,
|
||||
...(isNormal ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isCritical,
|
||||
color: "destructive",
|
||||
@@ -169,27 +162,19 @@ const AnalysisLevelBar = ({
|
||||
...(isCritical ? { arrowLocation } : {}),
|
||||
},
|
||||
] as const;
|
||||
|
||||
if (!hasLowerBound) {
|
||||
return [
|
||||
{ ...normal, isFirst: true },
|
||||
warning,
|
||||
critical,
|
||||
] as const;
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
isActive: isWarning,
|
||||
color: "warning",
|
||||
isFirst: true,
|
||||
...(isWarning ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isNormal,
|
||||
color: "success",
|
||||
normRangeText,
|
||||
...(isNormal ? { arrowLocation } : {}),
|
||||
},
|
||||
{
|
||||
isActive: isCritical,
|
||||
color: "destructive",
|
||||
isLast: true,
|
||||
...(isCritical ? { arrowLocation } : {}),
|
||||
},
|
||||
{ ...warning, isFirst: true },
|
||||
normal,
|
||||
{ ...critical, isLast: true },
|
||||
] as const;
|
||||
}, [isValueBelowLower, isValueAboveUpper, isValueInNormalRange, arrowLocation, normRangeText, isNormal, isWarning, isCritical]);
|
||||
|
||||
|
||||
@@ -2,27 +2,18 @@
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type {
|
||||
AnalysisResultDetailsElementResults,
|
||||
AnalysisResultDetailsElement,
|
||||
AnalysisResultsDetailsElementNested,
|
||||
} from '@/packages/features/user-analyses/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: elementOriginal,
|
||||
@@ -41,7 +32,7 @@ const Analysis = ({
|
||||
}
|
||||
return elementOriginal!;
|
||||
})();
|
||||
const results: AnalysisResultDetailsElementResults = useMemo(() => {
|
||||
const results: AnalysisResultDetailsElement['results'] = useMemo(() => {
|
||||
if (isNestedElement) {
|
||||
const nestedElement = element as AnalysisResultsDetailsElementNested;
|
||||
return {
|
||||
@@ -115,7 +106,8 @@ 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 = (() => {
|
||||
if (normLower === null && normUpper === null) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Database } from '@kit/supabase/database';
|
||||
import { toArray } from '@kit/shared/utils';
|
||||
import type { UuringuVastus } from '@kit/shared/types/medipost-analysis';
|
||||
|
||||
import type { AnalysisResultDetails, AnalysisResultDetailsMapped, AnalysisResultsDetailsElementNested, 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';
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ class UserAnalysesApi {
|
||||
order: {
|
||||
status: analysisOrder.status,
|
||||
medusaOrderId: analysisOrder.medusa_order_id,
|
||||
createdAt: new Date(analysisOrder.created_at),
|
||||
createdAt: analysisOrder.created_at,
|
||||
},
|
||||
orderedAnalysisElements: mappedOrderedAnalysisElements,
|
||||
summary:
|
||||
@@ -107,7 +107,7 @@ class UserAnalysesApi {
|
||||
.eq('analysis_order_id', analysisOrderId)
|
||||
.throwOnError();
|
||||
|
||||
return analysisResponse?.[0] as AnalysisResultDetails | null;
|
||||
return analysisResponse?.[0] as AnalysisResultsQuery | null;
|
||||
}
|
||||
|
||||
async getOrderedAnalysisElements({
|
||||
@@ -133,9 +133,9 @@ class UserAnalysesApi {
|
||||
analysisResponseElements,
|
||||
orderedAnalysisElements,
|
||||
}: {
|
||||
analysisResponseElements: AnalysisResultDetails['elements'];
|
||||
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.getOrderedAnalysisElement({
|
||||
analysisIdOriginal: analysis_id_original,
|
||||
@@ -186,8 +186,8 @@ class UserAnalysesApi {
|
||||
}: {
|
||||
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 {
|
||||
@@ -202,7 +202,7 @@ class UserAnalysesApi {
|
||||
isWaitingForResults: false,
|
||||
analysisName: analysisNameLab,
|
||||
results: {
|
||||
nestedElements: (() => {
|
||||
nestedElements: ((): AnalysisResultsDetailsElementNested[] => {
|
||||
const nestedElements = toArray(elementResponse.original_response_element?.UuringuElement)
|
||||
return nestedElements.map<AnalysisResultsDetailsElementNested>((element) => {
|
||||
const mappedResponse = this.mapUuringVastus({
|
||||
@@ -220,13 +220,12 @@ class UserAnalysesApi {
|
||||
normLowerIncluded: mappedResponse.normLowerIncluded,
|
||||
normUpperIncluded: mappedResponse.normUpperIncluded,
|
||||
analysisElementOriginalId: element.UuringId,
|
||||
status: elementResponse.status,
|
||||
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,
|
||||
@@ -237,9 +236,8 @@ class UserAnalysesApi {
|
||||
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,
|
||||
elementResponse,
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -260,7 +258,7 @@ class UserAnalysesApi {
|
||||
return {
|
||||
normLower: uuringVastus?.NormAlum?.['#text'] ?? null,
|
||||
normUpper: uuringVastus?.NormYlem?.['#text'] ?? null,
|
||||
normStatus: uuringVastus?.NormiStaatus ?? null,
|
||||
normStatus: (uuringVastus?.NormiStaatus ?? null) as AnalysisResultLevel | null,
|
||||
responseTime: uuringVastus?.VastuseAeg ?? null,
|
||||
responseValue: responseValueIsNegative || !responseValueIsNumeric ? null : (responseValueNumber ?? null),
|
||||
responseValueIsNegative: responseValueIsNumeric ? null : responseValueIsNegative,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { AnalysisOrderStatus, NormStatus } from '@kit/shared/types/medipost-analysis';
|
||||
import type { Database } from '@kit/supabase/database';
|
||||
import type { AnalysisOrderStatus, NormStatus } from '@kit/shared/types/medipost-analysis';
|
||||
|
||||
import type { AnalysisOrder } from './analysis-orders';
|
||||
|
||||
export type UserAnalysisElement =
|
||||
Database['medreport']['Tables']['analysis_response_elements']['Row'];
|
||||
@@ -9,7 +11,15 @@ export type UserAnalysisResponse =
|
||||
};
|
||||
export type UserAnalysis = UserAnalysisResponse[];
|
||||
|
||||
type ElementSchema = {
|
||||
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,
|
||||
@@ -51,23 +61,13 @@ type ElementSchema = {
|
||||
},
|
||||
UuringuKommentaar: string | null,
|
||||
},
|
||||
};
|
||||
|
||||
type OrderSchema = {
|
||||
}[],
|
||||
order: {
|
||||
status: string,
|
||||
medusa_order_id: string,
|
||||
created_at: string,
|
||||
};
|
||||
|
||||
type DoctorAnalysisFeedbackSchema = {
|
||||
id: number,
|
||||
status: string,
|
||||
user_id: string,
|
||||
created_at: string,
|
||||
created_by: string,
|
||||
};
|
||||
|
||||
type SummarySchema = {
|
||||
},
|
||||
summary: {
|
||||
id: number,
|
||||
value: string,
|
||||
status: string,
|
||||
@@ -78,20 +78,14 @@ type SummarySchema = {
|
||||
updated_by: string,
|
||||
doctor_user_id: string | null,
|
||||
analysis_order_id: number,
|
||||
doctor_analysis_feedback: DoctorAnalysisFeedbackSchema[],
|
||||
};
|
||||
|
||||
export type AnalysisResultDetails = {
|
||||
doctor_analysis_feedback: {
|
||||
id: number,
|
||||
analysis_order_id: number,
|
||||
order_number: string,
|
||||
order_status: string,
|
||||
status: string,
|
||||
user_id: string,
|
||||
created_at: string,
|
||||
updated_at: string | null,
|
||||
elements: ElementSchema[],
|
||||
order: OrderSchema,
|
||||
summary: SummarySchema | null,
|
||||
created_by: string,
|
||||
}[],
|
||||
} | null,
|
||||
};
|
||||
|
||||
export type AnalysisResultsDetailsElementNested = {
|
||||
@@ -113,18 +107,33 @@ export type AnalysisResultsDetailsElementNested = {
|
||||
'analysisElementOriginalId'
|
||||
>;
|
||||
|
||||
export enum AnalysisResultLevel {
|
||||
NORMAL = 0,
|
||||
WARNING = 1,
|
||||
CRITICAL = 2,
|
||||
}
|
||||
|
||||
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: AnalysisResultsDetailsElementNested[];
|
||||
labComment?: string | null;
|
||||
@@ -140,10 +149,9 @@ export type AnalysisResultDetailsElement = {
|
||||
export type AnalysisResultDetailsMapped = {
|
||||
id: number;
|
||||
order: {
|
||||
status: string;
|
||||
medusaOrderId: string;
|
||||
createdAt: Date | string;
|
||||
};
|
||||
createdAt: string;
|
||||
} & Pick<AnalysisOrder, 'status'>;
|
||||
orderedAnalysisElements: AnalysisResultDetailsElement[];
|
||||
summary: {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user