class Reports::SystmOneExporter
Constants
- DELIVERY_METHOD_MAPPINGS
- DELIVERY_SITE_MAPPINGS
- GENDER_CODE_MAPPINGS
- PROCEDURE_DOSE_MAPPINGS
- PRODUCT_DOSE_MAPPINGS
-
We think these are CVT3 Read codes still used within SystmOne They have been looked up from the SystmOne Code Browser Some of them are also available online here: biobank.ndph.ox.ac.uk/ukb/coding.cgi?id=8708&nl=1
Public Class Methods
Source
# File app/lib/reports/systm_one_exporter.rb, line 104 def self.call(...) = new(...).call private_class_method :new private attr_reader :team, :programme, :academic_year, :start_date, :end_date def headers [ "Practice code", "NHS number", "Surname", "Middle name", "Forename", "Gender", "Date of Birth", "House name", "House number and road", "Town", "Postcode", "Vaccination", "Part", "Admin date", "Batch number", "Expiry date", "Dose", "Reason", "Site", "Method", "Notes" ] end def vaccination_records team .vaccination_records .administered .sourced_from_service .for_programme(programme) .for_academic_year(academic_year) .created_or_updated_between(start_date, end_date) .includes( :location, :patient, :performed_by_user, :session, :supplied_by, :vaccine ) end def row(vaccination_record:) patient = vaccination_record.patient [ practice_code(vaccination_record), # Practice code patient.nhs_number, # NHS number patient.family_name, # Surname "", # Middle name (not stored) patient.given_name, # Forename gender_code(patient.gender_code), # Gender patient.date_of_birth.to_fs(:uk_short), patient.restricted? ? "" : patient.address_line_2, # House name patient.restricted? ? "" : patient.address_line_1, # House number and road patient.restricted? ? "" : patient.address_town, # Town patient.restricted? ? "" : patient.address_postcode, # Postcode vaccination(vaccination_record), # Vaccination "", # Part vaccination_record.performed_at.to_date.to_fs(:uk_short), # Admin date vaccination_record.batch_number, # Batch number vaccination_record.batch_expiry&.to_fs(:uk_short), # Expiry date vaccination_record.dose_volume_ml, # Dose reason(vaccination_record), # Reason (not specified) site(vaccination_record), # Site method(vaccination_record), # Method notes(vaccination_record) # Notes ] end def practice_code(vaccination_record) location = vaccination_record.location if location&.systm_one_code.present? location.systm_one_code elsif location&.gias_school? location.urn elsif location location.ods_code else vaccination_record.session.location.ods_code end end def gender_code(code) GENDER_CODE_MAPPINGS[code] end # TODO: These mappings are valid for Hertforshire, but may not be correct for # other SAIS teams. We'll need to check these are correct with new SAIS # teams. def vaccination(vaccination_record) return if vaccination_record.not_administered? programme = vaccination_record.programme vaccine_brand = vaccination_record.vaccine.brand dose_sequence = vaccination_record.dose_sequence if programme.mmr? procedure_mapping = PROCEDURE_DOSE_MAPPINGS.dig(programme.variant_type, dose_sequence) return procedure_mapping if procedure_mapping.present? end product_mapping = PRODUCT_DOSE_MAPPINGS.dig(vaccine_brand, dose_sequence) return product_mapping if product_mapping.present? dose_sequence ? "#{vaccine_brand} Part #{dose_sequence}" : vaccine_brand end def reason(vaccination_record) case vaccination_record.dose_sequence when 1, nil "Routine" else "At Risk" end end # TODO: These mappings are valid for Hertforshire, but may not be correct for # other SAIS teams. We'll need to check these are correct with new SAIS # teams. def site(vaccination_record) return if vaccination_record.not_administered? DELIVERY_SITE_MAPPINGS.fetch(vaccination_record.delivery_site) end def notes(vaccination_record) [ vaccination_record.notes, if (user = vaccination_record.performed_by) "Administered by: #{user.full_name}" end, if (user = vaccination_record.supplied_by) if vaccination_record.pgd? "Authorised by: #{user.full_name}" else "Prescribed by: #{user.full_name}" end end ].compact_blank.join("\n") end def method(vaccination_record) return if vaccination_record.not_administered? DELIVERY_METHOD_MAPPINGS.fetch(vaccination_record.delivery_method) end end
Source
# File app/lib/reports/systm_one_exporter.rb, line 88 def initialize(team:, programme:, academic_year:, start_date:, end_date:) @team = team @programme = programme @academic_year = academic_year @start_date = start_date @end_date = end_date end
Public Instance Methods
Source
# File app/lib/reports/systm_one_exporter.rb, line 96 def call CSV.generate(headers:, write_headers: true) do |csv| vaccination_records.find_each do |vaccination_record| csv << row(vaccination_record:) end end end
Source
# File app/lib/reports/systm_one_exporter.rb, line 198 def gender_code(code) GENDER_CODE_MAPPINGS[code] end
Source
# File app/lib/reports/systm_one_exporter.rb, line 112 def headers [ "Practice code", "NHS number", "Surname", "Middle name", "Forename", "Gender", "Date of Birth", "House name", "House number and road", "Town", "Postcode", "Vaccination", "Part", "Admin date", "Batch number", "Expiry date", "Dose", "Reason", "Site", "Method", "Notes" ] end
Source
# File app/lib/reports/systm_one_exporter.rb, line 258 def method(vaccination_record) return if vaccination_record.not_administered? DELIVERY_METHOD_MAPPINGS.fetch(vaccination_record.delivery_method) end
Source
# File app/lib/reports/systm_one_exporter.rb, line 242 def notes(vaccination_record) [ vaccination_record.notes, if (user = vaccination_record.performed_by) "Administered by: #{user.full_name}" end, if (user = vaccination_record.supplied_by) if vaccination_record.pgd? "Authorised by: #{user.full_name}" else "Prescribed by: #{user.full_name}" end end ].compact_blank.join("\n") end
Source
# File app/lib/reports/systm_one_exporter.rb, line 184 def practice_code(vaccination_record) location = vaccination_record.location if location&.systm_one_code.present? location.systm_one_code elsif location&.gias_school? location.urn elsif location location.ods_code else vaccination_record.session.location.ods_code end end
Source
# File app/lib/reports/systm_one_exporter.rb, line 224 def reason(vaccination_record) case vaccination_record.dose_sequence when 1, nil "Routine" else "At Risk" end end
Source
# File app/lib/reports/systm_one_exporter.rb, line 156 def row(vaccination_record:) patient = vaccination_record.patient [ practice_code(vaccination_record), # Practice code patient.nhs_number, # NHS number patient.family_name, # Surname "", # Middle name (not stored) patient.given_name, # Forename gender_code(patient.gender_code), # Gender patient.date_of_birth.to_fs(:uk_short), patient.restricted? ? "" : patient.address_line_2, # House name patient.restricted? ? "" : patient.address_line_1, # House number and road patient.restricted? ? "" : patient.address_town, # Town patient.restricted? ? "" : patient.address_postcode, # Postcode vaccination(vaccination_record), # Vaccination "", # Part vaccination_record.performed_at.to_date.to_fs(:uk_short), # Admin date vaccination_record.batch_number, # Batch number vaccination_record.batch_expiry&.to_fs(:uk_short), # Expiry date vaccination_record.dose_volume_ml, # Dose reason(vaccination_record), # Reason (not specified) site(vaccination_record), # Site method(vaccination_record), # Method notes(vaccination_record) # Notes ] end
Source
# File app/lib/reports/systm_one_exporter.rb, line 236 def site(vaccination_record) return if vaccination_record.not_administered? DELIVERY_SITE_MAPPINGS.fetch(vaccination_record.delivery_site) end
TODO: These mappings are valid for Hertforshire, but may not be correct for
other SAIS teams. We'll need to check these are correct with new SAIS teams.
Source
# File app/lib/reports/systm_one_exporter.rb, line 205 def vaccination(vaccination_record) return if vaccination_record.not_administered? programme = vaccination_record.programme vaccine_brand = vaccination_record.vaccine.brand dose_sequence = vaccination_record.dose_sequence if programme.mmr? procedure_mapping = PROCEDURE_DOSE_MAPPINGS.dig(programme.variant_type, dose_sequence) return procedure_mapping if procedure_mapping.present? end product_mapping = PRODUCT_DOSE_MAPPINGS.dig(vaccine_brand, dose_sequence) return product_mapping if product_mapping.present? dose_sequence ? "#{vaccine_brand} Part #{dose_sequence}" : vaccine_brand end
TODO: These mappings are valid for Hertforshire, but may not be correct for
other SAIS teams. We'll need to check these are correct with new SAIS teams.
Source
# File app/lib/reports/systm_one_exporter.rb, line 138 def vaccination_records team .vaccination_records .administered .sourced_from_service .for_programme(programme) .for_academic_year(academic_year) .created_or_updated_between(start_date, end_date) .includes( :location, :patient, :performed_by_user, :session, :supplied_by, :vaccine ) end