Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
- Implemented ExportWindow class for exporting data and graphs in various formats (JSON, XML, PDF). - Integrated ExportManager to handle export logic. - Added export option in the main application menu. - Enhanced user interface with data summary and export options. - Included error handling and success messages for export operations. - Updated dependencies in the lock file to include reportlab and lxml for PDF generation.
6.4 KiB
6.4 KiB
TheChart Export System Documentation
Overview
The TheChart application now includes a comprehensive data export system that allows users to export their medication tracking data and visualizations to multiple formats:
- JSON - Structured data format with metadata
- XML - Hierarchical data format
- PDF - Formatted report with optional graph visualization
Features
Export Formats
JSON Export
- Exports all CSV data to structured JSON format
- Includes metadata about the export (date, total entries, date range)
- Lists all pathologies and medicines being tracked
- Data is exported as an array of entry objects
XML Export
- Exports data to hierarchical XML format
- Includes comprehensive metadata section
- All entries are properly structured with XML tags
- Column names are sanitized for valid XML element names
PDF Export
- Creates a formatted report document
- Includes export metadata and summary information
- Optional graph visualization inclusion
- Data table with all entries
- Proper pagination and styling
- Notes are truncated for better table formatting
User Interface
The export functionality is accessible through:
- File Menu - "Export Data..." option in the main menu bar
- Export Window - Modal dialog with export options
- Format Selection - Radio buttons for JSON, XML, or PDF
- Graph Option - Checkbox to include graph in PDF exports
- File Dialog - Standard save dialog for choosing export location
Export Manager Architecture
The export system consists of three main components:
ExportManager Class (src/export_manager.py)
- Core export functionality
- Handles data transformation and file generation
- Integrates with existing data and graph managers
- Supports all three export formats
ExportWindow Class (src/export_window.py)
- GUI interface for export operations
- Modal dialog with export options
- File save dialog integration
- Progress feedback and error handling
Integration in MedTrackerApp (src/main.py)
- Export manager initialization
- Menu integration
- Seamless integration with existing managers
Technical Implementation
Dependencies Added
reportlab- PDF generation librarylxml- XML processing (added for future enhancements)charset-normalizer- Character encoding support
Data Flow
- User selects export format and options
- ExportManager loads data from DataManager
- Data is transformed according to selected format
- Graph image is optionally generated for PDF
- Output file is created and saved
- User receives success/failure feedback
Error Handling
- Graceful handling of missing data
- File system error management
- User-friendly error messages
- Logging of export operations
Usage Examples
Basic Export Process
- Open TheChart application
- Go to File → Export Data...
- Select desired format (JSON/XML/PDF)
- For PDF: choose whether to include graph
- Click "Export..." button
- Choose save location and filename
- Confirm successful export
Export File Examples
JSON Structure
{
"metadata": {
"export_date": "2025-08-02T09:03:22.580489",
"total_entries": 32,
"date_range": {
"start": "07/02/2025",
"end": "08/02/2025"
},
"pathologies": ["depression", "anxiety", "sleep", "appetite"],
"medicines": ["bupropion", "hydroxyzine", "gabapentin", "propranolol", "quetiapine"]
},
"entries": [
{
"date": "07/02/2025",
"depression": 8,
"anxiety": 5,
"sleep": 3,
"appetite": 1,
"bupropion": 0,
"bupropion_doses": "",
"note": "Starting medication tracking"
}
]
}
XML Structure
<?xml version="1.0" encoding="UTF-8"?>
<thechart_data>
<metadata>
<export_date>2025-08-02T09:03:22.613013</export_date>
<total_entries>32</total_entries>
<date_range>
<start>07/02/2025</start>
<end>08/02/2025</end>
</date_range>
</metadata>
<entries>
<entry>
<date>07/02/2025</date>
<depression>8</depression>
<anxiety>5</anxiety>
<note>Starting medication tracking</note>
</entry>
</entries>
</thechart_data>
Testing
Automated Tests
- Export functionality is tested through
simple_export_test.py - Creates sample exports in all three formats
- Validates file creation and basic content structure
Manual Testing
- GUI testing available through
test_export_gui.py - Opens export window for interactive testing
- Allows testing of all user interface components
Test Files Location
Exported test files are created in the test_exports/ directory:
export.json- JSON format exportexport.xml- XML format exportexport.csv- CSV format copytest_export.pdf- PDF format with graph
File Locations
Source Files
src/export_manager.py- Core export functionalitysrc/export_window.py- GUI export interface
Test Files
simple_export_test.py- Basic export functionality testtest_export_gui.py- GUI testing interfacescripts/test_export_functionality.py- Comprehensive export tests
Dependencies
- Added to
requirements.txtand managed byuv - PDF generation requires
reportlab - XML processing enhanced with
lxml
Future Enhancements
Potential improvements for the export system:
- Additional Formats - Excel, CSV with formatting
- Export Filtering - Date range selection, specific pathologies/medicines
- Batch Exports - Multiple formats at once
- Email Integration - Direct email export
- Cloud Storage - Export to cloud services
- Export Scheduling - Automated periodic exports
- Advanced PDF Styling - Charts, graphs, custom layouts
Troubleshooting
Common Issues
- No Data to Export - Ensure CSV file has entries before exporting
- PDF Generation Fails - Check ReportLab installation and permissions
- File Save Errors - Verify write permissions to selected directory
- Large File Exports - PDF exports may take longer for large datasets
Debugging
- Check application logs for detailed error messages
- Export operations are logged with DEBUG level information
- File system errors are captured and reported to user
Integration Notes
The export system integrates seamlessly with existing TheChart functionality:
- Uses same data validation and loading mechanisms
- Respects existing pathology and medicine configurations
- Maintains data integrity and formatting consistency
- Follows existing logging and error handling patterns