Skip to main content

API Documentation

Welcome to the LyfeAI Provider API documentation. This section covers all available APIs, server actions, and integration endpoints.

Overview

LyfeAI Provider uses a server-first architecture built on Next.js 14 App Router. Instead of traditional REST or GraphQL APIs, the system primarily uses Server Actions for data mutations and complex operations.

Documentation Structure

Quick Start

Using Server Actions

Server actions are TypeScript functions marked with "use server" that run on the server and can be called directly from client components:

// In a client component
import { addPatient } from '@/app/actions/patient-actions';

const handleSubmit = async (formData: FormData) => {
const result = await addPatient({
firstName: formData.get('firstName'),
lastName: formData.get('lastName'),
// ... other fields
});

if (result.success) {
// Handle success
} else {
// Handle error
console.error(result.error);
}
};

Response Format

All server actions return a consistent response format:

interface ActionResponse<T = any> {
success: boolean;
data?: T; // Success data (type varies by action)
error?: string; // Error message
message?: string; // User-friendly message
fieldErrors?: Record<string, string>; // Field validation errors
}

Authentication

The system uses a role-based access control (RBAC) system with the following roles:

  • Admin - Full system access
  • Doctor - Medical functions and patient management
  • Nurse - Patient care and limited ordering
  • Staff - Basic patient access
  • Patient - Portal access only

See the Authentication & Authorization guide for details.

Available APIs

1. Patient Management

  • Create, read, update, delete patients
  • Import patients from external sources
  • Manage patient medical records

2. AI Services

  • Document processing and data extraction
  • Medical image analysis
  • Clinical decision support
  • Predictive analytics

3. Clinical Operations

  • Order management (labs, medications, imaging)
  • Care plan creation and tracking
  • Patient communication
  • Appointment scheduling

4. Integration Services

  • EHR synchronization
  • Patient portal integration
  • Medical device connectivity
  • External lab interfaces

5. Administrative Functions

  • User management
  • System configuration
  • Audit logging
  • Analytics and reporting

Integration Patterns

FHIR Integration

LyfeAI Provider supports FHIR R4 for healthcare data exchange:

import { parseFHIRPatient } from '@/lib/enhanced-fhir-service';

const patient = await parseFHIRPatient(fhirBundle);

Webhook Integration

External systems can send updates via webhooks:

POST /api/webhooks/portal-sync
Content-Type: application/json

{
"event": "sync.completed",
"requestId": "123e4567-e89b-12d3-a456-426614174000",
"status": "success",
"data": { ... }
}

Development Tools

TypeScript Support

All APIs are fully typed with TypeScript. Import types from:

import type { Patient, User, Order } from '@/types';

Testing

Test server actions using the provided test utilities:

import { testDatabaseConnection } from '@/app/actions/patient-actions';

const result = await testDatabaseConnection();
expect(result.success).toBe(true);

Security Considerations

  1. Authentication Required - All actions require authentication
  2. Role-Based Access - Actions check user roles
  3. Input Validation - All inputs are validated with Zod
  4. SQL Injection Protection - Parameterized queries
  5. XSS Prevention - Automatic sanitization
  6. CSRF Protection - Built into Next.js

Performance

  • Server actions run on the edge when possible
  • Automatic caching and revalidation
  • Optimistic updates supported
  • Connection pooling for database

Support

For API support and questions:

Next Steps

  1. Review the Server Actions Reference
  2. Understand Authentication
  3. Explore Data Models
  4. Implement Error Handling