13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/davinci_pas_test_kit/endpoints/claim_endpoint.rb', line 13
def make_response
response.status = 200
response.format = :json
user_inputted_response = UserInputResponse.user_inputted_response(test, result)
if user_inputted_response.present?
response.body = user_inputted_response
return
end
req_bundle = FHIR.from_contents(request.body.string)
claim_entry = req_bundle&.entry&.find { |e| e&.resource&.resourceType == 'Claim' }
claim_full_url = claim_entry&.fullUrl
if claim_entry.blank? || claim_full_url.blank?
handle_missing_required_elements(claim_entry, response)
return
end
root_url = base_url(claim_full_url)
claim_response = mock_claim_response(claim_entry.resource, req_bundle, root_url)
res_bundle = FHIR::Bundle.new(
id: SecureRandom.uuid,
meta: FHIR::Meta.new(profile: if operation == 'submit'
'http://hl7.org/fhir/us/davinci-pas/StructureDefinition/profile-pas-response-bundle'
else
'http://hl7.org/fhir/us/davinci-pas/StructureDefinition/profile-pas-inquiry-response-bundle'
end),
timestamp: Time.now.utc.iso8601,
type: 'collection',
entry: [
FHIR::Bundle::Entry.new(fullUrl: "urn:uuid:#{claim_response.id}",
resource: claim_response)
]
)
res_bundle.entry.concat(referenced_entities(claim_response, req_bundle.entry, root_url))
response.body = res_bundle.to_json
end
|