Module Types
Event Type Modules
Event type modules represent clinical encounters. They follow naming conventions based on the type of event:-
OphCi - Clinical Investigation
OphCiExamination- Clinical examinationOphCiPhasing- Phasing testsOphCiDidNotAttend- DNA tracking
-
OphDr - Drug/Prescription related
OphDrPrescription- PrescriptionsOphDrPGDPSD- PGD/PSD protocols
-
OphTr - Treatment events
OphTrOperationnote- Operation notes
-
OphCo - Correspondence/Communication
OphCoCorrespondence- LettersOphCoMessaging- MessagesOphCoCvi- Certificate of Vision Impairment
Administrative Modules
- Admin - System administration
- Api - API functionality
- Genetics - Genetics features
Module Structure
A typical event type module has this structure:Creating a Module
Step 1: Module Definition
Create the module class extendingBaseEventTypeModule:
protected/modules/OphCiExample/OphCiExampleModule.php
Step 2: Controller
Create the default controller extendingBaseEventTypeController:
protected/modules/OphCiExample/controllers/DefaultController.php
Step 3: Element Models
Create element models for the event:protected/modules/OphCiExample/models/Element_OphCiExample_Data.php
Step 4: Views
Create view templates:protected/modules/OphCiExample/views/default/form_Element_OphCiExample_Data.php
Step 5: Database Migration
Create the database structure:protected/modules/OphCiExample/migrations/m240101_120000_initial_tables.php
Module Elements
Element Basics
Elements are the building blocks of events. Each element:- Extends
BaseEventTypeElement - Represents a section of the event form
- Has its own database table
- Can be required or optional
Multiple Elements
Events can have multiple elements:Element Dependencies
Elements can depend on other elements:Module API Component
Create an API component for module-specific functionality:protected/modules/OphCiExample/components/OphCiExample_API.php
Module Configuration
Modules can have their own configuration:protected/modules/OphCiExample/config/common.php
Testing Modules
Create factories for your models:protected/modules/OphCiExample/factories/models/Element_OphCiExample_DataFactory.php
Real-World Example
The OphCiExamination module is a comprehensive example:protected/modules/OphCiExamination/OphCiExaminationModule.php
Module Registration
Modules are automatically discovered if placed inprotected/modules/. They can also be registered in the application configuration.
Best Practices
- Follow naming conventions - Use appropriate prefixes (OphCi, OphDr, etc.)
- Use namespaces - Organize code with PHP namespaces
- Create factories - Support testing with model factories
- Write migrations - Always version database changes
- Document elements - Add PHPDoc comments to models
- Use the API component - Expose module functionality through an API class
- Test thoroughly - Write unit and feature tests
Next Steps
Architecture
Understand the technical architecture
Testing
Learn about testing your modules