Module: Identity::Parsers::GCIds

Includes:
GCIdsConstants, GCIdsHelper
Included in:
MPI::Responses::AddParser, MPI::Responses::ProfileParser, SAML::UserAttributes::SSOe
Defined in:
lib/identity/parsers/gc_ids.rb

Constant Summary

Constants included from GCIdsConstants

Identity::Parsers::GCIdsConstants::ACTIVE_MHV_IDS_REGEX, Identity::Parsers::GCIdsConstants::BIRLS_IDS_REGEX, Identity::Parsers::GCIdsConstants::CERNER_FACILITY_IDS_REGEX, Identity::Parsers::GCIdsConstants::CERNER_ID_REGEX, Identity::Parsers::GCIdsConstants::DOD_ROOT_OID, Identity::Parsers::GCIdsConstants::EDIPI_REGEX, Identity::Parsers::GCIdsConstants::ICN_ASSIGNING_AUTHORITY_ID, Identity::Parsers::GCIdsConstants::ICN_REGEX, Identity::Parsers::GCIdsConstants::IDENTIFIERS_SPLIT_TOKEN, Identity::Parsers::GCIdsConstants::IDME_ID_REGEX, Identity::Parsers::GCIdsConstants::IDS_SPLIT_TOKEN, Identity::Parsers::GCIdsConstants::ID_MAPPINGS, Identity::Parsers::GCIdsConstants::LOGINGOV_ID_REGEX, Identity::Parsers::GCIdsConstants::MHV_IDS_REGEX, Identity::Parsers::GCIdsConstants::MHV_IEN_REGEX, Identity::Parsers::GCIdsConstants::PERMANENT_ICN_REGEX, Identity::Parsers::GCIdsConstants::SEC_ID_REGEX, Identity::Parsers::GCIdsConstants::VA_ROOT_OID, Identity::Parsers::GCIdsConstants::VBA_CORP_ID_REGEX, Identity::Parsers::GCIdsConstants::VET360_ID_REGEX, Identity::Parsers::GCIdsConstants::VHA_FACILITY_IDS_REGEX

Instance Method Summary collapse

Methods included from GCIdsHelper

#sanitize_edipi, #sanitize_id, #sanitize_id_array

Instance Method Details

#build_hash(extensions, key, value) ⇒ Object (private)



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/identity/parsers/gc_ids.rb', line 83

def build_hash(extensions, (key, value))
  return nil if extensions.empty?

  key_token = select_token_position(key)
  value_token = select_token_position(value)
  ids_hash = Hash.new { |h, k| h[k] = [] }

  extensions.each_with_object(ids_hash) do |e, hsh|
    split_string = e[:extension].split(IDENTIFIERS_SPLIT_TOKEN)
    hsh[split_string[key_token]] << split_string[value_token]
  end
end

#parse_string_gcids(ids, root_oid = VA_ROOT_OID) ⇒ Hash

Returns An hash representing the parsed ids.

Parameters:

  • ids (String)

    A string representing ids to parse

  • root_oid (String) (defaults to: VA_ROOT_OID)

    A string representing the originating service for the ids

Returns:

  • (Hash)

    An hash representing the parsed ids



41
42
43
44
45
46
47
48
# File 'lib/identity/parsers/gc_ids.rb', line 41

def parse_string_gcids(ids, root_oid = VA_ROOT_OID)
  return unless ids

  mapped_ids = ids.split(IDS_SPLIT_TOKEN).map do |id|
    OpenStruct.new(attributes: { extension: id, root: root_oid })
  end
  parse_xml_gcids(mapped_ids)
end

#parse_xml_gcids(ids) ⇒ Hash

Returns An hash representing the parsed ids.

Parameters:

  • ids (Array)

    An array of XML objects representing ids to parse

Returns:

  • (Hash)

    An hash representing the parsed ids



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/identity/parsers/gc_ids.rb', line 14

def parse_xml_gcids(ids)
  return unless ids.is_a? Array

  ids_mapped = ids.map(&:attributes)

  ID_MAPPINGS.map do |id_to_parse, parse_options|
    extension = select_extension(ids_mapped, parse_options[:regex], parse_options[:root_oid])
    parsed_ids =
      case parse_options[:type]
      when :single_id
        select(extension, :id)&.first
      when :multiple_ids
        select(extension, :id)
      when :facility
        select(extension, :assigning_facility)
      when :icn_with_aaid
        select_icn_with_aaid(extension)
      when :facility_to_ids
        build_hash(extension, %i[assigning_facility id])
      end
    { id_to_parse => parsed_ids }
  end.reduce(:merge)
end

#select(extensions, select_token = :id) ⇒ Object (private)

Extension is expected to be formatted as: <id>^<id_type>^<assigning_facility>^<assigning_authority>^<id_state>



53
54
55
56
57
# File 'lib/identity/parsers/gc_ids.rb', line 53

def select(extensions, select_token = :id)
  return nil if extensions.empty?

  extensions.map { |e| e[:extension].split(IDENTIFIERS_SPLIT_TOKEN)[select_token_position(select_token)] }
end

#select_extension(ids, pattern, root) ⇒ Object (private)



64
65
66
67
68
# File 'lib/identity/parsers/gc_ids.rb', line 64

def select_extension(ids, pattern, root)
  ids.select do |id|
    id[:extension] =~ pattern && id[:root] == root
  end
end

#select_icn_with_aaid(extension) ⇒ String, Nil (private)

for example, ‘12345678901234567^NI^200M^USVHA’

Parameters:

  • extension (Array)

    An array of hashes, of the format :root=>‘string’

Returns:

  • (String)

    A string representing an icn_with_aaid, with the ID status removed,

  • (Nil)

    If icn regex not parsed, or status not applicable, return nil



74
75
76
77
78
79
80
81
# File 'lib/identity/parsers/gc_ids.rb', line 74

def select_icn_with_aaid(extension)
  return unless extension.is_a?(Array) && extension.present?

  *identifiers_array, status = extension.first[:extension].split(IDENTIFIERS_SPLIT_TOKEN)
  return unless status == 'P'

  identifiers_array.join(IDENTIFIERS_SPLIT_TOKEN)
end

#select_token_position(token_symbol) ⇒ Object (private)



59
60
61
62
# File 'lib/identity/parsers/gc_ids.rb', line 59

def select_token_position(token_symbol)
  token_positions = { id: 0, id_type: 1, assigning_facility: 2, assigning_authority: 3, id_state: 4 }
  token_positions[token_symbol]
end