If the patient_data is null Patient Portal get the pid for new patient is as null...
[openemr.git] / library / classes / Pharmacy.class.php
blobabc2852dd4d75def251e3581cec63efc2ada312c
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 **************************************************************************/
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");
22 /**
23 * class Pharmacy
26 class Pharmacy extends ORDataObject{
27 var $id;
28 var $name;
29 var $phone_numbers;
30 var $address;
31 var $transmit_method;
32 var $email;
33 var $transmit_method_array = array("","Print", "Email" ,"Fax");
35 /**
36 * Constructor sets all Prescription attributes to their default value
38 function Pharmacy($id = "", $prefix = "") {
39 $this->id = $id;
40 $this->name = "";
41 $this->email = "";
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();
48 if ($id != "") {
49 $this->populate();
53 function set_id($id = "") {
54 $this->id = $id;
56 function get_id() {
57 return $this->id;
59 function set_form_id ($id = "") {
60 if (!empty($id)) {
61 $this->populate($id);
64 function set_fax_id($id) {
65 $this->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) {
90 $this->name = $name;
92 function get_name() {
93 return $this->name;
95 function set_email($email) {
96 $this->email = $email;
98 function get_email() {
99 return $this->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)) {
106 return TYPE_PRINT;
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();
119 return "";
121 function _set_number($num, $type) {
122 $found = false;
123 for ($i=0;$i<count($this->phone_numbers);$i++) {
124 if ($this->phone_numbers[$i]->type == $type) {
125 $found = true;
126 $this->phone_numbers[$i]->set_phone($num);
129 if ($found == false) {
130 $p = new PhoneNumber("",$this->id);
131 $p->set_type($type);
132 $p->set_phone($num);
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);
146 function get_fax() {
147 foreach($this->phone_numbers as $phone) {
148 if ($phone->type == TYPE_FAX) {
149 return $phone->get_phone_display();
152 return "";
154 function populate() {
155 parent::populate();
156 $this->address = Address::factory_address($this->id);
157 $this->phone_numbers = PhoneNumber::factory_phone_numbers($this->id);
160 function persist() {
161 parent::persist();
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";
171 $res = sqlQ($sql);
172 while ($row = mysql_fetch_array($res) ) {
173 $d_string = $row['city'];
174 if (!empty($row['city']) && $row['state']) {
175 $d_string .= ", ";
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") {
184 if (empty($city)) {
185 $city= "";
187 else {
188 $city = " WHERE city = " . mysql_real_escape_string($foreign_id);
190 $p = new Pharmacy();
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);
196 //echo "sql: $sql";
197 //print_r($results);
198 while($row = mysql_fetch_array($results) ) {
199 $pharmacies[] = new Pharmacy($row['id']);
201 return $pharmacies;
204 function toString($html = false) {
205 $string .= "\n"
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];
213 if ($html) {
214 return nl2br($string);
216 else {
217 return $string;
221 } // end of Pharmacy
222 /*$p = new Pharmacy("1");
223 echo $p->toString(true);