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);
22 use OpenEMR\Common\ORDataObject\ORDataObject
;
23 use OpenEMR\Common\ORDataObject\Address
;
25 class Pharmacy
extends ORDataObject
33 var $transmit_method_array; //set in constructor
40 * Constructor sets all Prescription attributes to their default value
42 function __construct($id = "", $prefix = "")
45 $this->state
= $this->getState();
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();
60 function set_id($id = "")
68 function set_form_id($id = "")
74 function set_fax_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)
115 function set_npi($npi)
123 function set_ncpdp($ncpdp)
125 $this->ncpdp
= $ncpdp;
131 function set_email($email)
133 $this->email
= $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
];
157 foreach ($this->phone_numbers
as $phone) {
158 if ($phone->type
== TYPE_WORK
) {
159 return $phone->get_phone_display();
165 function set_number($num, $type)
168 for ($i = 0; $i < count($this->phone_numbers
); $i++
) {
169 if ($this->phone_numbers
[$i]->type
== $type) {
171 $this->phone_numbers
[$i]->set_phone($num);
175 if ($found == false) {
176 $p = new PhoneNumber("", $this->id
);
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
);
196 foreach ($this->phone_numbers
as $phone) {
197 if ($phone->type
== TYPE_FAX
) {
198 return $phone->get_phone_display();
207 $this->address
= Address
::factory_address($this->id
);
208 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
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";
226 while ($row = sqlFetchArray($res)) {
227 $d_string = $row['city'];
228 if (!empty($row['city']) && $row['state']) {
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")
244 $city = " WHERE city = '" . add_escape_custom($foreign_id) . "'";
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);
261 while ($row = sqlFetchArray($results)) {
262 $pharmacies[] = new Pharmacy($row['id']);
270 $sql = "SELECT state FROM facility";
271 $res = sqlQuery($sql);
272 return $res['state'];
275 function toString($html = false)
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
];
286 return nl2br($string);
292 function totalPages()
294 $sql = "select count(*) AS numberof from " . escape_table_name($this->_table
);
295 $count = sqlQuery($sql);
296 return $count['numberof'];
301 return $this->pageno
= 1;