Class: DaVinciPASTestKit::ClaimEndpoint

Inherits:
Inferno::DSL::SuiteEndpoint
  • Object
show all
Defined in:
lib/davinci_pas_test_kit/endpoints/claim_endpoint.rb

Instance Method Summary collapse

Instance Method Details

#make_responseObject



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

#tagsObject



9
10
11
# File 'lib/davinci_pas_test_kit/endpoints/claim_endpoint.rb', line 9

def tags
  [operation == 'submit' ? SUBMIT_TAG : INQUIRE_TAG]
end

#test_run_identifierObject



5
6
7
# File 'lib/davinci_pas_test_kit/endpoints/claim_endpoint.rb', line 5

def test_run_identifier
  request.headers['authorization']&.delete_prefix('Bearer ')
end

#update_resultObject



54
55
56
# File 'lib/davinci_pas_test_kit/endpoints/claim_endpoint.rb', line 54

def update_result
  results_repo.update_result(result.id, 'pass') unless test.config.options[:accepts_multiple_requests]
end