Class: Roqua::Healthy::A19::Transformer
- Inherits:
-
Object
- Object
- Roqua::Healthy::A19::Transformer
- Defined in:
- lib/roqua/healthy/a19/transformer.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #birthdate ⇒ Object
- #deceased ⇒ Object
- #email ⇒ Object
- #gender ⇒ Object
- #identities ⇒ Object
-
#initialize(message) ⇒ Transformer
constructor
A new instance of Transformer.
- #medoq_data ⇒ Object
- #phone_cell ⇒ Object
- #source ⇒ Object
-
#status ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
-
#to_patient ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Constructor Details
#initialize(message) ⇒ Transformer
Returns a new instance of Transformer.
18 19 20 21 22 23 24 25 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 18 def initialize() raise ::Roqua::Healthy::PatientNotFound unless ['PID'].present? ['PID']['PID.3'] = [.fetch('PID').fetch('PID.3')].flatten.compact ['PID']['PID.5'] = [.fetch('PID').fetch('PID.5')].flatten.compact ['PID']['PID.11'] = [.fetch('PID').fetch('PID.11')].flatten.compact ['PID']['PID.13'] = [.fetch('PID').fetch('PID.13')].flatten.compact @message = MessageCleaner.new(). end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
16 17 18 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 16 def @message end |
Instance Method Details
#birthdate ⇒ Object
86 87 88 89 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 86 def birthdate birthdate_details = .fetch('PID').fetch('PID.7') birthdate_details&.fetch('PID.7.1') end |
#deceased ⇒ Object
110 111 112 113 114 115 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 110 def deceased case .dig('PID', 'PID.30', 'PID.30.1') when 'Y' then true when 'N' then false end end |
#email ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 91 def email email_record = .fetch('PID').fetch('PID.13').find do |record| record.fetch('PID.13.2', :unknown_type_of_phone_record) == 'NET' end return nil unless email_record email_address = email_record.fetch('PID.13.1', "") email_address = email_record.fetch('PID.13.4', "") if email_address.blank? email_address end |
#gender ⇒ Object
106 107 108 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 106 def gender .dig('PID', 'PID.8', 'PID.8.1') end |
#identities ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 61 def identities @identities ||= .fetch('PID').fetch('PID.3').map do |identity| next if identity.fetch('PID.3.1').blank? = identity.fetch('PID.3.5') # medoq sends all its (possibly identifying) metadata in 1 json encoded identity # non medoq hl7 clients could fake being medoq, so do not add any trusted behavior # to medoq identities beyond what a regular hl7 field would enable if == 'MEDOQ' parsed_medoq_data = JSON.parse(identity.fetch('PID.3.1')).with_indifferent_access {ident: parsed_medoq_data[:epd_id], research_number: parsed_medoq_data[:research_number], metadata: parsed_medoq_data[:metadata], authority: } else {ident: identity.fetch('PID.3.1'), authority: } end end.compact end |
#medoq_data ⇒ Object
80 81 82 83 84 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 80 def medoq_data identities.find do |identity| identity[:authority] == 'MEDOQ' end || {} end |
#phone_cell ⇒ Object
102 103 104 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 102 def phone_cell PhoneParser.new().to_s end |
#source ⇒ Object
57 58 59 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 57 def source .fetch('MSH').fetch('MSH.4').fetch('MSH.4.1') end |
#status ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
53 54 55 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 53 def status 'SUCCESS' end |
#to_patient ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/roqua/healthy/a19/transformer.rb', line 28 def to_patient { status: status, source: source, identities: identities, firstname: name.firstname, initials: name.initials, lastname: name.lastname, display_name: name.display_name, nickname: name.nickname, email: email, address_type: address.address_type, street: address.street, city: address.city, zipcode: address.zipcode, country: address.country, birthdate: birthdate, gender: gender, phone_cell: phone_cell, medoq_data: medoq_data, deceased: deceased } end |