Beispiel #1
0
 // so convert it back to a DateTime so you can compare it
 $lastResetTime = DateTime::createFromFormat(DATABASE_DATETIME_FORMAT, $lastResetTime);
 // if the reset time is less than two hours ago, compare kicks to reset time
 if ($lastResetTime > $twoHoursAgo) {
     $curNumKicks = DataPoint::getNumDataPointsWithinReset(DataPoint::$BABY_KICK, $userId);
 } else {
     $curNumKicks = DataPoint::getNumDataPointsWithinTwoHours(DataPoint::$BABY_KICK, $userId);
 }
 boldError('curNumKicks is: ' . (string) $curNumKicks);
 $curNumKicksBeforeIncrement = $curNumKicks;
 // $curNumKicks is -1 if the method errored out
 if ($curNumKicks < 0) {
     echo json_encode(array('status' => 'error', 'error' => 'couldn\'t get current number of kicks'));
     exit;
 }
 $oldNumKicks = DataPoint::getMostRecentKickCount($userId, DataPoint::$BABY_KICK);
 // if the current number of records is successfully gotten from the database
 // increment the number of kicks then update the value in the database
 $completed = DataPoint::updateUserDataPoint($userId, DataPoint::$BABY_KICK, ++$curNumKicks);
 if (!$completed) {
     echo json_encode(array('status' => 'error', 'error' => 'failed insert'));
     exit;
 }
 // if the number of kicks before the update is greater than the amount after the update
 // then that means the patient never reached 10 kicks in an hour, so send an alert email
 // but disregard the case where people start from 0 and go to 1 kick
 if ($oldNumKicks >= $curNumKicks && $curNumKicksBeforeIncrement != 0 && $timesBeenEmailed < 1) {
     $data = array('email' => $patientEmail, 'subject' => 'Irregular Kick Count', 'textArgs' => json_encode(array('name' => $patientFirstName)));
     $user_group_admin_id = Group::getGroupAdminByUser($userId);
     $user_group_admin = User::findById($user_group_admin_id)->getAdditionalInfo();
     $userGroupAdminEmail = $user_group_admin->email;