IV Drip Rate Calculator (Expanded Version)

Drip Rate Calculator Expanded
IV Drip Rate Calculator (Expanded) is an expanded version of the IV Drip Rate Calculator that I started working on May 30th and completed on June 5th 2018. While the first version has more calculators, this one is designed specifically for calculating the Drip Rate. It now has radio buttons that allow users to automatically calculate base on the IV Infusion Set being used (ie. Macroset or Regular Set, Microset, and Blood Set [for blood transfusion]), with the following having a Drop Factor of 15 gtts/ml, 60 gtts/ml, and 10 gtts/ml consecutively. It also allows users to switch between hrs or mins for the time to complete infusion. Now, for the calculator to work, it requires data to be entered for IV Fluid Volume, and Time to complete Solution. The radio buttons are set to default, but if it needs to be changed, users can configure it easily. Users would just have to pick the IV Infusion Set to be use and the setting for the time to complete infusion whether the input data will be in minutes or in hours. Finally, just press “Solve” button and the calculator will do the math. The PHP file also comes with a Background Color Switch, but it doesn’t really do much other than recolor the background.

I’m dedicating this project to my grandmother, who passed away last June 8th 2018. She has always been the one pushing me to keep achieving more. Whenever, I become lazy, she would scold me to move forward so that I won’t get left behind. She is a tough woman, but I know she cares a lot. That’s why she’s like that… She was like a mother to me. I will definitely miss her.

Open IV Drip Rate Calculator (Expanded Version)

Let’s talk about the Source Code

Drip Rate Calculator Expanded Source Code

The code was borrowed from the previous project, but I rehashed the method to get the values. Instead of using GET method, I used POST method to retrieve the data from the forms, but PHP still runs in the same file and does not have to call another PHP file to achieve the required function. I also removed the ISNUMERIC checker since it’s no longer necessary because the form type has already been set to “numbers”. As an added feature, I integrated another function — the background color switch that makes use of a PHP construct called “foreach”, it allowed me to move an array content into another variable.

I have one problem with this code though, while the calculator is good, the background color changer has some problems. While it changes the background, it cannot really keep the background color changed. When you use the background color switch, it works fine, but when you use the Drip Rate Calculator, the background color switches back to default white. The reason for that is because the variable for the color, $_POST[‘color’] or $bgcolor empties on page reload. It has the value of the picked color and without that value, the page can’t be recolored. I still need to find a way how to keep that value without the need of a database.

For educational purposes, I’m sharing the code for this PHP file. Feel free to use it, but I would really appreciate it if you provide a link back. Also, if you guys want it to be mobile friendly, you may have to create a CSS file for it.

PHP File

<html>
<head>
<title>Your Page Title</title>
<meta name="description" content="IV Fluid Drip Rate Calculator complete with settings that allows it to switch from Blood Set, Macroset and Microset." />
<meta name="robots" content="index,follow" />
<meta name="keywords" content="drip rate, IV Flow Rate, drip rate calculator, drop factor, flow rate, macroset, microset, blood set" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="yourcssfile.css" type="text/css" media="all" />
</head>
<body<?php
	$selected = "selected=\"selected\"";
	if(empty($_POST['color'])) {
		echo ' bgcolor="#ffffff"';
	} else {
		if(isset($_POST['changebgcolor'])) {
			foreach ($_POST['color'] as $bgcolor )
				echo ' bgcolor="' . $bgcolor . '"';
		}
	}
?>>
<center><h1>IV Drip Rate Calculator (Expanded Version)</h1></center><br/><br/>
<form action="" method="post">Change Background Color: <select size="1" name="color[]">
	<option value="#ffffff" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#ffffff") { echo $selected;} else { echo "";}}}?>>White</option>
	<option value="#ffff00" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#ffff00") { echo $selected;} else { echo "";}}}?>>Yellow</option>
	<option value="#ffc0cb" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#ffc0cb") { echo $selected;} else { echo "";}}}?>>Pink</option>
	<option value="#87cefa" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#87cefa") { echo $selected;} else { echo "";}}}?>>Sky Blue</option>
	<option value="#90ee90" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#90ee90") { echo $selected;} else { echo "";}}}?>>Light Green</option>
	<option value="#faebd7" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#faebd7") { echo $selected;} else { echo "";}}}?>>Antique White</option>
	<option value="#ff8000" <?php if(isset($_POST['color'])) { foreach($_POST['color'] as $tmp) {  if($tmp == "#ff8000") { echo $selected;} else { echo "";}}}?>>Orange</option>
</select>
<input name="changebgcolor" type="submit" value="Change Color" />
</form>
<br/>
<b>Notes:</b><br/><br/>
gtts - drops<br/>
min - minute<br/>
hr - hour<br/>
ml - milliliter<br/>
cc - cubic centimer<br/>
Macroset - 15 gtts/ml<br/>
Microset - 60 gtts/ml<br/>
Blood Set - 10 gtts/ml<br/><br/>
<b>Drip Rate Calculator</b><br/><br/>
<form action="#answer" method="post">
	IV Fluid Volume: <input name="vol" type="number" step="any"> ml or cc<br/><br/>
	Choose type of IV Infusion Set:<br/><br/>
	<input name="set" type="radio" value="macroset" checked="checked"> Macroset or Regular Set<br/>
	<input name="set" type="radio" value="microset"> Microset<br/>
	<input name="set" type="radio" value="bloodset"> Blood Set<br/><br/>
	Time to complete Solution: <input name="time" type="number" step="any"> in <input name="timebtn" type="radio" value="minute"> min(s) <input name="timebtn" type="radio" value="hour" checked="checked"> hr(s)<br/>
	<input name="calculate" value="Solve" type="submit">
</form><br/>
	<a name="answer"></a>
<?php

	if(isset($_POST['calculate'])) {
		$volume = $_POST['vol'];
		$chrono = $_POST['time'];
		$ivset = $_POST['set'];
			if($ivset == 'macroset') {
				$ivset = 15;
			}
			if($ivset == 'microset') {
				$ivset = 60;
			}
			if($ivset == 'bloodset') {
				$ivset = 10;
			} else {
				1;
			}
		$timeset = $_POST['timebtn'];
			if($timeset == 'minute') {
				$timeset = 1;
			}
			if($timeset == 'hour') {
				$timeset = 60;
			} else {
				1;
			}
		if(!empty($volume) && ($chrono)) {
			echo '<font color="#ff0000"><b>ANSWER:</b></font> ' . ($volume * $ivset) / ($chrono * $timeset) . " gtts/min<br/>";
		} else {
			echo "All values must be entered.";
		}
	}
?><br/><br/>
</body>
</html>
Follow me at:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.