Skip to content

Commit

Permalink
Extended appointment filters test with Episodes and created new Appoi…
Browse files Browse the repository at this point in the history
…ntmentFilter types for #378
  • Loading branch information
mddejong committed Oct 31, 2018
1 parent 755b02b commit 3c1fc8e
Show file tree
Hide file tree
Showing 23 changed files with 1,187 additions and 179 deletions.
27 changes: 18 additions & 9 deletions classes/Gems/Agenda.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,6 @@ public function getEpisodeOfCare($episodeData)
'$episodeData array should atleast have a key "gec_episode_of_care_id" containing the requested episode id'
);
}
$episodeId = $episodeData['gec_episode_of_care_id'];
} else {
$episodeId = $episodeData;
}
// \MUtil_Echo::track($appointmentId, $appointmentData);

Expand Down Expand Up @@ -1179,20 +1176,32 @@ public function matchActivity($name, $organizationId, $create = true)

/**
*
* @param \Gems_Agenda_Appointment $appointment
* @param mixed $to \Gems_Agenda_Appointment:EpsiodeOfCare
* @return AppointmentFilterInterface[]
*/
public function matchFilters(\Gems_Agenda_Appointment $appointment)
public function matchFilters($to)
{
$filters = $this->loadDefaultFilters();
$output = array();

foreach ($filters as $filter) {
if ($filter instanceof AppointmentFilterInterface) {
if ($filter->matchAppointment($appointment)) {
$output[] = $filter;
if ($to instanceof \Gems_Agenda_Appointment) {
foreach ($filters as $filter) {
if ($filter instanceof AppointmentFilterInterface) {
if ($filter->matchAppointment($to)) {
$output[] = $filter;
}
}
}
} elseif ($to instanceof EpisodeOfCare) {
foreach ($filters as $filter) {
if ($filter instanceof AppointmentFilterInterface) {
if ($filter->matchEpisode($to)) {
$output[] = $filter;
}
}
}
} else {
throw new \Gems_Coding_Exception('The $to paramater must be either an appointment or an episode object.');
}

return $output;
Expand Down
9 changes: 9 additions & 0 deletions classes/Gems/Agenda/Appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,15 @@ public function getSubject()
return isset($this->_gemsData['gap_subject']) ? $this->_gemsData['gap_subject'] : null;
}

/**
*
* @return boolean
*/
public function hasEpisode()
{
return (boolean) $this->_gemsData['gap_id_episode'];
}

/**
* Return true when the status is active
*
Expand Down
3 changes: 3 additions & 0 deletions classes/Gems/Agenda/AppointmentFilterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ class AppointmentFilterModel extends \Gems_Model_JoinModel
'AndModelDependency',
'DiagnosisEpisodeModelDependency',
'FieldLikeModelDependency',
'JsonDiagnosisDependency',
'LocationModelDependency',
'NotAnyModelDependency',
'OrganizationModelDependency',
'OrModelDependency',
'SqlLikeModelDependency',
'SubjectAppointmentModelDependency',
'SubjectEpisodeModelDependency',
'WithModelDependency',
);

/**
Expand Down
36 changes: 35 additions & 1 deletion classes/Gems/Agenda/EpisodeOfCare.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($episodeData)
{
if (is_array($episodeData)) {
$this->_gemsData = $episodeData;
$this->_episodeId = $episodeData['gec_episode_of_care_id'];
$this->_episodeId = $episodeData['gec_episode_of_care_id'];
if ($this->currentUser instanceof \Gems_User_User) {
$this->_gemsData = $this->currentUser->applyGroupMask($this->_gemsData);
}
Expand Down Expand Up @@ -127,6 +127,23 @@ public function getDiagnosis()
return isset($this->_gemsData['gec_diagnosis']) ? $this->_gemsData['gec_diagnosis'] : null;
}

/**
* The diagnosis data of the episode translated from Json
*
* @return array of Json data
*/
public function getDiagnosisData()
{
if (! isset($this->_gemsData['gec_diagnosis'])) {
return [];
}
if (is_string($this->_gemsData['gec_diagnosis'])) {
$this->_gemsData['gec_diagnosis'] = json_decode($this->_gemsData['gec_diagnosis'], true);
}

return $this->_gemsData['gec_diagnosis'];
}

/**
* Get a general description of this appointment
*
Expand All @@ -143,6 +160,23 @@ public function getDisplayString()
return implode($this->_('; '), array_filter($results));
}

/**
* The extra data of the episode translated from Json
*
* @return array of Json data
*/
public function getExtraData()
{
if (! isset($this->_gemsData['gec_extra_data'])) {
return [];
}
if (is_string($this->_gemsData['gec_extra_data'])) {
$this->_gemsData['gec_extra_data'] = json_decode($this->_gemsData['gec_extra_data'], true);
}

return $this->_gemsData['gec_extra_data'];
}

/**
* Return the episode id
*
Expand Down
6 changes: 3 additions & 3 deletions classes/Gems/Agenda/Filter/FieldLikeModelDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getFieldLabels()
'gap_id_location' => $this->_('Location'),
'gap_subject' => $this->_('Subject'),
);

asort($output);

return $output;
Expand Down Expand Up @@ -123,9 +123,9 @@ public function getFilterName()
public function getTextSettings()
{
$fields = $this->agenda->getFieldLabels();
$description = $this->_(
$description = sprintf($this->_(
"Use the %%-sign to search for zero or more random characters and an _ for a single random character."
);
));

return array(
'gaf_filter_text1' => array(
Expand Down
120 changes: 120 additions & 0 deletions classes/Gems/Agenda/Filter/JsonDiagnosisDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

/**
*
* @package Gems
* @subpackage Agenda\Filter
* @author Matijs de Jong <mjong@magnafacta.nl>
* @copyright Copyright (c) 2018, Erasmus MC and MagnaFacta B.V.
* @license New BSD License
*/

namespace Gems\Agenda\Filter;

use Gems\Agenda\FilterModelDependencyAbstract;

/**
*
* @package Gems
* @subpackage Agenda\Filter
* @copyright Copyright (c) 2018, Erasmus MC and MagnaFacta B.V.
* @license New BSD License
* @since Class available since version 1.8.4 30-Oct-2018 15:35:50
*/
class JsonDiagnosisDependency extends FilterModelDependencyAbstract
{
/**
* A ModelAbstract->setOnSave() function that returns the input
* date as a valid date.
*
* @see \MUtil_Model_ModelAbstract
*
* @param mixed $value The value being saved
* @param boolean $isNew True when a new item is being saved
* @param string $name The name of the current field
* @param array $context Optional, the other values being saved
* @return string
*/
public function calcultateName($value, $isNew = false, $name = null, array $context = array())
{
$filter[] = $context['gaf_filter_text1'];
$filter[] = $context['gaf_filter_text2'];
$filter[] = $context['gaf_filter_text3'];
$filter = array_filter($filter);

if ($filter) {
if (1 == count($filter)) {
return sprintf(
$this->_('Episode diagnosis contains %s after key: %s'),
$context['gaf_filter_text4'],
reset($filter)
);
} else {
return sprintf(
$this->_('Episode diagnosis contains %s after keys: %s'),
$context['gaf_filter_text4'],
implode(', ', $filter)
);
}
} else {
return sprintf($this->_('Diagnosis data contains %s'), $context['gaf_filter_text4']);
}
}

/**
* Get the class name for the filters, the part after *_Agenda_Filter_
*
* @return string
*/
public function getFilterClass()
{
return 'JsonDiagnosisEpisodeFilter';
}

/**
* Get the name for this filter class
*
* @return string
*/
public function getFilterName()
{
return $this->_('Diagnosis Data match');
}

/**
* Get the settings for the gaf_filter_textN fields
*
* Fields not in this array are not shown in any way
*
* @return array gaf_filter_textN => array(modelFieldName => fieldValue)
*/
public function getTextSettings()
{
$description = sprintf($this->_(
"Use the %%-sign to search for zero or more random characters and an _ for a single random character."
));

return [
'gaf_filter_text1' => [
'label' => $this->_('1st optional key'),
'description' => $description,
'required' => false,
],
'gaf_filter_text2' => [
'label' => $this->_('2nd optional key'),
'description' => $description,
'required' => false,
],
'gaf_filter_text3' => [
'label' => $this->_('3rd optional key'),
'description' => $description,
'required' => false,
],
'gaf_filter_text4' => [
'label' => $this->_('Data value'),
'description' => $description,
'required' => true,
],
];
}
}
Loading

0 comments on commit 3c1fc8e

Please sign in to comment.