Class: Renalware::Letters::LetterFactory
- Inherits:
-
Object
- Object
- Renalware::Letters::LetterFactory
- Defined in:
- app/models/renalware/letters/letter_factory.rb
Overview
Build a new draft letter. Used e.g from:
-
LettersController#new - when building the initial letter form (in which case params are those suppplied in #new)
-
LettersController#create via DraftLetter.build - before saving the letter, in which case params is the posted hash of letter attributes from the html form.
TODO: think about spitting this into 2 classes, one for build (new/get) and one for creating (create/post)?
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(patient, params = {}) ⇒ LetterFactory
constructor
A new instance of LetterFactory.
- #with_contacts_as_default_ccs ⇒ Object
Constructor Details
#initialize(patient, params = {}) ⇒ LetterFactory
Returns a new instance of LetterFactory.
16 17 18 19 20 |
# File 'app/models/renalware/letters/letter_factory.rb', line 16 def initialize(patient, params = {}) @params = LetterParamsProcessor.new(patient).call(params) @patient = Letters.cast_patient(patient) @default_ccs = [] end |
Instance Method Details
#build ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/renalware/letters/letter_factory.rb', line 22 def build # *Important this line is here and not in initialize. If moved to initialize we will get # two copies of eCCs because of the way .with_contacts_as_default_ccs can be called # before .build @electronic_cc_recipient_ids = params.delete(:electronic_cc_recipient_ids) # see * @letter = build_letter build_electronic_ccs include_primary_care_physician_as_default_main_recipient assign_default_ccs build_salutation letter. = Time.zone.now stub_letter_electronic_cc_recipient_ids_using_patients_default_eccs letter end |
#with_contacts_as_default_ccs ⇒ Object
39 40 41 42 43 |
# File 'app/models/renalware/letters/letter_factory.rb', line 39 def with_contacts_as_default_ccs @default_ccs = contacts_with_default_cc_option self end |