Skip to content

Commit

Permalink
Hook into patient cards (openemr#4853)
Browse files Browse the repository at this point in the history
New Event added to append and prepend content in cards rendered on the Patient Summary (aka Dashboard)
  • Loading branch information
robertdown committed Feb 21, 2022
1 parent 17dacb4 commit 9dc93c8
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 4 deletions.
73 changes: 69 additions & 4 deletions interface/patient_file/summary/demographics.php

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions src/Events/Patient/Summary/Card/RenderEvent.php
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;
}
}
31 changes: 31 additions & 0 deletions src/Events/Patient/Summary/Card/RenderInterface.php
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;
}
42 changes: 42 additions & 0 deletions src/Events/Patient/Summary/Card/RenderModel.php
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;
}
}
20 changes: 20 additions & 0 deletions templates/patient/macros/card.macro.twig
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 %}
9 changes: 9 additions & 0 deletions templates/patient/partials/portal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ The Patient Portal card for the Medical Record Dashboard

{% extends "patient/card/card_base.html.twig" %}

{% if (prependedInjection is defined) or (appendedInjection is defined) %}
{% import "patient/macros/card.macro.twig" as cardMacros %}
{% set prepend = cardMacros.injectedContent(prependedInjection) %}
{% set append = cardMacros.injectedContent(appendedInjection) %}
{% endif %}


{% block content %}
<div class="text d-flex pl-1">
{% if portalAuthorized == false %}
{{ "Patient Portal Not Authorized"|xlt }}
{% else %}
{{ prepend }}
{% if portalAuthorized.created == true %}
{% set class = "fa-key" %}
{% set text = "Reset Credentials"|xlt %}
Expand All @@ -22,6 +30,7 @@ The Patient Portal card for the Medical Record Dashboard
{% endif %}
<a href="{{ portalLoginHref|attr }}?patient={{ pid|attr_url }}" class="btn btn-link btn-sm w-50 small_modal"><i class="fa {{ class|attr }}"></i>&nbsp;{{ text|text }}</a>
<button type="button" class="btn btn-link btn-sm w-50" onclick='top.assignPatientDocuments({{pid|attr_js}})'><i class="fa fa-file-signature"></i>&nbsp;{{ "Assign Documents"|xlt }}</button>
{{ append }}
{% endif %}
</div>
{% endblock %}
2 changes: 2 additions & 0 deletions templates/patient/partials/testing.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{# THIS IS FOR POC ONLY - REMOVE BEFORE SUBMITTING PR #}
{{ var1 }}

0 comments on commit 9dc93c8

Please sign in to comment.