Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / library / classes / Pharmacy.class.php
blob5645a8782e5189fa4bce94dd2235cf8822d724da
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{
21 var $id;
22 var $name;
23 var $phone_numbers;
24 var $address;
25 var $transmit_method;
26 var $email;
27 var $transmit_method_array = array("","Print", "Email" ,"Fax");
29 /**
30 * Constructor sets all Prescription attributes to their default value
32 function __construct($id = "", $prefix = "") {
33 $this->id = $id;
34 $this->name = "";
35 $this->email = "";
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();
42 if ($id != "") {
43 $this->populate();
47 function set_id($id = "") {
48 $this->id = $id;
50 function get_id() {
51 return $this->id;
53 function set_form_id ($id = "") {
54 if (!empty($id)) {
55 $this->populate($id);
58 function set_fax_id($id) {
59 $this->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) {
84 $this->name = $name;
86 function get_name() {
87 return $this->name;
89 function set_email($email) {
90 $this->email = $email;
92 function get_email() {
93 return $this->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)) {
100 return TYPE_PRINT;
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();
113 return "";
115 function _set_number($num, $type) {
116 $found = false;
117 for ($i=0;$i<count($this->phone_numbers);$i++) {
118 if ($this->phone_numbers[$i]->type == $type) {
119 $found = true;
120 $this->phone_numbers[$i]->set_phone($num);
123 if ($found == false) {
124 $p = new PhoneNumber("",$this->id);
125 $p->set_type($type);
126 $p->set_phone($num);
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);
140 function get_fax() {
141 foreach($this->phone_numbers as $phone) {
142 if ($phone->type == TYPE_FAX) {
143 return $phone->get_phone_display();
146 return "";
148 function populate() {
149 parent::populate();
150 $this->address = Address::factory_address($this->id);
151 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
154 function persist() {
155 parent::persist();
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";
165 $res = sqlQ($sql);
166 while ($row = sqlFetchArray($res) ) {
167 $d_string = $row['city'];
168 if (!empty($row['city']) && $row['state']) {
169 $d_string .= ", ";
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") {
178 if (empty($city)) {
179 $city= "";
181 else {
182 $city = " WHERE city = " . add_escape_custom($foreign_id);
184 $p = new Pharmacy();
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);
190 //echo "sql: $sql";
191 //print_r($results);
192 while($row = sqlFetchArray($results) ) {
193 $pharmacies[] = new Pharmacy($row['id']);
195 return $pharmacies;
198 function toString($html = false) {
199 $string .= "\n"
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];
207 if ($html) {
208 return nl2br($string);
210 else {
211 return $string;
215 } // end of Pharmacy
216 /*$p = new Pharmacy("1");
217 echo $p->toString(true);