TRICC (Transformable Rule-based Interactive Clinical Calculator) is a Python library that converts Clinical Decision Support System (CDSS) Level 2 specifications into Level 3 implementations. It processes visual flowcharts created in draw.io and converts them into various output formats like XLSForm, CHT, OpenMRS, FHIR, and HTML.
- Language: Python 3.8+
- Core Dependencies: lxml, pydantic, pandas, xlsxwriter, antlr4
- Code Style: PEP 8, max line length 120 (see .flake8)
- Architecture: Strategy pattern for input/output processing
- Models: Pydantic-based data models with custom types
tricc_oo/
├── converters/ # Format conversion logic (drawio→tricc, tricc→outputs)
Γö£ΓöÇΓöÇ models/ # Pydantic data models (nodes, edges, operations)
Γö£ΓöÇΓöÇ parsers/ # XML parsing for draw.io files
Γö£ΓöÇΓöÇ serializers/ # Output format serialization
Γö£ΓöÇΓöÇ strategies/ # Input/output strategy implementations
Γö£ΓöÇΓöÇ tools/ # Draw.io templates and utilities
ΓööΓöÇΓöÇ visitors/ # Graph traversal and processing
tests/ # Test suite and build scripts
docs/ # MkDocs documentation
- Follow PEP 8 style guide
- Maximum line length: 120 characters
- Use type hints with Pydantic models
- Write docstrings for public functions and classes
- Prefer composition over inheritance where appropriate
- Use logging instead of print statements
- Use
snake_casefor variables and functions - Use
PascalCasefor class names - Use
UPPER_CASEfor constants - Private methods/attributes prefixed with underscore
- Module-level docstrings for packages
- Use specific exception types
- Log errors with appropriate levels (debug, info, warning, error, critical)
- Fail early with clear error messages
- Validate inputs at boundaries
- Write unit tests for new functionality
- Use existing test patterns in
tests/directory - Test both happy paths and edge cases
- Maintain test coverage for critical paths
The system uses various node types defined in TriccNodeType enum:
- Flow anchors:
start,activity_start,activity_end,end - Questions:
select_one,select_multiple,select_yesno,note - Inputs:
integer,decimal,text,date - Logic:
calculate,rhombus,wait,add,count - Navigation:
goto,link_in,link_out,bridge - Diagnosis:
diagnosis,proposed_diagnosis
- Expressions are built using
TriccOperationwithTriccOperatorenum - Operators include boolean logic, arithmetic, comparisons, and domain-specific functions
- Use
TriccReferencefor variable references - Expressions are evaluated lazily during graph processing
- Input strategies:
DrawioStrategy(default) - Output strategies:
XLSFormStrategy,XLSFormCHTStrategy,XLSFormCHTHFStrategy, etc. - Each strategy handles specific conversion requirements
- Nodes are connected via edges with optional labels
- Processing follows topological order when possible
- Support for multiple activity instances and cross-page linking
- Experimental pages have limited processing
- Update relevant documentation in
docs/directory - Add inline code comments for complex logic
- Update README if user-facing changes
- Add type hints to all function signatures
- Include docstrings with Args, Returns, Raises sections
docs/getting-started.md- Installation and basic usagedocs/cli-and-inputs.md- Command-line interface documentationdocs/tricc-elements.md- Element reference and semanticsdocs/pipeline.md- Processing pipeline explanationdocs/visual-authoring-concepts.md- Visual design patternsdocs/troubleshooting.md- Common issues and solutions
- Create class inheriting from
BaseOutputStrategy - Implement required methods:
convert(),validate() - Register strategy in strategy factory
- Add tests for conversion logic
- Document strategy capabilities and limitations
- Add to
TriccNodeTypeenum inmodels/base.py - Define Pydantic model inheriting from
TriccNodeBaseModel - Update
drawio_type_map.pyfor XML mapping - Implement conversion logic in appropriate converter
- Add to documentation in
docs/tricc-elements.md
- Update
TriccOperatorenum if new operators needed - Modify expression building in
converters/directory - Update operator mappings and evaluation logic
- Add comprehensive tests for expression evaluation
- Document operator behavior and return types
Before committing code changes:
- Code follows PEP 8 and project style (120 char lines)
- All public functions have type hints
- Docstrings added for public APIs
- No print statements (use logging)
- Error handling is appropriate
- Tests pass (
python -m pytest tests/) - Documentation updated if needed
- No breaking changes to existing APIs
- Import statements are clean and organized
- No hardcoded values (use constants/config)
- Security considerations addressed (file paths, injections)
# Run all tests
python -m pytest tests/
# Run specific test file
python tests/test_cql.py
# Build and test conversion
python tests/build.py -i tests/data/demo.drawio -o tests/output/- Use files in
tests/data/directory - Draw.io files:
demo.drawio,combacal.drawio,etat.drawio - JSON files for specific formats:
medlacreator.json
- Check
tests/output/directory for generated files - Compare against expected outputs
- Validate XLSForm, CHT, or other format-specific outputs
- XML Parse Errors: Check draw.io file format (must be valid XML)
- Expression Errors: Verify operator syntax and reference validity
- Graph Errors: Check for cycles or disconnected nodes
- Strategy Errors: Ensure correct strategy for output format
- Use
logger.debug()for detailed processing info - Use
logger.warning()for recoverable issues - Use
logger.error()for failures - Check
log.txtfor execution logs
- Use
tricc_typeto identify node types - Check
instancenumbers for multi-instance activities - Verify edge connections and labels
- Validate expression references exist in graph
- Process large diagrams incrementally when possible
- Cache computed expressions to avoid recalculation
- Use efficient data structures (OrderedSet for ordered collections)
- Profile before optimizing critical paths
- Consider memory usage for large graphs
- Validate file paths to prevent directory traversal
- Sanitize user inputs in expressions
- Be cautious with XML parsing (XXE prevention)
- Validate external URLs before downloading
- Use appropriate file permissions for outputs
- Main Repository: https://github.com/SwissTPH/tricc
- Documentation: https://swisstph.github.io/tricc/
- Issue Tracker: https://github.com/SwissTPH/tricc/issues
- PyPI Package: tricc-oo
tricc_oo/models/base.py- Core data modelstricc_oo/converters/xml_to_tricc.py- Draw.io to TRICC conversiontricc_oo/strategies/- Input/output strategy implementationstests/build.py- Main entry point for conversionspyproject.toml- Project configuration and dependencies
# Convert a drawio file
tricc -i input.drawio -o output/
# Specify output strategy
tricc -i input.drawio -o output/ -O XLSFormCHTStrategy
# Set form ID
tricc -i input.drawio -o output/ -d my_form_id
# Set log level
tricc -i input.drawio -o output/ -l d # debug- Use
generate_id()for creating unique identifiers - Use
get_rand_name()for human-readable names - Use
OrderedSetfor maintaining order without duplicates - Use Pydantic validation for data integrity
- Follow strategy pattern for extensibility
SEARCH AND REPLACE ARE MANDATORY
------- SEARCH
var ftpClient = GetOrCreateFtpClient(machineName);
=======
var ftpClient = GetOrCreateFtpClient(machineName);
X
+++++++ REPLACE