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