2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
26 // +------------------------------------------------------------------------------+
28 //SANITIZE ALL ESCAPES
29 $sanitize_all_escapes=true;
32 //STOP FAKE REGISTER GLOBALS
33 $fake_register_globals=false;
39 //this will return the query string along with the parameter array, according to the case case.
40 //actual execution is done in the select_query function in Server_side
43 public function query_formation($data){
46 // Entries pending for approval for Existing Patient and New Patient.
48 $query= "select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2')";
49 return array($query,array($pid));
51 // Entries pending for approval for documents only (no demo change).
53 $query = " select * from audit_master where pid=? and approval_status='1' and type='3' ";
54 return array($query,array($pid));
57 $query = "SELECT fname FROM patient_data WHERE pid=?";
58 return array($query,array($pid));
61 $query= "select MAX(pid)+1 AS pid from patient_data ";
65 //for building patient Demo
67 $query="select * from layout_options " .
68 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
69 "ORDER BY group_name, seq";
72 //for building patient Demo Date of Birth
74 $query="select *, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD from patient_data where pid=? order by date DESC limit 0,1 ";
75 return array($query,array($pid));
77 //for building patient Demo Employer Data
79 $query="select * from employer_data where pid=? order by date DESC limit 0,1 ";
80 return array($query,array($pid));
82 //for building patient Demo Insurance company details for Patient
84 $query=" select insd.*, ic.name as provider_name from insurance_data as insd " .
85 "left join insurance_companies as ic on ic.id = insd.provider " .
86 "where pid = ? and type =? order by date DESC limit 1 ";
87 array_unshift($data[1],$pid);
88 return array($query,$data[1]);
90 // Entries pending for approval demo and documents.
92 $query=" select * from audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id and am.pid=? and am.approval_status='1'
93 and (am.type='1' or am.type='2' or am.type='3') order by ad.id";
94 return array($query,array($pid));
96 // Demo building from layout options.
99 $query=" select * from layout_options WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
100 " ORDER BY group_name, seq";
102 return array($query);
104 //Global specific application for building demo.
106 $query="select * from globals where gl_name ='specific_application' ";
107 return array($query);
109 //Global omit employers for building demo.
111 $query=" select * from globals where gl_name ='omit_employers' ";
112 return array($query);
114 //getting the password
116 $query = "select portal_username from patient_access_offsite where portal_username =? ";
117 return array($query,$data[1]);
121 $x=array($data[1][0]);
122 $query="select count(*) AS count from patient_data where pubpid = ?";
123 return array($query,$x);
125 //getting DOB and SSN for verifying the duplicate patient existance
127 $x=array($data[1][0]);
128 $query="select ss,DOB from patient_data where DOB=?";
129 return array($query,$x);
131 //master data for calendar from Globals
134 if($data[1][0]=='calendar_interval'||
$data[1][0]=='schedule_start'||
$data[1][0]=='schedule_end')
136 $query="select gl_value from globals where gl_name=?";
137 return array($query,$data[1]);
144 //Check whether an entry exist in the form Encounter to decide whether patient is an existing patient.
145 $query="select COUNT(*) AS cnt from form_encounter WHERE pid=?";
146 return array($query,array($pid));
150 //Existing appointments for a patient
151 array_unshift($data[1],$pid);
152 $query="select pc_eid,pc_eventDate,pc_startTime,pc_endTime,fname,lname,name,pc_apptstatus from openemr_postcalendar_events AS c,
153 users AS u,facility AS f WHERE pc_pid=? AND pc_aid=u.id AND pc_facility=f.id AND pc_apptstatus!=? order by pc_eventDate desc";
154 return array($query,$data[1]);
158 //Appointments pending for approval
159 array_push($data[1],$pid);
160 $query="select am.id,am.approval_status,ad.audit_master_id,ad.field_name,ad.field_value,u.fname,u.lname,f.name from audit_master AS am,
161 audit_details AS ad LEFT JOIN users AS u ON ad.field_value=u.id AND ad.field_name=? LEFT JOIN facility AS f ON ad.field_value=f.id AND
162 ad.field_name=? WHERE am.pid=? AND am.id=ad.audit_master_id AND am.type='10' AND am.approval_status NOT IN ('2','4')
163 ORDER BY approval_status, am.id desc,ad.id desc";
164 return array($query,$data[1]);
168 //patient appointment history
169 array_unshift($data[1],$pid);
170 $query="select pc_eid,pc_eventDate,pc_startTime,pc_endTime,fname,lname,name,pc_apptstatus from openemr_postcalendar_events AS c,
171 users AS u,facility AS f WHERE pc_pid=? AND pc_aid=u.id AND pc_facility=f.id AND pc_apptstatus=? order by pc_eventDate desc";
172 return array($query,$data[1]);
176 //List of Service Facility
177 $query="select * from facility where service_location != 0 and id in (".add_escape_custom($data[1][0]).") order by name";
178 return array($query);
183 $query="select id, lname, fname from users WHERE authorized = 1 AND username != '' AND username NOT LIKE '%Admin%' AND active = 1
184 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) ORDER BY lname, fname";
185 return array($query);
189 //Calendar default visit time for visit category. value for Admin--->others-->calendar
190 $query="select pc_duration from openemr_postcalendar_categories WHERE pc_catid = ?";
191 return array($query,$data[1]);
195 //patient appointment
196 $query="select pc_eventDate, pc_endDate, pc_startTime, pc_duration, pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid,
197 pc_prefcatid from openemr_postcalendar_events WHERE pc_aid = ? AND ((pc_endDate >= ? AND pc_eventDate < ?) OR
198 (pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?)) AND pc_facility = ?";
199 return array($query,$data[1]);
203 //Appointments pending for approval
204 $query="select * from audit_master WHERE pid =? AND type='10'";
205 return array($query,array($pid));
208 //G series for form menu inc
210 $query = "SELECT * FROM `documents_legal_categories` where dlc_category_name=? and dlc_category_type=2";
211 return array($query,$data[1]);
215 $query = "SELECT * FROM documents_legal_master AS dlm WHERE dlm_subcategory <> ? and dlm_effective_date <= now() AND
216 dlm_effective_date<>? AND dlm_upload_type = '0' AND dlm_document_id Not IN (SELECT distinct(dld_master_docid) FROM documents_legal_detail WHERE
217 dld_id IS NOT NULL AND dld_pid=?)";
218 array_push($data[1],$pid);
219 return array($query,$data[1]);
223 $query = "SELECT * FROM documents_legal_master AS dlm LEFT OUTER JOIN documents_legal_detail as dld ON
224 dlm_document_id=dld_master_docid WHERE dlm_subcategory <> ? and dlm_effective_date <= now() AND dlm_effective_date<>?
225 AND dld_id IS NOT NULL AND dld_signed=? AND dld_pid=? ORDER BY dlm_effective_date DESC";
226 array_push($data[1],$pid);
227 return array($query,$data[1]);
231 $query = "SELECT * FROM documents_legal_master AS dlm JOIN documents_legal_detail as dld ON dlm_document_id=dld_master_docid
232 JOIN form_encounter as fe ON encounter=dld_encounter WHERE dlm_subcategory = ? AND dlm_effective_date <= now() AND
233 dlm_effective_date<>? AND dld_id IS NOT NULL AND dld_signed=? AND dld_signing_person=? AND dld_pid=?
234 ORDER BY dlm_effective_date DESC";
235 array_push($data[1],$pid);
236 return array($query,$data[1]);
240 $query = "SELECT * FROM documents_legal_master AS dlm JOIN documents_legal_detail as dld ON dlm_document_id=dld_master_docid
241 JOIN form_encounter as fe ON encounter=dld_encounter WHERE dlm_subcategory = ? and dlm_effective_date <= now() AND
242 dlm_effective_date<>? AND dld_id IS NOT NULL AND dld_filename != '' AND dld_pid=? GROUP BY dld_encounter,dlm_document_id
243 ORDER BY dld_id DESC";
244 array_push($data[1],$pid);
245 return array($query,$data[1]);
249 $query = "SELECT * FROM documents_legal_master AS dlm LEFT OUTER JOIN documents_legal_detail as dld ON
250 dlm_document_id=dld_master_docid WHERE dlm_subcategory <> ? and dlm_effective_date <= now() AND dlm_effective_date<>?
251 AND dld_id IS NOT NULL AND (dld_signed = ? OR dlm_upload_type = '1') AND dld_pid=? ORDER BY dlm_effective_date DESC";
252 array_push($data[1],$pid);
253 return array($query,$data[1]);
258 $query="select * from patient_data where pid=?";
259 return array($query,array($pid));
263 //PDF forms detail selected
264 $query="select * from documents_legal_master where dlm_document_id=?";
265 return array($query,$data[1]);
270 array_unshift($data[1],$pid);
271 $query="select * from documents_legal_detail where dld_pid = ? and dld_signed='3' and dld_master_docid = ?";
272 return array($query,$data[1]);
277 $query="select * from documents_legal_master where dlm_document_id=?";
278 return array($query,$data[1]);
282 // Entries to be approved demo for new patient, existing patient and only documents
283 $query="select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2' or type='3')";
284 return array($query,array($pid));
289 $query="select * from documents_legal_master WHERE dlm_document_id=?";
290 return array($query,$data[1]);
294 //Documents ready to be signed and documents unsigned
295 array_unshift($data[1],$pid);
296 $query="select * from documents_legal_detail where dld_pid=? and (dld_signed='2' or dld_signed='0') and dld_master_docid=?";
297 return array($query,$data[1]);
301 //Selection from master document for showing to patient
302 $query="select * from documents_legal_master WHERE dlm_document_name=?";
303 return array($query,$data[1]);