Refactor previous name into dedicated service (#7571)
[openemr.git] / library / classes / Pharmacy.class.php
bloba8fde21bf7ba6637d00db8c3c4f83d1f594c8701
1 <?php
3 /************************************************************************
4 pharmacy.php - Copyright duhlman
6 /usr/share/apps/umbrello/headings/heading.php
8 This file was generated on %date% at %time%
9 The original location of this file is /home/duhlman/uml-generated-code/prescription.php
10 **************************************************************************/
12 define("TRANSMIT_PRINT", 1);
13 define("TRANSMIT_EMAIL", 2);
14 define("TRANSMIT_FAX", 3);
15 define("TRANSMIT_ERX", 4);
17 /**
18 * class Pharmacy
22 use OpenEMR\Common\ORDataObject\ORDataObject;
23 use OpenEMR\Common\ORDataObject\Address;
25 class Pharmacy extends ORDataObject
27 var $id;
28 var $name;
29 var $phone_numbers;
30 var $address;
31 var $transmit_method;
32 var $email;
33 var $transmit_method_array; //set in constructor
34 var $pageno;
35 var $state;
36 var $npi;
37 var $ncpdp;
39 /**
40 * Constructor sets all Prescription attributes to their default value
42 function __construct($id = "", $prefix = "")
44 $this->id = $id;
45 $this->state = $this->getState();
46 $this->name = "";
47 $this->email = "";
48 $this->transmit_method = 1;
49 $this->transmit_method_array = array(xl("None Selected"), xl("Print"), xl("Email"), xl("Fax"), xl("Transmit"), xl("eRx"));
50 $this->_table = "pharmacies";
51 $phone = new PhoneNumber();
52 $phone->set_type(TYPE_WORK);
53 $this->phone_numbers = array($phone);
54 $this->address = new Address();
55 if ($id != "") {
56 $this->populate();
60 function set_id($id = "")
62 $this->id = $id;
64 function get_id()
66 return $this->id;
68 function set_form_id($id = "")
70 if (!empty($id)) {
71 $this->populate($id);
74 function set_fax_id($id)
76 $this->id = $id;
78 function set_address($aobj)
80 $this->address = $aobj;
82 function get_address()
84 return $this->address;
86 function set_address_line1($line)
88 $this->address->set_line1($line);
90 function set_address_line2($line)
92 $this->address->set_line2($line);
94 function set_city($city)
96 $this->address->set_city($city);
98 function set_state($state)
100 $this->address->set_state($state);
102 function set_zip($zip)
104 $this->address->set_zip($zip);
107 function set_name($name)
109 $this->name = $name;
111 function get_name()
113 return $this->name;
115 function set_npi($npi)
117 $this->npi = $npi;
119 function get_npi()
121 return $this->npi;
123 function set_ncpdp($ncpdp)
125 $this->ncpdp = $ncpdp;
127 function get_ncpdp()
129 return $this->ncpdp;
131 function set_email($email)
133 $this->email = $email;
135 function get_email()
137 return $this->email;
139 function set_transmit_method($tm)
141 $this->transmit_method = $tm;
143 function get_transmit_method()
145 if ($this->transmit_method == TRANSMIT_EMAIL && empty($this->email)) {
146 return TRANSMIT_PRINT;
149 return $this->transmit_method;
151 function get_transmit_method_display()
153 return $this->transmit_method_array[$this->transmit_method];
155 function get_phone()
157 foreach ($this->phone_numbers as $phone) {
158 if ($phone->type == TYPE_WORK) {
159 return $phone->get_phone_display();
163 return "";
165 function set_number($num, $type)
167 $found = false;
168 for ($i = 0; $i < count($this->phone_numbers); $i++) {
169 if ($this->phone_numbers[$i]->type == $type) {
170 $found = true;
171 $this->phone_numbers[$i]->set_phone($num);
175 if ($found == false) {
176 $p = new PhoneNumber("", $this->id);
177 $p->set_type($type);
178 $p->set_phone($num);
179 $this->phone_numbers[] = $p;
180 //print_r($this->phone_numbers);
181 //echo "num is now:" . $p->get_phone_display() . "<br />";
185 function set_phone($phone)
187 $this->set_number($phone, TYPE_WORK);
189 function set_fax($fax)
191 $this->set_number($fax, TYPE_FAX);
194 function get_fax()
196 foreach ($this->phone_numbers as $phone) {
197 if ($phone->type == TYPE_FAX) {
198 return $phone->get_phone_display();
202 return "";
204 function populate()
206 parent::populate();
207 $this->address = Address::factory_address($this->id);
208 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
211 function persist()
213 parent::persist();
214 $this->address->persist($this->id);
215 foreach ($this->phone_numbers as $phone) {
216 $phone->persist($this->id);
220 function utility_pharmacy_array()
222 $pharmacy_array = array();
223 $sql = "SELECT p.id, p.name, a.city, a.state " .
224 "FROM " . escape_table_name($this->_table) . " AS p INNER JOIN addresses AS a ON p.id = a.foreign_id";
225 $res = sqlQ($sql);
226 while ($row = sqlFetchArray($res)) {
227 $d_string = $row['city'];
228 if (!empty($row['city']) && $row['state']) {
229 $d_string .= ", ";
232 $d_string .= $row['state'];
233 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
236 return ($pharmacy_array);
239 function pharmacies_factory($city = "", $sort = "ORDER BY name")
241 if (empty($city)) {
242 $city = "";
243 } else {
244 $city = " WHERE city = '" . add_escape_custom($foreign_id) . "'";
247 $p = new Pharmacy();
248 $pharmacies = array();
249 $sql = "SELECT p.id, a.city " .
250 "FROM " . escape_table_name($p->_table) . " AS p " .
251 "INNER JOIN addresses AS a ON p.id = a.foreign_id " . $city . " ";
252 if ($GLOBALS['weno_rx_enable']) {
253 $sql .= "WHERE state = '" . add_escape_custom($this->state) . "' ";
255 $sql .= add_escape_custom($sort);
257 //echo $sql . "<bR />";
258 $results = sqlQ($sql);
259 //echo "sql: $sql";
260 //print_r($results);
261 while ($row = sqlFetchArray($results)) {
262 $pharmacies[] = new Pharmacy($row['id']);
265 return $pharmacies;
268 function getState()
270 $sql = "SELECT state FROM facility";
271 $res = sqlQuery($sql);
272 return $res['state'];
275 function toString($html = false)
277 $string .= "\n"
278 . "ID: " . $this->id . "\n"
279 . "Name: " . $this->name . "\n"
280 . "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
281 . "Email:" . $this->email . "\n"
282 . "Address: " . $this->address->toString($html) . "\n"
283 . "Method: " . $this->transmit_method_array[$this->transmit_method];
285 if ($html) {
286 return nl2br($string);
287 } else {
288 return $string;
292 function totalPages()
294 $sql = "select count(*) AS numberof from " . escape_table_name($this->_table);
295 $count = sqlQuery($sql);
296 return $count['numberof'];
299 function getPageno()
301 return $this->pageno = 1;