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
{
27 var $transmit_method_array = array("","Print", "Email" ,"Fax");
30 * Constructor sets all Prescription attributes to their default value
32 function __construct($id = "", $prefix = "") {
36 $this->transmit_method
= 1;
37 $this->_table
= "pharmacies";
38 $phone = new PhoneNumber();
39 $phone->set_type(TYPE_WORK
);
40 $this->phone_numbers
= array($phone);
41 $this->address
= new Address();
47 function set_id($id = "") {
53 function set_form_id ($id = "") {
58 function set_fax_id($id) {
61 function set_address($aobj) {
62 $this->address
= $aobj;
64 function get_address() {
65 return $this->address
;
67 function set_address_line1($line) {
68 $this->address
->set_line1($line);
70 function set_address_line2($line) {
71 $this->address
->set_line2($line);
73 function set_city($city) {
74 $this->address
->set_city($city);
76 function set_state($state) {
77 $this->address
->set_state($state);
79 function set_zip($zip) {
80 $this->address
->set_zip($zip);
83 function set_name($name) {
89 function set_email($email) {
90 $this->email
= $email;
92 function get_email() {
95 function set_transmit_method($tm) {
96 $this->transmit_method
= $tm;
98 function get_transmit_method() {
99 if ($this->transmit_method
== TYPE_EMAIL
&& empty($this->email
)) {
102 return $this->transmit_method
;
104 function get_transmit_method_display() {
105 return $this->transmit_method_array
[$this->transmit_method
];
107 function get_phone() {
108 foreach($this->phone_numbers
as $phone) {
109 if ($phone->type
== TYPE_WORK
) {
110 return $phone->get_phone_display();
115 function _set_number($num, $type) {
117 for ($i=0;$i<count($this->phone_numbers
);$i++
) {
118 if ($this->phone_numbers
[$i]->type
== $type) {
120 $this->phone_numbers
[$i]->set_phone($num);
123 if ($found == false) {
124 $p = new PhoneNumber("",$this->id
);
127 $this->phone_numbers
[] = $p;
128 //print_r($this->phone_numbers);
129 //echo "num is now:" . $p->get_phone_display() . "<br />";
133 function set_phone($phone) {
134 $this->_set_number($phone, TYPE_WORK
);
136 function set_fax($fax) {
137 $this->_set_number($fax, TYPE_FAX
);
141 foreach($this->phone_numbers
as $phone) {
142 if ($phone->type
== TYPE_FAX
) {
143 return $phone->get_phone_display();
148 function populate() {
150 $this->address
= Address
::factory_address($this->id
);
151 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
156 $this->address
->persist($this->id
);
157 foreach ($this->phone_numbers
as $phone) {
158 $phone->persist($this->id
);
162 function utility_pharmacy_array() {
163 $pharmacy_array = array();
164 $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";
166 while ($row = sqlFetchArray($res) ) {
167 $d_string = $row['city'];
168 if (!empty($row['city']) && $row['state']) {
171 $d_string .= $row['state'];
172 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
174 return ($pharmacy_array);
177 function pharmacies_factory ($city = "", $sort = "ORDER BY name") {
182 $city = " WHERE city = " . add_escape_custom($foreign_id);
185 $pharmacies = array();
186 $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);
188 //echo $sql . "<bR />";
189 $results = sqlQ($sql);
192 while($row = sqlFetchArray($results) ) {
193 $pharmacies[] = new Pharmacy($row['id']);
198 function toString($html = false) {
200 . "ID: " . $this->id
."\n"
201 . "Name: " . $this->name
."\n"
202 . "Phone: " . $this->phone_numbers
[0]->toString($html) . "\n"
203 . "Email:" . $this->email
. "\n"
204 . "Address: " . $this->address
->toString($html) . "\n"
205 . "Method: " . $this->transmit_method_array
[$this->transmit_method
];
208 return nl2br($string);
216 /*$p = new Pharmacy("1");
217 echo $p->toString(true);