Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

code to multiply dose by times administered Expand / Collapse
Author
Message
Posted Wednesday, April 3, 2013 3:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
Hey Guys

I have to create a report which shows how many times a drug was administered and the dose is multiplied by the number of times administered (i.e 20mg dose x 2 times administered = 40 mg). The dose field is derived from a table. The table used to create the report from contains details about the the PatientNo., Dose, time prescribed, time administered.

The report needs to look like this:

PATIENT NO. | Number of Times Administred | DOSE
Patient A 2 40
Patient B 10 200

The parameters of the report is a startdate and an enddate.

I need help with SQL code to multiply the dose by times administered and identify how many times each patient no. has had the drug and to multiply that to get the value shown in the dose field.
Post #1438227
Posted Wednesday, April 3, 2013 8:04 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 12:10 PM
Points: 13,330, Visits: 12,829
Hi and welcome to SSC. It is nearly impossible to offer much assistance based on the details in your post. I am willing to help but I need something to work with. Please take a few minutes and read the article found at the first link in my signature for best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1438358
Posted Thursday, April 4, 2013 8:49 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 7:28 AM
Points: 317, Visits: 1,530
Couple of quick thoughts for you:

1) The key to making this work is to strip the unit of measure from the initial dose. For example, if a drug dose is "10 mg" taken twice, then you first need to strip "mg" from "10 mg". You'll be left with the 10 which you can then multiply against 2 to get 20. All of this parsing should be done in SQL (i.e., in the dataset).

2) Since you didn't indicate if your dataset contains different types of drugs with different types of units of measure, I"ll assume for now that "mg" is your only unit of measure. To strip "mg" from "10 mg" just use the sql replace command to eliminate "mg" with a zero-length string: Replace(drugdose,'mg','') * NumberOfTimesTaken = total dosing. If you have different units of measure, then nest your replace statements for each unit of measure.

3) Things get much trickier if a given drug has multiple active ingredients, suchas "10mg;5mg" -- in this scenario, the drug has a total of 15mg, but the information is split between two active ingredients. A much more elaborate parsing technique is required, which I won't go into right now.

--Pete



Post #1438843
Posted Thursday, April 4, 2013 9:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
okay many thanks for your suggestions.
Post #1438869
Posted Thursday, April 4, 2013 10:42 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 4:02 AM
Points: 495, Visits: 896
Just a note on units of measurement.

I have previously worked with many laboratory databases and there is always need for a unit conversion look up table for any sort of calculations.

Contents would look like this
SourceUnits ConvertedUnits Multiplier
mg g 0.001
g mg 1000

The use of a standard conversion table like this avoids maintaining multiple calculations elsewhere in the database.

Calculations should be converted to standard units, performed, and then converted to display units, and the very last operation performed should be any rounding if required. Particularly with chemistry or pharmaceuticals this is very important.

The fields in the rest of the database should not contain the values & units in the same column, fields should not contain multiple pieces of data as per best practice, which means you avoid any parsing to strip out units.
Dave
Post #1439092
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse