Skip to content

Commit

Permalink
Backend job to start up sessions on HL7 validator wrapper (#406)
Browse files Browse the repository at this point in the history
* FI-2234: starting point for a backend job that starts a validator session

* FI-2234: migrate job to start via boot process

* FI-2234: rework job to call Validator directly, DRY

* Fix variable in error message

* Add custom dockerfile for fhir_resource_validator to load SSL certs

* Inherit dockerfile CMD from parent, don't just copy&paste it
  • Loading branch information
dehall committed Nov 30, 2023
1 parent 47856ec commit a1115e8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Dockerfile.fhir_resource_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM markiantorno/validator-wrapper

USER root
# Java certs need to be installed as root, so switch to that user for this step only
# (the image does not contain 'sudo')
RUN wget https://gitlab.mitre.org/mitre-scripts/mitre-pki/-/raw/master/tool_scripts/install_certs.sh -O - | MODE=java sh

USER $APPLICATION_USER

# CMD is inherited from parent image as long as we don't override it or ENTRYPOINT
10 changes: 9 additions & 1 deletion docker-compose.background.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ services:
# the section in nginx.background.conf need to be uncommented
# hl7_validator_service:
# image: markiantorno/validator-wrapper
# # If running on the MITRE network, comment out the "image" line above
# # and uncomment the "build" section below
# # build:
# # context: .
# # dockerfile: Dockerfile.fhir_resource_validator
# # Update this path to match your directory structure
# volumes:
# - ./igs:/home/igs
# - ./igs:/home/igs
# # To let the service share your local FHIR package cache,
# # uncomment the below line
# # - ~/.fhir:/home/ktor/.fhir
19 changes: 19 additions & 0 deletions lib/inferno/config/boot/validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Inferno::Application.boot(:validator) do
init do
use :suites

# 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_with_index do |validator, index|
if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator
Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, suite.id, name.to_s, index)
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/inferno/dsl/fhir_resource_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def self.included(klass)

class Validator
attr_reader :requirements
attr_accessor :session_id

# @private
def initialize(requirements = nil, &)
Expand Down
1 change: 1 addition & 0 deletions lib/inferno/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'jobs/execute_test_run'
require_relative 'jobs/resume_test_run'
require_relative 'jobs/invoke_validator_session'

module Inferno
module Jobs
Expand Down
23 changes: 23 additions & 0 deletions lib/inferno/jobs/invoke_validator_session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Inferno
module Jobs
class InvokeValidatorSession
include Sidekiq::Worker

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]

response_body = validator.validate(FHIR::Patient.new, 'http://hl7.org/fhir/StructureDefinition/Patient')

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
validator.session_id = session_id
else
Inferno::Application['logger'].error("InvokeValidatorSession - error from validator: #{response_body}")
end
end
end
end
end

0 comments on commit a1115e8

Please sign in to comment.