Seamless Integration of Cardiac Devices and EKGs using OpenEMR’s HL7 Interface
Electronic health records (EHRs) like OpenEMR aim to centralize patient data from various sources into one integrated system. This helps improve clinical workflow and decision-making with a more holistic view of the patient.
One important aspect of this integration is bringing in data from cardiac devices and electrocardiograms (EKGs).
OpenEMR provides built-in support for the Health Level 7 (HL7) messaging standard that facilitates this integration. HL7 defines a format for the exchange, integration, sharing, and retrieval of electronic health information between various systems.
By leveraging HL7, we can build interfaces that automatically ingest new cardiac device readings and EKG reports into the OpenEMR database.
Setting Up the HL7 Listener
We first need to activate and configure the HL7 listener in OpenEMR. This is done by enabling the hl7 option in the modules configuration file:
//hl7.inc.php $GLOBALS['hl7_enable'] = true;
Next, we specify the HL7 server settings like IP address, port, and handler path:
//hl7.inc.php $GLOBALS['hl7_server_addr'] = '127.0.0.1'; $GLOBALS['hl7_server_port'] = '5678'; $GLOBALS['hl7_server_path'] = 'sites/default/hl7handler.php';
This will spin up an HL7 listener daemon on port 5678 to receive ORU messages.
Configuring HL7 ORU Messages Our EKG and cardiac devices need to be configured to send HL7 v2.x ORU R01 messages to the OpenEMR server. This contains segments like:
MSH|^~\&|AcmeDevice|1|||201501071106||ORU^R01|599102|P|2.3|||ER| PID|||325469^^^MRN^MRN|325254^^^Facility^MPI||Burns^Jimmy^J||19870219|M|||123 Main St^^Ann Arbor^MI^99999^^H||^PRN^PH^^^734^5559874|||||||||2186-4^Caucasian^HL70005 OBR|1|3495^LA^Acme Device|15545^Heart Rate^LA| OBX|1|NM|15545^HeartRate^LA|78|bpm||||F
We specify the test code in OBR and actual results in OBX segments.
Processing HL7 Messages
The hl7handler.php script receives and parses the HL7 content using a processing library like php-hl7. Key steps include:
//hl7handler.php $msg = parse_hl7_message($data); //parse HL7 string $pid = get_hl7_segment($msg, 'PID'); //get PID segment $pid_fields = split_hl7_segment($pid); //split into fields $patient_id = $pid_fields[3]; //MRN number $first_name = $pid_fields[5]; $last_name = $pid_fields[6]; //Lookup or register patient in OpenEMR database $pData = getPatientData($first_name, $last_name, $patient_id); $obx = get_hl7_segment($msg, 'OBX'); //Get OBX $obx_fields = split_hl7_segment($obx); $test_result = $obx_fields[5]; $test_code = get_related_hl7_field($msg,'OBR','universal_service_identifier'); insertHl7Results($pData, $test_code, $test_result);
Now the observation is added for the patient in OpenEMR linked by MRN.
Displaying EKG Waveforms To embed and display EKG waveforms, the OBX segment contains XML data that we extract:
//hl7handler.php $ekg_data = false; foreach($msg['OBX'] as $obx){ if($obx['observation_identifier'] == 'Waveform Data'){ $ekg_data = $obx['observation_value']; //XML graph data break; } } if($ekg_data){ $ekg = decodeEKG($ekg_data); //Convert XML to image displayEKG($pData->patient_id, $ekg); //Save and display image in OpenEMR }
Leveraging HL7 standard interfaces unlocks powerful opportunities for bidirectional data exchange between EHR and diagnostic systems. Specifically for cardiac care and EKGs, HL7 provides a structured pipeline for pulling device readings into OpenEMR alongside the ability to embed and display waveform graphs.
Beyond improving clinical efficiency, this paves the way for automated analysis and enhanced clinical decision support.