Add automatic calculator based on calculated values within a range

Hello again [using Welcome to KNIME 4.6.0]

Since my last post I have made some pretty good progress on my interactive calculator that can tell a patient’s kidney function. This is done through creatinine clearance and glomerular filtration rate calculation.

I have now been asked to make my calculator have the function of doing automatic drug dosage adjustments. To put it simple there are certain drugs, when you prescribe them, that have to first be dose adjusted for patients that have decreased kidney function (affecting how fast the body eliminates the drug). The goal is to avoid drug accumulation = drug toxicity.

So, I am asking for guidance on how I could set something like that up. Really looking to learn as it sounds a little more complex then what I have been doing thus far and my professor passionately recommends/insists I reach out here for any help as part of the learning process!

So, my calculator can already get a patient’s GFR values, now I want to take those values and have the calculator, when you select a drug from a separate drop down menu, put out the recommended dose, going off of the calculated GFR value (the severity of decreased kidney function).

I will be attaching the appropriate GFR ranges (showing stages of CKD - chronic kidney disease) and an example medication to use as reference, that is dependent on a patient’s GFR (I will be doing this for 11 drugs). If my workflow is needing to be posted, I will post if need be.

I’m feeling a lot of IF switches will have to be used as well as math formulas? I do hope what I am asking is not too complex.

The Ranges

Example medication Metformin (how it is to be adjusted)

If that example is too broad then this (sitagliptin). As you can see for the first three stages of CKD you use the standard 100 mg dosage but then you have to start reducing the dosage past those stages.

For more reference, here is the formula I am using to calculate GFR values
It’s really broken up into male or female, then non-african american or african american.

1 Like


This sounds very, very interesting. Before we can talk details, have you worked with widgets and configuration nodes before? These usually allow drop downs and then, yes, you may need switches but you may also be able to use the rule engine or other such nodes depending on exactly how your wf operates. Can you please attach what you have so far so I can get a sense of how well you can use KNIME and then tailor my response accordingly.

Thank you!



Yes I have. To be honest, I just recently received L1-L3 certification. Now I am applying what I learned but I am struggling as this is really my first time putting things together, outside of doing those certification practice exercises. So I am forgetting steps and knowing what nodes to use to make things easier.

I have attached my workflow. I will say the GFR calculator right now is calculating incorrectly, getting extremely high values. It seems I have to go back in and tweak it (it’s suppose to match the previously posted GFR equation, which is then tweaked for being male or female and non African American or African American). Guessing I have my parentheses wrong.

CrCl Calculator Restart v4b.knwf (142.2 KB)

You can also just write complex conditional formulas in the Column Expressions Node as well. It is a crazy powerful node.

When I need to make multi column changes based on the results of complex tests, I build a loop that tests for conditions then applies multiple changes based on criteria matches. That approach also simplifies what would be extremely lengthy formula construction and reduces the need to duplicate conditional tests for each column adjustment expression.


Alright, my initial suggestions is modularization. Wrap each “Input your values for XYZ” into a selection like Paolo does in this article (see item 1):

You may also want to incorporate Sequential Logic (see article) if one step follows another, but this is a personal preference.

Once you have cleaned up your workflow, let’s focus on the modules (components within components) that you need help with and please direct me very specifically to which part you are struggling with. Also, if you’re more coding inclined, you can check out the Column Expression node as @iCFO suggests. If not, we can stick with simpler KNIME nodes and perhaps math formulas or rule engines. I’m not sure yet as there is a lot going on within that component. So wrap components within components to make things very clear as a first step.



Ok, I am going to look into this, take it in, act upon it, and respond with where I am. Except a response tomorrow thank you!



Ok, I took a look at the article and started cleaning up the workflow by making multiple components!

I will most definitely use the sequential logic workflow, I do think I will do that once I get my calculator completed first then make a copy and label it as an “updated” version with the sequential workflow integrated. Potentially will even incorporate @iCFO 's suggestions.

For now, I am still trying to figure out where I am going wrong in regards in my GFR calculation math formula nodes (in the GFR workflow component).

The equation used is present in my previous post.

I was made aware that I was using the mathematical function exp (x) thinking that was how you raised something to the x power, for example 10^2. It seems I need to use the pow(x, y) function instead. However I am confused on the use of two values in pow vs the one in exp.

If you look at the original equation you will see there is a part where you raise (Scr/K) to the a power and then again but to the -1.209 power.

For example, what I had for the math formula node of GFR calculation - male, non-AA was:

141*($${Dpt-SCr}$$ / 0.9)exp(-0.412)($${Dpt-SCr}$$ / 0.9)exp(-1.209)(0.993)exp($${Ipt-age}$$)

If I am to be using pow, I am a little confused on how to do so properly.

Right now I have

141*($${Dpt-SCr}$$ / 0.9)pow(1,-0.412)($${Dpt-SCr}$$ / 0.9)pow(1,-1.209)(0.993)pow(1,$${Ipt-age}$$)

I have attached the latest workflow.

CrCl Calculator Restart v4c.knwf (184.4 KB)

I don’t mean to double post put I came up with this. I think this is the correct way to use the formula:

141*pow($${Dpt-SCr}$$ / 0.9, -0.411)*pow($${Dpt-SCr}$$ / 0.9,-1.209)*pow(0.993,$${Ipt-age}$$ )

versus what I had

