Turn your manual testers into automation experts Request a DemoStart testRigor Free

OpenEMR Testing

What is OpenEMR?

OpenEMR is open-source medical practice management software that supports Electronic Medical Records (EMR). It helps healthcare organizations to record, organize, and manage patient’s health information with features like e-Prescriptions, customizable forms, medical chart tracking, note-taking capabilities, and digital document management. OpenEMR software provides a patient portal through which patients can fill the registration forms online easily, view test reports and prescriptions.

OpenEMR Technical Aspects

The server side is written in PHP and can be used in conjunction with a LAMP "stack" on any operating system with PHP support. The system can run on Windows, Linux, and MacOS. The official OpenEMR code repository was migrated from CVS to GitHub.

OpenEMR Testing

Here're the main types of testing that you can perform:

Unit Testing

Unit testing is a software testing methodology in which individual components, modules, or functions of a software application are tested in isolation. Unit testing aims to verify that each part of the software behaves as expected and meets its design specifications. This helps developers identify and fix issues, bugs, or logic errors early in the development process, which leads to more robust and reliable software.

In unit testing, developers create test cases or test scripts for each unit (function, method, or class) to validate its correctness. Test cases typically consist of input data, expected output, and the actual output generated by the unit being tested.

Few points to be considered while doing unit testing are as below:
  • Each test should validate a single piece of logical code
  • Name of the methods should be self-explanatory
  • Assertions should be used in methods to validate individual pieces of code working fine.

Below is a sample unit test:

An example could involve testing a function that calculates a patient's body mass index (BMI). You can use a testing framework like PHPUnit to create a unit test for this function. First, install PHPUnit and create a test file named BMICalculatorTest.php:
<?php

use PHPUnit\Framework\TestCase;

class BMICalculatorTest extends TestCase
{
  public function testCalculateBMI()
  {
    // Test cases and expected results
    $testCases = [
      ['weight' => 70, 'height' => 1.75, 'expectedBMI' => 22.9],
      ['weight' => 60, 'height' => 1.60, 'expectedBMI' => 23.4],
      ['weight' => 80, 'height' => 1.80, 'expectedBMI' => 24.7],
    ];
    
    foreach ($testCases as $testCase) {
      $actualBMI = calculateBMI($testCase['weight'], $testCase['height']);
      $this->assertEquals($testCase['expectedBMI'], $actualBMI);
    }
  }
  
  public function testCalculateBMIWithInvalidInput()
  {
    $this->expectException(InvalidArgumentException::class);
    
    calculateBMI(0, 1.75);
    calculateBMI(70, 0);
    calculateBMI(-70, 1.75);
    calculateBMI(70, -1.75);
  }
}
In this test class, we have two test methods:
  1. testCalculateBMI(): This method tests the calculateBMI() function with valid input values. It contains an array of test cases, each with weight, height, and the expected BMI value. The test asserts that the calculated BMI matches the expected value for each test case.
  2. testCalculateBMIWithInvalidInput(): This method tests the calculateBMI() function with invalid input values. It expects the function to throw an InvalidArgumentException when either weight or height is less than or equal to zero.

Integration Testing

Integration testing focuses on testing the interactions and interfaces between individual software application components, modules, or units. The primary goal of integration testing is to ensure that the various parts of the system work together correctly and as expected when combined. Integration testing helps identify issues related to communication, data exchange, and coordination between components that might not be evident during unit testing.

Integration testing typically follows unit testing in the software development process. While unit testing verifies the correctness of individual components in isolation, integration testing checks how these components function when combined. This ensures that the overall system behavior is correct and that data flows and interactions between components are consistent and error-free.

We can perform integration testing on API and DB layers, as well as at the user interface level (which can also be a part of E2E testing)

Sample integration test:

An example of an integration test might involve verifying the correct interaction between a patient registration form and the database. In this scenario, the integration test checks if the patient's information is correctly saved and retrieved from the database after submitting the registration form.

You can use a testing framework like PHPUnit for PHP to perform this integration test. First, create a test file named PatientRegistrationIntegrationTest.php. Suppose the application has a Patient class and a PatientRepository class responsible for handling patient data in the database.

Here's a simple example of an integration test for the OpenEMR application:
<?php

use PHPUnit\Framework\TestCase;

class PatientRegistrationIntegrationTest extends TestCase
{
  protected $patientRepository;
  
  protected function setUp(): void
  {
    // Initialize the PatientRepository
    $this->patientRepository = new PatientRepository();
  }

