Class: DaVinciPASTestKit::Generator::ValidationTestGenerator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ValidationTestGenerator.



34
35
36
37
38
39
40
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 34

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

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



32
33
34
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 32

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



32
33
34
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 32

def 
  @group_metadata
end

#medication_request_metadataObject

Returns the value of attribute medication_request_metadata.



32
33
34
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 32

def 
  @medication_request_metadata
end

#systemObject

Returns the value of attribute system.



32
33
34
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 32

def system
  @system
end

#workflowObject

Returns the value of attribute workflow.



32
33
34
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 32

def workflow
  @workflow
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 8

def generate(, base_output_dir)
  ['server', 'client'].each do |system|
    if system == 'server'
      .bundle_groups.each do |group|
        new(group, system, base_output_dir:).generate
      end
    else
      .bundle_groups.each do |group|
        case group.profile_name
        when 'PAS Request Bundle'
          new(group, system, base_output_dir:).generate
        when 'PAS Inquiry Request Bundle'
          new(group, system, 'pended_inquiry', base_output_dir:).generate
        when 'PAS Response Bundle'
          ['denial', 'pended'].each do |workflow|
            new(group, system, workflow, base_output_dir:).generate
          end
        end
      end
    end
  end
end

Instance Method Details

#base_output_file_nameObject



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

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

#class_nameObject



94
95
96
97
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 94

def class_name
  pref = "#{system.capitalize}#{formatted_workflow.camelize}"
  "#{pref}#{Naming.upper_camel_case_for_profile()}ValidationTest"
end

#conformance_expectationObject



107
108
109
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 107

def conformance_expectation
  read_interaction[:expectation]
end

#descriptionObject



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 142

def description
  <<~DESCRIPTION
    #{system == 'server' ? description_intro_server : description_intro_client}
    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.

    Note that because X12 value sets are not public, elements bound to value
    sets containing X12 codes are not validated.
  DESCRIPTION
end

#description_intro_clientObject



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 168

def description_intro_client
  <<~GENERIC_INTRO
    This test validates the conformity of the
    #{request_type.include?('response') ? 'user input' : "client's request"} to the
    [#{profile_name}](#{profile_url}) structure.
    It also checks that other conformance requirements defined in the [PAS Formal
    Specification](https://hl7.org/fhir/us/davinci-pas/STU2/specification.html),
    such as the presence of all referenced instances within the bundle and the
    conformance of those instances to the appropriate profiles, are met.
  GENERIC_INTRO
end

#description_intro_serverObject



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 156

def description_intro_server
  <<~GENERIC_INTRO
    This test validates the conformity of the
    #{request_type.include?('request') ? 'user input' : "server's response"} to the
    [#{profile_name}](#{profile_url}) structure#{request_type.include?('request') ? ', ensuring subsequent tests can accurately simulate content.' : '.'}
    It also checks that other conformance requirements defined in the [PAS Formal
    Specification](https://hl7.org/fhir/us/davinci-pas/STU2/specification.html),
    such as the presence of all referenced instances within the bundle and the
    conformance of those instances to the appropriate profiles, are met.
  GENERIC_INTRO
end

#directory_nameObject



63
64
65
66
67
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 63

def directory_name
  return 'client_tests' if system == 'client'

  Naming.snake_case_for_profile( || )
end

#formatted_workflowObject



85
86
87
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 85

def formatted_workflow
  workflow.to_s.split('_').first.to_s
end

#generateObject



121
122
123
124
125
126
127
128
129
130
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 121

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.write(output_file_name, output)

   = {
    id: test_id,
    file_name: base_output_file_name
  }
  .add_test(**)
end

#module_nameObject



99
100
101
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 99

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

#outputObject



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

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

#output_file_directoryObject



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

def output_file_directory
  File.join(base_output_dir, directory_name)
end

#output_file_nameObject



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

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



69
70
71
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 69

def profile_identifier
  Naming.snake_case_for_profile()
end

#profile_nameObject



77
78
79
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 77

def profile_name
  .profile_name
end

#profile_urlObject



73
74
75
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 73

def profile_url
  .profile_url
end

#profile_versionObject



81
82
83
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 81

def profile_version
  .profile_version
end

#request_typeObject



117
118
119
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 117

def request_type
  Naming.request_type_for_bundle_or_claim[profile_name]
end

#resource_typeObject



103
104
105
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 103

def resource_type
  .resource
end

#skip_if_emptyObject



111
112
113
114
115
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 111

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



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

def template
  temp = system == 'server' ? 'validation.rb.erb' : 'validation_client.rb.erb'
  @template ||= File.read(File.join(__dir__, 'templates', temp))
end

#test_idObject



89
90
91
92
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 89

def test_id
  pref = "pas_#{system}_#{.reformatted_version}_#{formatted_workflow}".delete_suffix('_')
  "#{pref}_#{profile_identifier}_validation_test"
end

#titleObject



132
133
134
135
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 132

def title
  pref = user_input? ? '[USER INPUT VALIDATION] ' : ''
  "#{pref}#{.title} is valid"
end

#user_input?Boolean

Returns:

  • (Boolean)


137
138
139
140
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 137

def user_input?
  (system == 'server' && request_type.include?('request')) ||
    (system == 'client' && request_type.include?('response'))
end