Skip to content

Commit

Permalink
Adding checkEvent function for recurring events
Browse files Browse the repository at this point in the history
psr2 fixes by bradymiller
  • Loading branch information
epsdky authored and bradymiller committed Apr 24, 2018
1 parent c573c08 commit 0c93801
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
6 changes: 6 additions & 0 deletions interface/main/calendar/modules/PostCalendar/pnuserapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,9 @@ function calculateEvents($days, $events, $viewtype)
list($esY,$esM,$esD) = explode('-', $event['eventDate']);
$event_recurrspec = @unserialize($event['recurrspec']);

if (checkEvent($event['recurrtype'], $event_recurrspec)) {
break; }

$rfreq = $event_recurrspec['event_repeat_freq'];
$rtype = $event_recurrspec['event_repeat_freq_type'];
$exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http:https://www.ietf.org/rfc/rfc2445.txt
Expand Down Expand Up @@ -1612,6 +1615,9 @@ function calculateEvents($days, $events, $viewtype)
list($esY,$esM,$esD) = explode('-', $event['eventDate']);
$event_recurrspec = @unserialize($event['recurrspec']);

if (checkEvent($event['recurrtype'], $event_recurrspec)) {
break; }

$rfreq = $event_recurrspec['event_repeat_on_freq'];
$rnum = $event_recurrspec['event_repeat_on_num'];
$rday = $event_recurrspec['event_repeat_on_day'];
Expand Down
4 changes: 2 additions & 2 deletions interface/patient_file/report/custom_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ function postToGet($arin)
$recurrences = fetchRecurrences($pid);

