Skip to content

Instantly share code, notes, and snippets.

@ShaileshPrajapati-BTC
Last active April 23, 2018 13:15
Show Gist options
  • Save ShaileshPrajapati-BTC/7495143985f1ef828aeb19705c809fc5 to your computer and use it in GitHub Desktop.
Save ShaileshPrajapati-BTC/7495143985f1ef828aeb19705c809fc5 to your computer and use it in GitHub Desktop.
Todo.all.each do |todo|
unless todo.name.nil?
todo.update(name: todo.name.strip)
else
todo.destroy
end
end
AgencyUser.all.each do |agency|
category = Category.create(name: 'Caregiver Personal Care', agency_user_id: agency.id)
breakfast_todo = Todo.create(name: "Caregiver's Breakfast", phrase: "Were you offered 30 minutes uninterrupted time for Breakfast",
agency_user_id: agency.id, category_id: category.id)
lunch_todo = Todo.create(name: "Caregiver's Lunch", phrase: "Were you offered 30 minutes uninterrupted time for Lunch",
agency_user_id: agency.id, category_id: category.id)
dinner_todo = Todo.create(name: "Caregiver's Dinner", phrase: "Were you offered 30 minutes uninterrupted time for Dinner",
agency_user_id: agency.id, category_id: category.id)
sleep_todo = Todo.create(name: "Sleep", phrase: "Were you afforded 8 hours for sleep",
agency_user_id: agency.id, category_id: category.id)
end
Client.all.each do |client|
if client.is_live_in?
agency = client.agency
todo_ids = client.todo_ids
breakfast_todo = agency.todos.find_by(['name iLike ?', "Caregiver's Breakfast"])
lunch_todo = agency.todos.find_by(['name iLike ?', "Caregiver's Lunch"])
dinner_todo = agency.todos.find_by(['name iLike ?', "Caregiver's Dinner"])
sleep_todo = agency.todos.find_by(['name iLike ?', "Sleep"])
todo_ids += [ breakfast_todo.present? ? breakfast_todo.id : nil, lunch_todo.present? ? lunch_todo.id : nil, dinner_todo.present? ? dinner_todo.id : nil, sleep_todo.present? ? sleep_todo.id : nil ]
todo_ids.delete(nil)
client.todo_ids = todo_ids.uniq
client.save(validate: false)
end
end
AgencyUser.all.each do |x|
if x.categories.where(name: "Caregiver Personal Care").nil?
category = x.categories.create(name: "Caregiver Personal Care")
category.todos.create([
{ name: "Caregiver's Breakfast", phrase: "Were you offered 30 minutes uninterrupted time for Breakfast", agency_user_id: x.id },
{ name: "Caregiver's Lunch", phrase: "Were you offered 30 minutes uninterrupted time for Lunch", agency_user_id: x.id },
{ name: "Caregiver's Dinner", phrase: "Were you offered 30 minutes uninterrupted time for Dinner", agency_user_id: x.id },
{ name: "Sleep", phrase: "Were you afforded 8 hours for sleep", agency_user_id: x.id }
])
end
end
Client.all.each do |client|
if client.is_live_in?
todo_ids = client.todo_ids + client.agency.todos.where(name: ["Breakfast", "Lunch", "Dinner", "Caregiver's Breakfast", "Caregiver's Lunch", "Caregiver's Dinner", "Sleep"]).ids
client.todo_ids = todo_ids.uniq
client.save(validate: false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment