Class: MPI::Messages::UpdateProfileMessage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

rubocop:disable Metrics/ParameterLists



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

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def address
  @address
end

#birth_dateObject (readonly)

Returns the value of attribute birth_date.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def birth_date
  @birth_date
end

#edipiObject (readonly)

Returns the value of attribute edipi.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def edipi
  @edipi
end

#emailObject (readonly)

Returns the value of attribute email.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def first_name
  @first_name
end

#icnObject (readonly)

Returns the value of attribute icn.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def icn
  @icn
end

#idme_uuidObject (readonly)

Returns the value of attribute idme_uuid.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def idme_uuid
  @idme_uuid
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def last_name
  @last_name
end

#logingov_uuidObject (readonly)

Returns the value of attribute logingov_uuid.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def logingov_uuid
  @logingov_uuid
end

#ssnObject (readonly)

Returns the value of attribute ssn.



10
11
12
# File 'lib/mpi/messages/update_profile_message.rb', line 10

def ssn
  @ssn
end

Instance Method Details

#build_bodyObject (private)



56
57
58
59
60
# File 'lib/mpi/messages/update_profile_message.rb', line 56

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

#build_patientObject (private)



83
84
85
86
87
88
89
90
# File 'lib/mpi/messages/update_profile_message.rb', line 83

def build_patient
  element = RequestHelper.build_patient_element
  element << RequestHelper.build_identifier(identifier: icn_with_aaid, root: icn_root)
  element << RequestHelper.build_status_code
  element << build_patient_person
  element << RequestHelper.build_provider_organization
  element
end

#build_patient_personObject (private)



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/mpi/messages/update_profile_message.rb', line 92

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:)
  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)
  element << RequestHelper.build_telecom(type: email_type, value: email)
  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)



68
69
70
71
72
73
74
75
# File 'lib/mpi/messages/update_profile_message.rb', line 68

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)



62
63
64
65
66
# File 'lib/mpi/messages/update_profile_message.rb', line 62

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

#build_subject_1Object (private)



77
78
79
80
81
# File 'lib/mpi/messages/update_profile_message.rb', line 77

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

#combined_streetObject (private)



114
115
116
# File 'lib/mpi/messages/update_profile_message.rb', line 114

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

#csp_identifierObject (private)



122
123
124
125
126
127
128
129
130
# File 'lib/mpi/messages/update_profile_message.rb', line 122

def csp_identifier
  if edipi
    Constants::DSLOGON_FULL_IDENTIFIER
  elsif logingov_uuid
    Constants::LOGINGOV_FULL_IDENTIFIER
  else
    Constants::IDME_FULL_IDENTIFIER
  end
end

#csp_uuidObject (private)



132
133
134
# File 'lib/mpi/messages/update_profile_message.rb', line 132

def csp_uuid
  edipi || logingov_uuid || idme_uuid
end

#email_typeObject (private)



156
157
158
# File 'lib/mpi/messages/update_profile_message.rb', line 156

def email_type
  'H'
end

#icn_rootObject (private)



168
169
170
# File 'lib/mpi/messages/update_profile_message.rb', line 168

def icn_root
  MPI::Constants::VA_ROOT_OID
end

#icn_with_aaidObject (private)



140
141
142
# File 'lib/mpi/messages/update_profile_message.rb', line 140

def icn_with_aaid
  "#{icn}^NI^200M^USVHA^P"
end

#identifierObject (private)



118
119
120
# File 'lib/mpi/messages/update_profile_message.rb', line 118

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

#identifier_class_codeObject (private)



152
153
154
# File 'lib/mpi/messages/update_profile_message.rb', line 152

def identifier_class_code
  'PAT'
end

#identifier_rootObject (private)



160
161
162
163
164
165
166
# File 'lib/mpi/messages/update_profile_message.rb', line 160

def identifier_root
  if edipi
    Constants::DOD_ROOT_OID
  else
    MPI::Constants::VA_ROOT_OID
  end
end

#null_flavor_typeObject (private)



136
137
138
# File 'lib/mpi/messages/update_profile_message.rb', line 136

def null_flavor_type
  'NA'
end

#performObject

rubocop:enable Metrics/ParameterLists



36
37
38
39
40
41
42
# File 'lib/mpi/messages/update_profile_message.rb', line 36

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

#ssn_class_codeObject (private)



148
149
150
# File 'lib/mpi/messages/update_profile_message.rb', line 148

def ssn_class_code
  'SSN'
end

#ssn_rootObject (private)



144
145
146
# File 'lib/mpi/messages/update_profile_message.rb', line 144

def ssn_root
  '2.16.840.1.113883.4.1'
end

#validate_required_fieldsObject (private)



46
47
48
49
50
51
52
53
54
# File 'lib/mpi/messages/update_profile_message.rb', line 46

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