Lens Execution Environment (LEE)
note
The LEE provides the structure needed for lens development and execution. This structure includes the interface that lenses should follow, as well as the inputs they should expect. The LEE implements critical functions, like:
- preparing the inputs (epi, ips, and pv) for each lens, extracting the Patient Information Leaflet (PIL) from the p(ePI) and transforming it as a separate input
htmlto the first lens. - ensuring the lenses are executed sequentially the
htmloutput of each lens is the input for the next one, this allows lenses to build on top of each other and create complex adaptations. - isolating the lens execution, when the different functions of the lens are invoked, they are executed in an isolated thread. This not only improves security and robustness of the lens execution process, it also allows the LEE to impose security constraints such as timeout, limiting execution to 1 second by default, or network access (currently planned, but not implemented).
- configuration of the log handling, logs can be deactivated (useful for production environments) or independent logging for each lens can be customized (useful for development environments).
- LEE converts the final
htmloutput of the lens execution back into a FHIRCompositionresource, embedding it within the ePI resource, as well as adding metadata, to produce the final f(ePI). This means that lens developers can focus on the adaptation logic and return the adapted content ashtml, without needing to worry about the FHIR structure of the output, which is handled by the LEE.
Critically, LEE ensures that lenses can be developed agnostically to the execution mode, i.e. the exact same lens can operate for client-side and server-side focusing.
The LEE is offered as a NPMJS package, so client agents may download and use it, being this package the same one the Focusing Manager is using for applying lenses means the agent will obtain the same results.
Purpose
LEE provides a sandboxed runtime environment for executing Lens JavaScript code safely and efficiently.
Execution Process
- invoked through the function
applyLens(lensId, pEpi, ips, pv) - Loads Lens code from FHIR Library resource
- Decodes Base64 content, then interprets as UTF-8 JavaScript
- Prepares inputs: p(ePI), IPS, PV
- Executes lens in isolated context
- Applies modifications to generate f(ePI)
- Returns FHIR-compliant resource to caller
Execution Modes
Client-Side Focusing
- LEE runs in patient's browser/app, it is published as a JavaScript library that can be embedded in client applications for enhanced privacy and responsiveness.
- Uses local patient data (IPS/PV)
- Privacy-preserving (data never leaves device)
- Requires lightweight Lenses
Server-Side Focusing
- LEE is imported and run by Focusing Manager on FOSPS servers
- Receives patient data from secure sources
- Focusing Manager scales for concurrent users
Security & Isolation
- Sandboxed execution: Lenses cannot access system resources
- Time limits: Prevent infinite loops
- Memory limits: Prevent resource exhaustion
- API restrictions: Only approved network access available
Integration
- Called by Focusing Manager
- Decodes Lenses
- Produces f(ePI) for end-users
Related Concepts
- Lens - Executed code
- p(ePI) - Input content
- f(ePI) - Output result
- Focusing Manager - Orchestrator
- Attention Modification - Primary operation
- IPS - Patient input
- Persona Vector - Context input