Class: CarinForBlueButtonTestKit::Generator::ReadTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/carin_for_blue_button_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.



20
21
22
23
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 20

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.



18
19
20
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 18

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



18
19
20
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 18

def 
  @group_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



7
8
9
10
11
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 7

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

.read_interaction(group_metadata) ⇒ Object



13
14
15
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 13

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

Instance Method Details

#base_output_file_nameObject



33
34
35
36
37
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 33

def base_output_file_name
  file_name = class_name.underscore
  file_name.sub!("#{profile_identifier}_", '')
  "#{file_name}.rb"
end

#class_nameObject



59
60
61
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 59

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

#conformance_expectationObject



106
107
108
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 106

def conformance_expectation
  read_interaction[:expectation]
end

#generateObject



119
120
121
122
123
124
125
126
127
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 119

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

#input_descriptionObject



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 129

def input_description
  desc_content = if profile_identifier == 'patient'
                   "
                    Comma separated list of patient IDs that in sum
                    contain all MUST SUPPORT elements
                    "
                 else
                   "#{profile_identifier} Resource ID"
                 end
  <<~INPUT_DESCRIPTION
    #{desc_content}
  INPUT_DESCRIPTION
end

#module_nameObject



63
64
65
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 63

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

#no_search_params?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 115

def no_search_params?
  search_params.blank?
end

#outputObject



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

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

#output_file_directoryObject



39
40
41
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 39

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



43
44
45
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 43

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



51
52
53
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 51

def profile_identifier
  Naming.snake_case_for_profile()
end

#read_interactionObject



47
48
49
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 47

def read_interaction
  self.class.read_interaction()
end

#resource_collection_stringObject



98
99
100
101
102
103
104
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 98

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

#resource_typeObject



67
68
69
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 67

def resource_type
  .resource
end

#search_paramsObject



110
111
112
113
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 110

def search_params
  .searches.map { |search| search[:names] }
                .flatten
end

#specific_resource_typeObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 71

def specific_resource_type
  case profile_identifier
  when 'eob_inpatient_institutional'
    'ExplanationOfBenefitInpatientInstitutional'
  when 'eob_inpatient_institutional_nonfinancial'
    'ExplanationOfBenefitInpatientInstitutionalNonFinancial'
  when 'eob_oral'
    'ExplanationOfBenefitOral'
  when 'eob_oral_nonfinancial'
    'ExplanationOfBenefitOralNonFinancial'
  when 'eob_outpatient_institutional'
    'ExplanationOfBenefitOutpatientInstitutional'
  when 'eob_outpatient_institutional_nonfinancial'
    'ExplanationOfBenefitOutpatientInstitutionalNonFinancial'
  when 'eob_pharmacy'
    'ExplanationOfBenefitPharmacy'
  when 'eob_pharmacy_nonfinancial'
    'ExplanationOfBenefitPharmacyNonFinancial'
  when 'eob_professional_non_clinician'
    'ExplanationOfBenefitProfessionalNonClinician'
  when 'eob_professional_non_clinician_nonfinancial'
    'ExplanationOfBenefitProfessionalNonClinicianNonFinancial'
  else
    resource_type
  end
end

#templateObject



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

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

#test_idObject



55
56
57
# File 'lib/carin_for_blue_button_test_kit/generator/read_test_generator.rb', line 55

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