Sha256: 9055c09d31173ab88b98e5b8f412a103632c2b6363641eea98bddaa7da3bde0d

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
module Roqua
  module Healthy
    module A19
      class PhoneParser
        attr_reader :message

        def initialize(message)
          @message = message
        end

        # this is a heuristic to pick likely dutch cell phone numbers from hl7 messages
        def to_s
          pid13 = message.fetch('PID').fetch('PID.13')

          # prefer PRN (Primary Residence Number) that contains a cell phone number
          phone_cell_record = pid13.find do |record|
            phone_cell_number?(record.fetch('PID.13.1', '') || '') &&
              record.fetch('PID.13.2', :unknown_type_of_phone_record) == 'PRN'
          end

          # otherwise choose the first occuring cell phone number
          phone_cell_record ||= pid13.find do |record|
            phone_cell_number?(record.fetch('PID.13.1', '') || '')
          end

          # any number for which phone_cell_number? returns false is ignored

          strip_non_phone_number_characters(phone_cell_record.fetch('PID.13.1')) if phone_cell_record.present?
        end

        private

        def strip_non_phone_number_characters(number)
          Roqua::Healthy::A19::PhoneValidator.strip_non_phone_number_characters number
        end

        def phone_cell_number?(number)
          Roqua::Healthy::A19::PhoneValidator.phone_cell_number? number
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roqua-healthy-1.5.10 lib/roqua/healthy/a19/phone_parser.rb
roqua-healthy-1.5.9 lib/roqua/healthy/a19/phone_parser.rb
roqua-healthy-1.5.8 lib/roqua/healthy/a19/phone_parser.rb
roqua-healthy-1.5.7 lib/roqua/healthy/a19/phone_parser.rb
roqua-healthy-1.5.6 lib/roqua/healthy/a19/phone_parser.rb