revert attr() in path that was breaking admin calendar
[openemr.git] / services / FacilityService.php
blob8fa610bc359773ed1bbf78bd73f8e351affb6ead
1 <?php
2 /**
3 * FacilityService
5 * Copyright (C) 2017 Matthew Vita <matthewvita48@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Matthew Vita <matthewvita48@gmail.com>
20 * @link http://www.open-emr.org
23 namespace OpenEMR\Services;
25 use OpenEMR\Common\Utils\QueryUtils;
27 class FacilityService
29 /**
30 * Default constructor.
32 public function __construct()
36 public function getAll()
38 return $this->get(array("order" => "ORDER BY FAC.name ASC"));
41 public function getPrimaryBusinessEntity($options = null)
43 if (!empty($options) && !empty($options["useLegacyImplementation"])) {
44 return $this->getPrimaryBusinessEntityLegacy();
47 $args = array(
48 "where" => "WHERE FAC.primary_business_entity = 1",
49 "data" => null,
50 "limit" => 1
53 if (!empty($options) && !empty($options["excludedId"])) {
54 $args["where"] .= " AND FAC.id != ?";
55 $args["data"] = $options["excludedId"];
56 return $this->get($args);
59 return $this->get($args);
62 public function getAllServiceLocations($options = null)
64 $args = array(
65 "where" => null,
66 "order" => "ORDER BY FAC.name ASC"
69 if (!empty($options) && !empty($options["orderField"])) {
70 $args["order"] = "ORDER BY FAC." . escape_sql_column_name($options["orderField"], array("facility")) . " ASC";
73 $args["where"] = "WHERE FAC.service_location = 1";
75 return $this->get($args);
78 public function getPrimaryBillingLocation()
80 return $this->get(array(
81 "order" => "ORDER BY FAC.billing_location DESC, FAC.id DESC",
82 "limit" => 1
83 ));
86 public function getAllBillingLocations()
88 return $this->get(array(
89 "where" => "WHERE FAC.billing_location = 1",
90 "order" => "ORDER BY FAC.id ASC"
91 ));
94 public function getById($id)
96 return $this->get(array(
97 "where" => "WHERE FAC.id = ?",
98 "data" => array($id),
99 "limit" => 1
103 public function getFacilityForUser($userId)
105 return $this->get(array(
106 "where" => "WHERE USER.id = ?",
107 "data" => array($userId),
108 "join" => "JOIN users USER ON FAC.name = USER.facility",
109 "limit" => 1
113 public function getFacilityForUserFormatted($userId)
115 $facility = $this->getFacilityForUser($userId);
117 if (!empty($facility)) {
118 $formatted = "";
119 $formatted .= $facility["name"];
120 $formatted .= "\n";
121 $formatted .= $facility["street"];
122 $formatted .= "\n";
123 $formatted .= $facility["city"];
124 $formatted .= "\n";
125 $formatted .= $facility["state"];
126 $formatted .= "\n";
127 $formatted .= $facility["postal_code"];
129 return array("facility_address" => $formatted);
132 return array("facility_address" => "");
135 public function getFacilityForEncounter($encounterId)
137 return $this->get(array(
138 "where" => "WHERE ENC.encounter = ?",
139 "data" => array($encounterId),
140 "join" => "JOIN form_encounter ENC ON FAC.id = ENC.facility_id",
141 "limit" => 1
145 public function update($data)
147 $sql = " UPDATE facility SET";
148 $sql .= " name='" . add_escape_custom($data["name"]) . "',";
149 $sql .= " phone='" . add_escape_custom($data["phone"]) . "',";
150 $sql .= " fax='" . add_escape_custom($data["fax"]) . "',";
151 $sql .= " street='" . add_escape_custom($data["street"]) . "',";
152 $sql .= " city='" . add_escape_custom($data["city"]) . "',";
153 $sql .= " state='" . add_escape_custom($data["state"]) . "',";
154 $sql .= " postal_code='" . add_escape_custom($data["postal_code"]) . "',";
155 $sql .= " country_code='" . add_escape_custom($data["country_code"]) . "',";
156 $sql .= " federal_ein='" . add_escape_custom($data["federal_ein"]) . "',";
157 $sql .= " website='" . add_escape_custom($data["website"]) . "',";
158 $sql .= " email='" . add_escape_custom($data["email"]) . "',";
159 $sql .= " color='" . add_escape_custom($data["color"]) . "',";
160 $sql .= " service_location='" . add_escape_custom($data["service_location"]) . "',";
161 $sql .= " billing_location='" . add_escape_custom($data["billing_location"]) . "',";
162 $sql .= " accepts_assignment='" . add_escape_custom($data["accepts_assignment"]) . "',";
163 $sql .= " pos_code='" . add_escape_custom($data["pos_code"]) . "',";
164 $sql .= " domain_identifier='" . add_escape_custom($data["domain_identifier"]) . "',";
165 $sql .= " attn='" . add_escape_custom($data["attn"]) . "',";
166 $sql .= " tax_id_type='" . add_escape_custom($data["tax_id_type"]) . "',";
167 $sql .= " primary_business_entity='" . add_escape_custom($data["primary_business_entity"]) . "',";
168 $sql .= " facility_npi='" . add_escape_custom($data["facility_npi"]) . "',";
169 $sql .= " facility_code='" . add_escape_custom($data["facility_code"]) . "'";
170 $sql .= " WHERE id='" . add_escape_custom($data["fid"]) . "'";
172 return sqlStatement($sql);
175 public function insert($data)
177 $sql = " INSERT INTO facility SET";
178 $sql .= " name='" . add_escape_custom($data["name"]) . "',";
179 $sql .= " phone='" . add_escape_custom($data["phone"]) . "',";
180 $sql .= " fax='" . add_escape_custom($data["fax"]) . "',";
181 $sql .= " street='" . add_escape_custom($data["street"]) . "',";
182 $sql .= " city='" . add_escape_custom($data["city"]) . "',";
183 $sql .= " state='" . add_escape_custom($data["state"]) . "',";
184 $sql .= " postal_code='" . add_escape_custom($data["postal_code"]) . "',";
185 $sql .= " country_code='" . add_escape_custom($data["country_code"]) . "',";
186 $sql .= " federal_ein='" . add_escape_custom($data["federal_ein"]) . "',";
187 $sql .= " website='" . add_escape_custom($data["website"]) . "',";
188 $sql .= " email='" . add_escape_custom($data["email"]) . "',";
189 $sql .= " color='" . add_escape_custom($data["color"]) . "',";
190 $sql .= " service_location='" . add_escape_custom($data["service_location"]) . "',";
191 $sql .= " billing_location='" . add_escape_custom($data["billing_location"]) . "',";
192 $sql .= " accepts_assignment='" . add_escape_custom($data["accepts_assignment"]) . "',";
193 $sql .= " pos_code='" . add_escape_custom($data["pos_code"]) . "',";
194 $sql .= " domain_identifier='" . add_escape_custom($data["domain_identifier"]) . "',";
195 $sql .= " attn='" . add_escape_custom($data["attn"]) . "',";
196 $sql .= " tax_id_type='" . add_escape_custom($data["tax_id_type"]) . "',";
197 $sql .= " primary_business_entity='" . add_escape_custom($data["primary_business_entity"]) . "',";
198 $sql .= " facility_npi='" . add_escape_custom($data["facility_npi"]) . "',";
199 $sql .= " facility_code='" . add_escape_custom($data["facility_code"]) . "'";
201 return sqlInsert($sql);
204 public function updateUsersFacility($facility_name, $facility_id)
206 $sql = " UPDATE users SET";
207 $sql .= " facility='" . add_escape_custom($facility_name) . "'";
208 $sql .= " WHERE facility_id='" . add_escape_custom($facility_id) . "'";
210 return sqlStatement($sql);
214 * Shared getter for the various specific facility getters.
216 * @param $map - Query information.
217 * @return array of associative arrays | one associative array.
219 private function get($map)
221 $sql = " SELECT FAC.id,";
222 $sql .= " FAC.name,";
223 $sql .= " FAC.phone,";
224 $sql .= " FAC.fax,";
225 $sql .= " FAC.street,";
226 $sql .= " FAC.city,";
227 $sql .= " FAC.state,";
228 $sql .= " FAC.postal_code,";
229 $sql .= " FAC.country_code,";
230 $sql .= " FAC.federal_ein,";
231 $sql .= " FAC.website,";
232 $sql .= " FAC.email,";
233 $sql .= " FAC.service_location,";
234 $sql .= " FAC.billing_location,";
235 $sql .= " FAC.accepts_assignment,";
236 $sql .= " FAC.pos_code,";
237 $sql .= " FAC.x12_sender_id,";
238 $sql .= " FAC.attn,";
239 $sql .= " FAC.domain_identifier,";
240 $sql .= " FAC.facility_npi,";
241 $sql .= " FAC.tax_id_type,";
242 $sql .= " FAC.color,";
243 $sql .= " FAC.primary_business_entity,";
244 $sql .= " FAC.facility_code,";
245 $sql .= " FAC.extra_validation";
246 $sql .= " FROM facility FAC";
248 return QueryUtils::selectHelper($sql, $map);
251 private function getPrimaryBusinessEntityLegacy()
253 return $this->get(array(
254 "order" => "ORDER BY FAC.billing_location DESC, FAC.accepts_assignment DESC, FAC.id ASC",
255 "limit" => 1