Forked from progressiverocker/Premeds Calculator
Last active
December 23, 2015 05:19
-
-
Save ninmonkey/6586365 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The Premedicant Dose for animal type is the weight of animal multipled by drug dose rate, divided | |
by drugconcertration. | |
""" | |
from __future__ import division | |
drug_concentrations = {"meloxicam": 5.0, "amoxicillin clavulanic acid": 32.5, "ketamine": 100, | |
"enrofloxacin 2.5 percent solution": 25, "enrofloxacin 5.0 percent solution": 50} | |
rates = { | |
'dog': {"meloxicam": [0.2], "amoxicillin clavulanic acid": [8.75,12.5], "ketamine": [5.0,7.0]}, | |
'cat': {"meloxicam": [0.2], "amoxicillin clavulanic acid": [8.75,12.5], "ketamine": [5.0,7.5]}, | |
'rabbit': {"meloxicam": [0.6], "ketamine": [20], "enrofloxacin 2.5 percent solution": [10.0, 15.0, 20.0, 25.0], "enrofloxacin 5.0 percent solution": [10.0, 15.0, 20.0, 25.0]} | |
} | |
# maximum weight inputs | |
weight_max = {"dog": 100.0, "cat": 15.0, "rabbit": 15.0} | |
valid_species = [ name for name in weight_max.keys() ] | |
def input_species(): | |
# force input of species. Keep looping until valid. | |
while True: | |
species = raw_input("\nEnter species as one of: {}".format(valid_species)) | |
species = species.lower().strip() | |
if species in rates.iterkeys(): | |
return species | |
# match input with species dict, or first letter of species | |
# else keep looping.return species | |
for animal in rates: | |
if species == animal or species == animal[:1]: | |
return species | |
print("\nEnter species as one of: {}".format(valid_species)) | |
def input_weight(): | |
# force input of species. Keep looping until valid. | |
while True: | |
try: | |
weight_float = float(raw_input("\nEnter weight as float: ")) | |
# valid, but in range? | |
if (weight_float > 0.0 and weight_float < weight_max[species]): | |
return weight_float | |
else: | |
print("Error, weight not in range: 0.0 - {} for a {}".format(weight_max[species], species)) | |
except ValueError: | |
print("Error, invalid weight is not a float: ", weight_float) | |
continue | |
while True: | |
# Grab two inputs and return premeds. | |
species = input_species() | |
weight_float = input_weight() | |
# Calculate Vet's premed dosage based on animal type | |
# weight * dose_rate / drug_concentration | |
print("Calculate:\n\tanimal = {} \n\tweight = {}\n".format(species, weight_float)) | |
# iterate every drug, since none was chosen for this animal | |
for animal in valid_species: | |
for drug in rates[animal]: | |
print("\nRates for drug={} uses: {}".format(drug, rates[animal][drug])) | |
for rate in rates[animal][drug]: | |
dosage_calculated = (weight_float * rate) / drug_concentrations[drug] | |
print("\tRate = {:.2f} ml, calculated dosage = {:.2f} ml".format(rate, dosage_calculated)) | |
if raw_input("\nTo run again, type: 'Y': ").lower() not in 'y': | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment