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);
40 function getPage ( $query ) {
41 $url = "http://www.rxlist.com/script/main/srchcont_rxlist.asp?src=".
42 //$url = "http://www.rxlist.com/cgi/rxlist.cgi?drug=".
43 // $url = "http://129.250.146.18/cgi/rxlist.cgi?drug=".
46 if (!($fp = fopen($url, "r"))) {
47 // If we fail to get the page, return false
53 $buffer .= fgets($fp, 4096);
57 } // end checking for successful open
58 } // end function RxList::getPage
60 function get_list ( $query ) {
61 $page = RxList
::getPage($query);
62 $tokens = RxList
::parse2tokens($page);
63 $hash = RxList
::tokens2hash($tokens);
64 foreach ($hash AS $index => $data) {
66 foreach ($data AS $k => $v) {
69 $list[trim($my_data[brand_name
])." (".trim($my_data[generic_name
]).")"] =
70 trim($my_data[brand_name
]);
73 } // end function RxList::get_list
75 /* break the web page into a collection of TAGS
76 * such as <input ..> or <img ... >
78 function parse2tokens( $page ) {
79 $pos = 0; $token = 0; unset ($tokens);
81 while ($pos < strlen($page)) {
82 switch(substr($page, $pos, 1)) {
88 $tokens[$token] .= substr($page,$pos,1);
93 $tokens[$token] .= substr($page,$pos,1);
99 $tokens[$token] .= substr($page,$pos,1);
103 } // end decide what to do
105 } // end looping through string
107 } // end function RxList::parse2tokens
110 /* WTF does this crap do? */
111 function tokens2hash ( $tokens ) {
112 $record = false; $current = 0; unset($hash); unset($all);
113 for ($pos=0; $pos<count($tokens); $pos++
) {
115 if (!(strpos($tokens[$pos], "Brand Name") === false)){
116 // found a brand line 'token'
117 $type = "brand_name";
122 if (!(strpos($tokens[$pos], "Generic Name") === false)){
123 // found a generic line 'token'
124 $type = "generic_name";
125 //print "generic_name record start at $pos<BR>\n";
130 if (!(strpos($tokens[$pos], "Drug Class") === false)){
131 // found a drug-class 'token'
132 $type = "drug_class";
133 //print "drug_class record start at $pos<BR>\n";
138 // Handle the ending (assume when all fields are set
141 // May 2008 - RXList doesn't always return all three types of 'tokens'
142 // for a drug, so I replaced the 'and's with 'or's -- JRM
143 //if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
144 if (isset($hash["drug_class"]) or isset($hash["brand_name"]) or isset($hash["generic_name"])) {
149 // Unset hash and type
150 unset($hash); $type = ""; $ending = "";
153 if ((($pos == ($record +
1)) or
154 ($pos == ($record +
2)) or
155 ($pos == ($record +
3)))
158 //print "tokens[$pos] = ".htmlentities($tokens[$pos])."<BR>\n";
159 if ((!(strpos(strtoupper($tokens[$pos]), "</A>" ) === false)) or
160 (!(strpos(strtoupper($tokens[$pos]), "</FONT>") === false)) or
161 (!(strpos(strtoupper($tokens[$pos]), "</TD>" ) === false)))
163 // Find where anchor is
164 $my_pos = strpos(strtoupper($tokens[$pos]), "<");
165 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
166 $hash[$type] = str_replace("&", "&", $hash[$type]);
167 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
168 $type = ""; $ending = "";
173 } // end function RxList::tokens2hash
175 } // end class RxList
177 } // end if not defined
180 //$page = RxList::getPage("http://129.250.146.18/cgi/rxlist.cgi?drug=lipitor");
181 $page = RxList::getPage("http://www.rxlist.com/cgi/rxlist.cgi?drug=lipitor");
182 $tokens = RxList::parse2tokens($page);
183 $hash = RxList::tokens2hash($tokens);
184 foreach ($hash AS $k => $v) {
185 print "<UL>k = ".htmlentities($k)." \n";
186 foreach ($v AS $key => $value) {
187 print "<LI>$key = $value\n";
193 print html_form::select_widget("test", RxList::get_list($drug));