Skip to content

Instantly share code, notes, and snippets.

@panSarin
Created March 14, 2022 12:47
Show Gist options
  • Save panSarin/412999746389a355106f9abe516bc7fd to your computer and use it in GitHub Desktop.
Save panSarin/412999746389a355106f9abe516bc7fd to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module Visits
class Create
include BaseService
def initialize(patient:, visit_params:)
@patient = patient
@visit_params = visit_params
end
def call
category = Category.find_by_name(visit_params[:category])
return add_error('There is no category with that name') if category.nil?
new_visit = Visit.create(slot_id: visit_params[:slot_id],
category: category,
patient: patient)
return add_error(new_visit.errors.full_messages) if new_visit.new_record?
new_order = Order.create(visit_id: new_visit.id)
return add_error(new_order.errors.full_messages) if new_order.new_record?
CheckPaidVisitWorker.perform_in(11.minutes, visit_id: new_visit.id)
add_result(visit: new_visit)
end
private
attr_reader :patient, :visit_params
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment