6 // Revision 1.4 2008/05/09 20:10:28 cfapress
7 // Changes to handle to HTML returned by rxlist.com
9 // Revision 1.3 2007/06/19 02:34:45 sunsetsystems
10 // drug lookup fix from Sam Rajan
12 // Revision 1.2 2005/12/27 00:45:19 sunsetsystems
15 // Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
18 // Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
21 // Revision 1.1.1.1 2005/03/09 19:59:43 wpennington
22 // First import of OpenEMR
24 // Revision 1.2 2002/08/06 13:49:08 rufustfirefly
25 // updated rxlist class for changes in RxList.com
27 // Revision 1.1 2002/07/08 14:42:25 rufustfirefly
28 // RxList.com prescription "module" for formulary
31 if (!defined('__CLASS_RXLIST_PHP__')) {
32 define('__CLASS_RXLIST_PHP__', true);
36 function getPage ( $query ) {
37 $url = "http://www.rxlist.com/cgi/rxlist.cgi?drug=".
38 // $url = "http://129.250.146.18/cgi/rxlist.cgi?drug=".
41 if (!($fp = fopen($url, "r"))) {
42 // If we fail to get the page, return false
48 $buffer .= fgets($fp, 4096);
52 } // end checking for successful open
53 } // end function RxList::getPage
55 function get_list ( $query ) {
56 $page = RxList
::getPage($query);
57 $tokens = RxList
::parse2tokens($page);
58 $hash = RxList
::tokens2hash($tokens);
59 foreach ($hash AS $index => $data) {
61 foreach ($data AS $k => $v) {
64 $list[trim($my_data[brand_name
])." (".trim($my_data[generic_name
]).")"] =
65 trim($my_data[brand_name
]);
68 } // end function RxList::get_list
70 /* break the web page into a collection of TAGS
71 * such as <input ..> or <img ... >
73 function parse2tokens( $page ) {
74 $pos = 0; $token = 0; unset ($tokens);
76 while ($pos < strlen($page)) {
77 switch(substr($page, $pos, 1)) {
83 $tokens[$token] .= substr($page,$pos,1);
88 $tokens[$token] .= substr($page,$pos,1);
94 $tokens[$token] .= substr($page,$pos,1);
98 } // end decide what to do
100 } // end looping through string
102 } // end function RxList::parse2tokens
105 /* WTF does this crap do? */
106 function tokens2hash ( $tokens ) {
107 $record = false; $current = 0; unset($hash); unset($all);
108 for ($pos=0; $pos<count($tokens); $pos++
) {
110 if (!(strpos($tokens[$pos], "Brand Name") === false)){
111 // found a brand line 'token'
112 $type = "brand_name";
117 if (!(strpos($tokens[$pos], "Generic Name") === false)){
118 // found a generic line 'token'
119 $type = "generic_name";
120 //print "generic_name record start at $pos<BR>\n";
125 if (!(strpos($tokens[$pos], "Drug Class") === false)){
126 // found a drug-class 'token'
127 $type = "drug_class";
128 //print "drug_class record start at $pos<BR>\n";
133 // Handle the ending (assume when all fields are set
136 // May 2008 - RXList doesn't always return all three types of 'tokens'
137 // for a drug, so I replaced the 'and's with 'or's -- JRM
138 //if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
139 if (isset($hash["drug_class"]) or isset($hash["brand_name"]) or isset($hash["generic_name"])) {
144 // Unset hash and type
145 unset($hash); $type = ""; $ending = "";
148 if ((($pos == ($record +
1)) or
149 ($pos == ($record +
2)) or
150 ($pos == ($record +
3)))
153 //print "tokens[$pos] = ".htmlentities($tokens[$pos])."<BR>\n";
154 if ((!(strpos(strtoupper($tokens[$pos]), "</A>" ) === false)) or
155 (!(strpos(strtoupper($tokens[$pos]), "</FONT>") === false)) or
156 (!(strpos(strtoupper($tokens[$pos]), "</TD>" ) === false)))
158 // Find where anchor is
159 $my_pos = strpos(strtoupper($tokens[$pos]), "<");
160 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
161 $hash[$type] = str_replace("&", "&", $hash[$type]);
162 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
163 $type = ""; $ending = "";
168 } // end function RxList::tokens2hash
170 } // end class RxList
172 } // end if not defined
175 //$page = RxList::getPage("http://129.250.146.18/cgi/rxlist.cgi?drug=lipitor");
176 $page = RxList::getPage("http://www.rxlist.com/cgi/rxlist.cgi?drug=lipitor");
177 $tokens = RxList::parse2tokens($page);
178 $hash = RxList::tokens2hash($tokens);
179 foreach ($hash AS $k => $v) {
180 print "<UL>k = ".htmlentities($k)." \n";
181 foreach ($v AS $key => $value) {
182 print "<LI>$key = $value\n";
188 print html_form::select_widget("test", RxList::get_list($drug));