Class: MPI::Messages::AddPersonImplicitSearchMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/mpi/messages/add_person_implicit_search_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first_name:, last_name:, ssn:, birth_date:, email: nil, address: nil, idme_uuid: nil, logingov_uuid: nil) ⇒ AddPersonImplicitSearchMessage

rubocop:disable Metrics/ParameterLists



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 14

def initialize(first_name:,
               last_name:,
               ssn:,
               birth_date:,
               email: nil,
               address: nil,
               idme_uuid: nil,
               logingov_uuid: nil)
  @first_name = first_name
  @last_name = last_name
  @ssn = ssn
  @email = email
  @address = address
  @birth_date = birth_date
  @idme_uuid = idme_uuid
  @logingov_uuid = logingov_uuid
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def address
  @address
end

#birth_dateObject (readonly)

Returns the value of attribute birth_date.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def birth_date
  @birth_date
end

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def first_name
  @first_name
end

#idme_uuidObject (readonly)

Returns the value of attribute idme_uuid.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def idme_uuid
  @idme_uuid
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def last_name
  @last_name
end

#logingov_uuidObject (readonly)

Returns the value of attribute logingov_uuid.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def logingov_uuid
  @logingov_uuid
end

#ssnObject (readonly)

Returns the value of attribute ssn.



11
12
13
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 11

def ssn
  @ssn
end

Instance Method Details

#build_bodyObject (private)



51
52
53
54
55
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 51

def build_body
  element = RequestHelper.build_control_act_process_element
  element << build_subject
  element
end

#build_patientObject (private)



78
79
80
81
82
83
84
85
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 78

def build_patient
  element = RequestHelper.build_patient_element
  element << RequestHelper.build_id_null_flavor(type: null_flavor_type)
  element << RequestHelper.build_status_code
  element << build_patient_person
  element << RequestHelper.build_provider_organization
  element
end

#build_patient_personObject (private)



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 87

def build_patient_person
  element = RequestHelper.build_patient_person_element
  element << RequestHelper.build_patient_person_name(given_names: [first_name], family_name: last_name)
  element << RequestHelper.build_patient_person_birth_date(birth_date:)
  element << RequestHelper.build_telecom(type: email_type, value: email)
  if address.present?
    element << RequestHelper.build_patient_person_address(street: combined_street,
                                                          state: address[:state],
                                                          city: address[:city],
                                                          postal_code: address[:postal_code],
                                                          country: address[:country])
  end
  element << RequestHelper.build_identifier(identifier:, root: identifier_root)
  if ssn.present?
    element << RequestHelper.build_patient_identifier(identifier: ssn, root: ssn_root, class_code: ssn_class_code)
  end
  element << RequestHelper.build_patient_identifier(identifier:,
                                                    root: identifier_root,
                                                    class_code: identifier_class_code)
  element
end

#build_registration_eventObject (private)



63
64
65
66
67
68
69
70
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 63

def build_registration_event
  element = RequestHelper.build_registration_event_element
  element << RequestHelper.build_id_null_flavor(type: null_flavor_type)
  element << RequestHelper.build_status_code
  element << build_subject_1
  element << RequestHelper.build_custodian
  element
end

#build_subjectObject (private)



57
58
59
60
61
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 57

def build_subject
  element = RequestHelper.build_subject_element
  element << build_registration_event
  element
end

#build_subject_1Object (private)



72
73
74
75
76
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 72

def build_subject_1
  element = RequestHelper.build_subject_1_element
  element << build_patient
  element
end

#combined_streetObject (private)



109
110
111
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 109

def combined_street
  [address[:street], address[:street2]].compact.join(' ')
end

#csp_identifierObject (private)



117
118
119
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 117

def csp_identifier
  idme_uuid ? Constants::IDME_FULL_IDENTIFIER : Constants::LOGINGOV_FULL_IDENTIFIER
end

#csp_uuidObject (private)



121
122
123
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 121

def csp_uuid
  idme_uuid || logingov_uuid
end

#email_typeObject (private)



137
138
139
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 137

def email_type
  'H'
end

#identifierObject (private)



113
114
115
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 113

def identifier
  "#{csp_uuid}^#{csp_identifier}"
end

#identifier_class_codeObject (private)



141
142
143
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 141

def identifier_class_code
  'PAT'
end

#identifier_rootObject (private)



145
146
147
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 145

def identifier_root
  MPI::Constants::VA_ROOT_OID
end

#null_flavor_typeObject (private)



125
126
127
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 125

def null_flavor_type
  'UNK'
end

#performObject

rubocop:enable Metrics/ParameterLists



33
34
35
36
37
38
39
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 33

def perform
  validate_required_fields
  MPI::Messages::RequestBuilder.new(extension: MPI::Constants::ADD_PERSON, body: build_body).perform
rescue => e
  Rails.logger.error "[AddPersonImplicitSearchMessage] Failed to build request: #{e.message}"
  raise e
end

#ssn_class_codeObject (private)



133
134
135
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 133

def ssn_class_code
  'SSN'
end

#ssn_rootObject (private)



129
130
131
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 129

def ssn_root
  '2.16.840.1.113883.4.1'
end

#validate_required_fieldsObject (private)



43
44
45
46
47
48
49
# File 'lib/mpi/messages/add_person_implicit_search_message.rb', line 43

def validate_required_fields
  missing_values = []
  missing_values << :last_name if last_name.blank?
  missing_values << :birth_date if birth_date.blank?
  missing_values << :credential_identifier if idme_uuid.blank? && logingov_uuid.blank?
  raise Errors::ArgumentError, "Required values missing: #{missing_values}" if missing_values.present?
end