Monster method (too hard for my skill level)

I need to write a method for calculating the fee for medical
procedures with respect to area. I have all the tables and data but
its hard to give that here. Can someone take a look at this ‘stub’
method and help me out?

def calculate_fee

strip out the first 3 numbers of the user entered zip code

use those 3 numbers to identify row in [zipcodes table] (between

upper and lower zip code columns))

identify ‘RVS ID’ from that row

identify the ‘geographic zip area’ from that row

query on user entered procedure description using [procedures table]

to identify ‘procedure code’

use previously obtained ‘RVS ID’ and ‘Procedure code’ to get

‘Relative value’ from [relative values table]

use previously obtained ‘geographic zip area’ and ‘procedure code’

to identify ‘percentile’ from

[geographic factors table]

use formula (Percentile / 1000) x (Relative Value / 100) to

calculate fee

end

anything in quotes is a column from one of my tables and anything in
brackets is a table. I know this is a tough scenario without seeing
the tables but any help would be a start and I can answer any
questions if you are trying to help.

THANK YOU

Without any idea of your schema I’m completely stabbing in the dark
here. but…

def calculate_fee

strip out the first 3 numbers of the user entered zip code

zip = params[:id].first(3)

use those 3 numbers to identify row in [zipcodes table] (between

upper and lower zip code columns))
@zip = ZipCode.find(zip)

identify ‘RVS ID’ from that row ## You don’t need to do this, you

can get it through the object @zip.rvs_id (or whatever the column is
really called)

identify the ‘geographic zip area’ from that row ## Same as

above.

query on user entered procedure description using [procedures

table] to identify ‘procedure code’
@procedure = Procedure.find_by_procedure_code(params[:procedure]
[:code]) # This param depends on your form your posting in from?

use previously obtained ‘RVS ID’ and ‘Procedure code’ to get

‘Relative value’ from [relative values table]
@relative_value = RelativeValue.find(:first, :conditions => [‘rvs_id
= ? AND procedure_code = ?’, @zip.rvs_id, @procedure.procedure_code])

But what does this return I don’t what your objects return mate.

use previously obtained ‘geographic zip area’ and ‘procedure code’

to identify ‘percentile’ from [geographic factors table]
@percentile = GeographicFactor.find(:first, :conditions =>
[‘geographic_zip_area = ? AND procedure_code = ?’,
@zip.geographic_zip_area, @procedure.procedure_code])
use formula (Percentile / 1000) x (Relative Value / 100) to
calculate fee
return (@percentile.(some attribute) / 1000) * (@relative_value.
(some attribute) / 1000)
end

The code is there, to get the column, just use the accessor for that
column like this:

@zip.rvs_id

of course, that assumes that is the column name, if it is named
something else, just sub it for rvs_id.

-Bill

how do you do this…

identify ‘RVS ID’ from that row ## You don’t need to do this, you

can get it through the object @zip.rvs_id (or whatever the column is
really called)

I understand that each row is an object, so it makes sense - just not
sure how to execute

this confuses me…

@zip = ZipCode.find(zip)

where @zip is the first 3 digits of a zipcode
the table is zipcodes the model zipcode

so i understand @zip = Zipcode.find(zip) is attempting to look for zip
in the zipcodes table via the model zipcode

however i need to compare my 3 digit zip (@zip) againt two columns in
the table
column 1 - zipstart
column 2 - endzip

i need to find the row that my @zip falls inside the values of those
two columns, so i believe this line of code is too simple

example might be @zip = 034
startzip = 032 and endzip =037 in the table
i need to identify that row

can anyone help?

@zip = ZipCode.find(:all, :conditions => ["startzip <= ? AND endzip

= ?", zip, zip])