7 // Revision 1.5 2016/02/016 sherwin gaddis
10 // Revision 1.4 2008/05/09 20:10:28 cfapress
11 // Changes to handle to HTML returned by rxlist.com
13 // Revision 1.3 2007/06/19 02:34:45 sunsetsystems
14 // drug lookup fix from Sam Rajan
16 // Revision 1.2 2005/12/27 00:45:19 sunsetsystems
19 // Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
22 // Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
25 // Revision 1.1.1.1 2005/03/09 19:59:43 wpennington
26 // First import of OpenEMR
28 // Revision 1.2 2002/08/06 13:49:08 rufustfirefly
29 // updated rxlist class for changes in RxList.com
31 // Revision 1.1 2002/07/08 14:42:25 rufustfirefly
32 // RxList.com prescription "module" for formulary
35 if (!defined('__CLASS_RXLIST_PHP__')) {
36 define('__CLASS_RXLIST_PHP__', true);
41 function getPage($query)
43 $url = "http://www.rxlist.com/script/main/srchcont_rxlist.asp?src=".
44 //$url = "http://www.rxlist.com/cgi/rxlist.cgi?drug=".
45 // $url = "http://129.250.146.18/cgi/rxlist.cgi?drug=".
48 if (!($fp = fopen($url, "r"))) {
49 // If we fail to get the page, return false
55 $buffer .= fgets($fp, 4096);
60 } // end checking for successful open
61 } // end function RxList::getPage
63 function get_list($query)
65 $page = RxList
::getPage($query);
66 $tokens = RxList
::parse2tokens($page);
67 $hash = RxList
::tokens2hash($tokens);
68 foreach ($hash as $index => $data) {
70 foreach ($data as $k => $v) {
74 $list[trim($my_data[brand_name
])." (".trim($my_data[generic_name
]).")"] =
75 trim($my_data[brand_name
]);
79 } // end function RxList::get_list
81 /* break the web page into a collection of TAGS
82 * such as <input ..> or <img ... >
84 function parse2tokens($page)
90 while ($pos < strlen($page)) {
91 switch (substr($page, $pos, 1)) {
98 $tokens[$token] .= substr($page, $pos, 1);
103 $tokens[$token] .= substr($page, $pos, 1);
109 $tokens[$token] .= substr($page, $pos, 1);
112 } // end decide what to do
114 } // end looping through string
116 } // end function RxList::parse2tokens
119 /* WTF does this crap do? */
120 function tokens2hash($tokens)
126 for ($pos=0; $pos<count($tokens); $pos++
) {
127 if (!(strpos($tokens[$pos], "Brand Name") === false)) {
128 // found a brand line 'token'
129 $type = "brand_name";
134 if (!(strpos($tokens[$pos], "Generic Name") === false)) {
135 // found a generic line 'token'
136 $type = "generic_name";
137 //print "generic_name record start at $pos<BR>\n";
142 if (!(strpos($tokens[$pos], "Drug Class") === false)) {
143 // found a drug-class 'token'
144 $type = "drug_class";
145 //print "drug_class record start at $pos<BR>\n";
150 // Handle the ending (assume when all fields are set
153 // May 2008 - RXList doesn't always return all three types of 'tokens'
154 // for a drug, so I replaced the 'and's with 'or's -- JRM
155 //if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
156 if (isset($hash["drug_class"]) or isset($hash["brand_name"]) or isset($hash["generic_name"])) {
161 // Unset hash and type
167 if ((($pos == ($record +
1)) or
168 ($pos == ($record +
2)) or
169 ($pos == ($record +
3)))
170 and ($ending != "")) {
171 //print "tokens[$pos] = ".htmlentities($tokens[$pos])."<BR>\n";
172 if ((!(strpos(strtoupper($tokens[$pos]), "</A>") === false)) or
173 (!(strpos(strtoupper($tokens[$pos]), "</FONT>") === false)) or
174 (!(strpos(strtoupper($tokens[$pos]), "</TD>") === false))) {
175 // Find where anchor is
176 $my_pos = strpos(strtoupper($tokens[$pos]), "<");
177 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
178 $hash[$type] = str_replace("&", "&", $hash[$type]);
179 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
186 } // end function RxList::tokens2hash
187 } // end class RxList
189 } // end if not defined
192 //$page = RxList::getPage("http://129.250.146.18/cgi/rxlist.cgi?drug=lipitor");
193 $page = RxList::getPage("http://www.rxlist.com/cgi/rxlist.cgi?drug=lipitor");
194 $tokens = RxList::parse2tokens($page);
195 $hash = RxList::tokens2hash($tokens);
196 foreach ($hash AS $k => $v) {
197 print "<UL>k = ".htmlentities($k)." \n";
198 foreach ($v AS $key => $value) {
199 print "<LI>$key = $value\n";
205 print html_form::select_widget("test", RxList::get_list($drug));