67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { prisma } from '@/lib/db/prisma'
|
|
import { getCurrentUser } from '@/lib/auth'
|
|
import { canAccessWorkspace } from '@/lib/db/workspace-access'
|
|
|
|
// GET /api/workspaces/[id]/emergency-info
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
try {
|
|
const user = await getCurrentUser()
|
|
if (!user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const workspaceId = params.id
|
|
const access = await canAccessWorkspace(user.id, workspaceId)
|
|
if (!access) {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
|
}
|
|
|
|
// Get workspace with emergency info
|
|
const workspace = await prisma.workspace.findUnique({
|
|
where: { id: workspaceId },
|
|
select: {
|
|
patientName: true,
|
|
patientDOB: true,
|
|
bloodType: true,
|
|
allergies: true,
|
|
medicalConditions: true,
|
|
primaryPhysician: true,
|
|
physicianPhone: true,
|
|
clinicPhone: true,
|
|
emergencyPhone: true,
|
|
}
|
|
})
|
|
|
|
// Get active medications
|
|
const medications = await prisma.medication.findMany({
|
|
where: {
|
|
workspaceId,
|
|
active: true,
|
|
deletedAt: null
|
|
},
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
instructions: true
|
|
}
|
|
})
|
|
|
|
return NextResponse.json({
|
|
info: {
|
|
...workspace,
|
|
medications
|
|
}
|
|
})
|
|
} catch (error) {
|
|
console.error('Failed to fetch emergency info:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch emergency info' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|