Class: MPI::Messages::RequestBuilder

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Defined in:
lib/mpi/messages/request_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extension:, body:, search_token: nil) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



10
11
12
13
14
# File 'lib/mpi/messages/request_builder.rb', line 10

def initialize(extension:, body:, search_token: nil)
  @extension = extension
  @body = body
  @search_token = search_token
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/mpi/messages/request_builder.rb', line 8

def body
  @body
end

#extensionObject (readonly)

Returns the value of attribute extension.



8
9
10
# File 'lib/mpi/messages/request_builder.rb', line 8

def extension
  @extension
end

#search_tokenObject (readonly)

Returns the value of attribute search_token.



8
9
10
# File 'lib/mpi/messages/request_builder.rb', line 8

def search_token
  @search_token
end

Instance Method Details

#build_attention_lineObject (private)



90
91
92
93
94
# File 'lib/mpi/messages/request_builder.rb', line 90

def build_attention_line
  attention_line = element('attentionLine')
  attention_line << element('keyWordText', {}, 'Search.Token')
  attention_line << element('value', { 'xsi:type' => 'ST' }, search_token)
end

#build_document_componentObject (private)



22
23
24
25
26
# File 'lib/mpi/messages/request_builder.rb', line 22

def build_document_component
  document = Ox::Document.new(version: '1.0')
  document << build_instruct_component
  document << build_envelope_component
end

#build_envelopeObject (private)



101
102
103
104
105
106
107
108
109
110
# File 'lib/mpi/messages/request_builder.rb', line 101

def build_envelope
  env = element(
    'env:Envelope',
    'xmlns:soapenc' => 'http://schemas.xmlsoap.org/soap/encoding/',
    'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
    'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
  )
  env << element('env:Header')
end

#build_envelope_body_componentObject (private)



40
41
42
43
# File 'lib/mpi/messages/request_builder.rb', line 40

def build_envelope_body_component
  envelope_body = element('env:Body')
  envelope_body << build_message_component
end

#build_envelope_componentObject (private)



35
36
37
38
# File 'lib/mpi/messages/request_builder.rb', line 35

def build_envelope_component
  envelope = build_envelope
  envelope << build_envelope_body_component
end

#build_headerObject (private)



64
65
66
67
68
69
70
71
72
73
# File 'lib/mpi/messages/request_builder.rb', line 64

def build_header
  element = build_idm
  element << element('id', root: '1.2.840.114350.1.13.0.1.7.1.1', extension: "200VGOV-#{SecureRandom.uuid}")
  element << element('creationTime', value: Time.now.utc.strftime('%Y%m%d%H%M%S'))
  element << element('versionCode', code: '4.1')
  element << element('interactionId', root: '2.16.840.1.113883.1.6', extension:)
  element << element('processingCode', code: processing_code)
  element << element('processingModeCode', code: 'T')
  element << element('acceptAckCode', code: 'AL')
end

#build_idmObject (private)



53
54
55
56
57
58
59
60
61
62
# File 'lib/mpi/messages/request_builder.rb', line 53

def build_idm
  element(
    "idm:#{extension}",
    'xmlns:idm' => 'http://vaww.oed.oit.va.gov',
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema‐instance',
    'xsi:schemaLocation' => "urn:hl7‐org:v3 ../../schema/HL7V3/NE2008/multicacheschemas/#{extension}.xsd",
    'xmlns' => 'urn:hl7‐org:v3',
    'ITSVersion' => 'XML_1.0'
  )
end

#build_instruct_componentObject (private)



28
29
30
31
32
33
# File 'lib/mpi/messages/request_builder.rb', line 28

def build_instruct_component
  instruct = Ox::Instruct.new(:xml)
  instruct[:version] = '1.0'
  instruct[:encoding] = 'utf-8'
  instruct
end

#build_message_componentObject (private)



45
46
47
48
49
50
51
# File 'lib/mpi/messages/request_builder.rb', line 45

def build_message_component
  message = build_header
  message << build_receiver
  message << build_sender
  message << build_attention_line if search_token
  message << body
end

#build_receiverObject (private)



75
76
77
78
# File 'lib/mpi/messages/request_builder.rb', line 75

def build_receiver
  receiver = element('receiver', typeCode: 'RCV')
  receiver << build_receiver_device
end

#build_receiver_deviceObject (private)



80
81
82
83
# File 'lib/mpi/messages/request_builder.rb', line 80

def build_receiver_device
  device = element('device', classCode: 'DEV', determinerCode: 'INSTANCE')
  device << element('id', root: '1.2.840.114350.1.13.999.234', extension: '200M')
end

#build_senderObject (private)



85
86
87
88
# File 'lib/mpi/messages/request_builder.rb', line 85

def build_sender
  sender = element('sender', typeCode: 'SND')
  sender << build_sender_device
end

#build_sender_deviceObject (private)



96
97
98
99
# File 'lib/mpi/messages/request_builder.rb', line 96

def build_sender_device
  device = element('device', classCode: 'DEV', determinerCode: 'INSTANCE')
  device << element('id', root: MPI::Constants::VA_ROOT_OID, extension: '200VGOV')
end

#element(name, attributes = {}, body_text = nil) ⇒ Object (private)



116
117
118
119
120
121
# File 'lib/mpi/messages/request_builder.rb', line 116

def element(name, attributes = {}, body_text = nil)
  element = Ox::Element.new(name)
  attributes.each { |key, value| element[key] = value }
  element.replace_text(body_text) if body_text
  element
end

#performObject



16
17
18
# File 'lib/mpi/messages/request_builder.rb', line 16

def perform
  Ox.dump(build_document_component)
end

#processing_codeObject (private)



112
113
114
# File 'lib/mpi/messages/request_builder.rb', line 112

def processing_code
  Settings.mvi.processing_code
end