If that is correct, then the next issue I am having, before I begin creating the meaty part of the workflow = the automatic drug dosage calculator, is trying to get the GFR calculation table view node to display only one calculated value, which would be based on what patient inputs were inputted. So, for the GFR calculator, if I put in that I am a 23 year old, male non-african american, with a serum creatinine of 1, I should only get one calculated answer, not the four that are currently given. Is this where I need to use a rule based row filter, to only show the appropriate value?

For a complex formula like that, either break it down into simpler steps such that you can prove the answer by hand or calculator. Then make sure you try enough combinations of numbers such that you’re sure your answer is correct every time. Just keep the same code but replace all the complex numbers with simple numbers for a sanity check.

For the IF switches, after examining your data, you may find the Case Switch to be better because it allows as many conditions as you like so long as you add input/output ports.


The case switch would replace all 4 if switches and allow you to choose what path to take for calculation. The Case Switch End node would then take only the relevant data leaving you with one row.

The case nodes require right-clicking to create new input and output ports.


Given your area of work, I think you would be better served in the long-term to learn some of the very basic JavaScript syntax required for the Column Expressions Node. Basic conditional formulas are not difficult to write and are extremely flexible. I deal with similar complex multi-conditional calculations like this all of the time. I often take the approach of breaking complex formulas up into building blocks as well. Create all of the sub-totals first and name them clearly as new columns, then build final conditional formulas off of those to clean it up. This approach avoids all of the branching and re-joining which can be a pain as things like this are rarely static and conditional calculations will require future adjustments.

I sometimes include the conditional Row Splitter node to divide streams out for different calculation approaches as well, but that is more to make things easier to follow visually as those conditions could also just be included within the Column Expressions node.

You cans start by copying and pasting working conditional formula syntax in the beginning and work while you learn. It didn’t slow me down too much productivity wise when I used that approach in the beginning.

3 to 5 column expressions nodes could replace dozens upon dozens of if switches, stream split branches, etc. This approach also makes duplicating and repurposing conditions calculations for another task much easier.


@victor_palacios I replaced the if switches with case switch. It seems the calculator is working now. I was about to mention an issue but that issue seems to have disappeared.

I plan to begin constructing the Drug Dosage calculator in a few. Before I dive in, I am picturing an interactive calculator that lets me select a drug, and depending on what the pt’s calculated GFR value (and what stage it falls under), will provide a recommended dosage. So what I imagine need to do is gather the standard dosages for my 11 drugs and then see how they are adjusted as GFR decreases. ( see previous post with posted sitagliptin example).

Feeling like another case switch would be needed. Could I really do 11 drugs though at one time? And for the calculation, I’m thinking 2 things:

  1. Make it so the dosage recommendation spits outs a recommended dosage based off the GFR value alone. Thinking, pt is on sitagliptin, GFR value is 45, so 50 mg dosage needs to be recommended.
  2. Or with the calculated GFR, make the dosage be decreased by a percentage via math formula node for certain stages. So here, you have the GFR, the GFR is 45, that is stage 3b so decrease standard dose (100 mg) by 50%

@iCFO It does sound like I need to learn column expressions node. Do you have any recommended links on-hand that I can review. If not no worries, I can always browse for learning material.

Since this is not my domain of expertise I can’t advice on how your algorithm should make calculations. But you can do 11 drugs at once using widgets and case switches. Or you can go the column expression route with simple if-then statements.


@victor_palacios Ok, good to hear. Sorry, got a little ahead of myself. Thank you both for helping me out, learning a lot. I would like to ask another question if you do not mind.

I have a Single Selection Widget, I am trying to change the color of the possible choices. I am going to color code them by type of drug.

Diabetes meds = orange
pain = red
statins = blue
proton pump inhibitors (omeprazole) = purple

I am trying to figure how to do so using the css editor node, to no avail

it would be cool if I could permanently color the background area of each selection option (like instead of the gray color the omeprazole could have a purple background)

or better yet, color the text of each drug, according to type, that may be more appeasing to the eyes!

1 Like

You may need to use legacy mode because generally CSS does not work with our widgets:

Legacy mode may make your figures look strange, so I usually don’t recommend this.

I was actually messing around with legacy mode too. I’ll continue to play around with it. Thank you! I’ll go ahead and mark your answers as solutions so that others can use.

1 Like

Hi @gravesmr

Legacy mode with Custom CSS is indeed the way to go :wink:


In case you haven’t figured it out yourself yet, this achievable via the nth child selector.
In below code, I assign a color to the position of the text in your list as defined in the selection widget. As such, nth-child(1) is the first entry, etc, etc. Whereby color represents the text color, background-color is self explanatory. A combination of both is off course also possible.

I also covered different method of coloring you can apply: direct text (orange), rgb and rgba. The latter is useful because the last element, the a, sets the transparency. This is helpful with bright color like purple that could make plain text very hard to read otherwise.

.knime-single-line :nth-child(1) {
	color: orange;

.knime-single-line :nth-child(2) {
	color: red;

.knime-single-line :nth-child(3) {
	color: rgb(65,105,225)

.knime-single-line :nth-child(4) {
	background-color: rgba(153,50,204,0.8);

Some general introduction about nth selectors:

The code in action:

Make sure you apply the flow variable to the widget as well.

Color Coded Selection.knwf (13.8 KB)

Hope this helps.


@ArjenEX Aw yeah, this is exactly what I needed. Appreciate your help once again!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.