@eka-care/patient-ts-sdk
Version:
TypeScript SDK for Trinity Patient Profile Management System
213 lines (212 loc) • 5.87 kB
TypeScript
/**
* Trinity Profiles SDK
*
* A TypeScript SDK for interacting with the Trinity Patient Profile Management System.
* This SDK provides a type-safe, easy-to-use interface for managing patient profiles
* through the Trinity API.
*
* @example
* ```typescript
* import { TrinityProfilesSDK } from './trinity-profiles-sdk';
*
* const sdk = new TrinityProfilesSDK({
* baseUrl: 'https://api.trinity.example.com',
* accessToken: 'your-access-token'
* });
*
* // Create a patient
* const patient = await sdk.patients.create({
* oid: 'unique-patient-id',
* gen: 'M',
* dob: '1990-01-01',
* fn: 'John',
* ln: 'Doe'
* });
* ```
*/
import { PatientMethods } from './methods/patients';
import { SearchMethods } from './methods/search';
import { UtilsMethods } from './methods/utils';
import { CreatePatientData, Patient, SdkConfig } from './types';
/**
* Main SDK class
*/
export declare class TrinityProfilesSDK {
private client;
private static instance;
/** Patient CRUD operations */
patients: PatientMethods;
/** Search and lookup operations */
search: SearchMethods;
/** Utility operations */
utils: UtilsMethods;
/**
* Initialize the Trinity Profiles SDK
*
* @param config SDK configuration
*
* @example
* ```typescript
* const sdk = new TrinityProfilesSDK({
* baseUrl: 'https://api.trinity.example.com',
* accessToken: 'your-jwt-token',
* workspaceId: 'your-workspace-id',
* enableLocalSearch: true, // optional, enables local search functionality
* timeout: 30000 // optional, defaults to 30s
* });
* ```
*/
constructor(config: SdkConfig);
/**
* Static method to get the singleton instance with optional initialization
*
* @param config Optional SDK configuration for initialization
* @returns Singleton instance of TrinityProfilesSDK
*
* @example
* ```typescript
* // Get instance without initialization
* const sdk = TrinityProfilesSDK.getInstance();
*
* // Get instance with initialization
* const sdk = TrinityProfilesSDK.getInstance({
* baseUrl: 'https://api.trinity.example.com',
* accessToken: 'your-jwt-token',
* workspaceId: 'your-workspace-id'
* });
* ```
*/
static getInstance(config?: SdkConfig): TrinityProfilesSDK;
/**
* Reset the singleton instance (useful for testing or re-initialization)
*
* @example
* ```typescript
* TrinityProfilesSDK.resetInstance();
* ```
*/
static resetInstance(): void;
/**
* Update the access token (for token refresh scenarios)
*
* @param newToken New access token
*
* @example
* ```typescript
* // After token refresh
* sdk.updateAccessToken(newAccessToken);
* ```
*/
updateAccessToken(newToken: string): void;
/**
* Test the SDK connection
*
* @returns Promise that resolves if connection is successful
*
* @example
* ```typescript
* try {
* await sdk.testConnection();
* console.log('SDK is connected successfully');
* } catch (error) {
* console.error('Connection failed:', error.message);
* }
* ```
*/
testConnection(): Promise<void>;
/**
* Initialize local search functionality
*
* @example
* ```typescript
* await sdk.initializeLocalSearch();
* ```
*/
initializeLocalSearch(): Promise<void>;
searchPatientByPrefix(prefix: string, limit?: number, select?: string): Promise<Patient[]>;
createPatient(patient: CreatePatientData): Promise<Patient | {
oid: string;
}>;
/**
* Start background data synchronization
*
* @param callbacks Optional callbacks for sync progress
*
* @example
* ```typescript
* await sdk.startLocalSync({
* onProgress: (progress) => console.log(`Synced ${progress.progress} records`),
* onComplete: () => console.log('Sync complete'),
* onError: (error) => console.error('Sync error:', error)
* });
* ```
*/
startLocalSync(callbacks?: {
onProgress?: (progress: {
progress: number;
total: number;
isComplete: boolean;
}) => void;
onComplete?: () => void;
onError?: (error: string) => void;
}): Promise<void>;
/**
* Check if local search data is available
*
* @returns Promise that resolves to true if local data exists
*
* @example
* ```typescript
* const hasData = await sdk.hasLocalSearchData();
* if (!hasData) {
* await sdk.startLocalSync();
* }
* ```
*/
hasLocalSearchData(): Promise<boolean>;
/**
* Check if sync is complete
*
* @returns True if sync is complete
*/
isSyncComplete(): boolean;
/**
* Clear all local search data
*
* @example
* ```typescript
* await sdk.clearLocalSearchData();
* ```
*/
clearLocalSearchData(): Promise<void>;
/**
* Cleanup all resources including local search
* Call this when done with the SDK to prevent memory leaks
*
* @example
* ```typescript
* sdk.destroy();
* ```
*/
destroy(): void;
/**
* Check if local search is enabled
*/
private isLocalSearchEnabled;
/**
* Check if we should use Web Worker
*/
private shouldUseWorker;
/**
* Start sync with Web Worker
*/
private startSyncWithWorker;
/**
* Start sync without Web Worker (direct)
*/
private startSyncWithoutWorker;
private syncWorker;
}
export * from './errors';
export * from './types';
export declare const getTrinitySDKInstance: (config: SdkConfig) => TrinityProfilesSDK;