Class: Renalware::Forms::Homecare::Args

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/renalware/forms/homecare/args.rb

Defined Under Namespace

Classes: Medication

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.test_data(provider: :generic, version: 1) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/renalware/forms/homecare/args.rb', line 106

def self.test_data(provider: :generic, version: 1)
  new.tap do |args|
    args.provider = provider
    args.version = version
    args.title = "Mr"
    args.given_name = "Jack"
    args.family_name = "JONES"
    args.nhs_number = "0123456789"
    args.born_on = Date.parse("2001-01-01")
    args.fmc_patient = "123"
    args.telephone = "07000 000001"
    args.hospital_number = "ABC123"
    args.modality = "PD"
    args.address = ["line1", "", nil, "line2", "line3   "]
    args.postcode = "TW1 1UU"
    args.modality = "HD"
    args.prescriber_name = "Dr X Yz"
    args.prescription_date = Date.today.to_s
    args.consultant = "Dr Pepper"
    args.hospital_name = "THE ROYAL LONDON HOSPITAL"
    args.hospital_telephone = "0000 000001"
    args.hospital_department = "Renal"
    args.hospital_address = [
      nil,
      "WHITECHAPEL",
      "",
      "LONDON",
      "E1 1FR",
      "UK",
      "Tel: 0800 00000000",
      "Another line"
    ]
    args.no_known_allergies = false
    args.allergies = ["Nuts", nil, "Penicillin", "Mown grass"]
    args.drug_type = "ESA"
    args.administration_frequency = "Daily"
    args.administration_route = "Per Oral"
    args.prescription_duration = "1 month"
    args.administration_device = "device?"
    args.po_number = "P123"
    args.generated_at = Time.now
    args.delivery_frequencies = ["1 week", "3 months", "6 months", "12 month"]
    args.prescription_durations = ["3 months", "6 months", "12 months"]
    args.selected_prescription_duration = "6 months"

    args.medications << Medication.new(
      date: Date.today,
      drug: "Example drug",
      dose: "1 unit",
      route: "PO",
      frequency: "3"
    )

    raise ArgumentError, args.errors unless args.valid?
  end
end

Instance Method Details

#allergies_as_listObject



101
102
103
# File 'lib/renalware/forms/homecare/args.rb', line 101

def allergies_as_list
  Array(allergies).uniq.compact.join("<br>")
end

#format_address_array(add) ⇒ Object



89
90
91
92
93
# File 'lib/renalware/forms/homecare/args.rb', line 89

def format_address_array(add)
  return unless add.is_a?(Array)

  add.compact.reject { |line| line == "" }.uniq&.join("\n")
end

#formatted_addressObject



72
73
74
# File 'lib/renalware/forms/homecare/args.rb', line 72

def formatted_address
  format_address_array address
end

#formatted_address_and_postcodeObject



76
77
78
# File 'lib/renalware/forms/homecare/args.rb', line 76

def formatted_address_and_postcode
  format_address_array(address << postcode)
end

#formatted_hospital_addressObject



80
81
82
# File 'lib/renalware/forms/homecare/args.rb', line 80

def formatted_hospital_address
  format_address_array hospital_address
end

#formatted_hospital_name_and_addressObject



84
85
86
87
# File 'lib/renalware/forms/homecare/args.rb', line 84

def formatted_hospital_name_and_address
  arr = [hospital_name] + hospital_address
  format_address_array arr
end

#formatted_prescription_dateObject



95
96
97
98
99
# File 'lib/renalware/forms/homecare/args.rb', line 95

def formatted_prescription_date
  return unless prescription_date

  prescription_date
end

#medications_are_presentObject

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



164
165
166
167
168
# File 'lib/renalware/forms/homecare/args.rb', line 164

def medications_are_present
  if medications.size == 0
    errors.add(:base, "There are no home delivery prescriptions for this drug type")
  end
end

#patient_nameObject



66
67
68
69
70
# File 'lib/renalware/forms/homecare/args.rb', line 66

def patient_name
  name = [family_name, given_name].compact.join(", ")
  name += " (#{title})" if title.to_s != ""
  name
end