Class: DaVinciCRDTestKit::MockEHR::FHIRMetadataEndpoint
- Inherits:
-
Object
- Object
- DaVinciCRDTestKit::MockEHR::FHIRMetadataEndpoint
- Defined in:
- lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb
Constant Summary collapse
- MOCK_EHR_INTERACTIONS =
%w[read search-type create update delete].freeze
- US_CORE_METADATA_DIR =
File.join( Gem::Specification.find_by_name('us_core_test_kit').gem_dir, 'lib', 'us_core_test_kit', 'generated', 'v6.1.0' ).freeze
- SEARCH_PARAM_TYPES =
{ 'string' => 'string', 'HumanName' => 'string', 'Address' => 'string', 'http://hl7.org/fhirpath/System.String' => 'string', 'code' => 'token', 'CodeableConcept' => 'token', 'Coding' => 'token', 'Identifier' => 'token', 'patternCodeableConcept' => 'token', 'patternCoding' => 'token', 'patternIdentifier' => 'token', 'requiredBinding' => 'token', 'date' => 'date', 'dateTime' => 'date', 'instant' => 'date', 'Period' => 'date', 'Reference' => 'reference', 'uri' => 'uri', 'canonical' => 'uri', 'number' => 'number', 'integer' => 'number', 'decimal' => 'number', 'quantity' => 'quantity' }.freeze
Class Method Summary collapse
- .build_resource_entries ⇒ Object
- .build_resource_entry(resource_type, metadata_list) ⇒ Object
- .call ⇒ Object
- .collect_search_params(metadata_list) ⇒ Object
- .metadata_dir ⇒ Object
- .metadata_files ⇒ Object
- .resource_entries ⇒ Object
- .search_param_type(type) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build_resource_entries ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 103 def self.build_resource_entries by_type = .each_with_object(Hash.new { |h, k| h[k] = [] }) do |path, types| = USCoreTestKit::Generator::GroupMetadata.new(YAML.load_file(path, aliases: true)) types[.resource] << end by_type.map { |resource_type, | build_resource_entry(resource_type, ) } end |
.build_resource_entry(resource_type, metadata_list) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 85 def self.build_resource_entry(resource_type, ) search_params = collect_search_params() profile_urls = .map(&:profile_url).compact FHIR::CapabilityStatement::Rest::Resource.new( type: resource_type, supportedProfile: profile_urls, interaction: MOCK_EHR_INTERACTIONS.map do |code| FHIR::CapabilityStatement::Rest::Resource::Interaction.new(code:) end, searchParam: search_params.map do |name, type| FHIR::CapabilityStatement::Rest::Resource::SearchParam.new( name:, type: search_param_type(type) ) end ) end |
.call ⇒ Object
28 29 30 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 28 def self.call(...) new.call(...) end |
.collect_search_params(metadata_list) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 77 def self.collect_search_params() .each_with_object({}) do |, params| .search_definitions&.each do |name, definition| params[name.to_s] ||= definition[:type] end end end |
.metadata_dir ⇒ Object
61 62 63 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 61 def self. US_CORE_METADATA_DIR end |
.metadata_files ⇒ Object
65 66 67 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 65 def self. Dir.glob(File.join(, '*', 'metadata.yml')) end |
.resource_entries ⇒ Object
69 70 71 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 69 def self.resource_entries @resource_entries ||= build_resource_entries end |
.search_param_type(type) ⇒ Object
73 74 75 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 73 def self.search_param_type(type) SEARCH_PARAM_TYPES.fetch(type, 'string') end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 32 def call(env) request = Rack::Request.new(env) [200, { 'Content-Type' => 'application/fhir+json' }, [capability_statement_json(request)]] end |
#capability_statement_json(request) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/davinci_crd_test_kit/server/endpoints/mock_ehr/fhir_metadata_endpoint.rb', line 37 def capability_statement_json(request) fhir_base_url = request.url.delete_suffix('/metadata') suite_id = request.path.split('/')[2] suite_title = Inferno::Repositories::TestSuites.new.find(suite_id)&.title fhir_server_name = 'Inferno US Core FHIR Server Simulation' FHIR::CapabilityStatement.new( status: 'active', kind: 'instance', date: LAST_UPDATED, software: FHIR::CapabilityStatement::Software.new( name: fhir_server_name ), implementation: FHIR::CapabilityStatement::Implementation.new( description: "#{suite_title} #{fhir_server_name} hosted at #{fhir_base_url}", url: fhir_base_url ), fhirVersion: '4.0.1', format: ['application/fhir+json'], instantiates: ['http://hl7.org/fhir/us/core/CapabilityStatement/us-core-server'], rest: [FHIR::CapabilityStatement::Rest.new(mode: 'server', resource: self.class.resource_entries)] ).to_json end |