update type

This commit is contained in:
Danel Kungla
2025-09-20 18:42:18 +03:00
parent a52a9bec06
commit 643e67e2a1
2 changed files with 151 additions and 41 deletions

View File

@@ -96,6 +96,10 @@ async function recommendationsLoader(
.eq('prompt_id', analysesRecommendationsPromptId) .eq('prompt_id', analysesRecommendationsPromptId)
.eq('latest_data_change', latestISO); .eq('latest_data_change', latestISO);
if (previouslyRecommended.data?.[0]?.response) {
return previouslyRecommended.data[0].response;
}
const openAIClient = new OpenAI(); const openAIClient = new OpenAI();
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code); const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
const weight = account.accountParams?.weight || 'unknown'; const weight = account.accountParams?.weight || 'unknown';
@@ -110,7 +114,6 @@ async function recommendationsLoader(
})); }));
const response = await openAIClient.responses.create({ const response = await openAIClient.responses.create({
model: 'gpt-5-mini',
store: false, store: false,
prompt: { prompt: {
id: analysesRecommendationsPromptId, id: analysesRecommendationsPromptId,
@@ -126,6 +129,23 @@ async function recommendationsLoader(
}); });
const json = JSON.parse(response.output_text); const json = JSON.parse(response.output_text);
console.log('response.output_text', response.output_text); await supabaseClient
.schema('medreport')
.from('ai_responses')
.insert({
account_id: account.id,
prompt_name: 'Analysis Recommendations',
prompt_id: analysesRecommendationsPromptId,
input: JSON.stringify({
analyses: formattedAnalyses,
results: formattedAnalysisResponses,
gender,
age,
weight,
}),
latest_data_change: latestISO,
response: JSON.stringify(response.output_text),
});
return json.recommended; return json.recommended;
} }

View File

@@ -198,6 +198,7 @@ export type Database = {
action: string action: string
changed_by: string changed_by: string
created_at: string created_at: string
extra_data: Json | null
id: number id: number
} }
Insert: { Insert: {
@@ -205,6 +206,7 @@ export type Database = {
action: string action: string
changed_by: string changed_by: string
created_at?: string created_at?: string
extra_data?: Json | null
id?: number id?: number
} }
Update: { Update: {
@@ -212,6 +214,7 @@ export type Database = {
action?: string action?: string
changed_by?: string changed_by?: string
created_at?: string created_at?: string
extra_data?: Json | null
id?: number id?: number
} }
Relationships: [] Relationships: []
@@ -517,6 +520,61 @@ export type Database = {
}, },
] ]
} }
ai_responses: {
Row: {
account_id: string
created_at: string
id: string
input: Json
latest_data_change: string
prompt_id: string
prompt_name: string
response: Json
}
Insert: {
account_id: string
created_at?: string
id?: string
input: Json
latest_data_change: string
prompt_id: string
prompt_name: string
response: Json
}
Update: {
account_id?: string
created_at?: string
id?: string
input?: Json
latest_data_change?: string
prompt_id?: string
prompt_name?: string
response?: Json
}
Relationships: [
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "accounts"
referencedColumns: ["id"]
},
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "user_account_workspace"
referencedColumns: ["id"]
},
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "user_accounts"
referencedColumns: ["id"]
},
]
}
analyses: { analyses: {
Row: { Row: {
analysis_id_oid: string analysis_id_oid: string
@@ -685,11 +743,11 @@ export type Database = {
norm_upper: number | null norm_upper: number | null
norm_upper_included: boolean | null norm_upper_included: boolean | null
original_response_element: Json original_response_element: Json
response_time: string response_time: string | null
response_value: number | null response_value: number | null
response_value_is_negative?: boolean | null response_value_is_negative: boolean | null
response_value_is_within_norm?: boolean | null response_value_is_within_norm: boolean | null
status: string status: string | null
unit: string | null unit: string | null
updated_at: string | null updated_at: string | null
} }
@@ -706,11 +764,11 @@ export type Database = {
norm_upper?: number | null norm_upper?: number | null
norm_upper_included?: boolean | null norm_upper_included?: boolean | null
original_response_element: Json original_response_element: Json
response_time: string response_time?: string | null
response_value: number | null response_value?: number | null
response_value_is_negative?: boolean | null response_value_is_negative?: boolean | null
response_value_is_within_norm?: boolean | null response_value_is_within_norm?: boolean | null
status: string status?: string | null
unit?: string | null unit?: string | null
updated_at?: string | null updated_at?: string | null
} }
@@ -727,11 +785,11 @@ export type Database = {
norm_upper?: number | null norm_upper?: number | null
norm_upper_included?: boolean | null norm_upper_included?: boolean | null
original_response_element?: Json original_response_element?: Json
response_time?: string response_time?: string | null
response_value?: number | null response_value?: number | null
response_value_is_negative?: boolean | null response_value_is_negative?: boolean | null
response_value_is_within_norm?: boolean | null response_value_is_within_norm?: boolean | null
status: string status?: string | null
unit?: string | null unit?: string | null
updated_at?: string | null updated_at?: string | null
} }
@@ -1159,7 +1217,7 @@ export type Database = {
doctor_user_id: string | null doctor_user_id: string | null
id: number id: number
status: Database["medreport"]["Enums"]["analysis_feedback_status"] status: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at: string updated_at: string | null
updated_by: string | null updated_by: string | null
user_id: string user_id: string
value: string | null value: string | null
@@ -1171,7 +1229,7 @@ export type Database = {
doctor_user_id?: string | null doctor_user_id?: string | null
id?: number id?: number
status?: Database["medreport"]["Enums"]["analysis_feedback_status"] status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at?: string updated_at?: string | null
updated_by?: string | null updated_by?: string | null
user_id: string user_id: string
value?: string | null value?: string | null
@@ -1183,7 +1241,7 @@ export type Database = {
doctor_user_id?: string | null doctor_user_id?: string | null
id?: number id?: number
status?: Database["medreport"]["Enums"]["analysis_feedback_status"] status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at?: string updated_at?: string | null
updated_by?: string | null updated_by?: string | null
user_id?: string user_id?: string
value?: string | null value?: string | null
@@ -1268,27 +1326,42 @@ export type Database = {
} }
medipost_actions: { medipost_actions: {
Row: { Row: {
created_at: string
id: number
action: string action: string
xml: string created_at: string | null
has_analysis_results: boolean has_analysis_results: boolean
medipost_external_order_id: string
medipost_private_message_id: string
medusa_order_id: string
response_xml: string
has_error: boolean has_error: boolean
id: string
medipost_external_order_id: string | null
medipost_private_message_id: string | null
medusa_order_id: string | null
response_xml: string | null
xml: string | null
} }
Insert: { Insert: {
action: string action: string
xml: string created_at?: string | null
has_analysis_results: boolean has_analysis_results?: boolean
medipost_external_order_id: string has_error?: boolean
medipost_private_message_id: string id?: string
medusa_order_id: string medipost_external_order_id?: string | null
response_xml: string medipost_private_message_id?: string | null
has_error: boolean medusa_order_id?: string | null
response_xml?: string | null
xml?: string | null
} }
Update: {
action?: string
created_at?: string | null
has_analysis_results?: boolean
has_error?: boolean
id?: string
medipost_external_order_id?: string | null
medipost_private_message_id?: string | null
medusa_order_id?: string | null
response_xml?: string | null
xml?: string | null
}
Relationships: []
} }
medreport_product_groups: { medreport_product_groups: {
Row: { Row: {
@@ -1957,6 +2030,13 @@ export type Database = {
personal_code: string personal_code: string
}[] }[]
} }
get_latest_medipost_dispatch_state_for_order: {
Args: { medusa_order_id: string }
Returns: {
action_date: string
has_success: boolean
}[]
}
get_medipost_dispatch_tries: { get_medipost_dispatch_tries: {
Args: { p_medusa_order_id: string } Args: { p_medusa_order_id: string }
Returns: number Returns: number
@@ -2049,9 +2129,9 @@ export type Database = {
Args: { account_id: string; user_id: string } Args: { account_id: string; user_id: string }
Returns: boolean Returns: boolean
} }
medipost_retry_dispatch: { order_has_medipost_dispatch_error: {
Args: { order_id: string } Args: { medusa_order_id: string }
Returns: Json Returns: boolean
} }
revoke_nonce: { revoke_nonce: {
Args: { p_id: string; p_reason?: string } Args: { p_id: string; p_reason?: string }
@@ -2078,16 +2158,26 @@ export type Database = {
Returns: undefined Returns: undefined
} }
update_account: { update_account: {
Args: { Args:
p_city: string | {
p_has_consent_personal_data: boolean p_city: string
p_last_name: string p_email: string
p_name: string p_has_consent_personal_data: boolean
p_personal_code: string p_last_name: string
p_phone: string p_name: string
p_uid: string p_personal_code: string
p_email: string p_phone: string
} p_uid: string
}
| {
p_city: string
p_has_consent_personal_data: boolean
p_last_name: string
p_name: string
p_personal_code: string
p_phone: string
p_uid: string
}
Returns: undefined Returns: undefined
} }
update_analysis_order_status: { update_analysis_order_status: {