Skip to content

Commit

Permalink
FI-2234: rework job to call Validator directly, DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Nov 15, 2023
1 parent 61e6b4e commit da3f512
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
11 changes: 5 additions & 6 deletions lib/inferno/config/boot/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
init do
use :suites

# This process should only run once,
# so do not run this step on worker threads
# next if Sidekiq.server?
# This process should only run once, to start one job per validator,
# so skipping it on workers will start it only once from the "web" process
next if Sidekiq.server?

Inferno::Repositories::TestSuites.new.all.each do |suite|
suite.fhir_validators.each do |name, validators|

validators.each do |validator|
validators.each_with_index do |validator, index|
if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator
Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, validator.url, validator.igs)
Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, suite.id, name.to_s, index)
end
end
end
Expand Down
43 changes: 8 additions & 35 deletions lib/inferno/jobs/invoke_validator_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,17 @@ module Jobs
class InvokeValidatorSession
include Sidekiq::Worker

def perform(url, igs, disable_tx = false, display_issues_are_warnings = true)
request_body = {
cliContext: {
sv: '4.0.1',
displayWarnings: display_issues_are_warnings,
# txServer: nil, # -tx n/a
igs: igs || []
},
filesToValidate: [
{
fileName: 'session_starter.json',
fileContent: FHIR::Patient.new.to_json,
fileType: 'json'
}
]
}
def perform(suite_id, validator_name, validator_index)
suite = Inferno::Repositories::TestSuites.new.find suite_id
validator = suite.fhir_validators[validator_name.to_sym][validator_index]

request_body[:cliContext][:txServer] = nil if disable_tx
response_body = validator.validate(FHIR::Patient.new, 'http://hl7.org/fhir/StructureDefinition/Patient')

response = Faraday.new(
url,
request: { timeout: 600 }
).post('validate', request_body.to_json, content_type: 'application/json')

if response.body.start_with? '{'
res = JSON.parse(response.body)
if response_body.start_with? '{'
res = JSON.parse(response_body)
session_id = res['sessionId']
# TODO: (FI-2311) store this session ID so it can be referenced as needed,
# instead of iterating through all test suites to find where it goes
Inferno::Repositories::TestSuites.new.all.each do |suite|
suite.fhir_validators.each do |name, validators|
validators.each do |validator|
if validator.url == url and validator.igs == igs
validator.session_id = session_id
end
end
end
end
# TODO: (FI-2311) store this session ID so it can be referenced as needed
validator.session_id = session_id
else
Inferno::Application['logger'].error("InvokeValidatorSession - error calling validator. #{response.inspect}")
end
Expand Down

0 comments on commit da3f512

Please sign in to comment.