update header function to allow opting out of auto loaded assets (#1358)
[openemr.git] / portal / lib / section_fetch.class.php
blobc3956620d99928d3ccaff379df04cffd0ff5af52
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @package OpenEMR
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
23 //namespace OnsitePortal;
25 require_once(dirname(__file__) . "/../../custom/code_types.inc.php");
28 require_once(dirname(__file__) .'/appsql.class.php');
29 class FetchSection
33 * Fetch the current demographics data of a patient from patient_data table
35 * @param pid Integer Patient ID
36 * @return records Array current patient data
38 public function getDemographicsCurrent($pid)
40 $appTable = new ApplicationTable();
41 $query = "SELECT *
42 FROM patient_data
43 WHERE pid = ?";
44 $result = $appTable->zQuery($query, array($pid));
45 $records = array();
46 foreach ($result as $row) {
47 $records[] = $row;
50 return $records;
54 * Fetch the current Problems of a patient from lists table
56 * @param pid Integer patient id
57 * @return records Array list of problems
59 public function getProblems($pid)
61 $appTable = new ApplicationTable();
62 $query = "SELECT *
63 FROM lists
64 WHERE pid = ? AND TYPE = 'medical_problem'";
65 $result = $appTable->zQuery($query, array($pid));
66 $records = array();
67 foreach ($result as $row) {
68 $records[] = $row;
71 return $records;
75 * Fetch the current Allergies of a patient from lists table
77 * @param pid Integer patient id
78 * @return records Array list of allergies
80 public function getAllergies($pid)
82 $appTable = new ApplicationTable();
83 $query = "SELECT *
84 FROM lists
85 WHERE pid = ? AND TYPE = 'allergy'";
86 $result = $appTable->zQuery($query, array($pid));
87 $records = array();
88 foreach ($result as $row) {
89 $records[] = $row;
92 return $records;
96 * Fetch the current Medications of a patient from prescriptions table
98 * @param pid Integer patient id
99 * @return records Array list of medications
101 public function getMedications($pid)
103 $appTable = new ApplicationTable();
104 $query = "SELECT *
105 FROM prescriptions
106 WHERE patient_id = ?";
107 $result = $appTable->zQuery($query, array($pid));
108 $records = array();
109 foreach ($result as $row) {
110 $records[] = $row;
113 return $records;
117 * Fetch the current Immunizations of a patient from immunizations table
119 * @param pid Integer patient id
120 * @return records Array list of immunizations
122 public function getImmunizations($pid)
124 $appTable = new ApplicationTable();
125 $query = "SELECT im.*, cd.code_text, DATE(administered_date) AS administered_date,
126 DATE_FORMAT(administered_date,'%m/%d/%Y') AS administered_formatted, lo.title as route_of_administration,
127 u.title, u.fname, u.mname, u.lname, u.npi, u.street, u.streetb, u.city, u.state, u.zip, u.phonew1,
128 f.name, f.phone, lo.notes as route_code
129 FROM immunizations AS im
130 LEFT JOIN codes AS cd ON cd.code = im.cvx_code
131 JOIN code_types AS ctype ON ctype.ct_key = 'CVX' AND ctype.ct_id=cd.code_type
132 LEFT JOIN list_options AS lo ON lo.list_id = 'drug_route' AND lo.option_id = im.route
133 LEFT JOIN users AS u ON u.id = im.administered_by_id
134 LEFT JOIN facility AS f ON f.id = u.facility_id
135 WHERE im.patient_id=?";
136 $result = $appTable->zQuery($query, array($pid));
137 $records = array();
138 foreach ($result as $row) {
139 $records[] = $row;
142 return $records;
146 * Fetch the currect Lab Results of a patient
148 * @param pid Integer patient id
149 * @return records Array list of lab results
151 public function getLabResults($pid)
153 $appTable = new ApplicationTable();
154 $query = "SELECT CONCAT_WS('',po.procedure_order_id,poc.`procedure_order_seq`) AS tcode,
155 prs.result AS result_value,
156 prs.units, prs.range,
157 poc.procedure_name AS order_title,
158 prs.result_code as result_code,
159 prs.result_text as result_desc,
160 po.date_ordered,
161 prs.date AS result_time,
162 prs.abnormal AS abnormal_flag,
163 prs.procedure_result_id AS result_id
164 FROM procedure_order AS po
165 JOIN procedure_order_code AS poc ON poc.`procedure_order_id`=po.`procedure_order_id`
166 JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id
167 AND pr.`procedure_order_seq`=poc.`procedure_order_seq`
168 JOIN procedure_result AS prs ON prs.procedure_report_id = pr.procedure_report_id
169 WHERE po.patient_id = ? AND prs.result NOT IN ('DNR','TNP')";
170 $result = $appTable->zQuery($query, array($pid));
171 $records = array();
172 foreach ($result as $row) {
173 $records[] = $row;
176 return $records;
180 * Fetch the current Vitals of a patient from form_vitals table
182 * @param pid Integer patient id
183 * @return records Array list of vitals
185 public function getVitals($pid)
187 $appTable = new ApplicationTable();
188 $query = "SELECT *
189 FROM form_vitals
190 WHERE pid = ? AND activity=?";
191 $result = $appTable->zQuery($query, array($pid, 1));
192 $records = array();
193 foreach ($result as $row) {
194 $records[] = $row;
197 return $records;
201 * Fetch the social history of a patient from history_data table
203 * @param pid Integer patient id
204 * @return records Array history data
206 public function getSocialHistory($pid)
208 $appTable = new ApplicationTable();
209 $query = "SELECT *
210 FROM history_data
211 WHERE pid=?
212 ORDER BY id DESC LIMIT 1";
213 $result = $appTable->zQuery($query, array($pid));
214 $records = array();
215 foreach ($result as $row) {
216 $records[] = $row;
219 return $records;
223 * Fetch the encounter data of a patient from form_encounter table
225 * @param pid Integer patient id
226 * @return records Array encounter data
228 public function getEncounterData($pid)
230 $appTable = new ApplicationTable();
231 $query = "SELECT form_encounter.*,u.fname AS provider_name
232 FROM form_encounter
233 LEFT JOIN users AS u
234 ON form_encounter.provider_id=u.id
235 WHERE pid = ?";
236 $result = $appTable->zQuery($query, array($pid));
237 $records = array();
238 foreach ($result as $row) {
239 $records[] = $row;
242 return $records;
246 * Fetch the billing data of a patient from billing table
248 * @param pid Integer patient id
249 * @return records Array billing data
251 public function getProcedure($pid)
253 $appTable = new ApplicationTable();
254 $query = "SELECT *
255 FROM billing
256 WHERE pid=? AND code_type=?";
257 $result = $appTable->zQuery($query, array($pid, 'CPT4'));
258 $records = array();
259 foreach ($result as $row) {
260 $records[] = $row;
263 return $records;
267 * Fetch the current Care Plan of a patient from form_care_plan table
269 * @param pid Integer patient id
270 * @return records Array list of Care Plans
272 public function getCarePlan($pid)
274 $appTable = new ApplicationTable();
275 $query = "SELECT *
276 FROM form_care_plan
277 WHERE pid = ? AND activity=?";
278 $result = $appTable->zQuery($query, array($pid, 1));
279 $records = array();
280 foreach ($result as $row) {
281 $records[] = $row;
284 return $records;
288 * Fetch the current Functional Cognitive Status of a patient from form_functional_cognitive_status table
290 * @param pid Integer patient id
291 * @return records Array list of Functional Cognitive Status
293 public function getFunctionalCognitiveStatus($pid)
295 $appTable = new ApplicationTable();
296 $query = "SELECT *
297 FROM form_functional_cognitive_status
298 WHERE pid = ? AND activity=?";
299 $result = $appTable->zQuery($query, array($pid, 1));
300 $records = array();
301 foreach ($result as $row) {
302 $records[] = $row;
305 return $records;