Class: Ekylibre::FirstRun::Faker::Prescriptions
- Defined in:
- lib/ekylibre/first_run/faker/prescriptions.rb
Instance Method Summary collapse
Methods inherited from Base
#count, #files, #initialize, #path, run
Constructor Details
This class inherits a constructor from Ekylibre::FirstRun::Faker::Base
Instance Method Details
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ekylibre/first_run/faker/prescriptions.rb', line 5 def run file = files.join('prescription.jpg') count :animal_prescriptions do |w| # import veterinary prescription in PDF document = Document.create!(key: '2100000303_prescription_001', name: 'prescription-2100000303', nature: 'prescription', file: File.open(file, 'rb')) # create a veterinary veterinary = Entity.create!( first_name: 'Veto', last_name: 'PONTO', nature: :contact, client: false, supplier: false ) # create veterinary prescription with PDF and veterinary prescription = Prescription.create!(prescriptor: veterinary, reference_number: '2100000303') # Attach doc to prescription prescription..create!(document: document) # create an issue for all interventions on animals and update them with prescription and recommender Intervention.of_nature(:animal_illness_treatment).find_each do |intervention| # create an issue animal = intervention.product_parameters.of_role('animal_illness_treatment-target').first.actor started_at = (intervention.started_at - 1.day) || Time.zone.now nature = %i[mammite edema limping fever cough diarrhea].sample issue = Issue.create!(target_type: animal.class.name, target_id: animal.id, priority: 3, observed_at: started_at, nature: nature, state: %w[opened closed aborted].sample) # add prescription on intervention intervention.issue = issue intervention.prescription = prescription intervention.recommended = true intervention.recommender = veterinary intervention.save! w.check_point end end end |