4 * Misc. BatchCom convenience functions
7 * @link http://www.open-emr.org
8 * @author Andres Paglayan <andres@paglayan.com>
9 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
10 * @copyright Copyright (c) 2005 Andres Paglayan <andres@paglayan.com>
11 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 //validation functions
16 function check_date_format($date)
18 if (($date == '') ||
($date == '0000-00-00')) {
21 $ymd = explode('-', $date);
22 return (count($ymd) == 3) && ($ymd[0] > 1900) && checkdate($ymd[1], $ymd[2], $ymd[0]);
25 function check_age($age)
28 $pat = "/^([0-9]+)$/";
29 return preg_match($pat, $age) or $age == '';
32 function check_select($select, $array)
34 return array_search($select, $array) or 0 === array_search($select, $array);
37 function where_or_and($and)
41 } elseif ($and == 'WHERE ') {
50 function register_email($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text)
53 $sql = "INSERT INTO batchcom SET patient_id=?, sent_by=?,
54 msg_type=?, msg_subject=?,
55 msg_text=?, msg_date_sent=NOW()";
59 $res = sqlStatement($sql, array($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text));
62 function generate_csv($sql_result)
64 /* batch CSV processor, included from batchcom */
65 // create file header.
66 // menu for fields could be added in the future
68 while ($row = sqlFetchArray($sql_result)) {
71 foreach ($row as $key => $value) {
72 $file .= csvEscape($key) . ",";
75 $file = substr($file, 0, -1);
80 foreach ($row as $key => $value) {
81 $line .= csvEscape($value) . ",";
84 $line = substr($line, 0, -1);
91 $today = date('Y-m-d:H:i:s');
92 $filename = "CSVdata-" . $today . ".csv";
93 header('Pragma: private');
94 header('Cache-control: private, must-revalidate');
95 header("Content-type: text/comma-separated-values");
96 header("Content-Disposition: attachment; filename=" . $filename);