Let’s take a looks at this current code, it works but it is not DRY!
def create_key_performance_indicators
organization_aco = Organization.find_by_name('ACO').id
KeyPerformanceIndicator.where(name: 'ED Visits per 1,000').first_or_create(
target: 100,
organization_id: organization_aco
)
KeyPerformanceIndicator.where(name: 'Average Length of Stay').first_or_create(
target: 5,
organization_id: organization_aco
)
KeyPerformanceIndicator.where(name: 'Admits per 1,000').first_or_create(
target: 100,
organization_id: organization_aco
)
end
So there is a table called KeyPerformanceIndicators that has a foreign key with organization_id fields to the Organization table.
Well first thing to clean up is that three times copy-paste of KeyPerformanceIndictor.where command, perhaps we can put those values somehow in an array or a hash, etc…and just loop through them inside this method. But I am just very new to all this language and syntax, How can I achieve this? or also if you have better ideas to achieve this all are much welcome and appreciated 🙂
How about…