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);
20 class Pharmacy
extends ORDataObject
28 var $transmit_method_array; //set in constructor
31 * Constructor sets all Prescription attributes to their default value
33 function __construct($id = "", $prefix = "")
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();
50 function set_id($id = "")
58 function set_form_id($id = "")
64 function set_fax_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)
105 function set_email($email)
107 $this->email
= $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
)) {
123 return $this->transmit_method
;
125 function get_transmit_method_display()
127 return $this->transmit_method_array
[$this->transmit_method
];
131 foreach ($this->phone_numbers
as $phone) {
132 if ($phone->type
== TYPE_WORK
) {
133 return $phone->get_phone_display();
139 function _set_number($num, $type)
142 for ($i=0; $i<count($this->phone_numbers
); $i++
) {
143 if ($this->phone_numbers
[$i]->type
== $type) {
145 $this->phone_numbers
[$i]->set_phone($num);
149 if ($found == false) {
150 $p = new PhoneNumber("", $this->id
);
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
);
170 foreach ($this->phone_numbers
as $phone) {
171 if ($phone->type
== TYPE_FAX
) {
172 return $phone->get_phone_display();
181 $this->address
= Address
::factory_address($this->id
);
182 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
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";
199 while ($row = sqlFetchArray($res)) {
200 $d_string = $row['city'];
201 if (!empty($row['city']) && $row['state']) {
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")
217 $city = " WHERE city = " . add_escape_custom($foreign_id);
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);
228 while ($row = sqlFetchArray($results)) {
229 $pharmacies[] = new Pharmacy($row['id']);
235 function toString($html = false)
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
];
246 return nl2br($string);
252 /*$p = new Pharmacy("1");
253 echo $p->toString(true);