Hover over the menu bar to pick a physics animation.

Residual Medicine Vs Time

Reason for this Program

We need to be able to track the residual medicine in the blood stream of a person who takes a medication at any hours of the day. The residual medicine amount decays as an exponential function where the exponential decay constant has a simple relation to its conveniently available medical half life.

What this program can do

The utility creates 24 textBoxes (numbered 0-23) starting at 12:00 AM representing the 24 hours of an earth day. The original concept was for the client to select some checkboxes to represent times when a medicine dose was taken. From these dose times and the half lives of the medicine we could compute the amount of medicine still in effect in the body at any later time. It was assumed that the doses of the starting day and are the same on subsequent days. Other uses of the utility are, for example, temperature processing of materials such as semiconductors all of which have definite dopant diffusion rates versus temperature.

Instead of just the dosing times, here we have added a new variable which is dose amount at any chosen hour. The dose value is input to an indexed textBox where the index refers to the dose addition hour. As an extension of the utility, if dosage is not the same on subsequent days, using this program as a template, we can easily provide additional 24 hour textBox arrays that represent these subsequent days.

Note that all times are expressed in hours. As an example, let's have non-zero doses of [300,540,410] at hours [3,8,17] while the doses at the other hours are zero. Then an appropriate table of dose times and doses for the first day is:

Of course, on days represented by integer `j`, after the first day, the times in row Hour will have 24j added to them.

Decay of Medicine Doses

`"residual(t)"=sum_(j=1)^(j=n_j)sum_(i=1)^((t_d(i+24j))ltt)a_i(1/(2^(((t-t_d(i+24j))/tau_(1/2))))) `   (1)   

where `tau_(1/2)` is the half life of the medication and `d_i` is the dose quantity at time `t_d(i)`. The time of the dose, `t_d(i)`, is determined by the day of the dose times 24 summed with the filled textbox number times 1 hour.

Challenges of Defining HTML Elements Using Javasript

One of the challenges is to place the example Hour/Dose Javascript Table element at a specific location inside the appropriate division that describes it. This is done by choosing a id name, 'div0', for the describing division. Then we turn this id into a variable inside the Javascript script. We also choose another id name, 'div1', for the division that will contain the table. Then we append the table to a variable version of 'div1'. Then we append variable version of 'div1' to a variable version of 'div0'. If we did not go through this elaborate procedure, then, when the window is narrowed or widened the table would move up or down with respect to the other text and be meshed with other text so that both are jumbled.

For the HTML text elements and their labels, a div element also had to be added to control the positions of the text elements. When using programmed HTML elements, the elements do not appear in the HTML part of the file. So all functions and styling of these elements has to be done as part of their original javascript definition. The way that that can be accomplished is to place the text elements in an array of length 24 here. For each element of the array I needed to apply a filter that rejected alphabetical characters and accepted only the numerical chacters '0' through '9'. That is best done by using the ASCII codes of numerical characters '0'=48 through '9'=57.

Units

The values for residual medicine will be in the same units as the input doses. Thus if the input doses are milligrams, the residual medicine will also be in milligrams. The same goes for inputs of grams or ounces. This is because the program really just computes the ratio of residual to doses.