Slimmed down version of class OemrUI - Take 4 (#2044)
[openemr.git] / library / classes / Pharmacy.class.php
blob9f8d05dd19b96ca2589820ecc151d5b45b68a5c1
1 <?php
2 /************************************************************************
3 pharmacy.php - Copyright duhlman
5 /usr/share/apps/umbrello/headings/heading.php
7 This file was generated on %date% at %time%
8 The original location of this file is /home/duhlman/uml-generated-code/prescription.php
9 **************************************************************************/
12 define("TRANSMIT_PRINT", 1);
13 define("TRANSMIT_EMAIL", 2);
14 define("TRANSMIT_FAX", 3);
16 /**
17 * class Pharmacy
20 class Pharmacy extends ORDataObject
22 var $id;
23 var $name;
24 var $phone_numbers;
25 var $address;
26 var $transmit_method;
27 var $email;
28 var $transmit_method_array; //set in constructor
30 /**
31 * Constructor sets all Prescription attributes to their default value
33 function __construct($id = "", $prefix = "")
35 $this->id = $id;
36 $this->name = "";
37 $this->email = "";
38 $this->transmit_method = 1;
39 $this->transmit_method_array = array(xl("None Selected"), xl("Print"), xl("Email"), xl("Fax"));
40 $this->_table = "pharmacies";
41 $phone = new PhoneNumber();
42 $phone->set_type(TYPE_WORK);
43 $this->phone_numbers = array($phone);
44 $this->address = new Address();
45 if ($id != "") {
46 $this->populate();
50 function set_id($id = "")
52 $this->id = $id;
54 function get_id()
56 return $this->id;
58 function set_form_id($id = "")
60 if (!empty($id)) {
61 $this->populate($id);
64 function set_fax_id($id)
66 $this->id = $id;
68 function set_address($aobj)
70 $this->address = $aobj;
72 function get_address()
74 return $this->address;
76 function set_address_line1($line)
78 $this->address->set_line1($line);
80 function set_address_line2($line)
82 $this->address->set_line2($line);
84 function set_city($city)
86 $this->address->set_city($city);
88 function set_state($state)
90 $this->address->set_state($state);
92 function set_zip($zip)
94 $this->address->set_zip($zip);
97 function set_name($name)
99 $this->name = $name;
101 function get_name()
103 return $this->name;
105 function set_npi($npi)
107 $this->npi = $npi;
109 function get_npi()
111 return $this->npi;
113 function set_ncpdp($ncpdp)
115 $this->ncpdp = $ncpdp;
117 function get_ncpdp()
119 return $this->ncpdp;
121 function set_email($email)
123 $this->email = $email;
125 function get_email()
127 return $this->email;
129 function set_transmit_method($tm)
131 $this->transmit_method = $tm;
133 function get_transmit_method()
135 if ($this->transmit_method == TRANSMIT_EMAIL && empty($this->email)) {
136 return TRANSMIT_PRINT;
139 return $this->transmit_method;
141 function get_transmit_method_display()
143 return $this->transmit_method_array[$this->transmit_method];
145 function get_phone()
147 foreach ($this->phone_numbers as $phone) {
148 if ($phone->type == TYPE_WORK) {
149 return $phone->get_phone_display();
153 return "";
155 function _set_number($num, $type)
157 $found = false;
158 for ($i=0; $i<count($this->phone_numbers); $i++) {
159 if ($this->phone_numbers[$i]->type == $type) {
160 $found = true;
161 $this->phone_numbers[$i]->set_phone($num);
165 if ($found == false) {
166 $p = new PhoneNumber("", $this->id);
167 $p->set_type($type);
168 $p->set_phone($num);
169 $this->phone_numbers[] = $p;
170 //print_r($this->phone_numbers);
171 //echo "num is now:" . $p->get_phone_display() . "<br />";
175 function set_phone($phone)
177 $this->_set_number($phone, TYPE_WORK);
179 function set_fax($fax)
181 $this->_set_number($fax, TYPE_FAX);
184 function get_fax()
186 foreach ($this->phone_numbers as $phone) {
187 if ($phone->type == TYPE_FAX) {
188 return $phone->get_phone_display();
192 return "";
194 function populate()
196 parent::populate();
197 $this->address = Address::factory_address($this->id);
198 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
201 function persist()
203 parent::persist();
204 $this->address->persist($this->id);
205 foreach ($this->phone_numbers as $phone) {
206 $phone->persist($this->id);
210 function utility_pharmacy_array()
212 $pharmacy_array = array();
213 $sql = "Select p.id, p.name, a.city, a.state from " . $this->_table ." as p INNER JOIN addresses as a on p.id = a.foreign_id";
214 $res = sqlQ($sql);
215 while ($row = sqlFetchArray($res)) {
216 $d_string = $row['city'];
217 if (!empty($row['city']) && $row['state']) {
218 $d_string .= ", ";
221 $d_string .= $row['state'];
222 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
225 return ($pharmacy_array);
228 function pharmacies_factory($city = "", $sort = "ORDER BY name")
230 if (empty($city)) {
231 $city= "";
232 } else {
233 $city = " WHERE city = " . add_escape_custom($foreign_id);
236 $p = new Pharmacy();
237 $pharmacies = array();
238 $sql = "SELECT p.id, a.city FROM " . $p->_table . " as p INNER JOIN addresses as a on p.id = a.foreign_id " .$city . " " . add_escape_custom($sort);
240 //echo $sql . "<bR />";
241 $results = sqlQ($sql);
242 //echo "sql: $sql";
243 //print_r($results);
244 while ($row = sqlFetchArray($results)) {
245 $pharmacies[] = new Pharmacy($row['id']);
248 return $pharmacies;
251 function toString($html = false)
253 $string .= "\n"
254 . "ID: " . $this->id."\n"
255 . "Name: " . $this->name ."\n"
256 . "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
257 . "Email:" . $this->email . "\n"
258 . "Address: " . $this->address->toString($html) . "\n"
259 . "Method: " . $this->transmit_method_array[$this->transmit_method];
261 if ($html) {
262 return nl2br($string);
263 } else {
264 return $string;
267 } // end of Pharmacy
268 /*$p = new Pharmacy("1");
269 echo $p->toString(true);