6 // Revision 1.3 2007/06/19 02:34:45 sunsetsystems
7 // drug lookup fix from Sam Rajan
9 // Revision 1.2 2005/12/27 00:45:19 sunsetsystems
12 // Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
15 // Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
18 // Revision 1.1.1.1 2005/03/09 19:59:43 wpennington
19 // First import of OpenEMR
21 // Revision 1.2 2002/08/06 13:49:08 rufustfirefly
22 // updated rxlist class for changes in RxList.com
24 // Revision 1.1 2002/07/08 14:42:25 rufustfirefly
25 // RxList.com prescription "module" for formulary
28 if (!defined('__CLASS_RXLIST_PHP__')) {
29 define('__CLASS_RXLIST_PHP__', true);
33 function getPage ( $query ) {
34 $url = "http://www.rxlist.com/cgi/rxlist.cgi?drug=".
35 // $url = "http://129.250.146.18/cgi/rxlist.cgi?drug=".
38 if (!($fp = fopen($url, "r"))) {
39 // If we fail to get the page, return false
45 $buffer .= fgets($fp, 4096);
49 } // end checking for successful open
50 } // end function RxList::getPage
52 function get_list ( $query ) {
53 $page = RxList
::getPage($query);
54 $tokens = RxList
::parse2tokens($page);
55 $hash = RxList
::tokens2hash($tokens);
56 foreach ($hash AS $index => $data) {
58 foreach ($data AS $k => $v) {
61 $list[trim($my_data[brand_name
])." (".trim($my_data[generic_name
]).")"] =
62 trim($my_data[brand_name
]);
65 } // end function RxList::get_list
67 function parse2tokens( $page ) {
68 $pos = 0; $token = 0; unset ($tokens);
70 while ($pos < strlen($page)) {
71 switch(substr($page, $pos, 1)) {
77 $tokens[$token] .= substr($page,$pos,1);
82 $tokens[$token] .= substr($page,$pos,1);
88 $tokens[$token] .= substr($page,$pos,1);
92 } // end decide what to do
94 } // end looping through string
96 } // end function RxList::parse2tokens
98 function tokens2hash ( $tokens ) {
99 $record = false; $current = 0; unset($hash); unset($all);
100 for ($pos=0; $pos<count($tokens); $pos++
) {
101 if (!(strpos($tokens[$pos], "Brand Name") === false)){
102 $type = "brand_name";
106 if (!(strpos($tokens[$pos], "Generic Name") === false)){
107 $type = "generic_name";
108 //print "generic_name record start at $pos<BR>\n";
112 if (!(strpos($tokens[$pos], "Drug Class") === false)){
113 $type = "drug_class";
114 //print "drug_class record start at $pos<BR>\n";
118 // Handle the ending (assume when all fields are set
120 if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
125 // Unset hash and type
126 unset($hash); $type = ""; $ending = "";
128 if ((($pos == ($record +
1)) or
129 ($pos == ($record +
2)) or
130 ($pos == ($record +
3)))
131 and ($ending != "")) {
132 //print "tokens[$pos] = ".htmlentities($tokens[$pos])."<BR>\n";
133 if ((!(strpos(strtoupper($tokens[$pos]), "</A>" ) === false)) or
134 (!(strpos(strtoupper($tokens[$pos]), "</FONT>") === false)) or
135 (!(strpos(strtoupper($tokens[$pos]), "</TD>" ) === false))) {
136 // Find where anchor is
137 $my_pos = strpos(strtoupper($tokens[$pos]), "<");
138 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
139 $hash[$type] = str_replace("&", "&", $hash[$type]);
140 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
141 $type = ""; $ending = "";
146 } // end function RxList::tokens2hash
148 } // end class RxList
150 } // end if not defined
153 $page = RxList::getPage("http://129.250.146.18/cgi/rxlist.cgi?drug=lipitor");
154 $tokens = RxList::parse2tokens($page);
155 $hash = RxList::tokens2hash($tokens);
156 foreach ($hash AS $k => $v) {
157 print "<UL>k = ".htmlentities($k)." \n";
158 foreach ($v AS $key => $value) {
159 print "<LI>$key = $value\n";
165 print html_form::select_widget("test", RxList::get_list($drug));