UNPKG

emr-types

Version:

Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation

372 lines 10.3 kB
/** * External Service Integration Types * * Types for integrating with external services and APIs */ import { Id } from '../../domains/shared/value-objects/Id'; import { Timestamp } from '../../domains/shared/value-objects/Timestamp'; import { Money } from '../../domains/shared/value-objects/Money'; import { Email } from '../../domains/shared/value-objects/Email'; import { PhoneNumber } from '../../domains/shared/value-objects/PhoneNumber'; /** * External Service Configuration */ export interface ExternalServiceConfig { /** Service name/identifier */ name: string; /** Service base URL */ baseUrl: string; /** API key or authentication token */ apiKey?: string; /** Request timeout in milliseconds */ timeout?: number; /** Retry configuration */ retry?: { maxAttempts: number; delayMs: number; backoffMultiplier: number; }; /** Rate limiting configuration */ rateLimit?: { requestsPerMinute: number; burstLimit: number; }; } /** * External Service Response */ export interface ExternalServiceResponse<T = any> { /** Response success status */ success: boolean; /** Response data */ data?: T; /** Error message if failed */ error?: string; /** HTTP status code */ statusCode: number; /** Response headers */ headers: Record<string, string>; /** Response timestamp */ timestamp: Timestamp; /** Request correlation ID */ correlationId: string; } /** * External Service Request */ export interface ExternalServiceRequest<T = any> { /** Request method */ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; /** Request endpoint */ endpoint: string; /** Request headers */ headers?: Record<string, string>; /** Request body */ body?: T; /** Request parameters */ params?: Record<string, string>; /** Request timeout */ timeout?: number; /** Request correlation ID */ correlationId?: string; } /** * External Service Adapter Interface */ export interface ExternalServiceAdapter<TRequest = any, TResponse = any> { /** Service configuration */ config: ExternalServiceConfig; /** Send request to external service */ request(request: ExternalServiceRequest<TRequest>): Promise<ExternalServiceResponse<TResponse>>; /** Validate response from external service */ validateResponse(response: ExternalServiceResponse<TResponse>): boolean; /** Transform external service response to domain model */ transformResponse(response: TResponse): any; /** Transform domain model to external service request */ transformRequest(data: any): TRequest; } /** * Authentication Service Integration */ export declare namespace AuthService { interface LoginRequest { email: Email; password: string; tenantId?: Id; } interface LoginResponse { accessToken: string; refreshToken: string; expiresIn: number; user: { id: string; email: string; roles: string[]; tenantId?: string; }; } interface RefreshTokenRequest { refreshToken: string; } interface RefreshTokenResponse { accessToken: string; expiresIn: number; } interface ValidateTokenRequest { token: string; } interface ValidateTokenResponse { isValid: boolean; user?: { id: string; email: string; roles: string[]; tenantId?: string; }; } } /** * Payment Service Integration */ export declare namespace PaymentService { interface CreatePaymentRequest { amount: Money; currency: string; description: string; customerId: string; paymentMethod: 'card' | 'bank_transfer' | 'cash'; metadata?: Record<string, any>; } interface CreatePaymentResponse { paymentId: string; status: 'pending' | 'completed' | 'failed' | 'cancelled'; amount: Money; currency: string; paymentUrl?: string; transactionId?: string; } interface PaymentStatusRequest { paymentId: string; } interface PaymentStatusResponse { paymentId: string; status: 'pending' | 'completed' | 'failed' | 'cancelled'; amount: Money; currency: string; transactionId?: string; failureReason?: string; } } /** * Notification Service Integration */ export declare namespace NotificationService { interface SendEmailRequest { to: Email[]; cc?: Email[]; bcc?: Email[]; subject: string; body: string; templateId?: string; templateData?: Record<string, any>; } interface SendEmailResponse { messageId: string; status: 'sent' | 'delivered' | 'failed'; errorMessage?: string; } interface SendSMSRequest { to: PhoneNumber[]; message: string; templateId?: string; templateData?: Record<string, any>; } interface SendSMSResponse { messageId: string; status: 'sent' | 'delivered' | 'failed'; errorMessage?: string; } interface SendPushNotificationRequest { userIds: Id[]; title: string; body: string; data?: Record<string, any>; badge?: number; } interface SendPushNotificationResponse { messageId: string; status: 'sent' | 'delivered' | 'failed'; errorMessage?: string; } } /** * File Storage Service Integration */ export declare namespace FileStorageService { interface UploadFileRequest { file: Buffer; fileName: string; contentType: string; folder?: string; metadata?: Record<string, any>; } interface UploadFileResponse { fileId: string; fileName: string; fileUrl: string; fileSize: number; contentType: string; uploadedAt: Timestamp; } interface DownloadFileRequest { fileId: string; } interface DownloadFileResponse { file: Buffer; fileName: string; contentType: string; fileSize: number; } interface DeleteFileRequest { fileId: string; } interface DeleteFileResponse { success: boolean; errorMessage?: string; } } /** * Medical Data Service Integration */ export declare namespace MedicalDataService { interface ValidateDiagnosisRequest { diagnosisCode: string; symptoms: string[]; patientAge: number; patientGender: 'male' | 'female' | 'other'; } interface ValidateDiagnosisResponse { isValid: boolean; confidence: number; suggestions: string[]; warnings: string[]; } interface DrugInteractionRequest { medications: string[]; patientAge: number; patientGender: 'male' | 'female' | 'other'; existingConditions: string[]; } interface DrugInteractionResponse { interactions: Array<{ severity: 'low' | 'moderate' | 'high' | 'severe'; description: string; medications: string[]; recommendation: string; }>; } interface LabResultValidationRequest { testType: string; result: number; unit: string; referenceRange: { min: number; max: number; }; patientAge: number; patientGender: 'male' | 'female' | 'other'; } interface LabResultValidationResponse { isNormal: boolean; interpretation: string; severity: 'normal' | 'mild' | 'moderate' | 'severe'; recommendations: string[]; } } /** * External Service Error Types */ export declare namespace ExternalServiceErrors { interface ServiceError { code: string; message: string; details?: Record<string, any>; retryable: boolean; } interface NetworkError extends ServiceError { code: 'NETWORK_ERROR'; retryable: true; } interface TimeoutError extends ServiceError { code: 'TIMEOUT_ERROR'; retryable: true; } interface AuthenticationError extends ServiceError { code: 'AUTHENTICATION_ERROR'; retryable: false; } interface RateLimitError extends ServiceError { code: 'RATE_LIMIT_ERROR'; retryable: true; retryAfter?: number; } interface ValidationError extends ServiceError { code: 'VALIDATION_ERROR'; retryable: false; field: string; } interface ServiceUnavailableError extends ServiceError { code: 'SERVICE_UNAVAILABLE'; retryable: true; } } /** * External Service Monitoring */ export declare namespace ExternalServiceMonitoring { interface ServiceMetrics { /** Service name */ serviceName: string; /** Total requests */ totalRequests: number; /** Successful requests */ successfulRequests: number; /** Failed requests */ failedRequests: number; /** Average response time in milliseconds */ averageResponseTime: number; /** Error rate percentage */ errorRate: number; /** Last request timestamp */ lastRequestAt: Timestamp; } interface ServiceHealth { /** Service name */ serviceName: string; /** Service status */ status: 'healthy' | 'degraded' | 'unhealthy'; /** Response time in milliseconds */ responseTime: number; /** Error count */ errorCount: number; /** Last check timestamp */ lastCheckAt: Timestamp; } interface ServiceAlert { /** Alert ID */ id: string; /** Service name */ serviceName: string; /** Alert type */ type: 'error_rate_high' | 'response_time_slow' | 'service_down'; /** Alert severity */ severity: 'low' | 'medium' | 'high' | 'critical'; /** Alert message */ message: string; /** Alert timestamp */ timestamp: Timestamp; /** Alert resolved */ resolved: boolean; } } //# sourceMappingURL=index.d.ts.map