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 **************************************************************************/
11 //require_once("../../interface/globals.php");
12 require_once("PhoneNumber.class.php");
13 require_once("Address.class.php");
14 //$GLOBALS['fileroot'] = "/var/www/openemr";
15 //$GLOBALS['webroot'] = "/openemr";
17 define ("TRANSMIT_PRINT",1);
18 define ("TRANSMIT_EMAIL", 2);
19 define ("TRANSMIT_FAX", 3);
21 require_once("ORDataObject.class.php");
26 class Pharmacy
extends ORDataObject
{
33 var $transmit_method_array = array("","Print", "Email" ,"Fax");
36 * Constructor sets all Prescription attributes to their default value
38 function Pharmacy($id = "", $prefix = "") {
42 $this->transmit_method
= 1;
43 $this->_table
= "pharmacies";
44 $phone = new PhoneNumber();
45 $phone->set_type(TYPE_WORK
);
46 $this->phone_numbers
= array($phone);
47 $this->address
= new Address();
53 function set_id($id = "") {
59 function set_form_id ($id = "") {
64 function set_fax_id($id) {
67 function set_address($aobj) {
68 $this->address
= $aobj;
70 function get_address() {
71 return $this->address
;
73 function set_address_line1($line) {
74 $this->address
->set_line1($line);
76 function set_address_line2($line) {
77 $this->address
->set_line2($line);
79 function set_city($city) {
80 $this->address
->set_city($city);
82 function set_state($state) {
83 $this->address
->set_state($state);
85 function set_zip($zip) {
86 $this->address
->set_zip($zip);
89 function set_name($name) {
95 function set_email($email) {
96 $this->email
= $email;
98 function get_email() {
101 function set_transmit_method($tm) {
102 $this->transmit_method
= $tm;
104 function get_transmit_method() {
105 if ($this->transmit_method
== TYPE_EMAIL
&& empty($this->email
)) {
108 return $this->transmit_method
;
110 function get_transmit_method_display() {
111 return $this->transmit_method_array
[$this->transmit_method
];
113 function get_phone() {
114 foreach($this->phone_numbers
as $phone) {
115 if ($phone->type
== TYPE_WORK
) {
116 return $phone->get_phone_display();
121 function _set_number($num, $type) {
123 for ($i=0;$i<count($this->phone_numbers
);$i++
) {
124 if ($this->phone_numbers
[$i]->type
== $type) {
126 $this->phone_numbers
[$i]->set_phone($num);
129 if ($found == false) {
130 $p = new PhoneNumber("",$this->id
);
133 $this->phone_numbers
[] = $p;
134 //print_r($this->phone_numbers);
135 //echo "num is now:" . $p->get_phone_display() . "<br />";
139 function set_phone($phone) {
140 $this->_set_number($phone, TYPE_WORK
);
142 function set_fax($fax) {
143 $this->_set_number($fax, TYPE_FAX
);
147 foreach($this->phone_numbers
as $phone) {
148 if ($phone->type
== TYPE_FAX
) {
149 return $phone->get_phone_display();
154 function populate() {
156 $this->address
= Address
::factory_address($this->id
);
157 $this->phone_numbers
= PhoneNumber
::factory_phone_numbers($this->id
);
162 $this->address
->persist($this->id
);
163 foreach ($this->phone_numbers
as $phone) {
164 $phone->persist($this->id
);
168 function utility_pharmacy_array() {
169 $pharmacy_array = array();
170 $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";
172 while ($row = mysql_fetch_array($res) ) {
173 $d_string = $row['city'];
174 if (!empty($row['city']) && $row['state']) {
177 $d_string .= $row['state'];
178 $pharmacy_array[strval($row['id'])] = $row['name'] . " " . $d_string;
180 return ($pharmacy_array);
183 function pharmacies_factory ($city = "", $sort = "ORDER BY name") {
188 $city = " WHERE city = " . mysql_real_escape_string($foreign_id);
191 $pharmacies = array();
192 $sql = "SELECT p.id, a.city FROM " . $p->_table
. " as p INNER JOIN addresses as a on p.id = a.foreign_id " .$city . " " . mysql_real_escape_string($sort);
194 //echo $sql . "<bR />";
195 $results = sqlQ($sql);
198 while($row = mysql_fetch_array($results) ) {
199 $pharmacies[] = new Pharmacy($row['id']);
204 function toString($html = false) {
206 . "ID: " . $this->id
."\n"
207 . "Name: " . $this->name
."\n"
208 . "Phone: " . $this->phone_numbers
[0]->toString($html) . "\n"
209 . "Email:" . $this->email
. "\n"
210 . "Address: " . $this->address
->toString($html) . "\n"
211 . "Method: " . $this->transmit_method_array
[$this->transmit_method
];
214 return nl2br($string);
222 /*$p = new Pharmacy("1");
223 echo $p->toString(true);