Skip to content

Commit afec2b3

Browse files
Add gender column to CarePlus export
As requested by local CHIS providers. Jira-Issue: MAV-3439
1 parent 3ce8b7a commit afec2b3

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

app/lib/reports/careplus_exporter.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def self.call(...) = new(...).call
2626

2727
private
2828

29+
GENDER_CODE_MAPPINGS = {
30+
female: "F",
31+
male: "M",
32+
not_known: "U",
33+
not_specified: "I"
34+
}.with_indifferent_access.freeze
35+
2936
attr_reader :team, :programme, :academic_year, :start_date, :end_date
3037

3138
def headers
@@ -50,7 +57,8 @@ def headers
5057
*vaccine_columns(2),
5158
*vaccine_columns(3),
5259
*vaccine_columns(4),
53-
*vaccine_columns(5)
60+
*vaccine_columns(5),
61+
"Gender"
5462
]
5563
end
5664

@@ -150,14 +158,15 @@ def rows(patient:, vaccination_records:)
150158
*vaccine_fields(records, 1),
151159
*vaccine_fields(records, 2),
152160
*vaccine_fields(records, 3),
153-
*vaccine_fields(records, 4)
161+
*vaccine_fields(records, 4),
162+
GENDER_CODE_MAPPINGS[patient.gender_code]
154163
]
155164
end
156165
end
157166
end
158167

159168
def blank_vaccine_fields
160-
["", "", "", "", "", ""]
169+
["", "", "", "", "", "", ""]
161170
end
162171

163172
def vaccine_fields(vaccination_records, index)

spec/lib/reports/careplus_exporter_spec.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"Staff Code",
5656
"Attended",
5757
"Reason Not Attended",
58-
"Suspension End Date"
58+
"Suspension End Date",
59+
"Gender"
5960
)
6061

6162
(1..5).each do |i|
@@ -388,4 +389,45 @@
388389

389390
include_examples "generates a report"
390391
end
392+
393+
context "gender mapping" do
394+
let(:programme) { Programme.hpv }
395+
let(:programmes) { [programme] }
396+
let(:team) { create(:team, programmes:) }
397+
let(:location) { create(:school) }
398+
let(:session) { create(:session, team:, programmes:, location:) }
399+
let(:parsed_csv) { CSV.parse(csv) }
400+
let(:headers) { parsed_csv.first }
401+
let(:data_rows) { parsed_csv[1..] }
402+
403+
{
404+
female: "F",
405+
male: "M",
406+
not_known: "U",
407+
not_specified: "I"
408+
}.each do |gender, expected_code|
409+
context "when the patient gender is #{gender}" do
410+
it "maps gender to #{expected_code}" do
411+
patient =
412+
create(
413+
:patient,
414+
:consent_given_triage_not_needed,
415+
programmes:,
416+
session:,
417+
gender_code: gender
418+
)
419+
create(
420+
:vaccination_record,
421+
programme:,
422+
patient:,
423+
session:,
424+
performed_at: 2.weeks.ago
425+
)
426+
427+
gender_index = headers.index("Gender")
428+
expect(data_rows.first[gender_index]).to eq(expected_code)
429+
end
430+
end
431+
end
432+
end
391433
end

0 commit comments

Comments
 (0)