6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
11 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 namespace OpenEMR\Services
;
19 use Particle\Validator\Validator
;
21 class EncounterService
25 * Default constructor.
27 public function __construct()
31 public function validateSoapNote($soapNote)
33 $validator = new Validator();
35 $validator->optional('subjective')->lengthBetween(2, 65535);
36 $validator->optional('objective')->lengthBetween(2, 65535);
37 $validator->optional('assessment')->lengthBetween(2, 65535);
38 $validator->optional('plan')->lengthBetween(2, 65535);
40 return $validator->validate($soapNote);
43 public function validateVital($vital)
45 $validator = new Validator();
47 $validator->optional('temp_method')->lengthBetween(1, 255);
48 $validator->optional('note')->lengthBetween(1, 255);
49 $validator->optional('BMI_status')->lengthBetween(1, 255);
50 $validator->optional('bps')->numeric();
51 $validator->optional('bpd')->numeric();
52 $validator->optional('weight')->numeric();
53 $validator->optional('height')->numeric();
54 $validator->optional('temperature')->numeric();
55 $validator->optional('pulse')->numeric();
56 $validator->optional('respiration')->numeric();
57 $validator->optional('BMI')->numeric();
58 $validator->optional('waist_circ')->numeric();
59 $validator->optional('head_circ')->numeric();
60 $validator->optional('oxygen_saturation')->numeric();
62 return $validator->validate($vital);
65 public function getEncountersForPatient($pid)
67 $sql = "SELECT fe.encounter as id,
90 fa.name AS billing_facility_name
91 FROM form_encounter as fe
92 LEFT JOIN openemr_postcalendar_categories as opc
93 ON opc.pc_catid = fe.pc_catid
94 LEFT JOIN facility as fa ON fa.id = fe.billing_facility
99 $statementResults = sqlStatement($sql, array($pid));
102 while ($row = sqlFetchArray($statementResults)) {
103 array_push($results, $row);
109 public function getEncountersBySearch($search)
111 $sqlBindArray = array();
113 $sql = "SELECT fe.encounter as id,
124 fe.last_level_billed,
125 fe.last_level_closed,
136 fa.name AS billing_facility_name
137 FROM form_encounter as fe
138 LEFT JOIN openemr_postcalendar_categories as opc
139 ON opc.pc_catid = fe.pc_catid
140 LEFT JOIN facility as fa ON fa.id = fe.billing_facility";
142 if ($search['pid'] ||
$search['provider_id']) {
145 $whereClauses = array();
146 if ($search['pid']) {
147 array_push($whereClauses, "pid=?");
148 array_push($sqlBindArray, $search['pid']);
150 if ($search['provider_id']) {
151 array_push($whereClauses, "provider_id=?");
152 array_push($sqlBindArray, $search['provider_id']);
155 $sql .= implode(" AND ", $whereClauses);
159 $sql .= " ORDER BY fe.id DESC";
160 $statementResults = sqlStatement($sql, $sqlBindArray);
163 while ($row = sqlFetchArray($statementResults)) {
164 array_push($results, $row);
170 public function getEncounter($eid)
172 $sql = "SELECT fe.encounter as id,
182 fe.last_level_billed,
183 fe.last_level_closed,
194 fa.name AS billing_facility_name
195 FROM form_encounter as fe
196 LEFT JOIN openemr_postcalendar_categories as opc
197 ON opc.pc_catid = fe.pc_catid
198 LEFT JOIN facility as fa ON fa.id = fe.billing_facility
203 return sqlQuery($sql, array($eid));
206 // @todo recm changing routes
207 // encounter id is system unique so pid is not needed
208 // resources should be independent where possible
209 public function getEncounterForPatient($pid, $eid)
211 $sql = "SELECT fe.encounter as id,
221 fe.last_level_billed,
222 fe.last_level_closed,
233 fa.name AS billing_facility_name
234 FROM form_encounter as fe
235 LEFT JOIN openemr_postcalendar_categories as opc
236 ON opc.pc_catid = fe.pc_catid
237 LEFT JOIN facility as fa ON fa.id = fe.billing_facility
238 WHERE pid=? and fe.encounter=?
242 return sqlQuery($sql, array($pid, $eid));
245 public function insertSoapNote($pid, $eid, $data)
247 $soapSql = " INSERT INTO form_soap SET";
248 $soapSql .= " date=NOW(),";
249 $soapSql .= " activity=1,";
250 $soapSql .= " pid=?,";
251 $soapSql .= " subjective=?,";
252 $soapSql .= " objective=?,";
253 $soapSql .= " assessment=?,";
254 $soapSql .= " plan=?";
256 $soapResults = sqlInsert(
271 $formSql = "INSERT INTO forms SET";
272 $formSql .= " date=NOW(),";
273 $formSql .= " encounter=?,";
274 $formSql .= " form_name='SOAP',";
275 $formSql .= " authorized='1',";
276 $formSql .= " form_id=?,";
277 $formSql .= " pid=?,";
278 $formSql .= " formdir='soap'";
280 $formResults = sqlInsert(
289 return array($soapResults, $formResults);
292 public function updateSoapNote($pid, $eid, $sid, $data)
294 $sql = " UPDATE form_soap SET";
295 $sql .= " date=NOW(),";
296 $sql .= " activity=1,";
298 $sql .= " subjective=?,";
299 $sql .= " objective=?,";
300 $sql .= " assessment=?,";
302 $sql .= " where id=?";
317 public function updateVital($pid, $eid, $vid, $data)
319 $sql = " UPDATE form_vitals SET";
320 $sql .= " date=NOW(),";
321 $sql .= " activity=1,";
325 $sql .= " weight=?,";
326 $sql .= " height=?,";
327 $sql .= " temperature=?,";
328 $sql .= " temp_method=?,";
330 $sql .= " respiration=?,";
332 $sql .= " waist_circ=?,";
333 $sql .= " head_circ=?,";
334 $sql .= " oxygen_saturation=?";
335 $sql .= " where id=?";
345 $data["temperature"],
346 $data["temp_method"],
348 $data["respiration"],
352 $data["oxygen_saturation"],
358 public function insertVital($pid, $eid, $data)
360 $vitalSql = " INSERT INTO form_vitals SET";
361 $vitalSql .= " date=NOW(),";
362 $vitalSql .= " activity=1,";
363 $vitalSql .= " pid=?,";
364 $vitalSql .= " bps=?,";
365 $vitalSql .= " bpd=?,";
366 $vitalSql .= " weight=?,";
367 $vitalSql .= " height=?,";
368 $vitalSql .= " temperature=?,";
369 $vitalSql .= " temp_method=?,";
370 $vitalSql .= " pulse=?,";
371 $vitalSql .= " respiration=?,";
372 $vitalSql .= " note=?,";
373 $vitalSql .= " waist_circ=?,";
374 $vitalSql .= " head_circ=?,";
375 $vitalSql .= " oxygen_saturation=?";
377 $vitalResults = sqlInsert(
385 $data["temperature"],
386 $data["temp_method"],
388 $data["respiration"],
392 $data["oxygen_saturation"]
396 if (!$vitalResults) {
400 $formSql = "INSERT INTO forms SET";
401 $formSql .= " date=NOW(),";
402 $formSql .= " encounter=?,";
403 $formSql .= " form_name='Vitals',";
404 $formSql .= " authorized='1',";
405 $formSql .= " form_id=?,";
406 $formSql .= " pid=?,";
407 $formSql .= " formdir='vitals'";
409 $formResults = sqlInsert(
418 return array($vitalResults, $formResults);
421 public function getVitals($pid, $eid)
423 $sql = " SELECT fs.*";
424 $sql .= " FROM forms fo";
425 $sql .= " JOIN form_vitals fs on fs.id = fo.form_id";
426 $sql .= " WHERE fo.encounter = ?";
427 $sql .= " AND fs.pid = ?";
429 $statementResults = sqlStatement($sql, array($eid, $pid));
432 while ($row = sqlFetchArray($statementResults)) {
433 array_push($results, $row);
439 public function getVital($pid, $eid, $vid)
441 $sql = " SELECT fs.*";
442 $sql .= " FROM forms fo";
443 $sql .= " JOIN form_vitals fs on fs.id = fo.form_id";
444 $sql .= " WHERE fo.encounter = ?";
445 $sql .= " AND fs.id = ?";
446 $sql .= " AND fs.pid = ?";
448 return sqlQuery($sql, array($eid, $vid, $pid));
451 public function getSoapNotes($pid, $eid)
453 $sql = " SELECT fs.*";
454 $sql .= " FROM forms fo";
455 $sql .= " JOIN form_soap fs on fs.id = fo.form_id";
456 $sql .= " WHERE fo.encounter = ?";
457 $sql .= " AND fs.pid = ?";
459 $statementResults = sqlStatement($sql, array($eid, $pid));
462 while ($row = sqlFetchArray($statementResults)) {
463 array_push($results, $row);
469 public function getSoapNote($pid, $eid, $sid)
471 $sql = " SELECT fs.*";
472 $sql .= " FROM forms fo";
473 $sql .= " JOIN form_soap fs on fs.id = fo.form_id";
474 $sql .= " WHERE fo.encounter = ?";
475 $sql .= " AND fs.id = ?";
476 $sql .= " AND fs.pid = ?";
478 return sqlQuery($sql, array($eid, $sid, $pid));