Class: Roqua::Healthy::A19::PhoneParser

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/healthy/a19/phone_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ PhoneParser

Returns a new instance of PhoneParser.



8
9
10
# File 'lib/roqua/healthy/a19/phone_parser.rb', line 8

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/roqua/healthy/a19/phone_parser.rb', line 6

def message
  @message
end

Instance Method Details

#to_sObject

this is a heuristic to pick likely dutch cell phone numbers from hl7 messages



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roqua/healthy/a19/phone_parser.rb', line 13

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