Skip to main content

Python-based solution for converting ECG data from XML format to the DICOM(Digital Imaging and Communications in Medicine) format

Project description

XML2DCM-ECG

Description

This repository contains a Python-based solution for converting ECG data from XML format to the DICOM (Digital Imaging and Communications in Medicine) format. The goal of this project is to facilitate the process of transforming clinical ECG data stored in XML files into a standardized, widely-used DICOM format, which is essential for healthcare systems, medical imaging devices, and Electronic Health Record (EHR) systems.

The solution handles the extraction and conversion of ECG information, including patient details, acquisition context, and waveform data, from XML files into the DICOM format. The project also integrates essential metadata such as the type of ECG lead (e.g., Lead I, Lead II), device information (e.g., acquisition device, software versions), and patient demographics.

Installation

You can install XML2DCM-ECG directly from PyPI:

pip install XML2DCM-ECG

Alternatively, you can use uv, a faster Python package manager with built-in script runner:

pip install uv

Usage

After installation, you can run the ECG XML-to-DICOM converter using either of the following methods.

1. Using standard CLI command

Run the following command:

   xml2dcm-ecg --debug True --debug_n 5 --project_root /path/to/project --data_root /path/to/data --ecg_xml_dir /path/to/xml_files --output_dir /path/to/save_dicom --filename_pattern "MUSE_(?P<examination_date>\d{8})_(?P<examination_time>\d{6})_(?P<seq>\d{5})" --out_filename_pattern "ECG_DICOM_{examination_date}_{seq}" 

2. Using uvx for fast execution

With uv installed, you can use uvx for faster execution:

   uvx xml2dcm-ecg --debug True --debug_n 5 --project_root /path/to/project --data_root /path/to/data --ecg_xml_dir /path/to/xml_files --output_dir /path/to/save_dicom --filename_pattern "MUSE_(?P<examination_date>\d{8})_(?P<examination_time>\d{6})_(?P<seq>\d{5})" --out_filename_pattern "ECG_DICOM_{examination_date}_{seq}"

CLI Options

Argument Type Required Default Description
--debug bool No False Enable debug mode to process a limited number of files
--debug_n int No 5 Number of files to process when debug is enabled
--project_root str Yes Root directory of the project
--data_root str Yes Root path for input data
--ecg_xml_dir str Yes Relative path to the directory containing ECG XML files
--output_dir str No ecg_dcm Directory (under project_root) where converted DICOM files will be saved
--filename_pattern str Yes Regex pattern to extract metadata from filenames
--out_filename_pattern str Yes Format for naming output DICOM files using named groups from the regex

Example

  • Input filename: MUSE_20250711_153012_00001.xml
  • Extracted:
    • examination_date = 20250711
    • seq = 00001
  • Output filename: ECG_DICOM_20250711_00001.dcm

Example results

The following are examples of the ECG data converted from XML to DICOM format: ecg_dicom.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xml2dcm_ecg-1.1.8.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xml2dcm_ecg-1.1.8-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file xml2dcm_ecg-1.1.8.tar.gz.

File metadata

  • Download URL: xml2dcm_ecg-1.1.8.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for xml2dcm_ecg-1.1.8.tar.gz
Algorithm Hash digest
SHA256 df940e692078b719a426d877dcbe0244c1afee0c8d24e17665c6c712bc953959
MD5 729e3f9ba611a22d826cc531f7a29076
BLAKE2b-256 24f77951a8e83e884b44256c5fb276d5ddcfbe3c221d4d9d4b33b8a35da65017

See more details on using hashes here.

File details

Details for the file xml2dcm_ecg-1.1.8-py3-none-any.whl.

File metadata

  • Download URL: xml2dcm_ecg-1.1.8-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for xml2dcm_ecg-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8a424ef9605866dd1898f41e107103b310727098c034872f8b0d53848c1f460c
MD5 99bfcacd02c1122ce3e3427f6b0897a2
BLAKE2b-256 51fb32ddb8bd88465ca9857b030eb0cf9a51bc9fafb8c2a01a0f92713f1912cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page