Skip to content

Commit

Permalink
New use RxNORM table for drug lookups. (openemr#4399)
Browse files Browse the repository at this point in the history
* New use RxNORM table for drug lookups.
- if installed option to use rxnorms
- fudge dialog size and replace Done button with Quit.

* Add Native load RxCUI lookup along with RxNORM table
  • Loading branch information
sjpadgett authored May 17, 2021
1 parent 724de4c commit a76b26d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 31 deletions.
6 changes: 5 additions & 1 deletion controllers/C_Prescription.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ function __construct($template_mod = "general")
$this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
$this->pconfig = $GLOBALS['oer_config']['prescriptions'];
$this->RxList = new RxList();

// test if rxnorm available for lookups.
$rxn = sqlQuery("SELECT table_name FROM information_schema.tables WHERE table_name = 'RXNCONSO' OR table_name = 'rxconso'");
$rxcui = sqlQuery("SELECT ct_id FROM `code_types` WHERE `ct_key` = ? AND `ct_active` = 1", array('RXCUI'));
$this->assign("RXNORMS_AVAILABLE", !empty($rxn));
$this->assign("RXCUI_AVAILABLE", !empty($rxcui));
// Assign the CSRF_TOKEN_FORM
$this->assign("CSRF_TOKEN_FORM", CsrfUtils::collectCsrfToken());

Expand Down
8 changes: 3 additions & 5 deletions interface/patient_file/summary/demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ function toggleIndicator(target, div) {
//
function editScripts(url) {
var AddScript = function () {

var __this = $(this);
__this.find("#clearButton").css("display", "");
__this.find("#backButton").css("display", "");
Expand All @@ -287,7 +286,6 @@ function editScripts(url) {
iam.location.href = '<?php echo $GLOBALS['webroot']?>/controller.php?prescription&edit&id=0&pid=' + <?php echo js_url($pid); ?>;
};
var ListScripts = function () {

var __this = $(this);
__this.find("#clearButton").css("display", "none");
__this.find("#backButton").css("display", "none");
Expand All @@ -297,14 +295,14 @@ function editScripts(url) {
};

let title = <?php echo xlj('Prescriptions'); ?>;
let w = 910; // for weno width
let w = 960; // for weno width

dlgopen(url, 'editScripts', w, 300, '', '', {
dlgopen(url, 'editScripts', w, 400, '', '', {
buttons: [
{text: <?php echo xlj('Add'); ?>, close: false, id: 'addButton', class: 'btn-primary btn-sm', click: AddScript},
{text: <?php echo xlj('Clear'); ?>, close: false, id: 'clearButton', style: 'display:none;', class: 'btn-primary btn-sm', click: AddScript},
{text: <?php echo xlj('Back'); ?>, close: false, id: 'backButton', style: 'display:none;', class: 'btn-primary btn-sm', click: ListScripts},
{text: <?php echo xlj('Done'); ?>, close: true, id: 'doneButton', class: 'btn-secondary btn-sm'}
{text: <?php echo xlj('Quit'); ?>, close: true, id: 'doneButton', class: 'btn-secondary btn-sm'}
],
onClosed: 'refreshme',
allowResize: true,
Expand Down
26 changes: 23 additions & 3 deletions library/ajax/prescription_drugname_lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @copyright Copyright (c) 2008 Jason Morrill <jason@italktech.net>
* @copyright Copyright (c) 2017 Sherwin Gaddis <sherwingaddis@gmail.com>
* @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2021 Jerry Padgett <sjpadgett@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

Expand All @@ -24,16 +25,35 @@
if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}
// will never be both
$is_rxnorm = $_GET['use_rxnorm'] == "true";
$is_rxcui = $_GET['use_rxcui'] == "true";

if (isset($_GET['term'])) {
$return_arr = array();
$term = filter_input(INPUT_GET, "term");

$sql = "SELECT `name` FROM `drugs` WHERE `name` LIKE ? ORDER BY `name`";
if ($is_rxnorm) {
$sql = "SELECT `str` as name, `RXCUI` as `rxnorm` FROM `rxnconso` WHERE `SAB` = 'RXNORM' AND `str` LIKE ? GROUP BY `RXCUI` ORDER BY `str` LIMIT 100";
} elseif ($is_rxcui) {
$sql = "SELECT `code_text` as name, `code` as rxnorm FROM `codes` WHERE `code_text` LIKE ? AND `code_type` = ? GROUP BY `code` ORDER BY `code_text` LIMIT 100";
} else {
$sql = "SELECT `name`, `drug_code` as rxnorm FROM `drugs` WHERE `name` LIKE ? GROUP BY `drug_code` ORDER BY `name` LIMIT 100";
}
$val = array($term . '%');
if ($is_rxcui) {
$code_type = sqlQuery("SELECT ct_id FROM `code_types` WHERE `ct_key` = ? AND `ct_active` = 1", array('RXCUI'));
$val = array($term . '%', $code_type['ct_id']);
if (empty($code_type['ct_id'])) {
throw new \Exception(xlt('Install RxCUI monthly via Native Load or enable in Lists!'));
}
}
$res = sqlStatement($sql, $val);
while ($row = sqlFetchArray($res)) {
$return_arr[] = $row['name'];
$return_arr[] = array(
'display_name' => text($row['name'] . " (RxCUI:" . trim($row['rxnorm']) . ")"),
'id_name' => text($row['name']),
'rxnorm' => text($row['rxnorm'])
);
}

/* Toss back results as json encoded array. */
Expand Down
24 changes: 12 additions & 12 deletions src/Rx/RxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public function getPage($query)
$url = "https://rxnav.nlm.nih.gov/REST/Prescribe/drugs";
$response = oeHttp::get($url, ['name' => $query]);
$buffer = $response->body();
return $buffer ? $buffer : false;
return $buffer ?: false;
}

public function getList($query)
{
$page = $this->getPage($query);
$tokens = $this->parse2tokens($page);
$hash = $this->tokens2hash($tokens);
$tokens = $this->parseToTokens($page);
$hash = $this->tokensToHash($tokens);
if (!empty($hash)) {
foreach ($hash as $index => $data) {
unset($my_data);
Expand All @@ -88,7 +88,7 @@ public function getList($query)
$rxcui = '';

if (trim($my_data['rxcui']) !== '') {
$rxcui = " RXCUI:" . trim($my_data['rxcui']);
$rxcui = " (RxCUI:" . trim($my_data['rxcui'] . ")");
}

$synonym = '';
Expand All @@ -97,7 +97,7 @@ public function getList($query)
}

$list[trim($my_data['name'] . $rxcui) . $synonym] =
trim($my_data['name']);
trim($my_data['name']);
}
}
return $list;
Expand All @@ -106,7 +106,7 @@ public function getList($query)
/* break the web page into a collection of TAGS
* such as <input ..> or <img ... >
*/
public function parse2tokens($page)
public function parseToTokens($page)
{
$pos = 0;
$token = 0;
Expand Down Expand Up @@ -140,30 +140,30 @@ public function parse2tokens($page)
return $tokens;
}

public function tokens2hash($tokens)
public function tokensToHash($tokens)
{
$record = false;
$current = 0;
unset($hash);
$hash = [];
unset($all);
for ($pos = 0; $pos < count($tokens); $pos++) {
if (!(strpos($tokens[$pos], "<name>") === false) && $pos !== 3) {
for ($pos = 0, $posMax = count($tokens); $pos < $posMax; $pos++) {
if ((bool)str_contains($tokens[$pos], "<name>") && $pos !== 3) {
// found a brand line 'token'
$type = "name";
$record = $pos;
$ending = "</name>";
}

if (!(strpos($tokens[$pos], "<synonym>") === false)) {
if ((bool)str_contains($tokens[$pos], "<synonym>")) {
// found a generic line 'token'
$type = "synonym";
//print "generic_name record start at $pos<BR>\n";
$ending = "</synonym>";
$record = $pos;
}

if (!(strpos($tokens[$pos], "<rxcui>") === false)) {
if ((bool)str_contains($tokens[$pos], "<rxcui>")) {
// found a drug-class 'token'
$type = "rxcui";
$ending = "</rxcui>";
Expand All @@ -182,7 +182,7 @@ public function tokens2hash($tokens)
}

if ($pos === ($record + 1) and ($ending != "")) {
$my_pos = strpos(strtoupper($tokens[$pos]), "<");
$my_pos = stripos($tokens[$pos], "<");
$hash[$type] = substr($tokens[$pos], 0, $my_pos);
$hash[$type] = str_replace("&amp;", "&", $hash[$type]);
//print "hash[$type] = ".htmlentities($hash[$type])."<BR>\n";
Expand Down
37 changes: 30 additions & 7 deletions templates/prescription/general_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,25 @@
<input type="hidden" name="patient_id" value="{$prescription->patient->id|attr}" />
</div>
<div class="form-group mt-3">
<label>{xlt t='Drug'}</label>
<label class="mr-2">{xlt t='Drug'}</label>
<div class="form-check-inline">
<label class="form-check-label" title="{xlt t='Search from native inventory drugs table'}">
<input type="radio" class="form-check-input" name="rxcui_select" checked />{xlt t='Use Default'}
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" title="{xlt t='Search from external RxNorm table. Vocabulary RXNORM'}">
<input type="radio" class="form-check-input" name="rxcui_select" {if empty($RXNORMS_AVAILABLE)} disabled{else} checked{/if} />{xlt t='Use RxNorm'}
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label" title="{xlt t='Search from native loaded RxCUI table.'}">
<input type="radio" class="form-check-input" name="rxcui_select" {if empty($RXCUI_AVAILABLE)}disabled{else} checked{/if} />{xlt t='Use RxCUI'}
</label>
</div>
<select class="input-sm form-control" type="input" size="35" name="drug" id="drug"></select>
<a href="javascript:;" id="druglookup" class="small" name="B4" onclick="$('#hiddendiv').show(); document.getElementById('hiddendiv').innerHTML='&lt;iframe src=&quot;controller.php?prescription&amp;lookup&amp;drug=&quot; width=&quot;100%&quot;height=&quot;75&quot; scrolling=&quot;no&quot; frameborder=&quot;no&quot;&gt;&lt;/iframe&gt;'">
({xlt t='click here to search'})
({xlt t='Search Web API'})
</a>
<div class="jumbotron jumbotron-fluid" id="hiddendiv" style="display: none">&nbsp;</div>
</div>
Expand Down Expand Up @@ -345,16 +360,18 @@
{/literal}
csrf_token_form: {$CSRF_TOKEN_FORM|js_escape},
{literal}
term: params.term
};
term: params.term,
use_rxnorm: document.prescribe.rxcui_select[1].checked,
use_rxcui: document.prescribe.rxcui_select[2].checked
}
},
processResults: function(data) {
return {
results: $.map(data, function(item, index) {
return {
text: item,
id: item,
value: item
text: item['display_name'],
id: item['id_name'],
value: item['display_name']
}
})
};
Expand Down Expand Up @@ -419,6 +436,12 @@
}


$(document).on('select2:select', 'select#drug', function(e) {
let optionText = document.getElementById("drug").options[this.selectedIndex].text;
let rxcode = (optionText.split('(RxCUI:').pop().split(')')[0]).trim();
$("#rxnorm_drugcode").val(rxcode);
});

$(function () {{/literal}
{datetimepickerSupport input='format'}
{literal}});</script>
Expand Down
6 changes: 3 additions & 3 deletions templates/prescription/general_lookup.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
function my_process () {
// Pass the variable
{/literal}
let rxText = document.lookup.drug[document.lookup.drug.selectedIndex].text;
let rxcode = (rxText.split('RXCUI:').pop().split('|')[0]).trim();
parent.my_process_lookup(document.lookup.drug.value, rxcode);
let rxText = document.lookup.drug[document.lookup.drug.selectedIndex].text;
let rxcode = (rxText.split('(RxCUI:').pop().split(')')[0]).trim();
parent.my_process_lookup(document.lookup.drug.value, rxcode);
{literal}
}
{/literal}
Expand Down

0 comments on commit a76b26d

Please sign in to comment.