Skip to content

Commit a08ac84

Browse files
committed
Order vaccines alphabetically in help message
This ensures that the order of the vaccines is always in alphabetical order which makes the page clearer for users and fixes a flaky test issue.
1 parent 9800a70 commit a08ac84

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

app/components/app_import_format_details_component.rb

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,7 @@ def parent_columns
277277

278278
def programme
279279
programmes = team.programmes.flat_map(&:import_names).map { tag.i(it) }
280-
281-
programmes_sentence =
282-
programmes.to_sentence(
283-
last_word_connector: " or ",
284-
two_words_connector: " or "
285-
)
280+
programmes_sentence = to_sentence_with_or(programmes)
286281

287282
[
288283
{
@@ -292,21 +287,13 @@ def programme
292287
]
293288
end
294289

295-
def make_vaccines_sentence(vaccines:)
296-
vaccines.to_sentence(
297-
last_word_connector: " or ",
298-
two_words_connector: " or "
299-
)
300-
end
301-
302290
def vaccine_and_batch
303291
vaccines = team.vaccines.pluck(:upload_name).map { tag.i(it) }
304-
vaccines_sentence = make_vaccines_sentence(vaccines:)
305292

306293
[
307294
{
308295
name: "VACCINE_GIVEN",
309-
notes: "Optional, must be one of: #{vaccines_sentence}."
296+
notes: "Optional, must be one of: #{to_sentence_with_or(vaccines)}."
310297
},
311298
{ name: "BATCH_NUMBER", notes: "Optional" },
312299
{
@@ -318,23 +305,26 @@ def vaccine_and_batch
318305
end
319306

320307
def national_reporting_vaccine_and_batch
321-
hpv_vaccines =
322-
Programme.hpv.vaccines.pluck(:nivs_name).compact.map { tag.i(it) }
323-
flu_vaccines =
324-
Programme.flu.vaccines.pluck(:nivs_name).compact.map { tag.i(it) }
325-
326-
hpv_vaccines_sentence = make_vaccines_sentence(vaccines: hpv_vaccines)
327-
flu_vaccines_sentence = make_vaccines_sentence(vaccines: flu_vaccines)
308+
vaccine_given_notes_per_programme =
309+
[Programme.hpv, Programme.flu].map do |programme|
310+
vaccines =
311+
programme
312+
.vaccines
313+
.where.not(nivs_name: [nil, ""])
314+
.order(:nivs_name)
315+
.pluck(:nivs_name)
316+
.map { tag.i(it) }
317+
318+
"#{tag.br}#{tag.br}" \
319+
"For #{programme.name_in_sentence} records, must be one of: " \
320+
"#{to_sentence_with_or(vaccines)}."
321+
end
328322

329323
[
330324
{
331325
name: "VACCINE_GIVEN",
332326
notes:
333-
"#{tag.strong("Required")}" \
334-
"#{tag.br}#{tag.br}" \
335-
"For HPV records, must be one of: #{hpv_vaccines_sentence}." \
336-
"#{tag.br}#{tag.br}" \
337-
"For flu records, must be one of: #{flu_vaccines_sentence}."
327+
([tag.strong("Required")] + vaccine_given_notes_per_programme).join
338328
},
339329
{ name: "BATCH_NUMBER", notes: tag.strong("Required") },
340330
{
@@ -367,7 +357,7 @@ def anatomical_site
367357
def reason_not_vaccinated_and_notes
368358
reasons =
369359
ImmunisationImportRow::REASONS_NOT_ADMINISTERED.keys.sort.map do
370-
tag.i(_1)
360+
tag.i(it)
371361
end
372362
reasons_sentence =
373363
reasons.to_sentence(
@@ -458,7 +448,7 @@ def supplier
458448
end
459449

460450
def national_reporting_anatomical_site
461-
sites = ImmunisationImportRow::DELIVERY_SITES.keys.sort.map { tag.i(_1) }
451+
sites = ImmunisationImportRow::DELIVERY_SITES.keys.sort.map { tag.i(it) }
462452

463453
site_sentence =
464454
sites.to_sentence(
@@ -503,4 +493,8 @@ def local_patient_id
503493
}
504494
]
505495
end
496+
497+
def to_sentence_with_or(items)
498+
items.to_sentence(last_word_connector: " or ", two_words_connector: " or ")
499+
end
506500
end

0 commit comments

Comments
 (0)