class VaccinationRecord
Schema Information
Table name: vaccination_records
id :bigint not null, primary key batch_expiry :date batch_number :string confirmation_sent_at :datetime delivery_method :integer delivery_site :integer discarded_at :datetime disease_types :enum not null, is an Array dose_sequence :integer full_dose :boolean local_patient_id_uri :string location_name :string nhs_immunisations_api_etag :string nhs_immunisations_api_identifier_system :string nhs_immunisations_api_identifier_value :string nhs_immunisations_api_primary_source :boolean nhs_immunisations_api_recorded_at :datetime nhs_immunisations_api_snomed_procedure_code :string nhs_immunisations_api_snomed_procedure_term :string nhs_immunisations_api_snomed_product_code :string nhs_immunisations_api_snomed_product_term :string nhs_immunisations_api_snomed_reason_code :string nhs_immunisations_api_snomed_reason_term :string nhs_immunisations_api_sync_pending_at :datetime nhs_immunisations_api_synced_at :datetime notes :text notify_parents :boolean outcome :integer not null pending_changes :jsonb not null performed_at_date :date not null performed_at_time :time performed_by_family_name :string performed_by_given_name :string performed_ods_code :string programme_type :enum not null protocol :integer source :integer not null uuid :uuid not null created_at :datetime not null updated_at :datetime not null duplicate_of_vaccination_record_id :bigint local_patient_id :string location_id :bigint next_dose_delay_triage_id :bigint nhs_immunisations_api_id :string patient_id :bigint not null performed_by_user_id :bigint reported_by_id :bigint session_id :bigint supplied_by_user_id :bigint vaccine_id :bigint
Indexes
idx_on_duplicate_of_vaccination_record_id_5071adce87 (duplicate_of_vaccination_record_id)
idx_on_patient_id_programme_type_outcome_453b557b54 (patient_id,programme_type,outcome) WHERE (discarded_at IS NULL)
index_vaccination_records_on_discarded_at (discarded_at)
index_vaccination_records_on_location_id (location_id)
index_vaccination_records_on_next_dose_delay_triage_id (next_dose_delay_triage_id)
index_vaccination_records_on_nhs_immunisations_api_id (nhs_immunisations_api_id) UNIQUE
index_vaccination_records_on_patient_id (patient_id)
index_vaccination_records_on_patient_id_and_session_id (patient_id,session_id)
index_vaccination_records_on_pending_changes_not_empty (id) WHERE (pending_changes <> '{}'::jsonb)
index_vaccination_records_on_performed_by_user_id (performed_by_user_id)
index_vaccination_records_on_performed_ods_code_and_patient_id (performed_ods_code,patient_id) WHERE (session_id IS NULL)
index_vaccination_records_on_programme_type (programme_type)
index_vaccination_records_on_reported_by_id (reported_by_id)
index_vaccination_records_on_session_id (session_id)
index_vaccination_records_on_supplied_by_user_id (supplied_by_user_id)
index_vaccination_records_on_uuid (uuid) UNIQUE
index_vaccination_records_on_vaccine_id (vaccine_id)
Foreign Keys
fk_rails_... (duplicate_of_vaccination_record_id => vaccination_records.id) fk_rails_... (next_dose_delay_triage_id => triages.id) fk_rails_... (patient_id => patients.id) fk_rails_... (performed_by_user_id => users.id) fk_rails_... (reported_by_id => users.id) fk_rails_... (session_id => sessions.id) fk_rails_... (supplied_by_user_id => users.id) fk_rails_... (vaccine_id => vaccines.id)
Constants
- DELIVERY_METHOD_SNOMED_CODES_AND_TERMS
- DELIVERY_SITE_SNOMED_CODES_AND_TERMS
Public Instance Methods
Source
# File app/models/vaccination_record.rb, line 327 def delivery_method_injection? delivery_method_intramuscular? || delivery_method_subcutaneous? end
Source
# File app/models/vaccination_record.rb, line 331 def delivery_method_snomed_code DELIVERY_METHOD_SNOMED_CODES_AND_TERMS.fetch(delivery_method).first end
Source
# File app/models/vaccination_record.rb, line 335 def delivery_method_snomed_term DELIVERY_METHOD_SNOMED_CODES_AND_TERMS.fetch(delivery_method).second end
Source
# File app/models/vaccination_record.rb, line 351 def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end
Source
# File app/models/vaccination_record.rb, line 386 def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id]) end end
Source
# File app/models/vaccination_record.rb, line 313 def not_administered? = !administered? def reported_as_already_vaccinated? administered? && sourced_from_manual_report? end def show_in_academic_year?(current_academic_year) if programme.seasonal? academic_year == current_academic_year else academic_year <= current_academic_year end end def delivery_method_injection? delivery_method_intramuscular? || delivery_method_subcutaneous? end def delivery_method_snomed_code DELIVERY_METHOD_SNOMED_CODES_AND_TERMS.fetch(delivery_method).first end def delivery_method_snomed_term DELIVERY_METHOD_SNOMED_CODES_AND_TERMS.fetch(delivery_method).second end def snomed_procedure_code = vaccine&.snomed_procedure_code(dose_sequence:) def snomed_procedure_term = vaccine&.snomed_procedure_term(dose_sequence:) def notifier = Notifier::VaccinationRecord.new(self) private def requires_location_name? = location.nil? delegate :maximum_dose_sequence, to: :programme def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id])
Source
# File app/models/vaccination_record.rb, line 343 def notifier = Notifier::VaccinationRecord.new(self) private def requires_location_name? = location.nil? delegate :maximum_dose_sequence, to: :programme def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id]) end end
Source
# File app/models/vaccination_record.rb, line 355 def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end
Source
# File app/models/vaccination_record.rb, line 315 def reported_as_already_vaccinated? administered? && sourced_from_manual_report? end
Source
# File app/models/vaccination_record.rb, line 347 def requires_location_name? = location.nil? delegate :maximum_dose_sequence, to: :programme def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id]) end end end
Source
# File app/models/vaccination_record.rb, line 378 def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end
Source
# File app/models/vaccination_record.rb, line 319 def show_in_academic_year?(current_academic_year) if programme.seasonal? academic_year == current_academic_year else academic_year <= current_academic_year end end
Source
# File app/models/vaccination_record.rb, line 339 def snomed_procedure_code = vaccine&.snomed_procedure_code(dose_sequence:) def snomed_procedure_term = vaccine&.snomed_procedure_term(dose_sequence:) def notifier = Notifier::VaccinationRecord.new(self) private def requires_location_name? = location.nil? delegate :maximum_dose_sequence, to: :programme def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id])
Source
# File app/models/vaccination_record.rb, line 341 def snomed_procedure_term = vaccine&.snomed_procedure_term(dose_sequence:) def notifier = Notifier::VaccinationRecord.new(self) private def requires_location_name? = location.nil? delegate :maximum_dose_sequence, to: :programme def fhir_mapper @fhir_mapper ||= FHIRMapper::VaccinationRecord.new(self) end def recalculate_next_dose_delay_triage_date return if next_dose_delay_triage.blank? return unless administered? previous_performed_at_date, current_performed_at_date = saved_change_to_performed_at_date days_difference = (current_performed_at_date - previous_performed_at_date).to_i new_delay_date = next_dose_delay_triage.delay_vaccination_until + days_difference.days next_dose_delay_triage.assign_attributes( delay_vaccination_until: new_delay_date, notes: "Next dose #{new_delay_date.to_fs(:long)}" ) next_dose_delay_triage.save! PatientStatusUpdater.call(patient:) end def should_generate_important_notice? if id_previously_changed? # new_record? is not available in after_save !notify_parents # important notices are only generated if this is false else notify_parents_previously_changed? end end def generate_important_notice_if_needed if should_generate_important_notice? ImportantNoticeGeneratorJob.perform_later([patient_id]) end