Vrda's picture
Deploy ClinIcPal frontend
9bc2f29 verified
import { NextResponse } from 'next/server';
import { quickDetectErrors } from '@/lib/ollama';
import type { QuickAnalyzeRequest } from '@/types';
// POST /api/analyze-quick - Quick clinical note analysis (Stage 1)
export async function POST(request: Request) {
try {
const body: QuickAnalyzeRequest = await request.json();
// Validate request
if (!body.text || body.text.trim().length === 0) {
return NextResponse.json(
{
success: false,
error: 'Clinical note text is required',
},
{ status: 400 }
);
}
if (!body.model) {
return NextResponse.json(
{
success: false,
error: 'Model selection is required',
},
{ status: 400 }
);
}
// Perform quick detection
const result = await quickDetectErrors(body.text, body.model);
return NextResponse.json({
success: true,
data: result,
});
} catch (error) {
const message = error instanceof Error ? error.message : 'Quick analysis failed';
// Check for specific error types
if (message.includes('timeout') || message.includes('Timeout')) {
return NextResponse.json(
{
success: false,
error: 'Quick analysis timed out.',
},
{ status: 504 }
);
}
if (message.includes('connect') || message.includes('Connection')) {
return NextResponse.json(
{
success: false,
error: 'Cannot connect to Ollama server. Make sure Ollama is running.',
},
{ status: 503 }
);
}
return NextResponse.json(
{
success: false,
error: message,
},
{ status: 500 }
);
}
}