6 // Revision 1.2 2005/12/27 00:45:19 sunsetsystems
9 // Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
12 // Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
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);
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=".
35 if (!($fp = fopen($url, "r"))) {
36 // If we fail to get the page, return false
42 $buffer .= fgets($fp, 4096);
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) {
55 foreach ($data AS $k => $v) {
58 $list[trim($my_data[brand_name
])." (".trim($my_data[generic_name
]).")"] =
59 trim($my_data[brand_name
]);
62 } // end function RxList::get_list
64 function parse2tokens( $page ) {
65 $pos = 0; $token = 0; unset ($tokens);
67 while ($pos < strlen($page)) {
68 switch(substr($page, $pos, 1)) {
74 $tokens[$token] .= substr($page,$pos,1);
79 $tokens[$token] .= substr($page,$pos,1);
85 $tokens[$token] .= substr($page,$pos,1);
89 } // end decide what to do
91 } // end looping through string
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)){
103 if (!(strpos($tokens[$pos], "Generic Name") === false)){
104 $type = "generic_name";
105 //print "generic_name record start at $pos<BR>\n";
109 if (!(strpos($tokens[$pos], "Drug Class") === false)){
110 $type = "drug_class";
111 //print "drug_class record start at $pos<BR>\n";
115 // Handle the ending (assume when all fields are set
117 if (isset($hash["drug_class"]) and isset($hash["brand_name"]) and isset($hash["generic_name"])) {
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("&", "&", $hash[$type]);
136 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
137 $type = ""; $ending = "";
142 } // end function RxList::tokens2hash
144 } // end class RxList
146 } // end if not defined
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";
161 print html_form::select_widget("test", RxList::get_list($drug));