forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook into patient cards (openemr#4853)
New Event added to append and prepend content in cards rendered on the Patient Summary (aka Dashboard)
- Loading branch information
1 parent
17dacb4
commit 9dc93c8
Showing
7 changed files
with
314 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of OpenEMR. | ||
* | ||
* @link https://github.com/openemr/openemr/tree/master | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
* @package OpenEMR\Events\Patient\Summary\Card | ||
* @author Robert Down <[email protected]> | ||
* @copyright Copyright (c) 2022 Robert Down <[email protected]> | ||
*/ | ||
|
||
namespace OpenEMR\Events\Patient\Summary\Card; | ||
|
||
use OpenEMR\Events\Patient\Summary\Card\RenderInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
class RenderEvent extends Event | ||
{ | ||
/** | ||
* The patiemtSummaryCard.render event occurs when card on the Patient | ||
* Demographics screen is rendered. | ||
*/ | ||
const EVENT_HANDLE = 'patientSummaryCard.render'; | ||
|
||
/** | ||
* ID of the card being rendered | ||
* | ||
* @var string | ||
*/ | ||
private $card; | ||
|
||
/** | ||
* Array holding the prepended data | ||
* | ||
* @var array | ||
*/ | ||
private $prependedData = []; | ||
|
||
/** | ||
* Array holding the appended data | ||
* | ||
* @var array | ||
*/ | ||
private $appendedData = []; | ||
|
||
/** | ||
* UpdateEvent constructor. | ||
* | ||
* @param string $cardID The ID of the card being rendered | ||
*/ | ||
public function __construct(string $cardID) | ||
{ | ||
$this->setCard($cardID); | ||
} | ||
|
||
/** | ||
* Get the name of the card | ||
* | ||
* @return string Name of the card | ||
*/ | ||
public function getCard(): string | ||
{ | ||
return $this->card; | ||
} | ||
|
||
/** | ||
* Set the card ID | ||
* | ||
* @param string $card Name of the card | ||
* @return void | ||
*/ | ||
public function setCard(string $card): void | ||
{ | ||
$this->card = $card; | ||
} | ||
|
||
/** | ||
* Add content to the end of a card | ||
* | ||
* @param RenderInterface $object | ||
* @param int|null $position Specific position in array, optional. Defaults to end. | ||
* @return void | ||
*/ | ||
public function addAppendedData(RenderInterface $object, $position = null): void | ||
{ | ||
$this->modifyArray('appendedData', $object, $position); | ||
} | ||
|
||
/** | ||
* Add content to the beginning of a card | ||
* | ||
* @param RenderInterface $object | ||
* @param int|null $position Specific position in array, optional. Defaults to end. | ||
* @return void | ||
*/ | ||
public function addPrependedData(RenderInterface $object, $position = null): void | ||
{ | ||
$this->modifyArray('prependedData', $object, $position); | ||
} | ||
|
||
/** | ||
* Modify the appended and prepended data array | ||
* | ||
* @param string $property Name of the property to modify | ||
* @param RenderInterface $object The object to add | ||
* @param int|null $position Specific position in array, optional. Defaults to end | ||
* @return void | ||
*/ | ||
private function modifyArray(string $property, RenderInterface $object, $position = null): void | ||
{ | ||
if (property_exists($this, $property)) { | ||
if (count($this->$property) === 0) { | ||
$this->$property[] = $object; | ||
} else { | ||
$position = $position ?? -1; | ||
array_splice($this->$property, $position, 0, $object); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the data to be appended data | ||
* | ||
* @return array | ||
*/ | ||
public function getAppendedInjection(): array | ||
{ | ||
return $this->appendedData; | ||
} | ||
|
||
/** | ||
* Get the data to be prepended data | ||
* | ||
* @return array | ||
*/ | ||
public function getPrependedInjection(): array | ||
{ | ||
return $this->prependedData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* Requirements for an object being sent to the CardRenderEvent class. Ensure core | ||
* can do its job | ||
* | ||
* @link https://github.com/openemr/openemr/tree/master | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
* @package OpenEMR\Events\Patient\Summary\Card | ||
* @author Robert Down <[email protected]> | ||
* @copyright Copyright (c) 2022 Robert Down <[email protected]> | ||
*/ | ||
|
||
namespace OpenEMR\Events\Patient\Summary\Card; | ||
|
||
interface RenderInterface | ||
{ | ||
/** | ||
* Return the name of the template to be rendered | ||
* | ||
* @return string | ||
*/ | ||
public function getTemplateFile(): string; | ||
|
||
/** | ||
* Return the array of variables to be rendered by the template | ||
* | ||
* @return array | ||
*/ | ||
public function getVariables(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of OpenEMR. | ||
* | ||
* @link https://github.com/openemr/openemr/tree/master | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
* @package OpenEMR\Events\Patient\Summary\Card | ||
* @author Robert Down <[email protected]> | ||
* @copyright Copyright (c) 2022 Robert Down <[email protected]> | ||
*/ | ||
|
||
namespace OpenEMR\Events\Patient\Summary\Card; | ||
|
||
class RenderModel implements RenderInterface | ||
{ | ||
private $templateFileName; | ||
|
||
private $variables; | ||
|
||
public function __construct(string $templateFileName, array $variables) | ||
{ | ||
$this->templateFileName = $templateFileName; | ||
$this->variables = $variables; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getTemplateFile(): string | ||
{ | ||
return $this->templateFileName; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getVariables(): array | ||
{ | ||
return $this->variables; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{# | ||
Macros for rendering a patient card | ||
@author Robert Down <[email protected]> | ||
@copyright Copyright (c) 2022 Robert Down <[email protected]> | ||
@package OpenEMR | ||
#} | ||
|
||
{# | ||
Render the prepended or appended content of a card. | ||
@var array Array of RenderInterface objects | ||
#} | ||
{% macro injectedContent(content) %} | ||
{% if content is iterable %} | ||
{% for row in content %} | ||
{{ include(row.getTemplateFile, row.getVariables)}} | ||
{% endfor %} | ||
{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{# THIS IS FOR POC ONLY - REMOVE BEFORE SUBMITTING PR #} | ||
{{ var1 }} |