module VaccinationRecord::NHSImmunisationsAPISync
Constants
- API_INTEGRATION_CUT_OFF_DATES
- SYNCED_FIELDS
-
Fields whose changes trigger a sync. Keep in sync with:
- FHIRMapper::VaccinationRecord#fhir_record (fields that affect the FHIR payload) - #should_be_in_nhs_immunisations_api? (fields that affect eligibility)
Public Instance Methods
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 123 def api_integration_cutoff_date API_INTEGRATION_CUT_OFF_DATES.fetch(programme_type) end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 127 def changes_need_to_be_synced_to_nhs_immunisations_api? (changes.keys & SYNCED_FIELDS).any? end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 75 def correct_source_for_nhs_immunisations_api? sourced_from_service? || ( Flipper.enabled?(:sync_national_reporting_to_imms_api) && sourced_from_national_reporting? ) end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 115 def created_before_api_integration? cut_off = API_INTEGRATION_CUT_OFF_DATES.fetch(programme_type) return false if cut_off.nil? created_at.to_date < cut_off end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 138 def queue_sync_to_nhs_immunisations_api return unless Flipper.enabled?(:imms_api_sync_job, programme) return unless correct_source_for_nhs_immunisations_api? return if nhs_immunisations_api_sync_pending_at.nil? if nhs_immunisations_api_synced_at && ( nhs_immunisations_api_sync_pending_at < nhs_immunisations_api_synced_at ) return end SyncVaccinationRecordToNHSJob.perform_async(id) end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 83 def should_be_in_nhs_immunisations_api? kept? && correct_source_for_nhs_immunisations_api? && administered? && Flipper.enabled?(:imms_api_sync_job, programme) && notify_parents != false && patient.not_invalidated? end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 89 def sync_status should_be_synced = should_be_in_nhs_immunisations_api? return :not_synced unless should_be_synced synced_at = nhs_immunisations_api_synced_at pending_at = nhs_immunisations_api_sync_pending_at if synced_at.present? && (pending_at.nil? || synced_at > pending_at) return :synced end return :not_synced if created_before_api_integration? return :failed if pending_at.present? && 24.hours.ago > pending_at :pending end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 154 def sync_to_nhs_immunisations_api! touch_nhs_immunisations_api_sync_pending_at save! # The after_commit callback queues the job to actually perform the sync # with the API. end
Source
# File app/models/vaccination_record/nhs_immunisations_api_sync.rb, line 131 def touch_nhs_immunisations_api_sync_pending_at return unless Flipper.enabled?(:imms_api_sync_job, programme) return unless correct_source_for_nhs_immunisations_api? self.nhs_immunisations_api_sync_pending_at = Time.current end