security fix in master branch
[openemr.git] / library / classes / Pharmacy.class.php
blob9773d39804c28dd61958eb6fbf4daa9715f43f91
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_email($email)
107 $this->email = $email;
109 function get_email()
111 return $this->email;
113 function set_transmit_method($tm)
115 $this->transmit_method = $tm;
117 function get_transmit_method()
119 if ($this->transmit_method == TYPE_EMAIL && empty($this->email)) {
120 return TYPE_PRINT;
123 return $this->transmit_method;
125 function get_transmit_method_display()
127 return $this->transmit_method_array[$this->transmit_method];
129 function get_phone()
131 foreach ($this->phone_numbers as $phone) {
132 if ($phone->type == TYPE_WORK) {
133 return $phone->get_phone_display();
137 return "";
139 function _set_number($num, $type)
141 $found = false;
142 for ($i=0; $i<count($this->phone_numbers); $i++) {
143 if ($this->phone_numbers[$i]->type == $type) {
144 $found = true;
145 $this->phone_numbers[$i]->set_phone($num);
149 if ($found == false) {
150 $p = new PhoneNumber("", $this->id);
151 $p->set_type($type);
152 $p->set_phone($num);
153 $this->phone_numbers[] = $p;
154 //print_r($this->phone_numbers);
155 //echo "num is now:" . $p->get_phone_display() . "<br />";
159 function set_phone($phone)
161 $this->_set_number($phone, TYPE_WORK);
163 function set_fax($fax)
165 $this->_set_number($fax, TYPE_FAX);
168 function get_fax()
170 foreach ($this->phone_numbers as $phone) {
171 if ($phone->type == TYPE_FAX) {
172 return $phone->get_phone_display();
176 return "";
178 function populate()
180 parent::populate();
181 $this->address = Address::factory_address($this->id);
182 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
185 function persist()
187 parent::persist();
188 $this->address->persist($this->id);
189 foreach ($this->phone_numbers as $phone) {
190 $phone->persist($this->id);
194 function utility_pharmacy_array()
196 $pharmacy_array = array();
197 $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";
198 $res = sqlQ($sql);
199 while ($row = sqlFetchArray($res)) {
200 $d_string = $row['city'];
201 if (!empty($row['city']) && $row['state']) {
202 $d_string .= ", ";
205 $d_string .= $row['state'];
206 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
209 return ($pharmacy_array);
212 function pharmacies_factory($city = "", $sort = "ORDER BY name")
214 if (empty($city)) {
215 $city= "";
216 } else {
217 $city = " WHERE city = " . add_escape_custom($foreign_id);
220 $p = new Pharmacy();
221 $pharmacies = array();
222 $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);
224 //echo $sql . "<bR />";
225 $results = sqlQ($sql);
226 //echo "sql: $sql";
227 //print_r($results);
228 while ($row = sqlFetchArray($results)) {
229 $pharmacies[] = new Pharmacy($row['id']);
232 return $pharmacies;
235 function toString($html = false)
237 $string .= "\n"
238 . "ID: " . $this->id."\n"
239 . "Name: " . $this->name ."\n"
240 . "Phone: " . $this->phone_numbers[0]->toString($html) . "\n"
241 . "Email:" . $this->email . "\n"
242 . "Address: " . $this->address->toString($html) . "\n"
243 . "Method: " . $this->transmit_method_array[$this->transmit_method];
245 if ($html) {
246 return nl2br($string);
247 } else {
248 return $string;
251 } // end of Pharmacy
252 /*$p = new Pharmacy("1");
253 echo $p->toString(true);