remove obsolete frame divider images
[openemr.git] / library / classes / RXList.class.php
blobbb415ea566e0eedc529a05945a4c9cf74160e4ea
1 <?php
2 // $Id$
3 // $Author$
4 //
5 // $Log$
6 // Revision 1.2 2005/12/27 00:45:19 sunsetsystems
7 // fix broken url
8 //
9 // Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
10 // Initial import.
12 // Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
13 // Initial import.
15 // Revision 1.1.1.1 2005/03/09 19:59:43 wpennington
16 // First import of OpenEMR
18 // Revision 1.2 2002/08/06 13:49:08 rufustfirefly
19 // updated rxlist class for changes in RxList.com
21 // Revision 1.1 2002/07/08 14:42:25 rufustfirefly
22 // RxList.com prescription "module" for formulary
25 if (!defined('__CLASS_RXLIST_PHP__')) {
26 define('__CLASS_RXLIST_PHP__', true);
28 class RxList {
30 function getPage ( $query ) {
31 $url = "http://www.rxlist.com/cgi/rxlist.cgi?drug=".
32 // $url = "http://129.250.146.18/cgi/rxlist.cgi?drug=".
33 urlencode($query);
35 if (!($fp = fopen($url, "r"))) {
36 // If we fail to get the page, return false
37 return false;
38 } else {
39 // Get the page
40 $buffer = 0;
41 while (!feof($fp)) {
42 $buffer .= fgets($fp, 4096);
44 fclose ($fp);
45 return $buffer;
46 } // end checking for successful open
47 } // end function RxList::getPage
49 function get_list ( $query ) {
50 $page = RxList::getPage($query);
51 $tokens = RxList::parse2tokens($page);
52 $hash = RxList::tokens2hash($tokens);
53 foreach ($hash AS $index => $data) {
54 unset($my_data);
55 foreach ($data AS $k => $v) {
56 $my_data[$k] = $v;
58 $list[trim($my_data[brand_name])." (".trim($my_data[generic_name]).")"] =
59 trim($my_data[brand_name]);
61 return $list;
62 } // end function RxList::get_list
64 function parse2tokens( $page ) {
65 $pos = 0; $token = 0; unset ($tokens);
66 $in_token = false;
67 while ($pos < strlen($page)) {
68 switch(substr($page, $pos, 1)) {
69 case "<":
70 if ($in_token) {
71 $token++;
72 $in_token = false;
74 $tokens[$token] .= substr($page,$pos,1);
75 $in_token = true;
76 break;
78 case ">":
79 $tokens[$token] .= substr($page,$pos,1);
80 $in_token = false;
81 $token++;
82 break;
84 default:
85 $tokens[$token] .= substr($page,$pos,1);
86 $in_token = false;
87 break;
89 } // end decide what to do
90 $pos++;
91 } // end looping through string
92 return $tokens;
93 } // end function RxList::parse2tokens
95 function tokens2hash ( $tokens ) {
96 $record = false; $current = 0; unset($hash); unset($all);
97 for ($pos=0; $pos<count($tokens); $pos++) {
98 if (!(strpos($tokens[$pos], "Brand Name") === false)){
99 $type = "brand_name";
100 $record = $pos;
101 $ending = "</a>";
103 if (!(strpos($tokens[$pos], "Generic Name") === false)){
104 $type = "generic_name";
105 //print "generic_name record start at $pos<BR>\n";
106 $ending = "</a>";
107 $record = $pos;
109 if (!(strpos($tokens[$pos], "Drug Class") === false)){
110 $type = "drug_class";
111 //print "drug_class record start at $pos<BR>\n";
112 $ending = "</font>";
113 $record = $pos;
115 // Handle the ending (assume when all fields are set
116 // that we're done)
117 if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
118 // Reset record
119 $record = false;
120 // Add hash to all
121 $all[] = $hash;
122 // Unset hash and type
123 unset($hash); $type = ""; $ending = "";
125 if ((($pos == ($record + 1)) or
126 ($pos == ($record + 2)) or
127 ($pos == ($record + 3)))
128 and ($ending != "")) {
129 //print "tokens[$pos] = ".htmlentities($tokens[$pos])."<BR>\n";
130 if ((!(strpos(strtoupper($tokens[$pos]), "</A>") === false)) or
131 (!(strpos(strtoupper($tokens[$pos]), "</FONT>") === false))) {
132 // Find where anchor is
133 $my_pos = strpos(strtoupper($tokens[$pos]), "<");
134 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
135 $hash[$type] = str_replace("&amp;", "&", $hash[$type]);
136 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
137 $type = ""; $ending = "";
140 } // end looping
141 return $all;
142 } // end function RxList::tokens2hash
144 } // end class RxList
146 } // end if not defined
148 // TEST CRAP HERE
149 $page = RxList::getPage("http://129.250.146.18/cgi/rxlist.cgi?drug=lipitor");
150 $tokens = RxList::parse2tokens($page);
151 $hash = RxList::tokens2hash($tokens);
152 foreach ($hash AS $k => $v) {
153 print "<UL>k = ".htmlentities($k)." \n";
154 foreach ($v AS $key => $value) {
155 print "<LI>$key = $value\n";
157 print "</UL>\n";
160 print "<FORM>\n";
161 print html_form::select_widget("test", RxList::get_list($drug));
162 print "</FORM>\n";