Skip to content

Commit f46d36d

Browse files
authored
Add support for uploading SystmOne vaccination records (#3327)
This updates the import process to allow users to upload a file in the SystmOne format which has a different set of fields to the existing format. We haven't got a real example of this type of file for testing, so this is a best guess at how the format should be parsed. We haven't updated any parts of the UI in this change, we might want to do this in a follow up PR to describe the two different formats. To build this, the import mechanism required a substantial refactor, which is covered by: - #3312 - #3317 - #3318 - #3325 - #3326
2 parents 573be56 + 6086f63 commit f46d36d

File tree

6 files changed

+509
-77
lines changed

6 files changed

+509
-77
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
class VaccinationDescriptionStringParser
4+
def initialize(string)
5+
@string = string
6+
end
7+
8+
def call
9+
return nil if string.blank?
10+
11+
known_programme = KNOWN_PROGRAMMES.keys.find { string.starts_with?(it) }
12+
13+
programme_name = KNOWN_PROGRAMMES[known_programme]
14+
return nil if known_programme.present? && programme_name.nil?
15+
16+
vaccine_name = (string.split(" ").first if known_programme.blank?)
17+
return nil if known_programme.blank? && vaccine_name.blank?
18+
19+
dose_sequence_string =
20+
if vaccine_name.present?
21+
string[vaccine_name.length..]
22+
elsif known_programme.present?
23+
string[known_programme.length..]
24+
end
25+
26+
dose_sequence =
27+
begin
28+
Integer(dose_sequence_string)
29+
rescue ArgumentError, TypeError
30+
dose_sequence_string&.strip&.presence
31+
end
32+
33+
{ programme_name:, vaccine_name:, dose_sequence: }.compact
34+
end
35+
36+
def self.call(...) = new(...).call
37+
38+
private_class_method :new
39+
40+
private
41+
42+
attr_reader :string
43+
44+
KNOWN_PROGRAMMES = {
45+
"Flu" => "Flu",
46+
"HPV" => "HPV",
47+
"Human Papillomavirus" => "HPV",
48+
"MMR" => "MMR",
49+
"Measles/Mumps/Rubella" => "MMR",
50+
"MenACWY" => "MenACWY",
51+
"Meningococcal conjugate A,C, W135 + Y" => "MenACWY",
52+
"Td/IPV" => "Td/IPV"
53+
}.freeze
54+
end

0 commit comments

Comments
 (0)