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/>.
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');
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();
44 $result = $appTable->zQuery($query, array($pid));
46 foreach ($result as $row) {
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();
64 WHERE pid = ? AND TYPE = 'medical_problem'";
65 $result = $appTable->zQuery($query, array($pid));
67 foreach ($result as $row) {
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();
85 WHERE pid = ? AND TYPE = 'allergy'";
86 $result = $appTable->zQuery($query, array($pid));
88 foreach ($result as $row) {
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();
106 WHERE patient_id = ?";
107 $result = $appTable->zQuery($query, array($pid));
109 foreach ($result as $row) {
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));
138 foreach ($result as $row) {
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,
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));
172 foreach ($result as $row) {
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();
190 WHERE pid = ? AND activity=?";
191 $result = $appTable->zQuery($query, array($pid, 1));
193 foreach ($result as $row) {
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();
212 ORDER BY id DESC LIMIT 1";
213 $result = $appTable->zQuery($query, array($pid));
215 foreach ($result as $row) {
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
234 ON form_encounter.provider_id=u.id
236 $result = $appTable->zQuery($query, array($pid));
238 foreach ($result as $row) {
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();
256 WHERE pid=? AND code_type=?";
257 $result = $appTable->zQuery($query, array($pid, 'CPT4'));
259 foreach ($result as $row) {
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();
277 WHERE pid = ? AND activity=?";
278 $result = $appTable->zQuery($query, array($pid, 1));
280 foreach ($result as $row) {
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();
297 FROM form_functional_cognitive_status
298 WHERE pid = ? AND activity=?";
299 $result = $appTable->zQuery($query, array($pid, 1));
301 foreach ($result as $row) {