Skip to content

Commit 192a5bd

Browse files
committed
Render offline health questions on individual lines
It seems like Excel is not interpreting the new line character correctly, so we need to add some styles to the cells to ensure the content is word wrapped. I don't have Excel to test this works correctly, but it's based on reading through: https://stackoverflow.com/questions/25770025/rails-axlsx-new-line-in-cell
1 parent 8c013e8 commit 192a5bd

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

app/lib/reports/export_formatters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def health_question_answers(consents:)
4949
"#{question} #{formatted_responses.join(", ")}"
5050
end
5151

52-
values.join("\n")
52+
values.join("\r\n")
5353
end
5454

5555
def gillick_status(gillick_assessment:)

app/lib/reports/offline_session_exporter.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ def self.call(*args, **kwargs)
2727
delegate :location, :organisation, to: :session
2828

2929
def add_vaccinations_sheet(package)
30+
package.use_shared_strings = true
31+
3032
workbook = package.workbook
3133

3234
date_style = workbook.styles.add_style(format_code: "dd/mm/yyyy")
35+
wrap_style = workbook.styles.add_style(alignment: { wrap_text: true })
3336

3437
types = headers_and_types.values
35-
style = types.map { _1 == :date ? date_style : nil }
38+
style =
39+
headers_and_types.map do |header, type|
40+
if type == :date
41+
date_style
42+
elsif header == "HEALTH_QUESTION_ANSWERS"
43+
wrap_style
44+
end
45+
end
3646

3747
workbook.add_worksheet(name: "Vaccinations") do |sheet|
3848
sheet.add_row(headers_and_types.keys)

spec/lib/reports/offline_session_exporter_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ def worksheet_to_hashes(worksheet)
191191
performed_at.to_date
192192
)
193193
end
194+
195+
context "with lots of health answers" do
196+
before do
197+
create(
198+
:consent,
199+
:from_dad,
200+
:recorded,
201+
patient:,
202+
programme:,
203+
health_questions_list: ["First question?", "Second question?"]
204+
)
205+
end
206+
207+
it "separates the answers by new lines" do
208+
expect(rows.first["HEALTH_QUESTION_ANSWERS"]).to eq(
209+
"First question? No from Dad\nSecond question? No from Dad"
210+
)
211+
end
212+
end
194213
end
195214

196215
context "with a patient who couldn't be vaccinated" do

0 commit comments

Comments
 (0)