Class: AUCoreTestKit::Generator::ReadTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/au_core_test_kit/generator/read_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, base_output_dir) ⇒ ReadTestGenerator

Returns a new instance of ReadTestGenerator.



24
25
26
27
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 24

def initialize(, base_output_dir)
  self. = 
  self.base_output_dir = base_output_dir
end

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



22
23
24
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 22

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



22
23
24
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 22

def 
  @group_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



10
11
12
13
14
15
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 10

def generate(, base_output_dir)
  .groups
             .reject { |group| SpecialCases.exclude_group? group }
             .select { |group| read_interaction(group).present? }
             .each { |group| new(group, base_output_dir).generate }
end

.read_interaction(group_metadata) ⇒ Object



17
18
19
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 17

def read_interaction()
  .interactions.find { |interaction| interaction[:code] == 'read' }
end

Instance Method Details

#base_output_file_nameObject



37
38
39
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 37

def base_output_file_name
  "#{class_name.underscore}.rb"
end

#class_nameObject



61
62
63
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 61

def class_name
  "#{Naming.upper_camel_case_for_profile()}ReadTest"
end

#conformance_expectationObject



81
82
83
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 81

def conformance_expectation
  read_interaction[:expectation]
end

#generateObject



105
106
107
108
109
110
111
112
113
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 105

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.open(output_file_name, 'w') { |f| f.write(output) }

  .add_test(
    id: test_id,
    file_name: base_output_file_name
  )
end

#module_nameObject



65
66
67
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 65

def module_name
  "AUCore#{.reformatted_version.upcase}"
end

#needs_healthcare_service_id?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 101

def needs_healthcare_service_id?
  resource_type == 'HealthcareService'
end

#needs_location_id?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 85

def needs_location_id?
  resource_type == 'Location'
end

#needs_organization_id?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 89

def needs_organization_id?
  resource_type == 'Organization'
end

#needs_practitioner_id?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 93

def needs_practitioner_id?
  resource_type == 'Practitioner'
end

#needs_practitioner_role_id?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 97

def needs_practitioner_role_id?
  resource_type == 'PractitionerRole'
end

#outputObject



33
34
35
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 33

def output
  @output ||= ERB.new(template).result(binding)
end

#output_file_directoryObject



41
42
43
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 41

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



45
46
47
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 45

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



53
54
55
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 53

def profile_identifier
  Naming.snake_case_for_profile()
end

#read_interactionObject



49
50
51
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 49

def read_interaction
  self.class.read_interaction()
end

#resource_collection_stringObject



73
74
75
76
77
78
79
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 73

def resource_collection_string
  if .delayed? && resource_type != 'Provenance'
    "scratch.dig(:references, '#{resource_type}')"
  else
    'all_scratch_resources'
  end
end

#resource_typeObject



69
70
71
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 69

def resource_type
  .resource
end

#templateObject



29
30
31
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 29

def template
  @template ||= File.read(File.join(__dir__, 'templates', 'read.rb.erb'))
end

#test_idObject



57
58
59
# File 'lib/au_core_test_kit/generator/read_test_generator.rb', line 57

def test_id
  "au_core_#{.reformatted_version}_#{profile_identifier}_read_test"
end