Secure SOAP APIs to support third party patient portals. Contributed
[openemr.git] / myportal / soap_service / server_newpatient.php
blob6436e01b9475e46df500dac3763c37764789923d
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_push($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 if($data[1][1]>0)
123 $string_query=" and pid !=?";
125 if($string_query)
127 $x=array($data[1][0],$pid);
129 else
131 $x=array($data[1][0]);
133 $query="select count(*) AS count from patient_data where pubpid = ? $string_query";
134 return array($query,$x);
135 break;
136 //getting DOB and SSN for verifying the duplicate patient existance
137 case 'P21':
138 if($data[1][1]>0)
140 $string_query=" and pid !=?";
142 if($string_query)
144 $x=array($data[1][0],$pid);
146 else
148 $x=array($data[1][0]);
150 $query="select ss,DOB from patient_data where DOB=? $string_query ";
151 return array($query,$x);
152 break;
153 //master data for calendar from Globals
154 case 'B1':
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]);
161 else
162 return 0;
163 break;
165 case 'B4':
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));
169 break;
171 case 'B5':
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]);
177 break;
179 case 'B6':
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]);
187 break;
189 case 'B7':
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]);
195 break;
197 case 'B8':
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);
201 break;
203 case 'B9':
204 //Providers list
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);
208 break;
210 case 'B10':
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]);
214 break;
216 case 'B11';
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]);
222 break;
224 case 'B12':
225 //Appointments pending for approval
226 $query="select * from audit_master WHERE pid =? AND type='10'";
227 return array($query,array($pid));
228 break;
230 //G series for form menu inc
231 case 'G1':
232 $query = "SELECT * FROM `documents_legal_categories` where dlc_category_name=? and dlc_category_type=2";
233 return array($query,$data[1]);
234 break;
236 case 'G2':
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]);
242 break;
244 case 'G3':
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]);
250 break;
252 case 'G4':
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]);
259 break;
261 case 'G5':
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]);
268 break;
270 case 'F1':
271 //Patient details .
272 $query="select * from patient_data where pid=?";
273 return array($query,array($pid));
274 break;
276 case 'F2':
277 //PDF forms detail selected
278 $query="select * from documents_legal_master where dlm_document_id=?";
279 return array($query,$data[1]);
280 break;
282 case 'F3':
283 //signing
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]);
287 break;
289 case 'F6':
290 //signing
291 $query="select * from documents_legal_master where dlm_document_id=?";
292 return array($query,$data[1]);
293 break;
295 case 'F8':
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));
299 break;
301 case 'F9':
302 //signing
303 $query="select * from documents_legal_master WHERE dlm_document_id=?";
304 return array($query,$data[1]);
305 break;
307 case 'F10':
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]);
312 break;
314 case 'F12':
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]);
318 break;