//print the recurring days to screen
if ($recurrences[0] == false) { //if there are no recurrent appointments:
if (empty($recurrences)) { //if there are no recurrent appointments:
echo "<div class='text' >";
echo "<span>" . xlt('None') . "</span>";
echo "</div>";
echo "<br>";
} else {
foreach ($recurrences as $row) {
//checks if there are recurrences and if they are current (git didn't end yet)
if ($row == false || !recurrence_is_current($row['pc_endDate'])) {
if (!recurrence_is_current($row['pc_endDate'])) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions interface/patient_file/summary/demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -1779,14 +1779,14 @@ function setMyPatient() {

//Fetch patient's recurrences. Function returns array with recurrence appointments' category, recurrence pattern (interpreted), and end date.
$recurrences = fetchRecurrences($pid);
if ($recurrences[0] == false) { //if there are no recurrent appointments:
if (empty($recurrences)) { //if there are no recurrent appointments:
echo "<div>";
echo "<span>" . "&nbsp;&nbsp;" . xlt('None') . "</span>";
echo "</div></div>";
} else {
foreach ($recurrences as $row) {
//checks if there are recurrences and if they are current (git didn't end yet)
if ($row == false || !recurrence_is_current($row['pc_endDate'])) {
if (!recurrence_is_current($row['pc_endDate'])) {
continue;
}

Expand Down
43 changes: 37 additions & 6 deletions library/appointments.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@
'6' => xl('Saturday')
);

function checkEvent($recurrtype, $recurrspec)
{

$eFlag = 0;

switch ($recurrtype) {
case 1:
case 3:
if (empty($recurrspec['event_repeat_freq']) || !isset($recurrspec['event_repeat_freq_type'])) {
$eFlag = 1; }

break;

case 2:
if (empty($recurrspec['event_repeat_on_freq']) || empty($recurrspec['event_repeat_on_num']) || !isset($recurrspec['event_repeat_on_day'])) {
$eFlag = 1; }

break;
}

return $eFlag;
}

function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param = null, $tracker_board = false, $nextX = 0, $bind_param = null, $query_param = null)
{

Expand Down Expand Up @@ -185,6 +208,9 @@ function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param =
case '3':
$event_recurrspec = @unserialize($event['pc_recurrspec']);

if (checkEvent($event['pc_recurrtype'], $event_recurrspec)) {
break; }

$rfreq = $event_recurrspec['event_repeat_freq'];
$rtype = $event_recurrspec['event_repeat_freq_type'];
$exdate = $event_recurrspec['exdate'];
Expand Down Expand Up @@ -234,6 +260,9 @@ function fetchEvents($from_date, $to_date, $where_param = null, $orderby_param =
case '2':
$event_recurrspec = @unserialize($event['pc_recurrspec']);

if (checkEvent($event['pc_recurrtype'], $event_recurrspec)) {
break; }

$rfreq = $event_recurrspec['event_repeat_on_freq'];
$rnum = $event_recurrspec['event_repeat_on_num'];
$rday = $event_recurrspec['event_repeat_on_day'];
Expand Down Expand Up @@ -663,13 +692,15 @@ function fetchRecurrences($pid)
$sqlBindArray = array();
array_push($sqlBindArray, $pid);
$res = sqlStatement($query, $sqlBindArray);
$row = 0;
while ($res_arr[$row] = sqlFetchArray($res)) {
$res_arr[$row]['pc_recurrspec'] = interpretRecurrence($res_arr[$row]['pc_recurrspec'], $res_arr[$row]['pc_recurrtype']);
$row++;
$result_data = array();
while ($row = sqlFetchArray($res)) {
$u_recurrspec = unserialize($row['pc_recurrspec']);
if (checkEvent($row['pc_recurrtype'], $u_recurrspec)) {
continue; }
$row['pc_recurrspec'] = interpretRecurrence($row['pc_recurrspec'], $row['pc_recurrtype']);
$result_data[] = $row;
}

return $res_arr;
return $result_data;
}

function ends_in_a_week($end_date)
Expand Down
17 changes: 12 additions & 5 deletions library/encounter_events.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ function calendar_arrived($form_pid)
//Take all recurring events relevent for today.
$result_event=sqlStatement(
"SELECT * FROM openemr_postcalendar_events WHERE pc_recurrtype != '0' and pc_pid = ? and pc_endDate != '0000-00-00'
and pc_eventDate < ? and pc_endDate >= ? ",
and pc_eventDate <= ? and pc_endDate >= ? ",
array($form_pid,$Today,$Today)
);
if (sqlNumRows($result_event)==0) {//no repeating appointment
$all_events = array();
while ($row = sqlFetchArray($result_event)) {
$u_recurrspec = unserialize($row['pc_recurrspec']);
if (checkEvent($row['pc_recurrtype'], $u_recurrspec)) {
continue; }
$all_events[] = $row;
}
if (empty($all_events)) { // no repeating appointment
$result_event=sqlStatement(
"SELECT * FROM openemr_postcalendar_events WHERE pc_pid =? and pc_eventDate = ?",
"SELECT * FROM openemr_postcalendar_events WHERE pc_pid = ? AND pc_eventDate = ? AND pc_recurrtype = '0'",
array($form_pid,$Today)
);
if (sqlNumRows($result_event)==0) {//no appointment
Expand All @@ -64,13 +71,13 @@ function calendar_arrived($form_pid)
$enc = todaysEncounterCheck($form_pid);//create encounter
$zero_enc=0;
sqlStatement(
"UPDATE openemr_postcalendar_events SET pc_apptstatus ='@' WHERE pc_pid =? and pc_eventDate = ?",
"UPDATE openemr_postcalendar_events SET pc_apptstatus ='@' WHERE pc_pid = ? and pc_eventDate = ? AND pc_recurrtype = '0'",
array($form_pid,$Today)
);
}
} else //repeating appointment set
{
while ($row_event=sqlFetchArray($result_event)) {
foreach ($all_events as $row_event) {
$pc_eid = $row_event['pc_eid'];
$pc_eventDate = $row_event['pc_eventDate'];
$pc_recurrspec_array = unserialize($row_event['pc_recurrspec']);
Expand Down

0 comments on commit 0c93801

Please sign in to comment.