<commit_before><?php defined('SYSPATH') or die('No direct script access.');

class Model_Appointment extends Model {

	const MESSAGE = "You have an appointment for %appt_name% in one week";
	private static $child_appts = array(
		array(
			"name" => "<NAME>",
			"interval" => "0 weeks",
			"after" => true
		),
		array(
			"name" => "Or<NAME>, DPT, Hepatitis B",
			"interval" => "6 weeks",
			"after" => true
		)
	);

	public function add_child($post) {
		$data['child_name'] = $post['child_name'];
		$data['case_id'] = $post['case_id'];

		foreach(self::$child_appts as $appt) {
			$birth_date = new DateTime($post['birth_date']);
			$data['message'] = preg_replace("/%appt_name%/", $appt['name'], self::MESSAGE);
			if($appt['after']) {
				$data['date'] = $birth_date->add(DateInterval::createFromDateSTring($appt['interval']));
			}
			else {
				$data['date'] = $birth_date->sub(DateInterval::createFromDateString($appt['interval']));
			}
			$data['date'] = $data['date']->getTimestamp();
			$this->add_appointment($data);
		}
	}

	public function add_appointment($data) {
		return DB::insert('appointments', array_keys($data))->values($data)->execute();
	}

	public function select_by_case_id($id) {
		return DB::query(Database::SELECT, 'SELECT * FROM appointments WHERE case_id=:case_id')
			->param(':case_id', $id)
			->execute();
	}

	public function delete_appointment($id) {
		return DB::query(Database::DELETE, 'DELETE FROM appointments WHERE id=:id LIMIT 1')
			->param(':id', $id)
			->execute();
	}
}<commit_msg>Don't add appointments that are in the past<commit_after><?php defined('SYSPATH') or die('No direct script access.');

class Model_Appointment extends Model {

	const MESSAGE = "You have an appointment for %appt_name% in one week";
	private static $child_appts = array(
		array(
			"name" => "<NAME>",
			"interval" => "0 weeks",
			"after" => true
		),
		array(
			"name" => "<NAME>, DPT, Hepatitis B",
			"interval" => "6 weeks",
			"after" => true
		)
	);

	public function add_child($post) {
		$data['child_name'] = $post['child_name'];
		$data['case_id'] = $post['case_id'];

		$now = new DateTime("now");
		foreach(self::$child_appts as $appt) {
			$birth_date = new DateTime($post['birth_date']);
			$data['message'] = preg_replace("/%appt_name%/", $appt['name'], self::MESSAGE);
			if($appt['after']) {
				$data['date'] = $birth_date->add(DateInterval::createFromDateSTring($appt['interval']));
			}
			else {
				$data['date'] = $birth_date->sub(DateInterval::createFromDateString($appt['interval']));
			}
			// Don't add appointments that are for the past.
			if($data['date'] < $now) {
				continue;
			}
			$data['date'] = $data['date']->getTimestamp();
			$this->add_appointment($data);
		}
	}

	public function add_appointment($data) {
		return DB::insert('appointments', array_keys($data))->values($data)->execute();
	}

	public function select_by_case_id($id) {
		return DB::query(Database::SELECT, 'SELECT * FROM appointments WHERE case_id=:case_id')
			->param(':case_id', $id)
			->execute();
	}

	public function delete_appointment($id) {
		return DB::query(Database::DELETE, 'DELETE FROM appointments WHERE id=:id LIMIT 1')
			->param(':id', $id)
			->execute();
	}
}
{'fraction_non_alphanumeric': 0.19869605712511643, 'fraction_numerical': 0.0018627755355479665, 'mean_word_length': 4.826401446654611, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1071122', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1104, 'n_words': 231}