add doctor feedback
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
import { confirmPatientAIResponses } from '@/app/home/(user)/_lib/server/ai-actions';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
@@ -104,11 +106,19 @@ export const giveFeedbackAction = doctorAction(
|
||||
userId,
|
||||
analysisOrderId,
|
||||
status,
|
||||
patientId,
|
||||
timestamp,
|
||||
recommendations,
|
||||
isRecommendationsEdited,
|
||||
}: {
|
||||
feedbackValue: string;
|
||||
userId: DoctorAnalysisFeedbackTable['user_id'];
|
||||
analysisOrderId: DoctorAnalysisFeedbackTable['analysis_order_id'];
|
||||
status: DoctorAnalysisFeedbackTable['status'];
|
||||
patientId: string;
|
||||
timestamp?: string;
|
||||
recommendations: string[];
|
||||
isRecommendationsEdited: boolean;
|
||||
}) => {
|
||||
const logger = await getLogger();
|
||||
const isCompleted = status === 'COMPLETED';
|
||||
@@ -122,6 +132,19 @@ export const giveFeedbackAction = doctorAction(
|
||||
await submitFeedback(analysisOrderId, userId, feedbackValue, status);
|
||||
logger.info({ analysisOrderId }, `Successfully submitted feedback`);
|
||||
|
||||
if (timestamp) {
|
||||
logger.info(
|
||||
{ timestamp, patientId },
|
||||
'Attempting to update patient ai responses',
|
||||
);
|
||||
await confirmPatientAIResponses(
|
||||
patientId,
|
||||
timestamp,
|
||||
recommendations,
|
||||
isRecommendationsEdited,
|
||||
);
|
||||
}
|
||||
|
||||
revalidateDoctorAnalysis();
|
||||
|
||||
if (isCompleted) {
|
||||
|
||||
@@ -41,7 +41,8 @@ export const PatientSchema = z.object({
|
||||
email: z.string().nullable(),
|
||||
height: z.number().optional().nullable(),
|
||||
weight: z.number().optional().nullable(),
|
||||
preferred_locale: z.string().nullable(),
|
||||
preferred_locale: z.enum(['en', 'et', 'ru']).nullable(),
|
||||
isSmoker: z.boolean().optional(),
|
||||
});
|
||||
export type Patient = z.infer<typeof PatientSchema>;
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ export const doctorAnalysisFeedbackSchema = z.object({
|
||||
userId: z.string().uuid(),
|
||||
analysisOrderId: z.number(),
|
||||
status: FeedbackStatus,
|
||||
patientId: z.string(),
|
||||
timestamp: z.string().optional(),
|
||||
recommendations: z.array(z.string()),
|
||||
isRecommendationsEdited: z.boolean(),
|
||||
});
|
||||
|
||||
export type DoctorAnalysisFeedback = z.infer<
|
||||
|
||||
@@ -424,7 +424,7 @@ export async function getAnalysisResultsForDoctor(
|
||||
.from('accounts')
|
||||
.select(
|
||||
`primary_owner_user_id, id, name, last_name, personal_code, phone, email, preferred_locale,
|
||||
accountParams:account_params(height,weight)`,
|
||||
accountParams:account_params(height,weight,is_smoker)`,
|
||||
)
|
||||
.eq('is_personal_account', true)
|
||||
.eq('primary_owner_user_id', userId)
|
||||
@@ -529,6 +529,7 @@ export async function getAnalysisResultsForDoctor(
|
||||
email,
|
||||
height: accountParams?.height,
|
||||
weight: accountParams?.weight,
|
||||
isSmoker: accountParams?.is_smoker || false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -434,7 +434,9 @@ class UserAnalysesApi {
|
||||
return data;
|
||||
}
|
||||
|
||||
async getAllUserAnalysisResponses(): Promise<
|
||||
async getAllUserAnalysisResponses(
|
||||
userId?: string,
|
||||
): Promise<
|
||||
Database['medreport']['Functions']['get_latest_analysis_response_elements_for_current_user']['Returns']
|
||||
> {
|
||||
const {
|
||||
@@ -448,7 +450,7 @@ class UserAnalysesApi {
|
||||
const { data, error } = await this.client
|
||||
.schema('medreport')
|
||||
.rpc('get_latest_analysis_response_elements_for_current_user', {
|
||||
p_user_id: user.id,
|
||||
p_user_id: userId ?? user.id,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
Bike,
|
||||
Apple,
|
||||
FileLineChart,
|
||||
HeartPulse,
|
||||
LineChart,
|
||||
@@ -57,7 +57,7 @@ const routes = [
|
||||
{
|
||||
label: 'common:routes.lifeStyle',
|
||||
path: pathsConfig.app.lifeStyle,
|
||||
Icon: <Bike className={iconClasses} />,
|
||||
Icon: <Apple className={iconClasses} />,
|
||||
end: true,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -623,6 +623,7 @@ export type Database = {
|
||||
created_at: string
|
||||
id: string
|
||||
input: Json
|
||||
is_visible_to_customer: boolean
|
||||
latest_data_change: string
|
||||
prompt_id: string
|
||||
prompt_name: string
|
||||
@@ -633,6 +634,7 @@ export type Database = {
|
||||
created_at?: string
|
||||
id?: string
|
||||
input: Json
|
||||
is_visible_to_customer?: boolean
|
||||
latest_data_change: string
|
||||
prompt_id: string
|
||||
prompt_name: string
|
||||
@@ -643,6 +645,7 @@ export type Database = {
|
||||
created_at?: string
|
||||
id?: string
|
||||
input?: Json
|
||||
is_visible_to_customer?: boolean
|
||||
latest_data_change?: string
|
||||
prompt_id?: string
|
||||
prompt_name?: string
|
||||
|
||||
Reference in New Issue
Block a user