openapi: 3.1.0 info: title: Api version: 0.1.0 description: ClinicDesk API specification servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: auth description: Authentication operations - name: patients description: Patient management - name: appointments description: Appointment management - name: medical-records description: Medical record management - name: prescriptions description: Prescription management - name: billing description: Billing and invoicing - name: dashboard description: Dashboard and reports paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" # Auth /auth/me: get: operationId: getMe tags: [auth] summary: Get current authenticated user responses: "200": description: Current user content: application/json: schema: $ref: "#/components/schemas/User" "401": description: Unauthorized /auth/register: post: operationId: register tags: [auth] summary: Register a new user requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterInput" responses: "201": description: Registered content: application/json: schema: $ref: "#/components/schemas/AuthResponse" /auth/login: post: operationId: login tags: [auth] summary: Login with credentials requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginInput" responses: "200": description: Login success content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "401": description: Invalid credentials /auth/logout: post: operationId: logout tags: [auth] summary: Logout current session responses: "200": description: Logged out # Users (admin management) /users: get: operationId: listUsers tags: [auth] summary: List all users (admin only) responses: "200": description: List of users content: application/json: schema: type: array items: $ref: "#/components/schemas/User" /users/{id}: get: operationId: getUser tags: [auth] summary: Get user by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: User content: application/json: schema: $ref: "#/components/schemas/User" patch: operationId: updateUser tags: [auth] summary: Update user role/status parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UserUpdate" responses: "200": description: Updated user content: application/json: schema: $ref: "#/components/schemas/User" # Patients /patients: get: operationId: listPatients tags: [patients] summary: List patients with optional search/filter parameters: - name: search in: query schema: type: string - name: page in: query schema: type: integer - name: limit in: query schema: type: integer responses: "200": description: Patients list content: application/json: schema: $ref: "#/components/schemas/PatientListResponse" post: operationId: createPatient tags: [patients] summary: Create a new patient requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PatientInput" responses: "201": description: Created patient content: application/json: schema: $ref: "#/components/schemas/Patient" /patients/{id}: get: operationId: getPatient tags: [patients] summary: Get patient by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Patient content: application/json: schema: $ref: "#/components/schemas/Patient" patch: operationId: updatePatient tags: [patients] summary: Update patient details parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PatientUpdate" responses: "200": description: Updated patient content: application/json: schema: $ref: "#/components/schemas/Patient" delete: operationId: deletePatient tags: [patients] summary: Delete a patient parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted /patients/{id}/summary: get: operationId: getPatientSummary tags: [patients] summary: Get patient overview with recent activity parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Patient summary content: application/json: schema: $ref: "#/components/schemas/PatientSummary" # Appointments /appointments: get: operationId: listAppointments tags: [appointments] summary: List appointments with filters parameters: - name: date in: query schema: type: string - name: doctorId in: query schema: type: integer - name: patientId in: query schema: type: integer - name: status in: query schema: type: string - name: from in: query schema: type: string - name: to in: query schema: type: string responses: "200": description: Appointments list content: application/json: schema: type: array items: $ref: "#/components/schemas/Appointment" post: operationId: createAppointment tags: [appointments] summary: Book a new appointment requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AppointmentInput" responses: "201": description: Created appointment content: application/json: schema: $ref: "#/components/schemas/Appointment" /appointments/{id}: get: operationId: getAppointment tags: [appointments] summary: Get appointment by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Appointment content: application/json: schema: $ref: "#/components/schemas/Appointment" patch: operationId: updateAppointment tags: [appointments] summary: Update appointment (reschedule, change status) parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AppointmentUpdate" responses: "200": description: Updated appointment content: application/json: schema: $ref: "#/components/schemas/Appointment" delete: operationId: deleteAppointment tags: [appointments] summary: Cancel/delete an appointment parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted /appointments/calendar: get: operationId: getCalendarAppointments tags: [appointments] summary: Get appointments in calendar format parameters: - name: from in: query required: true schema: type: string - name: to in: query required: true schema: type: string - name: doctorId in: query schema: type: integer responses: "200": description: Calendar events content: application/json: schema: type: array items: $ref: "#/components/schemas/CalendarEvent" # Medical Records /medical-records: get: operationId: listMedicalRecords tags: [medical-records] summary: List medical records parameters: - name: patientId in: query schema: type: integer - name: doctorId in: query schema: type: integer responses: "200": description: Medical records content: application/json: schema: type: array items: $ref: "#/components/schemas/MedicalRecord" post: operationId: createMedicalRecord tags: [medical-records] summary: Create a new medical record requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MedicalRecordInput" responses: "201": description: Created medical record content: application/json: schema: $ref: "#/components/schemas/MedicalRecord" /medical-records/{id}: get: operationId: getMedicalRecord tags: [medical-records] summary: Get medical record by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Medical record content: application/json: schema: $ref: "#/components/schemas/MedicalRecord" patch: operationId: updateMedicalRecord tags: [medical-records] summary: Update medical record parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MedicalRecordUpdate" responses: "200": description: Updated record content: application/json: schema: $ref: "#/components/schemas/MedicalRecord" delete: operationId: deleteMedicalRecord tags: [medical-records] summary: Delete medical record parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted # Prescriptions /prescriptions: get: operationId: listPrescriptions tags: [prescriptions] summary: List prescriptions parameters: - name: patientId in: query schema: type: integer - name: doctorId in: query schema: type: integer - name: medicalRecordId in: query schema: type: integer responses: "200": description: Prescriptions list content: application/json: schema: type: array items: $ref: "#/components/schemas/Prescription" post: operationId: createPrescription tags: [prescriptions] summary: Create a prescription requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PrescriptionInput" responses: "201": description: Created prescription content: application/json: schema: $ref: "#/components/schemas/Prescription" /prescriptions/{id}: get: operationId: getPrescription tags: [prescriptions] summary: Get prescription by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Prescription content: application/json: schema: $ref: "#/components/schemas/Prescription" patch: operationId: updatePrescription tags: [prescriptions] summary: Update prescription parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PrescriptionUpdate" responses: "200": description: Updated prescription content: application/json: schema: $ref: "#/components/schemas/Prescription" delete: operationId: deletePrescription tags: [prescriptions] summary: Delete prescription parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted # Billing / Invoices /invoices: get: operationId: listInvoices tags: [billing] summary: List invoices parameters: - name: patientId in: query schema: type: integer - name: status in: query schema: type: string - name: from in: query schema: type: string - name: to in: query schema: type: string responses: "200": description: Invoices list content: application/json: schema: type: array items: $ref: "#/components/schemas/Invoice" post: operationId: createInvoice tags: [billing] summary: Generate an invoice requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/InvoiceInput" responses: "201": description: Created invoice content: application/json: schema: $ref: "#/components/schemas/Invoice" /invoices/{id}: get: operationId: getInvoice tags: [billing] summary: Get invoice by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Invoice content: application/json: schema: $ref: "#/components/schemas/Invoice" patch: operationId: updateInvoice tags: [billing] summary: Update invoice (record payment, change status) parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/InvoiceUpdate" responses: "200": description: Updated invoice content: application/json: schema: $ref: "#/components/schemas/Invoice" delete: operationId: deleteInvoice tags: [billing] summary: Delete invoice parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted /invoices/{id}/payments: post: operationId: recordPayment tags: [billing] summary: Record a payment for an invoice parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PaymentInput" responses: "201": description: Payment recorded content: application/json: schema: $ref: "#/components/schemas/Payment" # Dashboard /dashboard/stats: get: operationId: getDashboardStats tags: [dashboard] summary: Get dashboard statistics responses: "200": description: Dashboard stats content: application/json: schema: $ref: "#/components/schemas/DashboardStats" /dashboard/recent-activity: get: operationId: getRecentActivity tags: [dashboard] summary: Recent activity feed parameters: - name: limit in: query schema: type: integer responses: "200": description: Recent activity content: application/json: schema: type: array items: $ref: "#/components/schemas/ActivityItem" /dashboard/revenue: get: operationId: getRevenueReport tags: [dashboard] summary: Revenue report by period parameters: - name: period in: query schema: type: string enum: [daily, weekly, monthly] - name: from in: query schema: type: string - name: to in: query schema: type: string responses: "200": description: Revenue data content: application/json: schema: $ref: "#/components/schemas/RevenueReport" /dashboard/appointments-stats: get: operationId: getAppointmentStats tags: [dashboard] summary: Appointment statistics grouped by status/doctor responses: "200": description: Appointment stats content: application/json: schema: $ref: "#/components/schemas/AppointmentStats" /doctors: get: operationId: listDoctors tags: [auth] summary: List all doctors responses: "200": description: List of doctors content: application/json: schema: type: array items: $ref: "#/components/schemas/User" components: schemas: HealthStatus: type: object required: [status] properties: status: type: string # Auth User: type: object required: [id, email, name, role, createdAt] properties: id: type: integer email: type: string name: type: string role: type: string enum: [admin, doctor, receptionist, patient] phone: type: ["string", "null"] specialization: type: ["string", "null"] isActive: type: boolean createdAt: type: string RegisterInput: type: object required: [email, password, name, role] properties: email: type: string password: type: string name: type: string role: type: string enum: [admin, doctor, receptionist, patient] phone: type: string specialization: type: string LoginInput: type: object required: [email, password] properties: email: type: string password: type: string AuthResponse: type: object required: [token, user] properties: token: type: string user: $ref: "#/components/schemas/User" UserUpdate: type: object properties: name: type: string role: type: string enum: [admin, doctor, receptionist, patient] phone: type: string specialization: type: string isActive: type: boolean # Patients Patient: type: object required: [id, firstName, lastName, dateOfBirth, gender, createdAt] properties: id: type: integer firstName: type: string lastName: type: string dateOfBirth: type: string gender: type: string enum: [male, female, other] phone: type: ["string", "null"] email: type: ["string", "null"] address: type: ["string", "null"] bloodType: type: ["string", "null"] allergies: type: ["string", "null"] medicalHistory: type: ["string", "null"] emergencyContact: type: ["string", "null"] emergencyPhone: type: ["string", "null"] createdAt: type: string PatientInput: type: object required: [firstName, lastName, dateOfBirth, gender] properties: firstName: type: string lastName: type: string dateOfBirth: type: string gender: type: string enum: [male, female, other] phone: type: string email: type: string address: type: string bloodType: type: string allergies: type: string medicalHistory: type: string emergencyContact: type: string emergencyPhone: type: string PatientUpdate: type: object properties: firstName: type: string lastName: type: string dateOfBirth: type: string gender: type: string enum: [male, female, other] phone: type: string email: type: string address: type: string bloodType: type: string allergies: type: string medicalHistory: type: string emergencyContact: type: string emergencyPhone: type: string PatientListResponse: type: object required: [patients, total, page, limit] properties: patients: type: array items: $ref: "#/components/schemas/Patient" total: type: integer page: type: integer limit: type: integer PatientSummary: type: object required: [patient, totalAppointments, totalInvoices, totalDue, recentRecords] properties: patient: $ref: "#/components/schemas/Patient" totalAppointments: type: integer lastVisit: type: ["string", "null"] totalInvoices: type: integer totalDue: type: number recentRecords: type: array items: $ref: "#/components/schemas/MedicalRecord" # Appointments Appointment: type: object required: [id, patientId, doctorId, scheduledAt, status, type, createdAt] properties: id: type: integer patientId: type: integer patient: $ref: "#/components/schemas/Patient" doctorId: type: integer doctor: $ref: "#/components/schemas/User" scheduledAt: type: string duration: type: integer status: type: string enum: [scheduled, confirmed, in_progress, completed, cancelled, no_show] type: type: string enum: [consultation, follow_up, emergency, checkup, procedure] notes: type: ["string", "null"] createdAt: type: string AppointmentInput: type: object required: [patientId, doctorId, scheduledAt, type] properties: patientId: type: integer doctorId: type: integer scheduledAt: type: string duration: type: integer type: type: string enum: [consultation, follow_up, emergency, checkup, procedure] notes: type: string AppointmentUpdate: type: object properties: scheduledAt: type: string duration: type: integer status: type: string enum: [scheduled, confirmed, in_progress, completed, cancelled, no_show] type: type: string enum: [consultation, follow_up, emergency, checkup, procedure] notes: type: string CalendarEvent: type: object required: [id, title, start, end, status, type] properties: id: type: integer title: type: string start: type: string end: type: string status: type: string type: type: string patientId: type: integer doctorId: type: integer doctorName: type: string patientName: type: string # Medical Records MedicalRecord: type: object required: [id, patientId, doctorId, visitDate, createdAt] properties: id: type: integer patientId: type: integer patient: $ref: "#/components/schemas/Patient" doctorId: type: integer doctor: $ref: "#/components/schemas/User" appointmentId: type: ["integer", "null"] visitDate: type: string chiefComplaint: type: ["string", "null"] diagnosis: type: ["string", "null"] examinationNotes: type: ["string", "null"] labResults: type: ["string", "null"] treatment: type: ["string", "null"] followUpDate: type: ["string", "null"] createdAt: type: string MedicalRecordInput: type: object required: [patientId, doctorId, visitDate] properties: patientId: type: integer doctorId: type: integer appointmentId: type: integer visitDate: type: string chiefComplaint: type: string diagnosis: type: string examinationNotes: type: string labResults: type: string treatment: type: string followUpDate: type: string MedicalRecordUpdate: type: object properties: chiefComplaint: type: string diagnosis: type: string examinationNotes: type: string labResults: type: string treatment: type: string followUpDate: type: string # Prescriptions PrescriptionItem: type: object required: [medicine, dosage, frequency, duration] properties: medicine: type: string dosage: type: string frequency: type: string duration: type: string instructions: type: ["string", "null"] Prescription: type: object required: [id, patientId, doctorId, prescribedAt, items, createdAt] properties: id: type: integer patientId: type: integer patient: $ref: "#/components/schemas/Patient" doctorId: type: integer doctor: $ref: "#/components/schemas/User" medicalRecordId: type: ["integer", "null"] prescribedAt: type: string notes: type: ["string", "null"] items: type: array items: $ref: "#/components/schemas/PrescriptionItem" createdAt: type: string PrescriptionInput: type: object required: [patientId, doctorId, prescribedAt, items] properties: patientId: type: integer doctorId: type: integer medicalRecordId: type: integer prescribedAt: type: string notes: type: string items: type: array items: $ref: "#/components/schemas/PrescriptionItem" PrescriptionUpdate: type: object properties: notes: type: string items: type: array items: $ref: "#/components/schemas/PrescriptionItem" # Billing InvoiceItem: type: object required: [description, quantity, unitPrice] properties: description: type: string quantity: type: number unitPrice: type: number total: type: number Invoice: type: object required: [id, patientId, totalAmount, paidAmount, status, dueDate, createdAt] properties: id: type: integer patientId: type: integer patient: $ref: "#/components/schemas/Patient" appointmentId: type: ["integer", "null"] items: type: array items: $ref: "#/components/schemas/InvoiceItem" totalAmount: type: number paidAmount: type: number status: type: string enum: [draft, pending, partial, paid, cancelled] dueDate: type: string notes: type: ["string", "null"] createdAt: type: string InvoiceInput: type: object required: [patientId, items, dueDate] properties: patientId: type: integer appointmentId: type: integer items: type: array items: $ref: "#/components/schemas/InvoiceItem" dueDate: type: string notes: type: string InvoiceUpdate: type: object properties: status: type: string enum: [draft, pending, partial, paid, cancelled] dueDate: type: string notes: type: string Payment: type: object required: [id, invoiceId, amount, method, paidAt] properties: id: type: integer invoiceId: type: integer amount: type: number method: type: string enum: [cash, card, insurance, bank_transfer] paidAt: type: string notes: type: ["string", "null"] PaymentInput: type: object required: [amount, method] properties: amount: type: number method: type: string enum: [cash, card, insurance, bank_transfer] notes: type: string # Dashboard DashboardStats: type: object required: [totalPatients, todayAppointments, pendingInvoices, monthlyRevenue, newPatientsThisMonth, appointmentsByStatus] properties: totalPatients: type: integer todayAppointments: type: integer upcomingAppointments: type: integer pendingInvoices: type: integer monthlyRevenue: type: number totalRevenue: type: number newPatientsThisMonth: type: integer appointmentsByStatus: type: object properties: scheduled: type: integer confirmed: type: integer completed: type: integer cancelled: type: integer ActivityItem: type: object required: [id, type, description, timestamp] properties: id: type: integer type: type: string enum: [appointment_booked, appointment_cancelled, patient_registered, invoice_paid, prescription_created, record_added] description: type: string timestamp: type: string patientName: type: ["string", "null"] doctorName: type: ["string", "null"] RevenueDataPoint: type: object required: [label, amount, count] properties: label: type: string amount: type: number count: type: integer RevenueReport: type: object required: [data, totalRevenue, totalInvoices] properties: data: type: array items: $ref: "#/components/schemas/RevenueDataPoint" totalRevenue: type: number totalInvoices: type: integer DoctorAppointmentStat: type: object required: [doctorId, doctorName, count] properties: doctorId: type: integer doctorName: type: string count: type: integer AppointmentStats: type: object required: [byStatus, byDoctor, byType] properties: byStatus: type: object additionalProperties: type: integer byDoctor: type: array items: $ref: "#/components/schemas/DoctorAppointmentStat" byType: type: object additionalProperties: type: integer