forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListService.php
159 lines (133 loc) · 4.49 KB
/
ListService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* ListService
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <matthewvita48@gmail.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
* @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\Services;
use Particle\Validator\Validator;
// 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
class ListService
{
/**
* Default constructor.
*/
public function __construct()
{
}
public function validate($list)
{
$validator = new Validator();
$validator->required('title')->lengthBetween(2, 255);
$validator->required('type')->lengthBetween(2, 255);
$validator->required('pid')->numeric();
$validator->optional('diagnosis')->lengthBetween(2, 255);
$validator->required('begdate')->datetime('Y-m-d');
$validator->optional('enddate')->datetime('Y-m-d');
return $validator->validate($list);
}
public function getAll($pid, $list_type)
{
$sql = "SELECT * FROM lists WHERE pid=? AND type=? ORDER BY date DESC";
$statementResults = sqlStatement($sql, array($pid, $list_type));
$results = array();
while ($row = sqlFetchArray($statementResults)) {
array_push($results, $row);
}
return $results;
}
public function getOptionsByListName($list_name, $search = array())
{
$sql = "SELECT * FROM list_options WHERE list_id = ? ";
$binding = [$list_name];
$whitelisted_columns = [
"option_id", "seq", "is_default", "option_value", "mapping", "notes", "codes", "activity", "edit_options", "toggle_setting_1", "toggle_setting_2", "subtype"
];
foreach ($whitelisted_columns as $column) {
if (!empty($search[$column])) {
$sql .= " AND $column = ? ";
$binding[] = $search[$column];
}
}
$sql .= " ORDER BY `seq` ";
$statementResults = sqlStatementThrowException($sql, $binding);
$results = array();
while ($row = sqlFetchArray($statementResults)) {
array_push($results, $row);
}
return $results;
}
/**
* Returns the list option record that was found
* @param $list_id
* @param $option_id
* @param array $search
* @return array Record
*/
public function getListOption($list_id, $option_id)
{
$records = $this->getOptionsByListName($list_id, ['option_id' => $option_id]);
if (!empty($records)) { // should only be one record
return $records[0];
}
return null;
}
public function getOne($pid, $list_type, $list_id)
{
$sql = "SELECT * FROM lists WHERE pid=? AND type=? AND id=? ORDER BY date DESC";
return sqlQuery($sql, array($pid, $list_type, $list_id));
}
public function insert($data)
{
$sql = " INSERT INTO lists SET";
$sql .= " date=NOW(),";
$sql .= " activity=1,";
$sql .= " pid=?,";
$sql .= " type=?,";
$sql .= " title=?,";
$sql .= " begdate=?,";
$sql .= " enddate=?,";
$sql .= " diagnosis=?";
return sqlInsert(
$sql,
array(
$data['pid'],
$data['type'],
$data["title"],
$data["begdate"],
$data["enddate"],
$data["diagnosis"]
)
);
}
public function update($data)
{
$sql = " UPDATE lists SET";
$sql .= " title=?,";
$sql .= " begdate=?,";
$sql .= " enddate=?,";
$sql .= " diagnosis=?";
$sql .= " WHERE id=?";
return sqlStatement(
$sql,
array(
$data["title"],
$data["begdate"],
$data["enddate"],
$data["diagnosis"],
$data["id"]
)
);
}
public function delete($pid, $list_id, $list_type)
{
$sql = "DELETE FROM lists WHERE pid=? AND id=? AND type=?";
return sqlStatement($sql, array($pid, $list_id, $list_type));
}
}