bye jquery 1.11.1 (#849)
[openemr.git] / services / FacilityService.php
blob0f9ecc080c6c478e950d067b2e920afcfee052f0
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 services;
25 class FacilityService
27 /**
28 * Default constructor.
30 public function __construct()
34 public function getAll()
36 return $this->get(array("order" => "ORDER BY FAC.name ASC"));
39 public function getPrimaryBusinessEntity($options = null)
41 if (!empty($options) && !empty($options["useLegacyImplementation"])) {
42 return $this->getPrimaryBusinessEntityLegacy();
45 $args = array(
46 "where" => "WHERE FAC.primary_business_entity = 1",
47 "data" => null,
48 "limit" => 1
51 if (!empty($options) && !empty($options["excludedId"])) {
52 $args["where"] .= " AND FAC.id != ?";
53 $args["data"] = $options["excludedId"];
54 return $this->get($args);
57 return $this->get($args);
60 public function getAllServiceLocations($options = null)
62 $args = array(
63 "where" => null,
64 "order" => "ORDER BY FAC.name ASC"
67 if (!empty($options) && !empty($options["orderField"])) {
68 $args["order"] = "ORDER BY FAC." . escape_sql_column_name($options["orderField"], array("facility")) . " ASC";
71 $args["where"] = "WHERE FAC.service_location = 1";
73 return $this->get($args);
76 public function getPrimaryBillingLocation() {
77 return $this->get(array(
78 "order" => "ORDER BY FAC.billing_location DESC, FAC.id DESC",
79 "limit" => 1
80 ));
83 public function getAllBillingLocations()
85 return $this->get(array(
86 "where" => "WHERE FAC.billing_location = 1",
87 "order" => "ORDER BY FAC.id ASC"
88 ));
91 public function getById($id)
93 return $this->get(array(
94 "where" => "WHERE FAC.id = ?",
95 "data" => array($id),
96 "limit" => 1
97 ));
100 public function getFacilityForUser($userId)
102 return $this->get(array(
103 "where" => "WHERE USER.id = ?",
104 "data" => array($userId),
105 "join" => "JOIN users USER ON FAC.name = USER.facility",
106 "limit" => 1
110 public function getFacilityForUserFormatted($userId)
112 $facility = $this->getFacilityForUser($userId);
114 if (!empty($facility)) {
115 $formatted = "";
116 $formatted .= $facility["name"];
117 $formatted .= "\n";
118 $formatted .= $facility["street"];
119 $formatted .= "\n";
120 $formatted .= $facility["city"];
121 $formatted .= "\n";
122 $formatted .= $facility["state"];
123 $formatted .= "\n";
124 $formatted .= $facility["postal_code"];
126 return array("facility_address" => $formatted);
129 return array("facility_address" => "");
132 public function getFacilityForEncounter($encounterId)
134 return $this->get(array(
135 "where" => "WHERE ENC.encounter = ?",
136 "data" => array($encounterId),
137 "join" => "JOIN form_encounter ENC ON FAC.id = ENC.facility_id",
138 "limit" => 1
142 public function update($data)
144 $sql = " UPDATE facility SET";
145 $sql .= " name='" . add_escape_custom($data["name"]) . "',";
146 $sql .= " phone='" . add_escape_custom($data["phone"]) . "',";
147 $sql .= " fax='" . add_escape_custom($data["fax"]) . "',";
148 $sql .= " street='" . add_escape_custom($data["street"]) . "',";
149 $sql .= " city='" . add_escape_custom($data["city"]) . "',";
150 $sql .= " state='" . add_escape_custom($data["state"]) . "',";
151 $sql .= " postal_code='" . add_escape_custom($data["postal_code"]) . "',";
152 $sql .= " country_code='" . add_escape_custom($data["country_code"]) . "',";
153 $sql .= " federal_ein='" . add_escape_custom($data["federal_ein"]) . "',";
154 $sql .= " website='" . add_escape_custom($data["website"]) . "',";
155 $sql .= " email='" . add_escape_custom($data["email"]) . "',";
156 $sql .= " color='" . add_escape_custom($data["color"]) . "',";
157 $sql .= " service_location='" . add_escape_custom($data["service_location"]) . "',";
158 $sql .= " billing_location='" . add_escape_custom($data["billing_location"]) . "',";
159 $sql .= " accepts_assignment='" . add_escape_custom($data["accepts_assignment"]) . "',";
160 $sql .= " pos_code='" . add_escape_custom($data["pos_code"]) . "',";
161 $sql .= " domain_identifier='" . add_escape_custom($data["domain_identifier"]) . "',";
162 $sql .= " attn='" . add_escape_custom($data["attn"]) . "',";
163 $sql .= " tax_id_type='" . add_escape_custom($data["tax_id_type"]) . "',";
164 $sql .= " primary_business_entity='" . add_escape_custom($data["primary_business_entity"]) . "',";
165 $sql .= " facility_npi='" . add_escape_custom($data["facility_npi"]) . "',";
166 $sql .= " facility_code='" . add_escape_custom($data["facility_code"]) . "'";
167 $sql .= " WHERE id='" . add_escape_custom($data["fid"]) . "'";
169 return sqlStatement($sql);
172 public function insert($data)
174 $sql = " INSERT INTO facility SET";
175 $sql .= " name='" . add_escape_custom($data["name"]) . "',";
176 $sql .= " phone='" . add_escape_custom($data["phone"]) . "',";
177 $sql .= " fax='" . add_escape_custom($data["fax"]) . "',";
178 $sql .= " street='" . add_escape_custom($data["street"]) . "',";
179 $sql .= " city='" . add_escape_custom($data["city"]) . "',";
180 $sql .= " state='" . add_escape_custom($data["state"]) . "',";
181 $sql .= " postal_code='" . add_escape_custom($data["postal_code"]) . "',";
182 $sql .= " country_code='" . add_escape_custom($data["country_code"]) . "',";
183 $sql .= " federal_ein='" . add_escape_custom($data["federal_ein"]) . "',";
184 $sql .= " website='" . add_escape_custom($data["website"]) . "',";
185 $sql .= " email='" . add_escape_custom($data["email"]) . "',";
186 $sql .= " color='" . add_escape_custom($data["color"]) . "',";
187 $sql .= " service_location='" . add_escape_custom($data["service_location"]) . "',";
188 $sql .= " billing_location='" . add_escape_custom($data["billing_location"]) . "',";
189 $sql .= " accepts_assignment='" . add_escape_custom($data["accepts_assignment"]) . "',";
190 $sql .= " pos_code='" . add_escape_custom($data["pos_code"]) . "',";
191 $sql .= " domain_identifier='" . add_escape_custom($data["domain_identifier"]) . "',";
192 $sql .= " attn='" . add_escape_custom($data["attn"]) . "',";
193 $sql .= " tax_id_type='" . add_escape_custom($data["tax_id_type"]) . "',";
194 $sql .= " primary_business_entity='" . add_escape_custom($data["primary_business_entity"]) . "',";
195 $sql .= " facility_npi='" . add_escape_custom($data["facility_npi"]) . "',";
196 $sql .= " facility_code='" . add_escape_custom($data["facility_code"]) . "'";
198 return sqlInsert($sql);
202 * Shared getter for the various specific facility getters.
204 * @param $map - Query information.
205 * @return array of associative arrays | one associative array.
207 private function get($map)
209 $sql = " SELECT FAC.id,";
210 $sql .= " FAC.name,";
211 $sql .= " FAC.phone,";
212 $sql .= " FAC.fax,";
213 $sql .= " FAC.street,";
214 $sql .= " FAC.city,";
215 $sql .= " FAC.state,";
216 $sql .= " FAC.postal_code,";
217 $sql .= " FAC.country_code,";
218 $sql .= " FAC.federal_ein,";
219 $sql .= " FAC.website,";
220 $sql .= " FAC.email,";
221 $sql .= " FAC.service_location,";
222 $sql .= " FAC.billing_location,";
223 $sql .= " FAC.accepts_assignment,";
224 $sql .= " FAC.pos_code,";
225 $sql .= " FAC.x12_sender_id,";
226 $sql .= " FAC.attn,";
227 $sql .= " FAC.domain_identifier,";
228 $sql .= " FAC.facility_npi,";
229 $sql .= " FAC.tax_id_type,";
230 $sql .= " FAC.color,";
231 $sql .= " FAC.primary_business_entity,";
232 $sql .= " FAC.facility_code,";
233 $sql .= " FAC.extra_validation";
234 $sql .= " FROM facility FAC";
236 return \common\utils\QueryUtils::selectHelper($sql, $map);
239 private function getPrimaryBusinessEntityLegacy()
241 return $this->get(array(
242 "order" => "ORDER BY FAC.billing_location DESC, FAC.accepts_assignment DESC, FAC.id ASC",
243 "limit" => 1