Class: PacioInfernoCore::Generator::IGResources

Inherits:
Object
  • Object
show all
Defined in:
lib/pacio_inferno_core/generator/ig_resources.rb

Instance Method Summary collapse

Instance Method Details

#add(resource) ⇒ Object



5
6
7
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 5

def add(resource)
  resources_by_type[resource.resourceType] << resource
end

#capability_statement(mode = 'server') ⇒ Object



13
14
15
16
17
18
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 13

def capability_statement(mode = 'server')
  resources_by_type['CapabilityStatement'].find do |capability_statement_resource|
    capability_statement_resource.rest.any? { |r| r.mode == mode } &&
    capability_statement_resource.implementationGuide.any? { |p| p.include?(naming.implementation_guide_id) }
  end
end

#code_system_by_url(url) ⇒ Object



46
47
48
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 46

def code_system_by_url(url)
  resources_by_type['CodeSystem'].find { |system| system.url == url }
end

#igObject



20
21
22
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 20

def ig
  resources_by_type['ImplementationGuide'].first
end

#inspectObject



24
25
26
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 24

def inspect
  'IGResources'
end

#namingObject



9
10
11
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 9

def naming
  self.class.module_parent::Naming
end

#profile_by_url(url) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 28

def profile_by_url(url)
  return if url.nil? || url.empty?

  normalized_url = url.split('|').first

  resources_by_type['StructureDefinition'].find do |profile|
    profile.url == normalized_url || profile.id == normalized_url
  end
end

#resource_for_profile(url) ⇒ Object



38
39
40
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 38

def resource_for_profile(url)
  profile_by_url(url).type
end

#search_param_by_resource_and_name(resource, name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 50

def search_param_by_resource_and_name(resource, name)
  # remove '_' from search parameter name, such as _id or _tag
  normalized_name = name.to_s.delete_prefix('_')

  exact_id_matches = []
  resource_scoped_code_matches = []

  resources_by_type['SearchParameter'].each do |param|
    exact_id_match = (param.id == "us-core-#{resource.downcase}-#{normalized_name}")
    resource_scoped_code_match = Array(param.base).include?(resource) &&
                                 (param.name == name || param.code == name)

    if exact_id_match
      exact_id_matches << param
    elsif resource_scoped_code_match
      resource_scoped_code_matches << param
    end
  end

  candidates = exact_id_matches.empty? ? resource_scoped_code_matches : exact_id_matches
  warn_about_multiple_search_param_candidates(resource, name, candidates) if candidates.length > 1

  candidates.first
end

#value_set_by_url(url) ⇒ Object



42
43
44
# File 'lib/pacio_inferno_core/generator/ig_resources.rb', line 42

def value_set_by_url(url)
  resources_by_type['ValueSet'].find { |profile| profile.url == url }
end