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, workflow = nil, medication_request_metadata = nil, base_output_dir:) ⇒ ValidationTestGenerator

Returns a new instance of ValidationTestGenerator.



17
18
19
20
21
22
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 17

def initialize(, workflow = nil,  = nil, base_output_dir:)
  self. = 
  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.



15
16
17
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 15

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



15
16
17
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 15

def 
  @group_metadata
end

#medication_request_metadataObject

Returns the value of attribute medication_request_metadata.



15
16
17
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 15

def 
  @medication_request_metadata
end

#workflowObject

Returns the value of attribute workflow.



15
16
17
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 15

def workflow
  @workflow
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 8

def generate(, base_output_dir)
  .bundle_groups.each do |group|
    new(group, base_output_dir:).generate
  end
end

Instance Method Details

#base_output_file_nameObject



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

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

#class_nameObject



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

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

#conformance_expectationObject



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

def conformance_expectation
  read_interaction[:expectation]
end

#descriptionObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 131

def description
  <<~DESCRIPTION
    #{description_user_input_validation if user_input?}

    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.

    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.

    **Limitations**

    Due to recognized errors in the PAS IG around extension context definitions,
    this test may not pass due to spurious errors of the form "The extension
    [extension url] is not allowed at this point". See [this
    issue](https://github.com/inferno-framework/davinci-pas-test-kit/issues/11)
    for additional details.
  DESCRIPTION
end

#description_user_input_validationObject



164
165
166
167
168
169
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 164

def description_user_input_validation
  <<~USER_INPUT_INTRO
    **USER INPUT VALIDATION**: This test validates input provided by the user instead of the system under test.
    Errors encountered will be treated as a skip instead of a failure.
  USER_INPUT_INTRO
end

#directory_nameObject



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

def directory_name
  Naming.snake_case_for_profile( || )
end

#formatted_workflowObject



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

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

#generateObject



100
101
102
103
104
105
106
107
108
109
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 100

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



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

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

#outputObject



28
29
30
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 28

def output
  @output ||= ERB.new(template, trim_mode: '-').result(binding)
end

#output_file_directoryObject



36
37
38
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 36

def output_file_directory
  File.join(base_output_dir, directory_name)
end

#output_file_nameObject



40
41
42
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 40

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



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

def profile_identifier
  Naming.snake_case_for_profile()
end

#profile_nameObject



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

def profile_name
  .profile_name
end

#profile_urlObject



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

def profile_url
  .profile_url
end

#profile_versionObject



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

def profile_version
  .profile_version
end

#request_typeObject



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

def request_type
  Naming.request_type_for_bundle_or_claim[profile_name]
end

#resource_typeObject



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

def resource_type
  .resource
end

#skip_if_emptyObject



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

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



24
25
26
# File 'lib/davinci_pas_test_kit/generator/validation_test_generator.rb', line 24

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

#test_idObject



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

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

#titleObject



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

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

#user_input?Boolean

Returns:

  • (Boolean)


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

def user_input?
  request_type.include?('request')
end

#verifies_requirementsObject



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

def verifies_requirements
  case test_id
  when 'pas_server_v201_pas_inquiry_response_bundle_validation_test'
    ['hl7.fhir.us.davinci-pas_2.0.1@131']
  when 'pas_server_v201_pas_response_bundle_validation_test'
    ['hl7.fhir.us.davinci-pas_2.0.1@64', 'hl7.fhir.us.davinci-pas_2.0.1@100',
     'hl7.fhir.us.davinci-pas_2.0.1@101', 'hl7.fhir.us.davinci-pas_2.0.1@102',
     'hl7.fhir.us.davinci-pas_2.0.1@103', 'hl7.fhir.us.davinci-pas_2.0.1@107']
  end
end