CCR-CCD module: upgrade to new security model and bug fix
[openemr.git] / library / sql-ccr.inc
blob06f3be247c198fa162c7d6dfe0ce03a49507ba57
1 <?php
2 //  ------------------------------------------------------------------------ //
3 //                     Garden State Health Systems                           //
4 //                    Copyright (c) 2010 gshsys.com                          //
5 //                      <http://www.gshsys.com/>                             //
6 //  ------------------------------------------------------------------------ //
7 //  This program is free software; you can redistribute it and/or modify     //
8 //  it under the terms of the GNU General Public License as published by     //
9 //  the Free Software Foundation; either version 2 of the License, or        //
10 //  (at your option) any later version.                                      //
11 //                                                                           //
12 //  You may not change or alter any portion of this comment or credits       //
13 //  of supporting developers from this source code or any supporting         //
14 //  source code which is considered copyrighted (c) material of the          //
15 //  original comment or credit authors.                                      //
16 //                                                                           //
17 //  This program is distributed in the hope that it will be useful,          //
18 //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20 //  GNU General Public License for more details.                             //
21 //                                                                           //
22 //  You should have received a copy of the GNU General Public License        //
23 //  along with this program; if not, write to the Free Software              //
24 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25 //  ------------------------------------------------------------------------ //
27 function getHeaderData() {
29 // Reserved for future use
30         
33 function getMedicationData() {
34         global $pid;
36         $sql = " 
37                 SELECT prescriptions.date_added ,
38                         prescriptions.patient_id,
39                         prescriptions.start_date,
40                         prescriptions.quantity,
41                         prescriptions.interval,
42                         prescriptions.note,
43                         prescriptions.drug,
44                         prescriptions.medication,
45                         prescriptions.active,
46                         prescriptions.provider_id 
47                 FROM prescriptions 
48                 WHERE prescriptions.patient_id = ?";
49                 
50         $result = sqlStatement($sql, array($pid) );
51         return $result;
54 function getImmunizationData() {
55         global $pid;
56         
57         $sql = " SELECT immunizations.administered_date,
58                         immunizations.patient_id,
59                         immunizations.vis_date,
60                         immunizations.note,
61                         immunizations.immunization_id,
62                         immunizations.manufacturer,
63                         list_options.title
64                 FROM immunizations , list_options
65                 WHERE immunizations.immunization_id = list_options.option_id and immunizations.patient_id = ? and list_id = 'immunizations' " ;
66         
67         $result = sqlStatement($sql, array($pid) );
68         return $result;
72 function getProcedureData() {
74         global $pid;
76         $sql = " 
77         SELECT 
78                 lists.date, 
79                 lists.pid,
80                 lists.type,
81                 lists.title as proc_title,
82                 lists.diagnosis,
83                 lists.outcome,
84                 lists.groupname,
85                 form_encounter.onset_date,
86                 form_encounter.encounter,
87                 lists.comments,
88                 facility.city,
89                 facility.street,
90                 facility.state,
91                 users.title,
92                 users.fname,
93                 users.lname
94         from lists
95         left join issue_encounter
96         on issue_encounter.list_id = lists.id
97         left join form_encounter
98         on form_encounter.encounter = issue_encounter.encounter
99         left join facility
100         on form_encounter.facility_id = facility.id
101         left join users
102         on form_encounter.provider_id = users.id
103         where lists.type = 'surgery' and lists.pid=?";
105         $result = sqlStatement($sql, array($pid) );
106         return $result;
110 function getProblemData() {
112         global $pid;
114         $sql = " 
115         select fe.encounter, fe.reason, fe.provider_id, u.title, u.fname, u.lname, 
116                 fe.facility_id, f.street, f.city, f.state, ie.list_id, l.pid, l.title as prob_title, l.diagnosis, 
117                 l.outcome, l.groupname, l.begdate, l.enddate, l.type, l.comments , l.date, cd.code_text
118         from lists as l 
119         left join issue_encounter as ie
120         on ie.list_id = l.id
121         left join form_encounter as fe
122         on fe.encounter = ie.encounter
123         left join facility as f
124         on fe.facility_id = f.id
125         left join users as u
126         on fe.provider_id = u.id
127         left join codes as cd
128         on cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
129         where l.type = 'medical_problem' and l.pid=?";
130                 
131         $result = sqlStatement($sql, array($pid) );
132         return $result;
136 function getAlertData() {
138         global $pid;
140         $sql = " 
141         select fe.reason, fe.provider_id, fe.facility_id, fe.encounter,
142                 ie.list_id, l.pid, l.title as alert_title, l.outcome, 
143                 l.groupname, l.begdate, l.enddate, l.type, l.diagnosis, l.date ,
144                         f.street, f.city, f.state, u.title, u.fname, u.lname, cd.code_text
145         from lists as l 
146         left join issue_encounter as ie
147         on ie.list_id = l.id
148         left join form_encounter as fe
149         on fe.encounter = ie.encounter
150         left join facility as f
151         on fe.facility_id = f.id
152         left join users as u
153         on fe.provider_id = u.id
154         left join codes as cd
155         on cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
156         where l.type = 'allergy' and l.pid=?";
157                 
158         $result = sqlStatement($sql, array($pid) );
159         return $result;
163 function getResultData() {
165         global $pid;
167         // Commented this out, since throws error because the form_ankleinjury table does not
168         // exist in default OpenEMR instance.
170         //$sql = " 
171         //select date, pid, groupname, ankle_able_to_bear_weight_steps, ankle_x_ray_interpretation
172         //from form_ankleinjury
173         //where pid =?";
174                 
175         //$result = sqlStatement($sql, array($pid) );
176         //return $result;
180 function getActorData() {
181         global $pid;
183         $sql = " 
184         select fname, lname, DOB, sex, pid, street, city, state, postal_code, phone_contact
185         from patient_data
186         where pid=?";
187                 
188         $result = sqlStatement($sql, array($pid) );
189         return $result;