random patient generator updates and ccda import php8 and other misc stuff (#4495)
[openemr.git] / portal / lib / section_fetch.class.php
blob355ee3dae475a3a30b005c25824479490f5285ca
1 <?php
3 /**
4 * section_fetch.class.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @copyright Copyright (c) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 //namespace OnsitePortal;
15 require_once(dirname(__file__) . "/../../custom/code_types.inc.php");
18 require_once(dirname(__file__) . '/appsql.class.php');
19 class FetchSection
23 * Fetch the current demographics data of a patient from patient_data table
25 * @param pid Integer Patient ID
26 * @return records Array current patient data
28 public function getDemographicsCurrent($pid)
30 $appTable = new ApplicationTable();
31 $query = "SELECT *
32 FROM patient_data
33 WHERE pid = ?";
34 $result = $appTable->zQuery($query, array($pid));
35 $records = array();
36 foreach ($result as $row) {
37 $records[] = $row;
40 return $records;
44 * Fetch the current Problems of a patient from lists table
46 * @param pid Integer patient id
47 * @return records Array list of problems
49 public function getProblems($pid)
51 $appTable = new ApplicationTable();
52 $query = "SELECT *
53 FROM lists
54 WHERE pid = ? AND TYPE = 'medical_problem'";
55 $result = $appTable->zQuery($query, array($pid));
56 $records = array();
57 foreach ($result as $row) {
58 $records[] = $row;
61 return $records;
65 * Fetch the current Allergies of a patient from lists table
67 * @param pid Integer patient id
68 * @return records Array list of allergies
70 public function getAllergies($pid)
72 $appTable = new ApplicationTable();
73 $query = "SELECT *
74 FROM lists
75 WHERE pid = ? AND TYPE = 'allergy'";
76 $result = $appTable->zQuery($query, array($pid));
77 $records = array();
78 foreach ($result as $row) {
79 $records[] = $row;
82 return $records;
86 * Fetch the current Medications of a patient from prescriptions table
88 * @param pid Integer patient id
89 * @return records Array list of medications
91 public function getMedications($pid)
93 $appTable = new ApplicationTable();
94 $query = "SELECT *
95 FROM prescriptions
96 WHERE patient_id = ?";
97 $result = $appTable->zQuery($query, array($pid));
98 $records = array();
99 foreach ($result as $row) {
100 $records[] = $row;
103 return $records;
107 * Fetch the current Immunizations of a patient from immunizations table
109 * @param pid Integer patient id
110 * @return records Array list of immunizations
112 public static function getImmunizations($pid)
114 $appTable = new ApplicationTable();
115 $query = "SELECT im.*, cd.code_text, DATE(administered_date) AS administered_date,
116 DATE_FORMAT(administered_date,'%m/%d/%Y') AS administered_formatted, lo.title as route_of_administration,
117 u.title, u.fname, u.mname, u.lname, u.npi, u.street, u.streetb, u.city, u.state, u.zip, u.phonew1,
118 f.name, f.phone, lo.notes as route_code
119 FROM immunizations AS im
120 LEFT JOIN codes AS cd ON cd.code = im.cvx_code
121 JOIN code_types AS ctype ON ctype.ct_key = 'CVX' AND ctype.ct_id=cd.code_type
122 LEFT JOIN list_options AS lo ON lo.list_id = 'drug_route' AND lo.option_id = im.route
123 LEFT JOIN users AS u ON u.id = im.administered_by_id
124 LEFT JOIN facility AS f ON f.id = u.facility_id
125 WHERE im.patient_id=?";
126 $result = $appTable->zQuery($query, array($pid));
127 $records = array();
128 foreach ($result as $row) {
129 $records[] = $row;
132 return $records;
136 * Fetch the currect Lab Results of a patient
138 * @param pid Integer patient id
139 * @return records Array list of lab results
141 public function getLabResults($pid)
143 $appTable = new ApplicationTable();
144 $query = "SELECT CONCAT_WS('',po.procedure_order_id,poc.`procedure_order_seq`) AS tcode,
145 prs.result AS result_value,
146 prs.units, prs.range,
147 poc.procedure_name AS order_title,
148 prs.result_code as result_code,
149 prs.result_text as result_desc,
150 po.date_ordered,
151 prs.date AS result_time,
152 prs.abnormal AS abnormal_flag,
153 prs.procedure_result_id AS result_id
154 FROM procedure_order AS po
155 JOIN procedure_order_code AS poc ON poc.`procedure_order_id`=po.`procedure_order_id`
156 JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id
157 AND pr.`procedure_order_seq`=poc.`procedure_order_seq`
158 JOIN procedure_result AS prs ON prs.procedure_report_id = pr.procedure_report_id
159 WHERE po.patient_id = ? AND prs.result NOT IN ('DNR','TNP')";
160 $result = $appTable->zQuery($query, array($pid));
161 $records = array();
162 foreach ($result as $row) {
163 $records[] = $row;
166 return $records;
170 * Fetch the current Vitals of a patient from form_vitals table
172 * @param pid Integer patient id
173 * @return records Array list of vitals
175 public function getVitals($pid)
177 $appTable = new ApplicationTable();
178 $query = "SELECT *
179 FROM form_vitals
180 WHERE pid = ? AND activity=?";
181 $result = $appTable->zQuery($query, array($pid, 1));
182 $records = array();
183 foreach ($result as $row) {
184 $records[] = $row;
187 return $records;
191 * Fetch the social history of a patient from history_data table
193 * @param pid Integer patient id
194 * @return records Array history data
196 public function getSocialHistory($pid)
198 $appTable = new ApplicationTable();
199 $query = "SELECT *
200 FROM history_data
201 WHERE pid=?
202 ORDER BY id DESC LIMIT 1";
203 $result = $appTable->zQuery($query, array($pid));
204 $records = array();
205 foreach ($result as $row) {
206 $records[] = $row;
209 return $records;
213 * Fetch the encounter data of a patient from form_encounter table
215 * @param pid Integer patient id
216 * @return records Array encounter data
218 public function getEncounterData($pid)
220 $appTable = new ApplicationTable();
221 $query = "SELECT form_encounter.*,u.fname AS provider_name
222 FROM form_encounter
223 LEFT JOIN users AS u
224 ON form_encounter.provider_id=u.id
225 WHERE pid = ?";
226 $result = $appTable->zQuery($query, array($pid));
227 $records = array();
228 foreach ($result as $row) {
229 $records[] = $row;
232 return $records;
236 * Fetch the billing data of a patient from billing table
238 * @param pid Integer patient id
239 * @return records Array billing data
241 public function getProcedure($pid)
243 $appTable = new ApplicationTable();
244 $query = "SELECT *
245 FROM billing
246 WHERE pid=? AND code_type=?";
247 $result = $appTable->zQuery($query, array($pid, 'CPT4'));
248 $records = array();
249 foreach ($result as $row) {
250 $records[] = $row;
253 return $records;
257 * Fetch the current Care Plan of a patient from form_care_plan table
259 * @param pid Integer patient id
260 * @return records Array list of Care Plans
262 public function getCarePlan($pid)
264 $appTable = new ApplicationTable();
265 $query = "SELECT *
266 FROM form_care_plan
267 WHERE pid = ? AND activity=?";
268 $result = $appTable->zQuery($query, array($pid, 1));
269 $records = array();
270 foreach ($result as $row) {
271 $records[] = $row;
274 return $records;
278 * Fetch the current Functional Cognitive Status of a patient from form_functional_cognitive_status table
280 * @param pid Integer patient id
281 * @return records Array list of Functional Cognitive Status
283 public function getFunctionalCognitiveStatus($pid)
285 $appTable = new ApplicationTable();
286 $query = "SELECT *
287 FROM form_functional_cognitive_status
288 WHERE pid = ? AND activity=?";
289 $result = $appTable->zQuery($query, array($pid, 1));
290 $records = array();
291 foreach ($result as $row) {
292 $records[] = $row;
295 return $records;