<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Retrieve Antimicrobial Drug Names and Doses from Clinical Text — ab_from_text • AMR (for R)</title><!-- favicons --><linkrel="icon"type="image/png"sizes="16x16"href="../favicon-16x16.png"><linkrel="icon"type="image/png"sizes="32x32"href="../favicon-32x32.png"><linkrel="apple-touch-icon"type="image/png"sizes="180x180"href="../apple-touch-icon.png"><linkrel="apple-touch-icon"type="image/png"sizes="120x120"href="../apple-touch-icon-120x120.png"><linkrel="apple-touch-icon"type="image/png"sizes="76x76"href="../apple-touch-icon-76x76.png"><linkrel="apple-touch-icon"type="image/png"sizes="60x60"href="../apple-touch-icon-60x60.png"><!-- jquery --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="crossorigin="anonymous"></script><!-- Bootstrap --><linkhref="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css"rel="stylesheet"crossorigin="anonymous"><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4="crossorigin="anonymous"></script><!-- bootstrap-toc --><linkrel="stylesheet"href="../bootstrap-toc.css"><scriptsrc="../bootstrap-toc.js"></script><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css"integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw="crossorigin="anonymous"><!-- clipboard.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI="crossorigin="anonymous"></script><!-- headroom.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js"integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js"integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4="crossorigin="anonymous"></script><!-- pkgdown --><linkhref="../pkgdown.css"rel="stylesheet"><scriptsrc="../pkgdown.js"></script><linkhref="../extra.css"rel="stylesheet"><scriptsrc="../extra.js"></script><metaproperty="og:title"content="Retrieve Antimicrobial Drug Names and Doses from Clinical Text — ab_from_text"><metaproperty="og:description"content="Use this function on e.g. clinical texts from health care records. It returns a list with all antimicrobial drugs, doses and forms of administration found in the texts."><metaproperty="og:image"content="https://msberends.github.io/AMR/logo.svg"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:creator"content="@msberends"><metaname="twitter:site"content="@univgroningen"><!-- mathjax --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js"integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA="crossorigin="anonymous"></script><!--[if lt IE 9]>
<p>Use this function on e.g. clinical texts from health care records. It returns a <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a> with all antimicrobial drugs, doses and forms of administration found in the texts.</p>
type <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"drug"</span>, <spanclass="st">"dose"</span>, <spanclass="st">"administration"</span><spanclass="op">)</span>,
info <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/interactive.html"class="external-link">interactive</a></span><spanclass="op">(</span><spanclass="op">)</span>,
<dd><p>type of property to search for, either <code>"drug"</code>, <code>"dose"</code> or <code>"administration"</code>, see <em>Examples</em></p></dd>
<dt>collapse</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> to pass on to <code>paste(, collapse = ...)</code> to only return one <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> per element of <code>text</code>, see <em>Examples</em></p></dd>
<dt>translate_ab</dt>
<dd><p>if <code>type = "drug"</code>: a column name of the <ahref="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><ahref="ab_property.html">ab_property()</a></code>. Defaults to <code>FALSE</code>. Using <code>TRUE</code> is equal to using "name".</p></dd>
<dt>thorough_search</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to <code>TRUE</code> will take considerably more time than when using <code>FALSE</code>. At default, it will turn <code>TRUE</code> when all input elements contain a maximum of three words.</p></dd>
<dt>info</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether a progress bar should be printed, defaults to <code>TRUE</code> only in interactive mode</p></dd>
<dt>...</dt>
<dd><p>arguments passed on to <code><ahref="as.ab.html">as.ab()</a></code></p></dd>
</dl></div>
<divid="value">
<h2>Value</h2>
<p>A <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a>, or a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> if <code>collapse</code> is not <code>NULL</code></p>
</div>
<divid="details">
<h2>Details</h2>
<p>This function is also internally used by <code><ahref="as.ab.html">as.ab()</a></code>, although it then only searches for the first drug name and will throw a note if more drug names could have been returned. Note: the <code><ahref="as.ab.html">as.ab()</a></code> function may use very long regular expression to match brand names of antimicrobial agents. This may fail on some systems.</p><divclass="section">
<p>At default, the function will search for antimicrobial drug names. All text elements will be searched for official names, ATC codes and brand names. As it uses <code><ahref="as.ab.html">as.ab()</a></code> internally, it will correct for misspelling.</p>
<p>With <code>type = "dose"</code> (or similar, like "dosing", "doses"), all text elements will be searched for <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a> values that are higher than 100 and do not resemble years. The output will be <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a>. It supports any unit (g, mg, IE, etc.) and multiple values in one clinical text, see <em>Examples</em>.</p>
<p>With <code>type = "administration"</code> (or abbreviations, like "admin", "adm"), all text elements will be searched for a form of drug administration. It supports the following forms (including common abbreviations): buccal, implant, inhalation, instillation, intravenous, nasal, oral, parenteral, rectal, sublingual, transdermal and vaginal. Abbreviations for oral (such as 'po', 'per os') will become "oral", all values for intravenous (such as 'iv', 'intraven') will become "iv". It supports multiple values in one clinical text, see <em>Examples</em>.</p>
<p>Without using <code>collapse</code>, this function will return a <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a>. This can be convenient to use e.g. inside a <code><ahref="https://dplyr.tidyverse.org/reference/mutate.html"class="external-link">mutate()</a></code>):<br><code>df %>% mutate(abx = ab_from_text(clinical_text))</code></p>
<p>The returned AB codes can be transformed to official names, groups, etc. with all <code><ahref="ab_property.html">ab_*</a></code> functions such as <code><ahref="ab_property.html">ab_name()</a></code> and <code><ahref="ab_property.html">ab_group()</a></code>, or by using the <code>translate_ab</code> argument.</p>
<p>With using <code>collapse</code>, this function will return a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a>:<br><code>df %>% mutate(abx = ab_from_text(clinical_text, collapse = "|"))</code></p>
The <ahref="lifecycle.html">lifecycle</a> of this function is <strong>stable</strong>. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.</p>
<p>If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.</p>
<p>On our website <ahref="https://msberends.github.io/AMR/">https://msberends.github.io/AMR/</a> you can find <ahref="https://msberends.github.io/AMR/articles/AMR.html">a comprehensive tutorial</a> about how to conduct AMR data analysis, the <ahref="https://msberends.github.io/AMR/reference/">complete documentation of all functions</a> and <ahref="https://msberends.github.io/AMR/articles/WHONET.html">an example analysis using WHONET data</a>.</p>
<divclass="sourceCode"><preclass="sourceCode r"><code><spanclass="co"># mind the bad spelling of amoxicillin in this line, </span>
<spanclass="co"># straight from a true health care record:</span>
<spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"28/03/2020 regular amoxicilliin 500mg po tds"</span><spanclass="op">)</span>
<spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span><spanclass="op">)</span>
<spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span>, type <spanclass="op">=</span><spanclass="st">"dose"</span><spanclass="op">)</span>
<spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span>, type <spanclass="op">=</span><spanclass="st">"admin"</span><spanclass="op">)</span>
<spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span>, collapse <spanclass="op">=</span><spanclass="st">", "</span><spanclass="op">)</span>
<spanclass="co"># \donttest{</span>
<spanclass="co"># if you want to know which antibiotic groups were administered, do e.g.:</span>
<spanclass="va">abx</span><spanclass="op"><-</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://tibble.tidyverse.org/reference/tibble.html"class="external-link">tibble</a></span><spanclass="op">(</span>clinical_text <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"given 400mg cipro and 500 mg amox"</span>,
<spanclass="st">"started on doxy iv today"</span><spanclass="op">)</span><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span>
abx_doses <spanclass="op">=</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="va">clinical_text</span>, type <spanclass="op">=</span><spanclass="st">"doses"</span><spanclass="op">)</span>,
abx_admin <spanclass="op">=</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="va">clinical_text</span>, type <spanclass="op">=</span><spanclass="st">"admin"</span><spanclass="op">)</span>,