add doctor feedback

This commit is contained in:
Danel Kungla
2025-10-28 16:09:06 +02:00
parent b5b01648fc
commit 8bc6089a7f
28 changed files with 820 additions and 95 deletions

View File

@@ -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) {

View File

@@ -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>;

View File

@@ -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<

View File

@@ -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,
},
};
}