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;
38 //this will return the query string along with the parameter array, according to the case case.
39 //actual execution is done in the select_query function in Server_side
41 private function getPid($id){
42 $row = sqlQuery("SELECT pid FROM audit_master WHERE id=? AND approval_status=1",array($id));
46 public function query_formation($data){
50 $query="select * from audit_master where approval_status='1' and (type='1' or type='2' or type='3') ";
55 $query=" select * from audit_master where approval_status='1' and (type='1' or type='2' or type='3') order by id limit ?,1";
56 return array($query,array($data[1][0]-1));
60 $pid = $this->getPid($data[1]);
61 $query="SELECT * FROM documents_legal_master AS dlm " .
62 "LEFT OUTER JOIN documents_legal_detail as dld ON dlm_document_id=dld_master_docid WHERE " .
63 " dlm_subcategory not in (SELECT dlc_id FROM `documents_legal_categories` where dlc_category_name='Layout Signed'".
64 " and dlc_category_type=2) and dlm_effective_date <= now() AND dlm_effective_date<>'0000-00-00 00:00:00' " .
65 "AND dld_id IS NOT NULL AND dld_pid=? and dld_signed='0' " .
66 "ORDER BY dlm_effective_date DESC";
67 return array($query,array($pid));
70 // Entries pending for approval for Existing Patient and New Patient.
72 $pid = $this->getPid($data[1]);
73 $query= "select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2')";
74 return array($query,array($pid));
77 // Entries pending for approval for documents only (no demo change).
79 $pid = $this->getPid($data[1]);
80 $query = " select * from audit_master where pid=? and approval_status='1' and type='3' ";
81 return array($query,array($pid));
85 $query= "select MAX(pid)+1 AS pid from patient_data ";
90 //for building patient Demo
92 $query="select * from layout_options " .
93 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
94 "ORDER BY group_name, seq";
98 //for building patient Demo Date of Birth
100 $pid = $this->getPid($data[1]);
101 $query="select *, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD from patient_data where pid=? order by date DESC limit 0,1 ";
102 return array($query,array($pid));
105 //for building patient Demo Employer Data
107 $pid = $this->getPid($data[1]);
108 $query="select * from employer_data where pid=? order by date DESC limit 0,1 ";
109 return array($query,array($pid));
112 //for building patient Demo Insurance company details for Patient
114 $data[1][0] = $this->getPid($data[1][0]);
115 $query=" select insd.*, ic.name as provider_name from insurance_data as insd " .
116 "left join insurance_companies as ic on ic.id = insd.provider " .
117 "where pid = ? and type =? order by date DESC limit 1 ";
118 return array($query,$data[1]);
121 // Entries pending for approval demo and documents.
123 $pid = $this->getPid($data[1]);
124 $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'
125 and (am.type='1' or am.type='2' or am.type='3') order by ad.id";
126 return array($query,array($pid));
128 // Demo building from layout options.
131 $query=" select * from layout_options WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
132 " ORDER BY group_name, seq";
133 return array($query);
136 //Global specific application for building demo.
138 $query="select * from globals where gl_name ='specific_application' ";
139 return array($query);
142 //Global omit employers for building demo.
144 $query=" select * from globals where gl_name ='omit_employers' ";
145 return array($query);
149 //patient appointment
150 $query="select * from facility where service_location != 0 order by name";
151 return array($query);
156 $query="select *,audit_master.id as audit_master_id from audit_master,patient_data where audit_master.pid=patient_data.pid and
157 audit_master.approval_status='1' order by audit_master.id";
158 return array($query);
163 $query="select * from facility";
164 return array($query);
169 $query="select id,fname,lname,mname from users where authorized=1";
170 return array($query);
175 $query="select * from audit_master,patient_data,audit_details where audit_master.pid=patient_data.pid and
176 audit_master.approval_status='1' and audit_master.type = 10 and audit_master_id=audit_master.id order by audit_master.id";
177 return array($query);
182 $query="select * from audit_master where audit_master.id=?";
183 $row = sqlQuery($query,$data[1]);
184 return array("SELECT * FROM documents_legal_detail join documents_legal_master on dld_master_docid=dlm_document_id WHERE dld_pid=? and dld_signed='0'
185 and dlm_document_id=dld_master_docid and dlm_subcategory not in (SELECT dlc_id FROM `documents_legal_categories`
186 where dlc_category_name='Layout Signed' and dlc_category_type=2)",array($row['pid']));
191 $query="select * from documents_legal_categories where dlc_category_name=? and dlc_category_type=2";
192 return array($query,$data[1]);
197 $query="select * from documents_legal_master LEFT OUTER JOIN documents_legal_categories ON dlm_category=dlc_id WHERE
198 dlm_subcategory <> ? and dlm_filename<>''";
199 return array($query,$data[1]);
204 $pid = $this->getPid($data[1]);
205 $query="select * from audit_master where pid=? and approval_status='1' and (type='1' or type='2' or type='3')";
206 return array($query,array($pid));
210 //Selection from master document for showing to patient
211 $query="select * from documents_legal_master WHERE dlm_document_name=?";
212 return array($query,$data[1]);