log failed queries to php log and provide stack trace in browser error message
[openemr.git] / library / immunization_helper.php
blobbfdbde713d07b8d0a7c2eee413710510ecda73ca
1 <?php
2 /**
3 * library/immunization_helper.php Upgrading and patching functions of database.
5 * Copyright (C) 2013 Jan Jajalla <jansta23@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Jan Jajalla <jansta23@gmail.com>
20 * @link http://www.open-emr.org
23 /**
24 * Return listing of immunizations for a patient.
26 * @param string $pid person id
27 * @param string $sortby sorting field ('vacc' sorts by name, otherwise will sort by date)
28 * @param boolean $showError indicator whether to retrieve the records that were added erroneously
29 * @return recordset listing of immunizations for a patient
31 function getImmunizationList($pid,$sortby,$showError) {
32 $sql = "select i1.id ,i1.immunization_id, i1.cvx_code, i1.administered_date, c.code_text_short, c.code".
33 ",i1.manufacturer ,i1.lot_number ".
34 ",ifnull(concat(u.lname,', ',u.fname),'Other') as administered_by ".
35 ",i1.education_date ,i1.note ".
36 ",i1.amount_administered, i1.amount_administered_unit, i1.route, i1.administration_site, i1.added_erroneously".
37 " from immunizations i1 ".
38 " left join users u on i1.administered_by_id = u.id ".
39 " left join code_types ct on ct.ct_key = 'CVX' ".
40 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
41 " where i1.patient_id = ? ";
42 if (!$showError) {
43 $sql .= "and i1.added_erroneously = 0 ";
46 $sql .= " order by ";
48 if ($sortby == "vacc") {
49 $sql .= " c.code_text_short, i1.immunization_id, i1.administered_date DESC";
51 else {
52 $sql .= " administered_date desc";
55 $results = sqlStatement($sql,array($pid));
56 return $results;