Class: DaVinciPlanNetTestKit::Generator::ValidationTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, medication_request_metadata = nil, base_output_dir:) ⇒ ValidationTestGenerator

Returns a new instance of ValidationTestGenerator.



25
26
27
28
29
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 25

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

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



23
24
25
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 23

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



23
24
25
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 23

def 
  @group_metadata
end

#medication_request_metadataObject

Returns the value of attribute medication_request_metadata.



23
24
25
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 23

def 
  @medication_request_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 8

def generate(, base_output_dir)
  .groups
    .reject { |group| SpecialCases.exclude_group? group }
    .each do |group|
      new(group, base_output_dir: base_output_dir).generate
      next unless group.resource == 'MedicationRequest'

      # The Medication validation test lives in the MedicationRequest
      # group, so we need to pass in that group's metadata
       = .groups.find { |group| group.resource == 'Medication' }
      new(, group, base_output_dir: base_output_dir).generate
    end
end

Instance Method Details

#base_output_file_nameObject



39
40
41
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 39

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

#class_nameObject



75
76
77
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 75

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

#conformance_expectationObject



87
88
89
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 87

def conformance_expectation
  read_interaction[:expectation]
end

#descriptionObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 113

def description
  <<~DESCRIPTION
  #{description_intro}
  It verifies the presence of mandatory elements and that elements with
  required bindings contain appropriate values. CodeableConcept element
  bindings will fail if none of their codings have a code/system belonging
  to the bound ValueSet. Quantity, Coding, and code element bindings will
  fail if their code/system are not found in the valueset.
  DESCRIPTION
end

#description_introObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 124

def description_intro
  if resource_type == 'Medication'
    <<~MEDICATION_INTRO
    This test verifies resources returned from previous tests conform to
    the [#{profile_name}](#{.versioned_profile_url}).
    MEDICATION_INTRO
  else
    <<~GENERIC_INTRO
    This test verifies resources returned from the first search conform to
    the [#{profile_name}](#{.versioned_profile_url}).
    Systems must demonstrate at least one valid example in order to pass this test.
    GENERIC_INTRO
  end
end

#directory_nameObject



51
52
53
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 51

def directory_name
  Naming.snake_case_for_profile( || )
end

#generateObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 97

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

   = {
    id: test_id,
    file_name: base_output_file_name
  }

  if resource_type == 'Medication'
    .add_test(**)
  else
    .add_test(**)
  end
end

#module_nameObject



79
80
81
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 79

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

#outputObject



35
36
37
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 35

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

#output_file_directoryObject



43
44
45
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 43

def output_file_directory
  File.join(base_output_dir, directory_name)
end

#output_file_nameObject



47
48
49
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 47

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



55
56
57
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 55

def profile_identifier
  Naming.snake_case_for_profile()
end

#profile_nameObject



63
64
65
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 63

def profile_name
  .profile_name
end

#profile_urlObject



59
60
61
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 59

def profile_url
  .profile_url
end

#profile_versionObject



67
68
69
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 67

def profile_version
  .profile_version
end

#resource_typeObject



83
84
85
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 83

def resource_type
  .resource
end

#skip_if_emptyObject



91
92
93
94
95
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 91

def skip_if_empty
  # Return true if a system must demonstrate at least one example of the resource type.
  # This drives omit vs. skip result statuses in this test.
  resource_type != 'Medication'
end

#templateObject



31
32
33
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 31

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

#test_idObject



71
72
73
# File 'lib/davinci_plan_net_test_kit/generator/validation_test_generator.rb', line 71

def test_id
  "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_validation_test"
end