6 * Revision 1.6 2019/02/18 avanss llc
7 * replaced rxlist API with rxnav.nlm.nih.gov
9 * Revision 1.5 2016/02/016 sherwin gaddis
12 * Revision 1.4 2008/05/09 20:10:28 cfapress
13 * Changes to handle to HTML returned by rxlist.com
15 * Revision 1.3 2007/06/19 02:34:45 sunsetsystems
16 * drug lookup fix from Sam Rajan
18 * Revision 1.2 2005/12/27 00:45:19 sunsetsystems
21 * Revision 1.1.1.3 2005/06/23 05:25:49 drbowen
24 * Revision 1.1.1.2 2005/03/28 00:44:54 drbowen
27 * Revision 1.1.1.1 2005/03/09 19:59:43 wpennington
28 * First import of OpenEMR
30 * Revision 1.2 2002/08/06 13:49:08 rufustfirefly
31 * updated rxlist class for changes in RxList.com
33 * Revision 1.1 2002/07/08 14:42:25 rufustfirefly
34 * RxList.com prescription "module" for formulary
37 * @link https://www.open-emr.org
38 * @author rufustfirefly
41 * @author sunsetsystems
43 * @author sherwin gaddis
45 * @author Brady Miller <brady.g.miller@gmail.com>
46 * @author Jerry Padgett <sjpadgett@gmail.com>
47 * @author Stephen Waite <stephen.waite@cmsvt.com>
48 * @copyright Copyright (c) 2002 rufustfirefly
49 * @copyright Copyright (c) 2005 wpennington
50 * @copyright Copyright (c) 2005 drbowen
51 * @copyright Copyright (c) 2005-2007 sunsetsystems
52 * @copyright Copyright (c) 2008 cfapress
53 * @copyright Copyright (c) 2016 sherwin gaddis
54 * @copyright Copyright (c) 2019 avanss llc
55 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
56 * @copyright Copyright (c) 2019-2021 Jerry Padgett <sjpadgett@gmail.com>
57 * @copyright Copyright (c) 2021 Stephen Waite <stephen.waite@cmsvt.com>
58 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
63 use OpenEMR\Common\Http\oeHttp
;
68 public function getPage($query)
70 $url = "https://rxnav.nlm.nih.gov/REST/Prescribe/drugs";
71 $response = oeHttp
::get($url, ['name' => $query]);
72 $buffer = $response->body();
73 return $buffer ?
: false;
76 public function getList($query)
78 $page = $this->getPage($query);
79 $tokens = $this->parseToTokens($page);
80 $hash = $this->tokensToHash($tokens);
82 foreach ($hash as $index => $data) {
84 foreach ($data as $k => $v) {
90 if (trim($my_data['rxcui']) !== '') {
91 $rxcui = " (RxCUI:" . trim($my_data['rxcui'] . ")");
95 if (trim($my_data['synonym']) !== '') {
96 $synonym = " | (" . trim($my_data['synonym']) . ")";
99 $list[trim($my_data['name'] . $rxcui) . $synonym] =
100 trim($my_data['name']);
106 /* break the web page into a collection of TAGS
107 * such as <input ..> or <img ... >
109 public function parseToTokens($page)
115 while ($pos < strlen($page)) {
116 switch (substr($page, $pos, 1)) {
123 $tokens[$token] .= substr($page, $pos, 1);
128 $tokens[$token] .= substr($page, $pos, 1);
134 $tokens[$token] .= substr($page, $pos, 1);
143 public function tokensToHash($tokens)
150 for ($pos = 0, $posMax = count($tokens); $pos < $posMax; $pos++
) {
151 if ((bool)str_contains($tokens[$pos], "<name>") && $pos !== 3) {
152 // found a brand line 'token'
158 if ((bool)str_contains($tokens[$pos], "<synonym>")) {
159 // found a generic line 'token'
161 //print "generic_name record start at $pos<BR>\n";
162 $ending = "</synonym>";
166 if ((bool)str_contains($tokens[$pos], "<rxcui>")) {
167 // found a drug-class 'token'
169 $ending = "</rxcui>";
173 if (isset($hash["synonym"])) {
178 // Unset hash and type
184 if ($pos === ($record +
1) and ($ending != "")) {
185 $my_pos = stripos($tokens[$pos], "<");
186 $hash[$type] = substr($tokens[$pos], 0, $my_pos);
187 $hash[$type] = str_replace("&", "&", $hash[$type]);
188 //print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";