feat(MED-161): move analysis types separately from accounts types
This commit is contained in:
@@ -1,22 +1,24 @@
|
|||||||
import { SupabaseClient } from '@supabase/supabase-js';
|
import { SupabaseClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
import { Database } from '@kit/supabase/database';
|
import { Database } from '@kit/supabase/database';
|
||||||
|
import type { UuringElement, UuringuVastus } from '@kit/shared/types/medipost-analysis';
|
||||||
import { AnalysisResultDetails, UserAnalysis } from '../types/accounts';
|
|
||||||
import PersonalCode from '~/lib/utils';
|
import PersonalCode from '~/lib/utils';
|
||||||
|
|
||||||
|
import type { AnalysisResultDetails, AnalysisResultDetailsMapped, UserAnalysis } from '../types/analysis-results';
|
||||||
|
import type { AnalysisOrder } from '../types/analysis-orders';
|
||||||
|
|
||||||
export type AccountWithParams =
|
export type AccountWithParams =
|
||||||
Database['medreport']['Tables']['accounts']['Row'] & {
|
Database['medreport']['Tables']['accounts']['Row'] & {
|
||||||
accountParams:
|
accountParams:
|
||||||
| (Pick<
|
| (Pick<
|
||||||
Database['medreport']['Tables']['account_params']['Row'],
|
Database['medreport']['Tables']['account_params']['Row'],
|
||||||
'weight' | 'height'
|
'weight' | 'height'
|
||||||
> & {
|
> & {
|
||||||
isSmoker:
|
isSmoker:
|
||||||
| Database['medreport']['Tables']['account_params']['Row']['is_smoker']
|
| Database['medreport']['Tables']['account_params']['Row']['is_smoker']
|
||||||
| null;
|
|
||||||
})
|
|
||||||
| null;
|
| null;
|
||||||
|
})
|
||||||
|
| null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +27,7 @@ export type AccountWithParams =
|
|||||||
* @param {SupabaseClient<Database>} client - The Supabase client instance.
|
* @param {SupabaseClient<Database>} client - The Supabase client instance.
|
||||||
*/
|
*/
|
||||||
class AccountsApi {
|
class AccountsApi {
|
||||||
constructor(private readonly client: SupabaseClient<Database>) {}
|
constructor(private readonly client: SupabaseClient<Database>) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name getAccount
|
* @name getAccount
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
import * as z from 'zod';
|
|
||||||
|
|
||||||
import { Database } from '@kit/supabase/database';
|
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[];
|
|
||||||
|
|
||||||
export type ApplicationRole =
|
export type ApplicationRole =
|
||||||
Database['medreport']['Tables']['accounts']['Row']['application_role'];
|
Database['medreport']['Tables']['accounts']['Row']['application_role'];
|
||||||
export enum ApplicationRoleEnum {
|
export enum ApplicationRoleEnum {
|
||||||
@@ -17,51 +7,3 @@ export enum ApplicationRoleEnum {
|
|||||||
Doctor = 'doctor',
|
Doctor = 'doctor',
|
||||||
SuperAdmin = 'super_admin',
|
SuperAdmin = 'super_admin',
|
||||||
}
|
}
|
||||||
|
|
||||||
export 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(),
|
|
||||||
norm_lower_included: z.boolean(),
|
|
||||||
norm_upper_included: z.boolean(),
|
|
||||||
});
|
|
||||||
export type Element = z.infer<typeof ElementSchema>;
|
|
||||||
|
|
||||||
export const OrderSchema = z.object({
|
|
||||||
status: z.string(),
|
|
||||||
medusa_order_id: z.string(),
|
|
||||||
created_at: z.coerce.date(),
|
|
||||||
});
|
|
||||||
export type Order = z.infer<typeof OrderSchema>;
|
|
||||||
|
|
||||||
export 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(),
|
|
||||||
});
|
|
||||||
export type Summary = z.infer<typeof SummarySchema>;
|
|
||||||
|
|
||||||
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>;
|
|
||||||
|
|||||||
3
packages/features/accounts/src/types/analysis-orders.ts
Normal file
3
packages/features/accounts/src/types/analysis-orders.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { Tables } from '@kit/supabase/database';
|
||||||
|
|
||||||
|
export type AnalysisOrder = Tables<{ schema: 'medreport' }, 'analysis_orders'>;
|
||||||
138
packages/features/accounts/src/types/analysis-results.ts
Normal file
138
packages/features/accounts/src/types/analysis-results.ts
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
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;
|
||||||
|
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;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user