/** * HL7 FHIR Integration Layer * * Connects to Electronic Health Record systems using the FHIR R4 standard. * Supports Epic, Cerner, AllScripts, and other FHIR-compliant EHR systems. * * IMPORTANT: This module requires proper HIPAA compliance setup before use. * All PHI access must be logged and patient consent must be verified. */ import { EventEmitter } from 'events'; export interface FHIRConfig { baseUrl: string; clientId: string; clientSecret?: string; scopes: string[]; authType: 'smart-on-fhir' | 'basic' | 'oauth2' | 'client-credentials'; ehrVendor: 'epic' | 'cerner' | 'allscripts' | 'meditech' | 'generic'; timeout?: number; retryAttempts?: number; } export interface FHIRPatient { resourceType: 'Patient'; id: string; identifier: FHIRIdentifier[]; name: FHIRHumanName[]; gender: 'male' | 'female' | 'other' | 'unknown'; birthDate: string; address?: FHIRAddress[]; telecom?: FHIRContactPoint[]; maritalStatus?: FHIRCodeableConcept; communication?: { language: FHIRCodeableConcept; preferred?: boolean; }[]; extension?: FHIRExtension[]; } export interface FHIRIdentifier { system: string; value: string; type?: FHIRCodeableConcept; use?: 'usual' | 'official' | 'temp' | 'secondary' | 'old'; } export interface FHIRHumanName { use?: 'usual' | 'official' | 'temp' | 'nickname' | 'anonymous' | 'old' | 'maiden'; family?: string; given?: string[]; prefix?: string[]; suffix?: string[]; } export interface FHIRAddress { use?: 'home' | 'work' | 'temp' | 'old' | 'billing'; type?: 'postal' | 'physical' | 'both'; line?: string[]; city?: string; state?: string; postalCode?: string; country?: string; } export interface FHIRContactPoint { system?: 'phone' | 'fax' | 'email' | 'pager' | 'url' | 'sms' | 'other'; value?: string; use?: 'home' | 'work' | 'temp' | 'old' | 'mobile'; } export interface FHIRCodeableConcept { coding?: FHIRCoding[]; text?: string; } export interface FHIRCoding { system?: string; version?: string; code?: string; display?: string; } export interface FHIRExtension { url: string; valueString?: string; valueCode?: string; valueDecimal?: number; valueBoolean?: boolean; valueCoding?: FHIRCoding; } export interface FHIRCondition { resourceType: 'Condition'; id: string; clinicalStatus: FHIRCodeableConcept; verificationStatus: FHIRCodeableConcept; category: FHIRCodeableConcept[]; severity?: FHIRCodeableConcept; code: FHIRCodeableConcept; bodySite?: FHIRCodeableConcept[]; subject: FHIRReference; onsetDateTime?: string; recordedDate?: string; stage?: { summary?: FHIRCodeableConcept; assessment?: FHIRReference[]; type?: FHIRCodeableConcept; }[]; evidence?: { code?: FHIRCodeableConcept[]; detail?: FHIRReference[]; }[]; } export interface FHIRObservation { resourceType: 'Observation'; id: string; status: 'registered' | 'preliminary' | 'final' | 'amended' | 'corrected' | 'cancelled' | 'entered-in-error' | 'unknown'; category?: FHIRCodeableConcept[]; code: FHIRCodeableConcept; subject: FHIRReference; effectiveDateTime?: string; valueQuantity?: FHIRQuantity; valueCodeableConcept?: FHIRCodeableConcept; valueString?: string; interpretation?: FHIRCodeableConcept[]; referenceRange?: { low?: FHIRQuantity; high?: FHIRQuantity; type?: FHIRCodeableConcept; text?: string; }[]; component?: { code: FHIRCodeableConcept; valueQuantity?: FHIRQuantity; valueCodeableConcept?: FHIRCodeableConcept; valueString?: string; }[]; } export interface FHIRQuantity { value?: number; comparator?: '<' | '<=' | '>=' | '>'; unit?: string; system?: string; code?: string; } export interface FHIRReference { reference?: string; type?: string; identifier?: FHIRIdentifier; display?: string; } export interface FHIRMedicationRequest { resourceType: 'MedicationRequest'; id: string; status: 'active' | 'on-hold' | 'cancelled' | 'completed' | 'entered-in-error' | 'stopped' | 'draft' | 'unknown'; intent: 'proposal' | 'plan' | 'order' | 'original-order' | 'reflex-order' | 'filler-order' | 'instance-order' | 'option'; medicationCodeableConcept?: FHIRCodeableConcept; medicationReference?: FHIRReference; subject: FHIRReference; authoredOn?: string; requester?: FHIRReference; dosageInstruction?: FHIRDosage[]; } export interface FHIRDosage { sequence?: number; text?: string; timing?: { repeat?: { frequency?: number; period?: number; periodUnit?: 's' | 'min' | 'h' | 'd' | 'wk' | 'mo' | 'a'; }; }; route?: FHIRCodeableConcept; doseAndRate?: { doseQuantity?: FHIRQuantity; rateQuantity?: FHIRQuantity; }[]; } export interface FHIRDiagnosticReport { resourceType: 'DiagnosticReport'; id: string; status: 'registered' | 'partial' | 'preliminary' | 'final' | 'amended' | 'corrected' | 'appended' | 'cancelled' | 'entered-in-error' | 'unknown'; category?: FHIRCodeableConcept[]; code: FHIRCodeableConcept; subject: FHIRReference; effectiveDateTime?: string; issued?: string; performer?: FHIRReference[]; result?: FHIRReference[]; conclusion?: string; conclusionCode?: FHIRCodeableConcept[]; presentedForm?: { contentType?: string; data?: string; url?: string; title?: string; }[]; } export interface FHIRProcedure { resourceType: 'Procedure'; id: string; status: 'preparation' | 'in-progress' | 'not-done' | 'on-hold' | 'stopped' | 'completed' | 'entered-in-error' | 'unknown'; code: FHIRCodeableConcept; subject: FHIRReference; performedDateTime?: string; performedPeriod?: { start?: string; end?: string; }; performer?: { actor: FHIRReference; function?: FHIRCodeableConcept; }[]; bodySite?: FHIRCodeableConcept[]; outcome?: FHIRCodeableConcept; report?: FHIRReference[]; } export interface FHIRBundle { resourceType: 'Bundle'; id?: string; type: 'document' | 'message' | 'transaction' | 'transaction-response' | 'batch' | 'batch-response' | 'history' | 'searchset' | 'collection'; total?: number; link?: { relation: string; url: string; }[]; entry?: { fullUrl?: string; resource?: FHIRResource; search?: { mode?: 'match' | 'include' | 'outcome'; score?: number; }; }[]; } export type FHIRResource = FHIRPatient | FHIRCondition | FHIRObservation | FHIRMedicationRequest | FHIRDiagnosticReport | FHIRProcedure | FHIRBundle; export interface CancerDiagnosis { patientId: string; conditionId: string; cancerType: string; icdCode: string; snomedCode?: string; histology?: string; primarySite?: string; laterality?: 'left' | 'right' | 'bilateral' | 'not-applicable'; stage?: { system: 'ajcc' | 'figo' | 'rai' | 'binet' | 'iss' | 'other'; stage: string; tnm?: { t?: string; n?: string; m?: string; }; grade?: string; }; diagnosisDate: Date; verificationStatus: 'confirmed' | 'provisional' | 'differential' | 'refuted'; } export interface CancerBiomarkers { patientId: string; collectionDate: Date; biomarkers: { name: string; value: string | number; unit?: string; status: 'positive' | 'negative' | 'equivocal' | 'not-tested'; method?: string; loincCode?: string; }[]; genomicAlterations?: { gene: string; alteration: string; type: 'mutation' | 'amplification' | 'deletion' | 'fusion' | 'rearrangement'; variantAlleleFrequency?: number; pathogenicity?: 'pathogenic' | 'likely-pathogenic' | 'vus' | 'likely-benign' | 'benign'; }[]; tumorMutationalBurden?: { value: number; unit: 'mutations/Mb'; status: 'high' | 'intermediate' | 'low'; threshold?: number; }; microsatelliteInstability?: { status: 'MSI-H' | 'MSI-L' | 'MSS'; method: 'PCR' | 'NGS' | 'IHC'; }; pdl1Expression?: { score: number; scoreType: 'TPS' | 'CPS' | 'IC'; antibody?: string; }; hrdStatus?: { status: 'positive' | 'negative'; score?: number; components?: { loh?: number; tai?: number; lst?: number; }; }; } export interface TreatmentHistory { patientId: string; treatments: { id: string; type: 'chemotherapy' | 'immunotherapy' | 'targeted-therapy' | 'radiation' | 'surgery' | 'hormone-therapy' | 'car-t' | 'other'; regimen?: string; drugs?: { name: string; dose?: string; route?: string; rxNormCode?: string; }[]; startDate: Date; endDate?: Date; status: 'planned' | 'active' | 'completed' | 'stopped' | 'on-hold'; cycles?: number; response?: 'CR' | 'PR' | 'SD' | 'PD' | 'NE'; responseDate?: Date; reasonStopped?: string; adverseEvents?: { name: string; grade: number; ctcaeCode?: string; }[]; }[]; } export declare class FHIRClient extends EventEmitter { private config; private accessToken?; private tokenExpiry?; private auditLogger?; constructor(config: FHIRConfig); /** * Set audit logger for HIPAA compliance */ setAuditLogger(logger: (event: AuditEvent) => Promise): void; /** * Authenticate with the FHIR server */ authenticate(): Promise; private smartOnFhirAuth; private clientCredentialsAuth; private oauth2Auth; private discoverTokenEndpoint; /** * Get a patient by ID */ getPatient(patientId: string): Promise; /** * Search for patients */ searchPatients(params: Record): Promise; /** * Get cancer diagnosis for a patient */ getCancerDiagnosis(patientId: string): Promise; /** * Get biomarkers and genomic data for a patient */ getBiomarkers(patientId: string): Promise; /** * Get treatment history for a patient */ getTreatmentHistory(patientId: string): Promise; /** * Get all observations for a patient */ getObservations(patientId: string, category?: string): Promise; /** * Get all medications for a patient */ getMedications(patientId: string): Promise; /** * Get diagnostic reports for a patient */ getDiagnosticReports(patientId: string): Promise; /** * Create a comprehensive cancer patient summary */ getComprehensiveCancerSummary(patientId: string): Promise<{ patient: FHIRPatient; diagnoses: CancerDiagnosis[]; biomarkers: CancerBiomarkers | null; treatmentHistory: TreatmentHistory; recentLabs: FHIRObservation[]; performanceStatus?: { score: number; scale: 'ECOG' | 'KPS'; date: Date; }; }>; /** * Read a resource by ID */ read(resourceType: string, id: string): Promise; /** * Search for resources */ search(resourceType: string, params: Record): Promise; /** * Create a resource */ create(resource: T): Promise; /** * Update a resource */ update(resource: T & { id: string; }): Promise; private getAuthHeaders; private httpRequest; private mapConditionToCancerDiagnosis; private determineStageSystem; private mapVerificationStatus; private aggregateBiomarkerData; private mapObservationToBiomarker; private mapObservationToGenomicAlteration; private determineAlterationType; private interpretBiomarkerStatus; private findBiomarker; private categorizeTMB; private categorizeMSI; private aggregateTreatmentHistory; private categorizeTreatment; private mapMedicationStatus; private mapProcedureStatus; private isSurgicalProcedure; private isRadiationProcedure; private logAudit; } export interface AuditEvent { timestamp: Date; userId: string; ipAddress: string; action: string; resourceType: string; resourceId?: string; outcome: 'success' | 'failure' | 'unknown'; duration?: number; errorMessage?: string; details?: Record; } export declare class EpicFHIRClient extends FHIRClient { constructor(config: Omit); /** * Epic-specific: Get MyChart patient context */ getMyChartContext(launchToken: string): Promise<{ patient: string; encounter?: string; practitioner?: string; }>; } export declare class CernerFHIRClient extends FHIRClient { constructor(config: Omit); /** * Cerner-specific: Handle Millennium-specific extensions */ parseMillenniumExtensions(resource: FHIRResource): Record; } export declare function createFHIRClient(config: FHIRConfig): FHIRClient; export default FHIRClient; //# sourceMappingURL=fhir.d.ts.map