The new changes helps serve two important aspects
[openemr.git] / myportal / soap_service / server_newpatient.php
blobc49a7912d481abb9692e498b5b93c62dc715f447
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
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.
22 //
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;
37 class newpatient{
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){
44 global $pid;
45 switch($data[0]){
46 // Entries pending for approval for Existing Patient and New Patient.
47 case 'U4':
48 $query= "select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2')";
49 return array($query,array($pid));
50 break;
51 // Entries pending for approval for documents only (no demo change).
52 case 'U5':
53 $query = " select * from audit_master where pid=? and approval_status='1' and type='3' ";
54 return array($query,array($pid));
55 break;
56 case 'J1':
57 $query = "SELECT fname FROM patient_data WHERE pid=?";
58 return array($query,array($pid));
59 break;
60 case 'P1':
61 $query= "select MAX(pid)+1 AS pid from patient_data ";
63 return array($query);
64 break;
65 //for building patient Demo
66 case 'P2':
67 $query="select * from layout_options " .
68 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
69 "ORDER BY group_name, seq";
70 return array($query);
71 break;
72 //for building patient Demo Date of Birth
73 case 'P3':
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));
76 break;
77 //for building patient Demo Employer Data
78 case 'P4':
79 $query="select * from employer_data where pid=? order by date DESC limit 0,1 ";
80 return array($query,array($pid));
81 break;
82 //for building patient Demo Insurance company details for Patient
83 case 'P5':
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]);
89 break;
90 // Entries pending for approval demo and documents.
91 case 'P6':
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));
95 break;
96 // Demo building from layout options.
97 case 'P7':
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);
103 break;
104 //Global specific application for building demo.
105 case 'P8':
106 $query="select * from globals where gl_name ='specific_application' ";
107 return array($query);
108 break;
109 //Global omit employers for building demo.
110 case 'P9':
111 $query=" select * from globals where gl_name ='omit_employers' ";
112 return array($query);
113 break;
114 //getting the password
115 case 'P18':
116 $query = "select portal_username from patient_access_offsite where portal_username =? ";
117 return array($query,$data[1]);
118 break;
120 case 'P20':
121 $x=array($data[1][0]);
122 $query="select count(*) AS count from patient_data where pubpid = ?";
123 return array($query,$x);
124 break;
125 //getting DOB and SSN for verifying the duplicate patient existance
126 case 'P21':
127 $x=array($data[1][0]);
128 $query="select ss,DOB from patient_data where DOB=?";
129 return array($query,$x);
130 break;
131 //master data for calendar from Globals
132 case 'B1':
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]);
139 else
140 return 0;
141 break;
143 case 'B4':
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));
147 break;
149 case 'B5':
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]);
155 break;
157 case 'B6':
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]);
165 break;
167 case 'B7':
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]);
173 break;
175 case 'B8':
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);
179 break;
181 case 'B9':
182 //Providers list
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);
186 break;
188 case 'B10':
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]);
192 break;
194 case 'B11';
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]);
200 break;
202 case 'B12':
203 //Appointments pending for approval
204 $query="select * from audit_master WHERE pid =? AND type='10'";
205 return array($query,array($pid));
206 break;
208 //G series for form menu inc
209 case 'G1':
210 $query = "SELECT * FROM `documents_legal_categories` where dlc_category_name=? and dlc_category_type=2";
211 return array($query,$data[1]);
212 break;
214 case 'G2':
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]);
220 break;
222 case 'G3':
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]);
228 break;
230 case 'G4':
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]);
237 break;
239 case 'G5':
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]);
246 break;
248 case 'G6':
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]);
254 break;
256 case 'F1':
257 //Patient details .
258 $query="select * from patient_data where pid=?";
259 return array($query,array($pid));
260 break;
262 case 'F2':
263 //PDF forms detail selected
264 $query="select * from documents_legal_master where dlm_document_id=?";
265 return array($query,$data[1]);
266 break;
268 case 'F3':
269 //signing
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]);
273 break;
275 case 'F6':
276 //signing
277 $query="select * from documents_legal_master where dlm_document_id=?";
278 return array($query,$data[1]);
279 break;
281 case 'F8':
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));
285 break;
287 case 'F9':
288 //signing
289 $query="select * from documents_legal_master WHERE dlm_document_id=?";
290 return array($query,$data[1]);
291 break;
293 case 'F10':
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]);
298 break;
300 case 'F12':
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]);
304 break;