.inc files migration to .inc.php (#5897)
[openemr.git] / src / Services / FormService.php
blob722220b077c0ffed319bbdc8b92916fb7869455e
1 <?php
3 /**
4 * FormService refactored getFormByEncounter
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author <Unknown> Authorship was not listed in encounter.inc.php
9 * @author Stephen Nielson <stephen@nielson.org>
10 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 namespace OpenEMR\Services;
16 class FormService
18 public function getFormByEncounter(
19 $attendant_id,
20 $encounter,
21 $cols = "form_id, form_name",
22 $name = "",
23 $orderby = "FIND_IN_SET(formdir,'vitals') DESC, date DESC"
24 ) {
26 global $attendant_type;
27 $arraySqlBind = array();
28 $sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('forms')) . " from forms where encounter = ? and deleted = 0 ";
29 array_push($arraySqlBind, $encounter);
30 if (!empty($name)) {
31 $sql .= "and form_name=? ";
32 array_push($arraySqlBind, $name);
35 if ($attendant_type == 'pid') {
36 $sql .= " and pid=? and therapy_group_id IS NULL ";
37 } else {
38 $sql .= " and therapy_group_id = ? and pid IS NULL ";
41 array_push($arraySqlBind, $attendant_id);
43 // Default $orderby puts vitals first in the list, and newpatient last:
44 $sql .= "ORDER BY $orderby";
46 $res = sqlStatement($sql, $arraySqlBind);
48 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
49 $all[$iter] = $row;
52 return $all;