Skip to content

Commit

Permalink
interim
Browse files Browse the repository at this point in the history
  • Loading branch information
bradymiller committed Oct 11, 2024
1 parent 92791a5 commit 1530593
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 26 deletions.
11 changes: 11 additions & 0 deletions tests/Tests/E2e/Base/BaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,15 @@ protected function goToUserMenuLink(string $menuTreeIcon): void
$this->crawler = $this->client->refreshCrawler();
$this->crawler->filterXPath($menuLink2)->click();
}

protected function isPatientExist(string $firstname, string $lastname, string $dob, string $sex): bool
{
$patientDatabase = sqlQuery("SELECT `fname` FROM `patient_data` WHERE `fname` = ? AND `lname` = ? AND `DOB` = ? AND `sex` = ?", [$firstname, $lastname, $dob, $sex]);
if (!empty($patientDatabase['fname']) && ($patientDatabase['fname'] == $firstname)) {
return true;
} else {
return false;
}

}
}
8 changes: 4 additions & 4 deletions tests/Tests/E2e/CheckUserMenuLinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* CheckUserMenuLinksTest class
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);
Expand Down
1 change: 0 additions & 1 deletion tests/Tests/E2e/CreatePatientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ class CreatePatientTest extends PantherTestCase

protected $client;
protected $crawler;

}
8 changes: 4 additions & 4 deletions tests/Tests/E2e/Login/LoginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* LoginTrait trait
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);
Expand Down
31 changes: 31 additions & 0 deletions tests/Tests/E2e/OpenPatientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* OpenPatientTest class
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);

namespace OpenEMR\Tests\E2e;

use OpenEMR\Tests\E2e\Base\BaseTrait;
use OpenEMR\Tests\E2e\Login\LoginTrait;
use OpenEMR\Tests\E2e\Patient\PatientOpenTrait;
use Symfony\Component\Panther\PantherTestCase;
use Symfony\Component\Panther\Client;

class OpenPatientTest extends PantherTestCase
{
use BaseTrait;
use LoginTrait;
use PatientOpenTrait;

protected $client;
protected $crawler;
}
14 changes: 1 addition & 13 deletions tests/Tests/E2e/Patient/PatientAddTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testPatientAdd(): void
{
$this->base();
try {
$this->patientAddIfNotExist('Addtestf', 'Addtestl', '1968-06-01', 'Male');
$this->patientAddIfNotExist('Ftest', 'Ltest', '1968-06-01', 'Male');
} catch (\Throwable $e) {
// Close client
$this->client->quit();
Expand Down Expand Up @@ -90,22 +90,10 @@ protected function PatientAddIfNotExist(string $firstname, string $lastname, str
$this->client->switchTo()->defaultContent();
$this->client->waitFor(XpathsConstants::PATIENT_IFRAME);
$this->switchToIFrame(XpathsConstants::PATIENT_IFRAME);
//$this->client->takeScreenshot('/pics/2.png');
// below line will timeout if did not go to the patient summary screen for the new patient
$this->client->waitFor('//*[text()="Medical Record Dashboard - ' . $firstname . " " . $lastname . '"]');

// ensure the patient was added
$this->assertTrue($this->isPatientExist($firstname, $lastname, $dob, $sex), 'New patient is not in database, so FAILED');
}

protected function isPatientExist(string $firstname, string $lastname, string $dob, string $sex): bool
{
$patientDatabase = sqlQuery("SELECT `fname` FROM `patient_data` WHERE `fname` = ? AND `lname` = ? AND `DOB` = ? AND `sex` = ?", [$firstname, $lastname, $dob, $sex]);
if (!empty($patientDatabase['fname']) && ($patientDatabase['fname'] == $firstname)) {
return true;
} else {
return false;
}

}
}
80 changes: 80 additions & 0 deletions tests/Tests/E2e/Patient/PatientOpenTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* PatientOpenTrait
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);

namespace OpenEMR\Tests\E2e\Patient;

use OpenEMR\Tests\E2e\Base\BaseTrait;
use OpenEMR\Tests\E2e\Login\LoginTrait;
use OpenEMR\Tests\E2e\Patient\PatientAddTrait;
use OpenEMR\Tests\E2e\Xpaths\XpathsConstants;
use OpenEMR\Tests\E2e\Xpaths\XpathsConstantsPatientOpenTrait;

trait PatientOpenTrait
{
use BaseTrait;
use LoginTrait;
use PatientAddTrait;

/**
* @depends testLoginAuthorized
*/
public function testPatientOpen(): void
{
$this->base();
try {
$this->patientOpenIfExist('Ftest', 'Ltest', '1968-06-01', 'Male');
} catch (\Throwable $e) {
// Close client
$this->client->quit();
// re-throw the exception
throw $e;
}
// Close client
$this->client->quit();
}

protected function PatientOpenIfExist(string $firstname, string $lastname, string $dob, string $sex): void
{
// if patient does not already exists, then fail
if (!$this->isPatientExist($firstname, $lastname, $dob, $sex)) {
$this->fail('Patient does not exist so FAIL');
}

// login
$this->login('admin', 'pass');

// search for last name via anySearchBox
$this->client->waitFor(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT);
$this->crawler = $this->client->refreshCrawler();
$searchForm = $this->crawler->filterXPath(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT)->form();
$searchForm['anySearchBox'] = $lastname;
$this->client->waitFor(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT);
$this->crawler = $this->client->refreshCrawler();
$this->crawler->filterXPath(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT)->click();

// click on the name in the patient list
$this->client->waitFor(XpathsConstants::PATIENT_FINDER_IFRAME);
$this->switchToIFrame(XpathsConstants::PATIENT_FINDER_IFRAME);
$this->client->waitFor('//a[text()="' . $lastname . ", " . $firstname . '"]');
$this->crawler = $this->client->refreshCrawler();
$this->crawler->filterXPath('//a[text()="' . $lastname . ", " . $firstname . '"]')->click();

// ensure the patient summary screen is shown
$this->client->switchTo()->defaultContent();
$this->client->waitFor(XpathsConstants::PATIENT_IFRAME);
$this->switchToIFrame(XpathsConstants::PATIENT_IFRAME);
// below line will timeout if did not go to the patient summary screen for the opened patient
$this->client->waitFor('//*[text()="Medical Record Dashboard - ' . $firstname . " " . $lastname . '"]');
}
}
10 changes: 6 additions & 4 deletions tests/Tests/E2e/Xpaths/XpathsConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* XpathsConstants class
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);
Expand All @@ -25,4 +25,6 @@ class XpathsConstants
public const ADMIN_IFRAME = "//*[@id='framesDisplay']//iframe[@name='adm']";

public const PATIENT_IFRAME = "//*[@id='framesDisplay']//iframe[@name='pat']";

public const PATIENT_FINDER_IFRAME = "//*[@id='framesDisplay']//iframe[@name='fin']";
}
27 changes: 27 additions & 0 deletions tests/Tests/E2e/Xpaths/XpathsConstantsPatientOpenTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* XpathsConstantsPatientOpenTrait class
*
*
* TODO when no longer supporting PHP 8.1
* THIS class is needed since unable to add constants directly to the PatientOpenTrait in PHP 8.1
*
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2024 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

declare(strict_types=1);

namespace OpenEMR\Tests\E2e\Xpaths;

class XpathsConstantsPatientOpenTrait
{
public const ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT = "//form[@name='frm_search_globals']";

public const ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT = "//button[@id='search_globals']";
}

0 comments on commit 1530593

Please sign in to comment.