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_push($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]);
123 $string_query=" and pid !=?";
127 $x=array($data[1][0],$pid);
131 $x=array($data[1][0]);
133 $query="select count(*) AS count from patient_data where pubpid = ? $string_query";
134 return array($query,$x);
136 //getting DOB and SSN for verifying the duplicate patient existance
140 $string_query=" and pid !=?";
144 $x=array($data[1][0],$pid);
148 $x=array($data[1][0]);
150 $query="select ss,DOB from patient_data where DOB=? $string_query ";
151 return array($query,$x);
153 //master data for calendar from Globals
156 if($data[1][0]=='calendar_interval'||
$data[1][0]=='schedule_start'||
$data[1][0]=='schedule_end')
158 $query="select gl_value from globals where gl_name=?";
159 return array($query,$data[1]);
166 //Check whether an entry exist in the form Encounter to decide whether patient is an existing patient.
167 $query="select COUNT(*) AS cnt from form_encounter WHERE pid=?";
168 return array($query,array($pid));
172 //Existing appointments for a patient
173 array_unshift($data[1],$pid);
174 $query="select pc_eid,pc_eventDate,pc_startTime,pc_endTime,fname,lname,name,pc_apptstatus from openemr_postcalendar_events AS c,
175 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";
176 return array($query,$data[1]);
180 //Appointments pending for approval
181 array_push($data[1],$pid);
182 $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,
183 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
184 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')
185 ORDER BY approval_status, am.id desc,ad.id desc";
186 return array($query,$data[1]);
190 //patient appointment history
191 array_unshift($data[1],$pid);
192 $query="select pc_eid,pc_eventDate,pc_startTime,pc_endTime,fname,lname,name,pc_apptstatus from openemr_postcalendar_events AS c,
193 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";
194 return array($query,$data[1]);
198 //List of Service Facility
199 $query="select * from facility where service_location != 0 and id in (".add_escape_custom($data[1][0]).") order by name";
200 return array($query);
205 $query="select id, lname, fname from users WHERE authorized = 1 AND username != '' AND username NOT LIKE '%Admin%' AND active = 1
206 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) ORDER BY lname, fname";
207 return array($query);
211 //Calendar default visit time for visit category. value for Admin--->others-->calendar
212 $query="select pc_duration from openemr_postcalendar_categories WHERE pc_catid = ?";
213 return array($query,$data[1]);
217 //patient appointment
218 $query="select pc_eventDate, pc_endDate, pc_startTime, pc_duration, pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid,
219 pc_prefcatid from openemr_postcalendar_events WHERE pc_aid = ? AND ((pc_endDate >= ? AND pc_eventDate < ?) OR
220 (pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?)) AND pc_facility = ?";
221 return array($query,$data[1]);
225 //Appointments pending for approval
226 $query="select * from audit_master WHERE pid =? AND type='10'";
227 return array($query,array($pid));
230 //G series for form menu inc
232 $query = "SELECT * FROM `documents_legal_categories` where dlc_category_name=? and dlc_category_type=2";
233 return array($query,$data[1]);
237 $query = "SELECT * FROM documents_legal_master AS dlm WHERE dlm_subcategory <> ? and dlm_effective_date <= now() AND
238 dlm_effective_date<>? AND dlm_document_id Not IN (SELECT distinct(dld_master_docid) FROM documents_legal_detail WHERE
239 dld_id IS NOT NULL AND dld_pid=?)";
240 array_push($data[1],$pid);
241 return array($query,$data[1]);
245 $query = "SELECT * FROM documents_legal_master AS dlm LEFT OUTER JOIN documents_legal_detail as dld ON
246 dlm_document_id=dld_master_docid WHERE dlm_subcategory <> ? and dlm_effective_date <= now() AND dlm_effective_date<>?
247 AND dld_id IS NOT NULL AND dld_signed=? AND dld_pid=? ORDER BY dlm_effective_date DESC";
248 array_push($data[1],$pid);
249 return array($query,$data[1]);
253 $query = "SELECT * FROM documents_legal_master AS dlm JOIN documents_legal_detail as dld ON dlm_document_id=dld_master_docid
254 JOIN form_encounter as fe ON encounter=dld_encounter WHERE dlm_subcategory = ? AND dlm_effective_date <= now() AND
255 dlm_effective_date<>? AND dld_id IS NOT NULL AND dld_signed=? AND dld_signing_person=? AND dld_pid=?
256 ORDER BY dlm_effective_date DESC";
257 array_push($data[1],$pid);
258 return array($query,$data[1]);
262 $query = "SELECT * FROM documents_legal_master AS dlm JOIN documents_legal_detail as dld ON dlm_document_id=dld_master_docid
263 JOIN form_encounter as fe ON encounter=dld_encounter WHERE dlm_subcategory = ? and dlm_effective_date <= now() AND
264 dlm_effective_date<>? AND dld_id IS NOT NULL AND dld_filename != '' AND dld_pid=? GROUP BY dld_encounter,dlm_document_id
265 ORDER BY dld_id DESC";
266 array_push($data[1],$pid);
267 return array($query,$data[1]);
272 $query="select * from patient_data where pid=?";
273 return array($query,array($pid));
277 //PDF forms detail selected
278 $query="select * from documents_legal_master where dlm_document_id=?";
279 return array($query,$data[1]);
284 array_unshift($data[1],$pid);
285 $query="select * from documents_legal_detail where dld_pid = ? and dld_signed='3' and dld_master_docid = ?";
286 return array($query,$data[1]);
291 $query="select * from documents_legal_master where dlm_document_id=?";
292 return array($query,$data[1]);
296 // Entries to be approved demo for new patient, existing patient and only documents
297 $query="select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2' or type='3')";
298 return array($query,array($pid));
303 $query="select * from documents_legal_master WHERE dlm_document_id=?";
304 return array($query,$data[1]);
308 //Documents ready to be signed and documents unsigned
309 array_unshift($data[1],$pid);
310 $query="select * from documents_legal_detail where dld_pid=? and (dld_signed='2' or dld_signed='0') and dld_master_docid=?";
311 return array($query,$data[1]);
315 //Selection from master document for showing to patient
316 $query="select * from documents_legal_master WHERE dlm_document_name=?";
317 return array($query,$data[1]);