Files
triqura-ecd/lib/types/client.ts
colinislit 982b23c4dc fix: consolidate database types to single source of truth
BREAKING: Removed duplicate lib/database.types.ts in favor of
lib/supabase/database.types.ts

Problem:
- Database types existed in two locations causing sync issues
- Old lib/database.types.ts was empty (0 bytes)
- Import paths were inconsistent across codebase
- Build failed due to missing type definitions

Solution:
- Generated fresh types from remote Supabase database
- Updated all imports from @/lib/database.types to @/lib/supabase/database.types
- Removed duplicate lib/database.types.ts file

Affected modules:
- lib/auth/server.ts - Auth server utilities
- lib/auth/client.ts - Auth client utilities
- lib/types/client.ts - Client type definitions
- lib/fhir/transforms/patient.ts - FHIR patient transforms
- lib/fhir/transforms/practitioner.ts - FHIR practitioner transforms

Impact: All database queries now use up-to-date type definitions
including new tables (intakes, risk_assessments, encounters, etc.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 12:19:47 +01:00

60 lines
1.5 KiB
TypeScript

/**
* Client Types
*
* Type definitions for client-related data structures
*/
import { Database } from '@/lib/supabase/database.types';
// Base client type from database
export type Client = Database['public']['Tables']['clients']['Row'];
export type ClientInsert = Database['public']['Tables']['clients']['Insert'];
export type ClientUpdate = Database['public']['Tables']['clients']['Update'];
// Extended client type with computed fields
export interface ClientWithAge extends Client {
age: number;
full_name: string;
}
// Client form data (for create/edit forms)
export interface ClientFormData {
first_name: string;
last_name: string;
birth_date: string; // ISO date string (YYYY-MM-DD)
}
// Client list filters
export interface ClientFilters {
search?: string;
sortBy?: 'name' | 'age' | 'created_at';
sortOrder?: 'asc' | 'desc';
}
/**
* Calculate age from birth date
*/
export function calculateAge(birthDate: string | Date): number {
const birth = typeof birthDate === 'string' ? new Date(birthDate) : birthDate;
const today = new Date();
let age = today.getFullYear() - birth.getFullYear();
const monthDiff = today.getMonth() - birth.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
age--;
}
return age;
}
/**
* Transform client to extended client with computed fields
*/
export function transformClient(client: Client): ClientWithAge {
return {
...client,
age: calculateAge(client.birth_date),
full_name: `${client.first_name} ${client.last_name}`,
};
}