views:

69

answers:

1

I'm working on an open-source harm reduction application for opioid addicts.

One of the features in this application is the conversion (in mg/mcg) between common opioids, so people don't overdose by accident.

If you're morally against opioid addiction and wouldn't respond because of your morals, please consider that this application is for HARM REDUCTION.. So people don't end up dead.

I have this data..

3mg morphine IV = 10mcg fentanyl IV
2mg morphine oral = 1mg oxycodone oral
3mg oral morphine = 1mg oxymorphone oral
7.0mg morphine oral = 1mg hydromorphone oral
1mg morphine iv = .10mg oxymorphone iv
1mg morphine oral = 1mg hydrocodone oral
1mg morphine oral = 6.67mg codeine oral
1mg morphine oral = .10mg methadone oral

And I have a textbox that is the source dosage in mg (a double) that the user can enter in. Underneath this, I have radio boxes for the source substance (ie: morphine) and the destination substance (ie oxycodone) for conversion..

I've been trying to think of the most efficient way to do this, but nearly every seems sloppy. If I were to do something like

public static double MorphinetoOxycodone(string morphineValue)
{
double morphine = Double.Parse(morphineValue);
return (morphine / 2 ); 
}

I would also have to make a function for OxycodonetoMorphine, OxycodonetoCodeine, etc.. and then would end up with dozens functions..

There must be an easier way than this that I'm missing.

If you'll notice, all of my conversions use morphine as the base value.. what might be the easiest way to use the morphine value to convert one opioid to another? For example, if 1mg morphine oral is equal to 1mg hydrocodone and 1mg morphine oral is equal to .10mg methadone, wouldn't I just multiply 1*.10 to get the hydrocodone->methadone value? Implementing this idea is what I'm having the most trouble with.

Any help would be GREATLY appreciated.. and if you'd like, I would add your name/nickname to the credits in this program. It's possible that many, many people around the world will use this (I'm translating it into several languages as well) and to know that your work could've helped an addict from dying.. I think that's a great thing :)

-cory

+2  A: 

I'd go with an array of morphine-conversion ratios, and a corresponding enum of drugs:

static enum Drug { Morphine, Fentanyl, Oxycodone, Oxymorphone, ... };
static double[] ratio = {1.0, 3.33, 0.5, 0.33, ... };

public static double ConvertToMorphine(Drug drug, double amount) 
{
    return amount / ratio[(int)drug];
} 

public static double ConvertFromMorphine(Drug drug, double amount)
{
    return amount * ratio[(int)drug];
}

public static double Convert(Drug from, Drug to, double amount)
{
    return ConvertFromMorphine(to, ConvertToMorphine(from, amount));
}

This way, you can get any conversion you want, like so:

Convert(Drug.Fentanyl, Drug.Oxymorphone, 5)

This will give you the equivalent of 5mg Fentanyl in Oxymorphone.
Disclaimer: I haven't coded C# much, so my syntax may be off.

tzaman
Thank you so much! Sorry it took a while to respond, firefox is being buggy. The syntax was perfect. If you'd like to be placed in the credits of the program, simply tell me and I'll add your username or e-mail :)I've got to work a bit on simplifying my code when I can't quite grasp a concept. I gotta remember to K.I.S.S ;)
C Patton
You're quite welcome! and crediting me is really unnecessary, this was pretty simple. :)
tzaman