Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created November 9, 2011 12:57
Show Gist options
  • Save jcalvert/1351347 to your computer and use it in GitHub Desktop.
Save jcalvert/1351347 to your computer and use it in GitHub Desktop.
pet image snippet
Dir.glob('/mnt/smb/images/pp_uploads/*').each do |glob|
hid = glob.split("/").last
next unless hid == "2882"
Dir.glob("#{glob}/*").each do |cglob|
client_id=cglob.split("/").last
Dir.glob("#{cglob}/*").each do |plob|
patient_id =plob.split("/").last
if(Patient.where(:id => patient_id).nil? || Patient.where(:id => patient_id).empty?)
next
end
patient = Patient.where(:id => patient_id).first
images = PetImage.find_all_by_pid("#{patient.hid}-#{patient.client.id}-#{patient.id}", :consistent_read=>true)
Dir.glob("#{plob}/*").each do |piclob|
picname= piclob.split("/").last
@pet_image = PetImage.new({:pet_record => patient.pet_record_img, :animal => patient, :idcard_img => patient.idcard_img, :file => File.new(piclob)})
@pet_image.skip_validation=true
@pet_image.save
p 'SAVED! ',@pet_image.errors
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment