/** * Function to check for existance of data for a patient in the rule_patient_data table * * @param string $patient_id pid of selected patient. * @param string $category label in category column * @param string $item label in item column * @param string $complete label in complete column (YES,NO, or blank) * @param string $num_items_comp number items comparison (eq,ne,gt,ge,lt,le) * @param integer $num_items_thres number of items threshold * @param string $intervalType type of interval (ie. year) * @param integer $intervalValue searched for within this many times of the interval type * @param string $dateTarget target date(format Y-m-d H:i:s). * @return boolean true if check passed, otherwise false */ function exist_custom_item($patient_id, $category, $item, $complete, $num_items_comp, $num_items_thres, $intervalType = '', $intervalValue = '', $dateTarget) { // Set the table $table = 'rule_patient_data'; // Collect the correct column label for patient id in the table $patient_id_label = collect_database_label('pid', $table); // Get the interval sql query string $dateSql = sql_interval_string($table, $intervalType, $intervalValue, $dateTarget); // search for number of specific items $sql = sqlStatementCdrEngine("SELECT `result` " . "FROM `" . add_escape_custom($table) . "` " . "WHERE `category`=? " . "AND `item`=? " . "AND `complete`=? " . "AND `" . add_escape_custom($patient_id_label) . "`=? " . $dateSql, array($category, $item, $complete, $patient_id)); // See if number of returned items passes the comparison return itemsNumberCompare($num_items_comp, $num_items_thres, sqlNumRows($sql)); }
/** * Function to fetch reminders. * * @param integer/array $patient_id pid(s) of patient(s). * @param string $type Can choose unsent ('unsent') vs all active (BLANK) reminders * @param string $due_status due status of reminders (soon_due,due,past_due). If blank, then will return all. * @param string $select Select component of select statement. If blank, then will return all columns. * @return array Returns an array of reminders. */ function fetch_reminders($patient_id = '', $type = '', $due_status = '', $select = '*') { $arraySqlBind = array(); if (!empty($patient_id)) { // check the specified pid(s) $where = "`pid` IN (" . add_escape_custom($patient_id) . ") AND "; } if (!empty($due_status)) { $where .= "`due_status`=? AND "; array_push($arraySqlBind, $due_status); } if (empty($type)) { $where .= "`active`='1'"; } else { // $type == 'unsent' $where .= "`active`='1' AND `date_sent` IS NULL"; } $order = "`due_status`, `date_created`"; $sql = "SELECT " . $select . " FROM `patient_reminders` WHERE " . $where . " ORDER BY " . $order; $rez = sqlStatementCdrEngine($sql, $arraySqlBind); $returnval = array(); for ($iter = 0; $row = sqlFetchArray($rez); $iter++) { $returnval[$iter] = $row; } return $returnval; }