  public function testPatientRegistration()
  {
    // Create a new patient
    $patient = new Patient();
    $patient->setFirstName('John');
    $patient->setLastName('Doe');
    $patient->setDateOfBirth('1980-01-01');
    $patient->setGender('Male'); 

    // Save the patient to the database
    $savedPatientId = $this->patientRepository->savePatient($patient);
    $this->assertNotNull($savedPatientId, 'Patient ID should not be null after saving'); 

    // Retrieve the patient from the database
    $retrievedPatient = $this->patientRepository->getPatientById($savedPatientId);   
     
    // Verify the retrieved patient data
    $this->assertEquals('John', $retrievedPatient->getFirstName());
    $this->assertEquals('Doe', $retrievedPatient->getLastName());
    $this->assertEquals('1980-01-01', $retrievedPatient->getDateOfBirth());
    $this->assertEquals('Male', $retrievedPatient->getGender());
  }

  protected function tearDown(): void
  {
    // Clean up the test data from the database
    $this->patientRepository->deleteAllPatients();
  }
}
In this test class, we have one test method, testPatientRegistration(), which performs the following steps:
  1. Create a new Patient object and set its properties.
  2. Save the patient to the database using the PatientRepository.
  3. Retrieve the patient from the database using the saved patient ID.
  4. Verify that the retrieved patient's properties match the original patient's properties.

End-to-End Testing

End-to-end (E2E) testing focuses on evaluating the functionality, performance, and user experience of a complete software application or system from the user's perspective. The goal of E2E testing is to ensure that the application behaves as expected and meets the defined requirements when used in real-world scenarios. E2E testing simulates the entire user journey, from the initial interaction with the application to the outcome.

Unlike unit testing and integration testing, which focus on individual components and their interactions, E2E testing validates the entire system, including front-end user interfaces, back-end services, databases, and any third-party integrations. E2E tests are typically executed after unit and integration tests and serve as a final verification step before deploying the software to production.

You can conduct E2E testing via:
  • Selenium with PHPUnit
  • testRigor

Selenium

You will first need to install and set up Selenium WebDriver and PHPUnit. Once you have the necessary tools installed, you can create a test file named OpenEMRUserAdditionE2ETest.php.

Here's an example of an end-to-end test for a sample scenario:
<?php

use PHPUnit\Framework\TestCase;
use Selenium\WebDriver\Remote\RemoteWebDriver;
use Selenium\WebDriver\WebDriverBy;
use Selenium\WebDriver\WebDriverExpectedCondition;
use Selenium\WebDriver\WebDriverSelect;

class OpenEMRUserAdditionE2ETest extends TestCase
{
  protected $webDriver;
  
  protected function setUp(): void
  {
    // Set up the WebDriver connection
    $host = 'http://localhost:4444/wd/hub';
    $this->webDriver = RemoteWebDriver::create($host, DesiredCapabilities::chrome());
  }
  
  public function testAddUser()
  {
    $this->webDriver->get('http://localhost/openemr');
    
    // Log in
    $usernameInput = $this->webDriver->findElement(WebDriverBy::name('authUser'));
    $passwordInput = $this->webDriver->findElement(WebDriverBy::name('clearPass'));
    $loginButton = $this->webDriver->findElement(WebDriverBy::xpath("//button[@type='submit']"));
    
    $usernameInput->sendKeys('admin');
    $passwordInput->sendKeys('*****');
    $loginButton->click();
    
    // Wait for the main OpenEMR page to load
    $this->webDriver->wait(10, 500)->until(
      WebDriverExpectedCondition::titleContains('openEMR')
    );
    
    // Navigate to the "Add Users" tab
    $addUsersTab = $this->webDriver->findElement(WebDriverBy::linkText('Add Users'));
    $addUsersTab->click();
    
    // Enter user details
    $firstNameInput = $this->webDriver->findElement(WebDriverBy::name('fname'));
    $lastNameInput = $this->webDriver->findElement(WebDriverBy::name('lname'));
    $departmentSelect = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('department')));
    $shiftSelect = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('shift')));
    $dobInput = $this->webDriver->findElement(WebDriverBy::name('dob'));
    $submitButton = $this->webDriver->findElement(WebDriverBy::xpath("//button[@type='submit']"));
    
    $firstNameInput->sendKeys('jenna');
    $lastNameInput->sendKeys('smith');
    $departmentSelect->selectByVisibleText('General medicine');
    $shiftSelect->selectByVisibleText('Day');
    $dobInput->sendKeys('09/10/1998');
    $submitButton->click();
    
    // Wait for the success message to appear
    $this->webDriver->wait(10, 500)->until(
      WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector('.alert-success'), 'Details saved successfully')
    );
    
    // Verify the success message
    $successMessage = $this->webDriver->findElement(WebDriverBy::cssSelector('.alert-success'))->getText();
    $this->assertEquals('Details saved successfully', $successMessage);
  }
  
  protected function tearDown(): void
  {
    // Close the WebDriver connection
    $this->webDriver->quit();
  }
}
In this test class, we have a test method, testAddUser(), which performs the following steps:
  1. Navigate to the login page.
  2. Enter the username and password and click the "Log In" button.
  3. Wait for the main OpenEMR page to load and verify that the page title contains "openEMR".
  4. Click the "Add Users" tab to navigate to the user addition form.
  5. Enter the user details, such as first name, last name, department, shift, and date of birth, in the appropriate input fields.
  6. Click the "Submit" button to save the user details.
  7. Wait for the success message to appear on the screen and verify that it contains the text "Details saved successfully".

