Initial commit
This commit is contained in:
34
src/app/api/patients/[id]/ordonnances/route.ts
Normal file
34
src/app/api/patients/[id]/ordonnances/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { db } from '@/lib/db'
|
||||
|
||||
// GET /api/patients/[id]/ordonnances - Get all ordonnances for a patient
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const ordonnances = await db.ordonnance.findMany({
|
||||
where: { patientId: id },
|
||||
include: {
|
||||
fichiers: true,
|
||||
patient: {
|
||||
include: {
|
||||
client: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
dateEmission: 'desc'
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json(ordonnances)
|
||||
} catch (error) {
|
||||
console.error('Error fetching ordonnances:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch ordonnances' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user