code to multiply dose by times administered

  • 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.

  • 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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • 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

  • okay many thanks for your suggestions.

  • 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

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply