No project description provided
Project description
py_xml_ccda
GitHub Repository: https://github.com/omkarmore2008/py_xml_ccda
A Python package for parsing XML CCDA (Continuity of Care Document Architecture) files and extracting structured patient data. This package converts complex medical XML documents into easy-to-use JSON format, making healthcare data more accessible for analysis and integration.
Features
- Comprehensive Data Extraction: Extracts multiple types of patient data from CCDA XML files
- Structured Output: Returns well-organized JSON data with consistent formatting
- Date Normalization: Automatically formats dates to ISO standard (YYYY-MM-DD)
- Base64 Support: Handles base64-encoded XML input
- Error Handling: Robust error handling with graceful fallbacks
Supported Data Types
The package extracts the following patient information from CCDA XML files:
🏥 Medications
- Medication name
- Route of administration
- Clinical notes
- Start and end dates
- Status
🩺 Medical Encounters
- Encounter type
- Location
- Encounter date
- Healthcare provider
- Diagnosis codes
⚠️ Allergies
- Allergy/allergen name
- Drug/non-drug classification
- Reaction details
- Allergy type
- Onset date
- Status
🔄 Referrals
- Referral reason
- Diagnosis information
- Referral organization
- Referring provider details
- Referred provider information
- Referral priority
🏷️ Problems/Conditions
- Problem type
- SNOMED codes
- ICD codes
- Onset date
- Problem status
- Work-up status
- Risk level
- Clinical notes
📋 Care Plans
- Test names
- Order dates
- Treatment plans
Installation
Install the package using pip:
pip install py_xml_ccda
Usage
Basic Usage
from py_xml_ccda import convert_ccda_to_json
import base64
# If you have a base64-encoded XML string
base64_xml = "your_base64_encoded_ccda_xml_here"
patient_data = convert_ccda_to_json(base64_xml)
# Access different data sections
medications = patient_data['medication_summary']
encounters = patient_data['encounter_summary']
allergies = patient_data['allergies_summary']
referrals = patient_data['referral_summary']
problems = patient_data['problems_summary']
care_plans = patient_data['care_plan_summary']
Working with XML Files
from py_xml_ccda.utils import get_clinical_summary
import base64
# Read XML file and convert to base64
with open('patient_ccda.xml', 'r', encoding='utf-8') as file:
xml_content = file.read()
# Convert to base64
base64_xml = base64.b64encode(xml_content.encode('utf-8')).decode('utf-8')
# Extract patient data
patient_data = convert_ccda_to_json(base64_xml)
# Or work directly with XML string
patient_data = get_clinical_summary(xml_content)
Example Output
{
"medication_summary": [
{
"medication_name": "Lisinopril 10mg",
"route": "Oral",
"notes": "Take once daily",
"start_date": "2023-01-15",
"end_date": "",
"status": "Active"
}
],
"encounter_summary": [
{
"encounter": "Office Visit",
"location": "Primary Care Clinic",
"encounter_date": "2023-06-15",
"provider": "Dr. Smith",
"diagnosis_codes": ["Z00.00", "I10"]
}
],
"allergies_summary": [
{
"allergy": "Penicillin",
"drug_non_drug": "Drug",
"reaction": "Rash",
"allergy_type": "Drug Allergy",
"onset_date": "2020-03-10",
"status": "Active"
}
],
"referral_summary": [...],
"problems_summary": [...],
"care_plan_summary": [...]
}
Command Line Usage
The package also provides a command-line interface:
py_xml_ccda
Requirements
- Python 3.6+
- No external dependencies (uses only Python standard library)
Error Handling
The package includes comprehensive error handling:
- Invalid XML files return empty data structures instead of crashing
- Missing sections are handled gracefully
- Date parsing errors result in empty date fields
- All functions include try-catch blocks with appropriate fallbacks
Data Format Standards
- Dates: All dates are normalized to ISO format (YYYY-MM-DD)
- Diagnosis Codes: Multiple codes are split and cleaned automatically
- Text Fields: All text is stripped of whitespace and normalized
- Missing Data: Empty or missing fields return empty strings instead of None
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Support
For issues, questions, or contributions, please visit the project repository or contact the maintainers.
Changelog
Version 0.1
- Initial release
- Support for medications, encounters, allergies, referrals, problems, and care plans
- Base64 XML input support
- Command-line interface
- Comprehensive error handling
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_xml_ccda-1.0.0.tar.gz.
File metadata
- Download URL: py_xml_ccda-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fb7fa09370970c92415312afda181c9f64c00a7d417bda2885fe8a953abcd2f
|
|
| MD5 |
8674b17b20e22be59965849360000679
|
|
| BLAKE2b-256 |
80c50dc2d26bfb70cc6e24ee7c04ae7d2d21c42d1692218c48e809d1a98f1fb1
|
File details
Details for the file py_xml_ccda-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_xml_ccda-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dc5795b3c19245e2304f5063426fe5990b6d7888653754349927f7fb3fc0445
|
|
| MD5 |
219bee2abeb264fcfe9aedcaadb5c2da
|
|
| BLAKE2b-256 |
f479427910b7934ae94179ba09a79a7498ae133dc5484a9fcd7fc577098fda83
|