class FHIRMapper::VaccinationRecord
Constants
- BATCH_EXPIRY_MAX
- BATCH_EXPIRY_MIN
- MAVIS_NATIONAL_REPORTING_SYSTEM_NAME
- MAVIS_SYSTEM_NAME
- MILLILITER_SUB_STRINGS
- VACCINATION_PROCEDURE_EXTENSION_URL
Public Class Methods
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 273 def self.delivery_method_from_fhir(fhir_record) route_code = fhir_record .route &.coding &.find { it.system == "http://snomed.info/sct" } &.code ::VaccinationRecord::DELIVERY_METHOD_SNOMED_CODES_AND_TERMS .find { |_key, value| value.first == route_code } &.first end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 401 def self.dose_number_string_note_from_fhir(fhir_record) dose_string = fhir_record.protocolApplied&.sole&.doseNumberString return if dose_string.blank? "Reported dose number string: #{dose_string}" end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 391 def self.dose_sequence_from_fhir(fhir_record) protocol = fhir_record.protocolApplied&.sole if protocol&.doseNumberPositiveInt.present? return protocol&.doseNumberPositiveInt end Integer(protocol&.doseNumberString, exception: false) end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 294 def self.dose_volume_ml_from_fhir(fhir_record) dq = fhir_record.doseQuantity return if dq.blank? if MILLILITER_SUB_STRINGS.any? { dq.unit.downcase.starts_with?(it) } dq.value.to_d end end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 70 def self.from_fhir_record(fhir_record, patient:) attrs = {} notes = [] attrs[:source] = "nhs_immunisations_api" attrs[:patient] = patient attrs[:nhs_immunisations_api_id] = fhir_record.id attrs[:nhs_immunisations_api_synced_at] = Time.current attrs[:nhs_immunisations_api_identifier_system] = fhir_record .identifier .sole .system attrs[:nhs_immunisations_api_identifier_value] = fhir_record .identifier .sole .value attrs[:nhs_immunisations_api_primary_source] = fhir_record.primarySource recorded = fhir_record.recorded attrs[:nhs_immunisations_api_recorded_at] = Time.zone.parse( recorded ) if recorded procedure_coding = vaccination_procedure_coding_from_fhir(fhir_record) attrs[ :nhs_immunisations_api_snomed_procedure_code ] = procedure_coding&.code attrs[ :nhs_immunisations_api_snomed_procedure_term ] = procedure_coding&.display attrs[:programme] = Programme.from_fhir_record(fhir_record) attrs[:performed_at] = Time.zone.parse(fhir_record.occurrenceDateTime) attrs[:outcome] = outcome_from_fhir(fhir_record) location_system = fhir_record.location.identifier.system location_value = fhir_record.location.identifier.value unless location_value == FHIRMapper::Location::UNKNOWN_IDENTIFIER case location_system when "https://fhir.hl7.org.uk/Id/urn-school-number" attrs[:location] = ::Location.find_by(urn: location_value) when "https://fhir.nhs.uk/Id/ods-organization-code" attrs[:location] = ::Location.find_by(ods_code: location_value) end end if attrs[:location].nil? attrs[:location_name] = ( if location_value == FHIRMapper::Location::UNKNOWN_IDENTIFIER "Unknown" else location_value end ) end org_actor = org_performer_actor_from_fhir(fhir_record) performer_ods_code = org_actor&.identifier&.value unless performer_ods_code == FHIRMapper::Location::UNKNOWN_IDENTIFIER attrs[:performed_ods_code] = performer_ods_code end if org_actor&.display.present? notes << "Performing organisation display name: #{org_actor.display}" end user_performer_name = user_performer_name_from_fhir(fhir_record) attrs[:performed_by_given_name] = user_performer_name&.given&.first attrs[:performed_by_family_name] = user_performer_name&.family attrs[:delivery_method] = delivery_method_from_fhir(fhir_record) attrs[:delivery_site] = site_from_fhir(fhir_record) dose_sequence = dose_sequence_from_fhir(fhir_record) if dose_sequence if dose_sequence > attrs[:programme].maximum_dose_sequence || dose_sequence < 1 notes << "Reported dose number: #{dose_sequence}" else attrs[:dose_sequence] = dose_sequence end else notes << dose_number_string_note_from_fhir(fhir_record) end reason_coding = reason_coding_from_fhir(fhir_record) attrs[:nhs_immunisations_api_snomed_reason_code] = reason_coding&.code attrs[:nhs_immunisations_api_snomed_reason_term] = reason_coding&.display product_coding = vaccine_product_coding_from_fhir(fhir_record) attrs[:nhs_immunisations_api_snomed_product_code] = product_coding&.code attrs[ :nhs_immunisations_api_snomed_product_term ] = product_coding&.display attrs[:vaccine] = Vaccine.from_fhir_record(fhir_record) attrs[:batch_number] = fhir_record.lotNumber&.to_s batch_expiry = fhir_record.expirationDate&.to_date attrs[:batch_expiry] = batch_expiry if ( BATCH_EXPIRY_MIN...BATCH_EXPIRY_MAX ).cover?(batch_expiry) if attrs[:vaccine] attrs[:disease_types] = attrs[:vaccine].disease_types attrs[:full_dose] = full_dose_from_fhir( fhir_record, vaccine: attrs[:vaccine] ) else attrs[:disease_types] = attrs[:programme].disease_types attrs[:full_dose] = true end attrs[:notes] = notes.compact.join("\n").presence ::VaccinationRecord.new(attrs) end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 304 def self.full_dose_from_fhir(fhir_record, vaccine:) if vaccine.programme.flu? && vaccine.nasal? dose_volume_ml = dose_volume_ml_from_fhir(fhir_record) return nil if dose_volume_ml.nil? case dose_volume_ml.to_d when vaccine.dose_volume_ml true when vaccine.dose_volume_ml * 0.5.to_d false end else true end end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 20 def initialize(vaccination_record) @vaccination_record = vaccination_record end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 348 def self.org_performer_actor_from_fhir(fhir_record) fhir_record.performer.find { it.actor&.type == "Organization" }&.actor end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 223 def self.outcome_from_fhir(fhir_record) case fhir_record.status when "completed" "administered" when "not-done" raise "Cannot import not-done vaccination records" else raise "Unexpected vaccination status: \"#{fhir_record.status}\". Expected only 'completed' or 'not-done'" end end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 363 def self.reason_coding_from_fhir(fhir_record) fhir_record.reasonCode&.first&.coding&.find do it.system == "http://snomed.info/sct" end end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 249 def self.site_from_fhir(fhir_record) site_code = fhir_record .site &.coding &.find { it.system == "http://snomed.info/sct" } &.code ::VaccinationRecord::DELIVERY_SITE_SNOMED_CODES_AND_TERMS .find { |_key, value| value.first == site_code } &.first end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 327 def self.user_performer_name_from_fhir(fhir_record) performer_references = fhir_record .performer .reject { it.actor&.type == "Organization" } .map { it.actor.reference&.sub("#", "") } .compact user_actor = fhir_record.contained&.find do |c| c.id.in?(performer_references) && c.resourceType == "Practitioner" end user_actor&.name&.find { it&.use == "official" } || user_actor&.name&.first end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 352 def self.vaccination_procedure_coding_from_fhir( fhir_record ) fhir_record .extension &.find { it.url == VACCINATION_PROCEDURE_EXTENSION_URL } &.valueCodeableConcept &.coding &.find { it.system == "http://snomed.info/sct" } end
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 369 def self.vaccine_product_coding_from_fhir(fhir_record) fhir_record.vaccineCode&.coding&.find do it.system == "http://snomed.info/sct" end end
Public Instance Methods
Source
# File app/lib/fhir_mapper/vaccination_record.rb, line 27 def fhir_record immunisation = FHIR::Immunization.new(id: nhs_immunisations_api_id) if performed_by.present? immunisation.contained << FHIRMapper::User.new( performed_by ).fhir_practitioner(reference_id: "Practitioner1") end immunisation.contained << patient.fhir_record(reference_id: "Patient1") immunisation.extension = [fhir_vaccination_procedure_extension] immunisation.identifier = [fhir_identifier] immunisation.status = fhir_status immunisation.vaccineCode = vaccine.fhir_codeable_concept immunisation.patient = FHIR::Reference.new(reference: "#Patient1") immunisation.occurrenceDateTime = performed_at.to_time.iso8601(3) immunisation.recorded = created_at.iso8601(3) immunisation.primarySource = sourced_from_service? || sourced_from_national_reporting? immunisation.manufacturer = vaccine.fhir_manufacturer_reference immunisation.location = (location || ::Location.gias_school.new).fhir_reference immunisation.lotNumber = batch_number immunisation.expirationDate = batch_expiry.to_s immunisation.site = fhir_site immunisation.route = fhir_route immunisation.doseQuantity = fhir_dose_quantity if performed_by.present? immunisation.performer << fhir_user_performer( reference_id: "Practitioner1" ) end immunisation.performer << fhir_org_performer immunisation.reasonCode = [fhir_reason_code] immunisation.protocolApplied = [fhir_protocol_applied] immunisation end
If you add or remove fields here, update SYNCED_FIELDS in VaccinationRecord::NHSImmunisationsAPISync so that changes to those fields correctly trigger or stop triggering a sync to the NHS Immunisations API.