Class: MPI::Responses::ProfileParser

Inherits:
ParserBase show all
Includes:
Identity::Parsers::GCIds, SentryLogging
Defined in:
lib/mpi/responses/profile_parser.rb

Overview

Parses a MVI response and returns a MviProfile

Constant Summary collapse

BODY_XPATH =
'env:Envelope/env:Body/idm:PRPA_IN201306UV02'
CODE_XPATH =
'acknowledgement/typeCode/@code'
QUERY_XPATH =
'controlActProcess/queryByParameter'
SSN_ROOT_ID =
'2.16.840.1.113883.4.1'
SUBJECT_XPATH =
'controlActProcess/subject'
PATIENT_XPATH =
'registrationEvent/subject1/patient'
STATUS_XPATH =
'statusCode/@code'
CONFIDENTIALITY_CODE_XPATH =
'confidentialityCode/@code'
ID_THEFT_INDICATOR =
'ID_THEFT^TRUE'
PATIENT_PERSON_PREFIX =
'patientPerson/'
RELATIONSHIP_PREFIX =
'relationshipHolder1/'
GENDER_XPATH =
'administrativeGenderCode/@code'
DOB_XPATH =
'birthTime/@value'
SSN_XPATH =
'asOtherIDs'
NAME_XPATH =
'name'
'L'
ADDRESS_XPATH =
'addr'
DECEASED_XPATH =
'deceasedTime/@value'
PHONE =
'telecom'
PERSON_TYPE =
'PERSON_TYPE'
PERSON_TYPE_SEPERATOR =
'~'
PERSON_TYPE_VALUE_XPATH =
'value/@code'
PERSON_TYPE_CODE_XPATH =
'code/@code'
ADMIN_OBSERVATION_XPATH =
'*/administrativeObservation'
ACKNOWLEDGEMENT_DETAIL_XPATH =
'acknowledgement/acknowledgementDetail/text'
ACKNOWLEDGEMENT_TARGET_MESSAGE_ID_EXTENSION_XPATH =
'acknowledgement/targetMessage/id/@extension'
MULTIPLE_MATCHES_FOUND =
'Multiple Matches Found'
PATIENT_RELATIONSHIP_XPATH =
'patientPerson/personalRelationship'

Constants included from Identity::Parsers::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

Constants inherited from ParserBase

MPI::Responses::ParserBase::EXTERNAL_RESPONSE_CODES

Instance Method Summary collapse

Methods included from Identity::Parsers::GCIds

#parse_string_gcids, #parse_xml_gcids

Methods included from Identity::Parsers::GCIdsHelper

#sanitize_edipi, #sanitize_id, #sanitize_id_array

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Methods inherited from ParserBase

#failed_or_invalid?, #failed_request?, #invalid_request?, #locate_element, #locate_elements, #unknown_error?

Constructor Details

#initialize(response) ⇒ ProfileParser

Returns a new instance of ProfileParser.



50
51
52
53
54
# File 'lib/mpi/responses/profile_parser.rb', line 50

def initialize(response)
  @transaction_id = response.response_headers['x-global-transaction-id']
  @original_body = locate_element(response.body, BODY_XPATH)
  @code = locate_element(@original_body, CODE_XPATH)
end

Instance Method Details

#error_detailsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mpi/responses/profile_parser.rb', line 77

def error_details
  error_details = {
    ack_detail_code: @code,
    id_extension: locate_element(@original_body, ACKNOWLEDGEMENT_TARGET_MESSAGE_ID_EXTENSION_XPATH),
    transaction_id: @transaction_id,
    error_texts: []
  }
  error_text_nodes = locate_elements(@original_body, ACKNOWLEDGEMENT_DETAIL_XPATH)
  if error_text_nodes.nil?
    error_details[:error_texts] = error_text_nodes
  else
    error_text_nodes.each do |node|
      error_text = node.text || node&.nodes&.first&.value
      error_details[:error_texts].append(error_text) unless error_details[:error_texts].include?(error_text)
    end
  end
  { error_details: }
end

#multiple_match?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/mpi/responses/profile_parser.rb', line 56

def multiple_match?
  acknowledgement_detail = locate_element(@original_body, ACKNOWLEDGEMENT_DETAIL_XPATH)
  return false unless acknowledgement_detail

  acknowledgement_detail.nodes.first == MULTIPLE_MATCHES_FOUND
end

#no_match?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/mpi/responses/profile_parser.rb', line 63

def no_match?
  locate_element(@original_body, SUBJECT_XPATH).blank?
end

#parseObject



67
68
69
70
71
72
73
74
75
# File 'lib/mpi/responses/profile_parser.rb', line 67

def parse
  subject = locate_element(@original_body, SUBJECT_XPATH)
  return MPI::Models::MviProfile.new({ transaction_id: @transaction_id }) unless subject

  patient = locate_element(subject, PATIENT_XPATH)
  return MPI::Models::MviProfile.new({ transaction_id: @transaction_id }) unless patient

  build_mpi_profile(patient)
end