Skip to content

Instantly share code, notes, and snippets.

@Dacello
Last active September 16, 2016 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dacello/9f555716acf99da56fc6dc8c39554cf1 to your computer and use it in GitHub Desktop.
Save Dacello/9f555716acf99da56fc6dc8c39554cf1 to your computer and use it in GitHub Desktop.
def fix_appointments_missing_timeslots
appts = Appointment.joins(time_block: [:time_slot]})
.upcoming
.where(organization_id: @org.id, status: [0,1,2])
.where(time_blocks: [time_slot: [deleted_at: nil]])
ts_ids = appts.pluck('time_slots.id')
tb_ids = appts.pluck('time_blocks.id')
end
def attach_appropriate_timeslot(appt)
ts = TimeSlot.only_deleted.find(appt.try(:time_block).try(:time_slot_id))
return unless ts
new_ts = @org.time_slots.find_by(
start: ts.start,
day: ts.day,
location_id: ts.location_id,
doctor_id: ts.doctor_id,
)
return unless new_ts
appt.time_block.update_attributes(time_slot_id: new_ts.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment