Skip to main content
OpenEyes modules encapsulate functionality for different event types and features. This guide covers how to create and structure custom modules.

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 examination
    • OphCiPhasing - Phasing tests
    • OphCiDidNotAttend - DNA tracking
  • OphDr - Drug/Prescription related
    • OphDrPrescription - Prescriptions
    • OphDrPGDPSD - PGD/PSD protocols
  • OphTr - Treatment events
    • OphTrOperationnote - Operation notes
  • OphCo - Correspondence/Communication
    • OphCoCorrespondence - Letters
    • OphCoMessaging - Messages
    • OphCoCvi - 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 extending BaseEventTypeModule:
protected/modules/OphCiExample/OphCiExampleModule.php

Step 2: Controller

Create the default controller extending BaseEventTypeController:
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
See Testing for more details on writing tests.

Real-World Example

The OphCiExamination module is a comprehensive example:
protected/modules/OphCiExamination/OphCiExaminationModule.php
Explore the OphCiExamination module source code for a complete implementation example.

Module Registration

Modules are automatically discovered if placed in protected/modules/. They can also be registered in the application configuration.

Best Practices

  1. Follow naming conventions - Use appropriate prefixes (OphCi, OphDr, etc.)
  2. Use namespaces - Organize code with PHP namespaces
  3. Create factories - Support testing with model factories
  4. Write migrations - Always version database changes
  5. Document elements - Add PHPDoc comments to models
  6. Use the API component - Expose module functionality through an API class
  7. Test thoroughly - Write unit and feature tests

Next Steps

Architecture

Understand the technical architecture

Testing

Learn about testing your modules