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

Inherits:
Dry::Struct
  • 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

Raises:

  • (ArgumentError)


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
162
163
164
# File 'lib/renalware/forms/homecare/args.rb', line 112

def self.test_data(provider: :generic, version: 1)
  args = new(
    provider: provider,
    version: version,
    title: "Mr",
    given_name: "Jack",
    family_name: "JONES",
    nhs_number: "0123456789",
    born_on: Date.parse("2001-01-01"),
    telephone: "07000 000001",
    hospital_number: "ABC123",
    modality: "HD",
    address: ["line1", "", nil, "line2", "line3   "],
    postcode: "TW1 1UU",
    prescriber_name: "Dr X Yz",
    prescription_date: Date.today.to_s,
    consultant: "Dr Pepper",
    hospital_name: "THE ROYAL LONDON HOSPITAL",
    hospital_telephone: "0000 000001",
    hospital_department: "Renal",
    hospital_address: [
      "The Royal London Hospital",
      "Barts Health NHS Trust",
      "Whitechapel",
      "LONDON",
      "E1 1FR",
      "UK",
      "Tel: 0800 00000000",
      "Another line"
    ],
    no_known_allergies: false,
    allergies: ["Nuts", nil, "Penicillin", "Mown grass"],
    drug_type: "ESA",
    prescription_duration: "1 month",
    administration_device: "device?",
    po_number: "P123",
    delivery_frequencies: ["1 week", "3 months", "6 months", "12 month"],
    prescription_durations: ["3 months", "6 months", "12 months"],
    selected_prescription_duration: "6 months",
    selected_delivery_frequency: "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?
  args
end

Instance Method Details

#allergies_as_listObject



108
109
110
# File 'lib/renalware/forms/homecare/args.rb', line 108

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

#format_address_array(add) ⇒ Object



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

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

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

#formatted_addressObject



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

def formatted_address
  format_address_array address
end

#formatted_address_and_postcodeObject



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

def formatted_address_and_postcode
  format_address_array(address << postcode)
end

#formatted_hospital_addressObject



87
88
89
# File 'lib/renalware/forms/homecare/args.rb', line 87

def formatted_hospital_address
  format_address_array hospital_address
end

#formatted_hospital_name_and_addressObject



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

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

#formatted_prescription_dateObject



102
103
104
105
106
# File 'lib/renalware/forms/homecare/args.rb', line 102

def formatted_prescription_date
  return unless prescription_date

  prescription_date
end

#medications_are_presentObject



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

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



73
74
75
76
77
# File 'lib/renalware/forms/homecare/args.rb', line 73

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