@gravitate-health/lens-tool-test
v1.0.3
Published
Testing toolkit for Gravitate Health lens development with bundled test data
Readme
Gravitate Health Lens Testing Toolkit
A comprehensive testing toolkit for Gravitate Health lens development. This library provides utilities for testing lenses with bundled test data (ePIs and IPS) and allows developers to extend the test data with their own resources.
Features
- 🧪 Bundled Test Data: Includes 7 preprocessed ePIs and 2 IPS resources for immediate testing
- 🔧 Extensible: Add your own test data alongside bundled resources
- ✅ Comprehensive Utilities: Helper functions for loading, applying, and validating lenses
- 📊 Content Validation: Automated checks for content preservation and lens behavior
- 💡 TypeScript Support: Full type definitions included
Installation
npm install @gravitate-health/lens-tool-testPeer Dependencies
npm install @gravitate-health/lens-execution-environmentQuick Start
Basic Usage
import {
loadEPI,
loadIPS,
loadLens,
applyLens,
hasFocusingErrors,
isContentPreserved
} from '@gravitate-health/lens-toolkit-test';
// Load test data from bundled resources
const epi = loadEPI('Bundle-processedbundledovato-en.json');
const ips = loadIPS('alicia-patient_summary.json');
// Load and compile your lens
const myLens = loadLens('./lenses', 'my-lens');
// Apply the lens
const result = await applyLens(epi, ips, myLens);
// Validate the results
if (hasFocusingErrors(result)) {
console.error('Lens has errors!');
}
if (!isContentPreserved(epi, result.epi)) {
console.error('Content was removed!');
}Writing Tests
import {
loadAllEPIs,
loadAllIPS,
loadLens,
applyLens,
hasFocusingErrors,
isContentPreserved,
isTextHighlighted
} from '@gravitate-health/lens-toolkit-test';
describe('My Lens Tests', () => {
const myLens = loadLens('./lenses', 'my-lens');
test('should highlight pregnancy warnings', async () => {
const epi = loadEPI('Bundle-processedbundledovato-en.json');
const ips = loadIPS('alicia-patient_summary.json');
const result = await applyLens(epi, ips, myLens);
expect(hasFocusingErrors(result)).toBe(false);
expect(isTextHighlighted(result.epi, 'pregnancy')).toBe(true);
expect(isContentPreserved(epi, result.epi)).toBe(true);
});
});Extending Test Data
Add your own test data alongside the bundled resources:
import { configureTestData, loadAllEPIs } from '@gravitate-health/lens-tool-test';
// Configure custom paths
configureTestData({
pepisPath: './my-test-data/pepis',
ipsPath: './my-test-data/ips'
});
// loadAllEPIs() now includes both bundled and custom ePIs
const allEPIs = loadAllEPIs();API Reference
Data Loading
loadEPI(filename)- Load specific ePI by filenameloadAllEPIs()- Load all ePIs (bundled + custom)loadIPS(filename)- Load specific IPS by filenameloadAllIPS()- Load all IPS resources (bundled + custom)configureTestData(paths)- Configure custom test data pathsresetTestDataConfig()- Reset to bundled data only
Lens Operations
loadLens(dir, baseName)- Load and compile a lensapplyLens(epi, ips, lens)- Apply single lensapplyMultipleLenses(epi, ips, lenses)- Apply multiple lenses
HTML Analysis
extractHTMLFromEPI(bundle)- Extract HTML sectionsextractTextContent(html)- Strip HTML tagsisTextHighlighted(epi, text, options?)- Check if text is highlightedisTextCollapsed(epi, text, options?)- Check if text is collapsedcountElementsWithClass(epi, className)- Count elements with CSS class
Validation
hasFocusingErrors(result)- Check for errorsgetFocusingErrors(result)- Get error messagesisContentPreserved(original, enhanced, threshold?)- Verify content preservationgetContentPreservationMetrics(original, enhanced)- Get detailed metrics
Project Structure
lens-tool-test/
├── src/ # Source code
│ ├── index.ts # Main exports
│ ├── types.ts # TypeScript definitions
│ ├── data-loader.ts # Test data loading
│ ├── lens-utils.ts # Lens operations
│ ├── html-utils.ts # HTML analysis
│ └── validation-utils.ts # Validation functions
├── data/ # Bundled test data
│ ├── PePIs/ # 7 preprocessed ePIs
│ └── IPS/ # 2 IPS resources
├── dist/ # Compiled output (published)
└── package.jsonBuilding from Source
# Install dependencies
npm install
# Build (compiles TypeScript and copies data)
npm run build
# Run tests
npm testLicense
MIT
Contributing
Contributions welcome! Please ensure:
- All tests pass
- TypeScript best practices followed
- New features include tests and documentation
Support
For issues, please open a GitHub issue.
