au_core_test_kit 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c32e06a580aec281c4cd8b9a3c81876c100aec48c3339da38039738c95076c33
4
- data.tar.gz: 9974c68cbd0a99509beec400b1f7c7fddb26df6d149cb718980b477780ff81d2
3
+ metadata.gz: 5f15fd88cfb916854facac06878f74b895ce349054166335ce53ad549e83957c
4
+ data.tar.gz: 7d3443b5ed200b329adfca57ea6b450041abe86617d71dbe48858624d2f9eff8
5
5
  SHA512:
6
- metadata.gz: ea07dad9fb4e636d9523fc880e2605595705abbab51314bc794b41f3e8242e68b76c86abfdf42d8677cd533967e37cfb92c9932811c05366efcbe84af11367f9
7
- data.tar.gz: 306aa54265e5a7f53cac8dd4e43d6d5f5a4878e299bd5a30bdb701533663713fd28ce2e7dc2d7edd61d73008f5b2811cb062a734749871a189144a907f51df8e
6
+ metadata.gz: 4a3f62dba98f75f60ffdf00b2301d803abf236a9e479857b7167fcb5152839c26661328f16c8e3a5d4d0b7dbb6dbec605177c73ddbf3a06ef0a452100c96cbe2
7
+ data.tar.gz: 7af925d33efc5a94d19afe5619216b54953646730ba6dccd187ea40b9948300ecd88f84bf342884153407dc17cce1a0a3d3856158d33c2e669db8cb9a2331321
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'assert_helpers'
4
+ require_relative 'validator_helpers'
4
5
 
5
6
  module AUCoreTestKit
6
7
  module ValidationTest
7
8
  include AssertHelpers
9
+ include ValidatorHelpers
8
10
 
9
11
  DAR_CODE_SYSTEM_URL = 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
10
12
  DAR_EXTENSION_URL = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason'
@@ -19,6 +21,8 @@ module AUCoreTestKit
19
21
  omit_if resources.blank?,
20
22
  "No #{resource_type} resources provided so the #{profile_url} profile does not apply"
21
23
 
24
+ show_validator_version
25
+
22
26
  profile_with_version = "#{profile_url}|#{profile_version}"
23
27
  resources.each do |resource|
24
28
  resource_is_valid?(resource:, profile_url: profile_with_version)
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helpers for validating FHIR resources
4
+ module ValidatorHelpers
5
+ VALIDATOR_KEY = 'validator_version'
6
+ WRAPPER_KEY = 'validator_wrapper_version'
7
+ RESPONSE_VALIDATOR_KEY = 'validatorVersion'
8
+ RESPONSE_WRAPPER_KEY = 'validatorWrapperVersion'
9
+ RESPONSE_KEYS = [RESPONSE_VALIDATOR_KEY, RESPONSE_WRAPPER_KEY].freeze
10
+ DEFAULT_VALUE = 'Unknown'
11
+
12
+ def show_validator_version
13
+ versions = read_or_create_validator_version
14
+ if versions.nil?
15
+ info 'Unable to fetch validator version'
16
+ return
17
+ end
18
+
19
+ validator_version = versions[VALIDATOR_KEY] || DEFAULT_VALUE
20
+ wrapper_version = versions[WRAPPER_KEY] || DEFAULT_VALUE
21
+
22
+ info "Using validator version #{validator_version} and validator wrapper version #{wrapper_version}"
23
+ end
24
+
25
+ private
26
+
27
+ def read_or_create_validator_version
28
+ return cached_versions if version_cached?
29
+
30
+ fetch_and_cache_versions
31
+ end
32
+
33
+ def validator_url
34
+ ENV['FHIR_RESOURCE_VALIDATOR_URL']
35
+ end
36
+
37
+ def response_valid?(version_data)
38
+ RESPONSE_KEYS.all? { |key| version_data.keys.include?(key) }
39
+ end
40
+
41
+ def fetch_and_cache_versions
42
+ response_body = fetch_validator_version(validator_url)
43
+ return warning("Unable to fetch validator version from #{validator_url}") if response_body.nil?
44
+
45
+ version_data = parse_response(response_body)
46
+
47
+ return warning "Invalid response from validator at #{validator_url}: #{version_data}" unless response_valid?(version_data)
48
+
49
+ cache_versions(version_data[RESPONSE_VALIDATOR_KEY], version_data[RESPONSE_WRAPPER_KEY])
50
+ build_version_hash(version_data[RESPONSE_VALIDATOR_KEY], version_data[RESPONSE_WRAPPER_KEY])
51
+ end
52
+
53
+ def cache_versions(validator_version, validator_wrapper_version)
54
+ scratch[VALIDATOR_KEY.to_sym] = validator_version
55
+ scratch[WRAPPER_KEY.to_sym] = validator_wrapper_version
56
+ end
57
+
58
+ def version_cached?
59
+ scratch[VALIDATOR_KEY.to_sym] && scratch[WRAPPER_KEY.to_sym]
60
+ end
61
+
62
+ def cached_versions
63
+ build_version_hash(scratch[VALIDATOR_KEY.to_sym], scratch[WRAPPER_KEY.to_sym])
64
+ end
65
+
66
+ def fetch_validator_version(url)
67
+ version_url = "#{url}/validator/version"
68
+ begin
69
+ response = Faraday.get(version_url)
70
+ response.body
71
+ rescue Faraday::Error => e
72
+ warning "Error connecting to validator at #{url}: #{e.message}"
73
+ nil
74
+ end
75
+ end
76
+
77
+ def parse_response(response_body)
78
+ JSON.parse(response_body)
79
+ rescue JSON::ParserError => e
80
+ warning "Error parsing response from validator: #{e.message}"
81
+ nil
82
+ end
83
+
84
+ def build_version_hash(validator_version, validator_wrapper_version)
85
+ {
86
+ 'validator_version' => validator_version,
87
+ 'validator_wrapper_version' => validator_wrapper_version
88
+ }
89
+ end
90
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AUCoreTestKit
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: au_core_test_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Beda
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-12-01 00:00:00.000000000 Z
12
+ date: 2025-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inferno_core
@@ -2482,6 +2482,7 @@ files:
2482
2482
  - lib/au_core_test_kit/search_test_properties.rb
2483
2483
  - lib/au_core_test_kit/special_identifier_search_test.rb
2484
2484
  - lib/au_core_test_kit/validation_test.rb
2485
+ - lib/au_core_test_kit/validator_helpers.rb
2485
2486
  - lib/au_core_test_kit/version.rb
2486
2487
  homepage: https://github.com/hl7au/au-fhir-core-inferno
2487
2488
  licenses: