Last active
September 16, 2016 21:01
-
-
Save Dacello/9f555716acf99da56fc6dc8c39554cf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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