Module: DaVinciDTRTestKit::MockEHR

Included in:
FHIRGetEndpoint
Defined in:
lib/davinci_dtr_test_kit/endpoints/mock_ehr.rb,
lib/davinci_dtr_test_kit/endpoints/mock_ehr/fhir_get_endpoint.rb,
lib/davinci_dtr_test_kit/endpoints/mock_ehr/questionnaire_response_endpoint.rb

Defined Under Namespace

Classes: FHIRGetEndpoint, QuestionnaireResponseEndpoint

Constant Summary collapse

RESOURCE_SERVER_BASE =
ENV.fetch('FHIR_REFERENCE_SERVER')
RESOURCE_SERVER_BEARER_TOKEN =
'SAMPLE_TOKEN'

Class Method Summary collapse

Class Method Details

.metadata(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/davinci_dtr_test_kit/endpoints/mock_ehr.rb', line 18

def (env)
  cs = resource_server_client.capability_statement
  if cs.present?
    # Overwrite the OAuth URIs returned by the reference server to point to the suite endpoints instead
    oauth_uris_url = 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris'
    base_url = MockAuthorization.env_base_url(env, METADATA_PATH)
    sec_ext = cs.rest.first&.security&.extension&.delete_if { |e| e.url == oauth_uris_url } # rubocop:disable Style/SafeNavigationChainLength
    sec_ext&.push(
      FHIR::Extension.new(
        url: oauth_uris_url,
        extension: [
          FHIR::Extension.new(url: 'authorize', valueUri: MockAuthorization.authorization_endpoint(base_url)),
          FHIR::Extension.new(url: 'token', valueUri: MockAuthorization.token_endpoint(base_url))
        ]
      )
    )

    [200, { 'Content-Type' => 'application/fhir+json', 'Access-Control-Allow-Origin' => '*' }, [cs.to_json]]
  else
    [500, { 'Access-Control-Allow-Origin' => '*' }, ['Unexpected error occurred while fetching metadata']]
  end
end

.resource_server_clientObject



12
13
14
15
16
# File 'lib/davinci_dtr_test_kit/endpoints/mock_ehr.rb', line 12

def resource_server_client
  client = FHIR::Client.new(RESOURCE_SERVER_BASE)
  client.set_bearer_token(RESOURCE_SERVER_BEARER_TOKEN)
  client
end