merge
This commit is contained in:
@@ -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;
|
||||
};
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -1401,6 +1401,7 @@ export type Database = {
|
||||
medipost_private_message_id: string | null
|
||||
medusa_order_id: string | null
|
||||
response_xml: string | null
|
||||
updated_at: string | null
|
||||
xml: string | null
|
||||
}
|
||||
Insert: {
|
||||
@@ -1413,6 +1414,7 @@ export type Database = {
|
||||
medipost_private_message_id?: string | null
|
||||
medusa_order_id?: string | null
|
||||
response_xml?: string | null
|
||||
updated_at?: string | null
|
||||
xml?: string | null
|
||||
}
|
||||
Update: {
|
||||
@@ -1425,6 +1427,7 @@ export type Database = {
|
||||
medipost_private_message_id?: string | null
|
||||
medusa_order_id?: string | null
|
||||
response_xml?: string | null
|
||||
updated_at?: string | null
|
||||
xml?: string | null
|
||||
}
|
||||
Relationships: []
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user