testRigor

testRigor is an excellent choice for end-to-end testing for QA teams. It is a powerful no-code AI-driven tool, which allows users to automate lengthy functional UI tests with ease. In addition, test maintenance is virtually eliminated, saving the team countless hours and allowing them to increase test coverage quickly. (You can look into a case study of how a large company was stuck at 34% test coverage, and then got to 90% within a year.)

Here're some of the big benefits of testRigor:
  1. Usage of plain English: Allows anyone to build and understand tests purely from an end-user's point of view, without relying on locators. This makes it easier for team members with varying technical expertise to create and maintain tests.
  2. Support for web testing on Desktop and Mobile: testRigor supports testing on almost all browsers and multiple operating systems, ensuring compatibility and smooth functioning of the OpenEMR application across different environments.
  3. API testing: Helps verify the correct functioning of APIs, which are crucial for the seamless integration of various services and components in an OpenEMR application.
  4. Data-driven testing: Supports testing with datasets, including data from CSVs, ensuring that the OpenEMR application can handle different types of input data correctly.
  5. Validation of downloaded files: Enables testing and validation of files, such as PDFs, CSVs, and Microsoft Office documents, ensuring that OpenEMR generates and handles these files correctly.
  6. Accessing databases: Allows testers to interact with databases, enabling them to verify data integrity and proper handling of data by the application.
  7. Built-in login support: Facilitates testing of authentication processes, which is essential for ensuring security and access control in the application.
  8. Integrations with CI platforms and infrastructure providers: testRigor integrates with popular CI platforms and infrastructure providers, such as Jenkins, CircleCI, Azure DevOps, BrowserStack, LambdaTest, and SauceLabs, enabling seamless testing within the development workflow and improving overall application quality.
Remember that example we've just created in Selenium? Let's write the same example in testRigor to show you how much cleaner (and faster!) it would be:
enter "admin" into "Enter your username"
enter "*****" into "Enter your password"
press "Log In"
check that page contains "openEMR"
click "Add Users" tab               
enter "jenna" into "First Name:"
enter "smith" into "Last Name:"
select "General medicine" from "Department:"
select "Day" from "shift"
enter "09/10/1998" into "Date of birth:"
click "Submit"
check that page contains "Details saved successfully"

Conclusion

In conclusion, ensuring the quality, reliability, and security of OpenEMR applications is of paramount importance, given the critical nature of healthcare data and services. A robust testing strategy, encompassing unit, integration, and end-to-end testing, is essential for verifying individual components' proper functioning, interactions, and overall user experience.

Leveraging advanced testing tools like testRigor can significantly enhance the testing process by simplifying test creation and maintenance, supporting multiple platforms and devices, and integrating with popular CI platforms and infrastructure providers. With its natural language-based approach and extensive feature set, testRigor empowers both technical and non-technical team members to contribute effectively to the testing process, ensuring comprehensive test coverage and ultimately delivering a high-quality, reliable, and secure OpenEMR application.

By investing in a well-rounded testing strategy and leveraging state-of-the-art testing tools, healthcare organizations, and developers can effectively mitigate risks, reduce potential downtime, and ensure the delivery of a seamless, dependable, and compliant OpenEMR system that meets the diverse needs of patients, medical professionals, and administrative staff alike.