7 * @link http://www.open-emr.org
8 * @author Matthew Vita <matthewvita48@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 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 namespace OpenEMR\Services
;
17 use OpenEMR\Common\Database\QueryUtils
;
18 use Particle\Validator\Validator
;
19 use OpenEMR\Common\Uuid\UuidRegistry
;
21 // TODO: @adunsulag should we rename this to be ListOptions service since that is the table it corresponds to? The lists table is a patient issues table so this could confuse new developers
25 * Default constructor.
27 public function __construct()
31 public function validate($list)
33 $validator = new Validator();
35 $validator->required('title')->lengthBetween(2, 255);
36 $validator->required('type')->lengthBetween(2, 255);
37 $validator->required('pid')->numeric();
38 $validator->optional('diagnosis')->lengthBetween(2, 255);
39 $validator->optional('begdate')->datetime('Y-m-d H:i:s');
40 $validator->optional('enddate')->datetime('Y-m-d H:i:s');
42 return $validator->validate($list);
45 public function getAll($pid, $list_type)
47 $sql = "SELECT * FROM lists WHERE pid=? AND type=? ORDER BY date DESC";
49 $statementResults = sqlStatement($sql, array($pid, $list_type));
52 while ($row = sqlFetchArray($statementResults)) {
53 $row['uuid'] = UuidRegistry
::uuidToString($row['uuid']);
54 array_push($results, $row);
60 public function getListOptionsForLists($lists)
62 $sql = "SELECT * FROM list_options WHERE list_id IN (" . str_repeat('?,', count($lists) - 1) . "?) "
63 . " ORDER BY list_id, seq";
64 $records = QueryUtils
::fetchRecords($sql, $lists, false);
68 public function getListIds()
70 $sql = "SELECT DISTINCT list_id FROM list_options ORDER BY list_id";
71 return QueryUtils
::fetchTableColumn($sql, 'list_id', []);
74 public function getOptionsByListName($list_name, $search = array())
76 $sql = "SELECT * FROM list_options WHERE list_id = ? ";
77 $binding = [$list_name];
80 $whitelisted_columns = [
81 "option_id", "seq", "is_default", "option_value", "mapping", "notes", "codes", "activity", "edit_options", "toggle_setting_1", "toggle_setting_2", "subtype"
83 foreach ($whitelisted_columns as $column) {
84 if (!empty($search[$column])) {
85 $sql .= " AND $column = ? ";
86 $binding[] = $search[$column];
89 $sql .= " ORDER BY `seq` ";
91 $statementResults = sqlStatementThrowException($sql, $binding);
94 while ($row = sqlFetchArray($statementResults)) {
95 array_push($results, $row);
102 * Returns the list option record that was found
105 * @param array $search
106 * @return array Record
108 public function getListOption($list_id, $option_id)
110 $records = $this->getOptionsByListName($list_id, ['option_id' => $option_id]);
111 if (!empty($records)) { // should only be one record
117 public function getOne($pid, $list_type, $list_id)
119 $sql = "SELECT * FROM lists WHERE pid=? AND type=? AND id=? ORDER BY date DESC";
121 return sqlQuery($sql, array($pid, $list_type, $list_id));
124 public function insert($data)
126 $sql = " INSERT INTO lists SET";
127 $sql .= " date=NOW(),";
128 $sql .= " activity=1,";
132 $sql .= " begdate=?,";
133 $sql .= " enddate=?,";
134 $sql .= " diagnosis=?";
149 public function update($data)
151 $sql = " UPDATE lists SET";
153 $sql .= " begdate=?,";
154 $sql .= " enddate=?,";
155 $sql .= " diagnosis=?";
156 $sql .= " WHERE id=?";
170 public function delete($pid, $list_id, $list_type)
172 $sql = "DELETE FROM lists WHERE pid=? AND id=? AND type=?";
174 return sqlStatement($sql, array($pid, $list_id, $list_type));