inferno_core 0.4.18 → 0.4.19
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 +4 -4
 - data/lib/inferno/apps/cli/main.rb +1 -1
 - data/lib/inferno/config/boot/suites.rb +8 -0
 - data/lib/inferno/dsl/fhir_validation.rb +52 -11
 - data/lib/inferno/exceptions.rb +10 -0
 - data/lib/inferno/public/bundle.js +15 -15
 - data/lib/inferno/version.rb +1 -1
 - metadata +6 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a9b06c0f0ce1702d3ba9662e4762e3174eb22527a19a3eb35a5ec0e01dbf57d3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8c019f778c84c0926ef1705e256e0d3b27fd39a2c6af4f32bd8c4d1ad731ff84
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 39690b392f9e9997081cc5d58ee93c249a15be3eaeecca3927619f4d116e00cd85cdecc8a91693385420bb7b7bc07398b05b636d9be94713b23ad52c99bc9161
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f2970277134ae396003da04b2ba09c19cd3dc02f70e513cbdbeaf7a7e014561cbf742a95fc8ed40cec034a23723ad54ed823637989628dd0661fc467b49db11a
         
     | 
| 
         @@ -25,5 +25,13 @@ Inferno::Application.boot(:suites) do 
     | 
|
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                ObjectSpace.each_object(TracePoint, &:disable)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                Inferno::Entities::TestSuite.descendants.each do |descendant|
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # When ID not assigned in custom test suites, Runnable.id will return default ID
         
     | 
| 
      
 31 
     | 
    
         
            +
                  # equal to the custom test suite's parent class name
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if descendant.id.blank? || descendant.id == 'Inferno::Entities::TestSuite'
         
     | 
| 
      
 33 
     | 
    
         
            +
                    raise StandardError, "Error initializing test suite #{descendant.name}: test suite ID is not set"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
       28 
36 
     | 
    
         
             
              end
         
     | 
| 
       29 
37 
     | 
    
         
             
            end
         
     | 
| 
         @@ -116,17 +116,26 @@ module Inferno 
     | 
|
| 
       116 
116 
     | 
    
         
             
                    def resource_is_valid?(resource, profile_url, runnable)
         
     | 
| 
       117 
117 
     | 
    
         
             
                      profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url
         
     | 
| 
       118 
118 
     | 
    
         | 
| 
       119 
     | 
    
         
            -
                      outcome =  
     | 
| 
      
 119 
     | 
    
         
            +
                      outcome, http_status = validate(resource, profile_url, runnable)
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                      message_hashes = outcome 
     | 
| 
      
 121 
     | 
    
         
            +
                      message_hashes = message_hashes_from_outcome(outcome, resource, profile_url)
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                      message_hashes 
     | 
| 
      
 123 
     | 
    
         
            +
                      message_hashes
         
     | 
| 
      
 124 
     | 
    
         
            +
                        .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) }
         
     | 
| 
       124 
125 
     | 
    
         | 
| 
       125 
     | 
    
         
            -
                       
     | 
| 
      
 126 
     | 
    
         
            +
                      unless http_status == 200
         
     | 
| 
      
 127 
     | 
    
         
            +
                        raise Inferno::Exceptions::ErrorInValidatorException,
         
     | 
| 
      
 128 
     | 
    
         
            +
                              'Error occurred in the validator. Review Messages tab or validator service logs for more information.'
         
     | 
| 
      
 129 
     | 
    
         
            +
                      end
         
     | 
| 
       126 
130 
     | 
    
         | 
| 
       127 
131 
     | 
    
         
             
                      message_hashes
         
     | 
| 
       128 
     | 
    
         
            -
                        .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) }
         
     | 
| 
       129 
132 
     | 
    
         
             
                        .none? { |message_hash| message_hash[:type] == 'error' }
         
     | 
| 
      
 133 
     | 
    
         
            +
                    rescue Inferno::Exceptions::ErrorInValidatorException
         
     | 
| 
      
 134 
     | 
    
         
            +
                      raise
         
     | 
| 
      
 135 
     | 
    
         
            +
                    rescue StandardError => e
         
     | 
| 
      
 136 
     | 
    
         
            +
                      runnable.add_message('error', e.message)
         
     | 
| 
      
 137 
     | 
    
         
            +
                      raise Inferno::Exceptions::ErrorInValidatorException,
         
     | 
| 
      
 138 
     | 
    
         
            +
                            'Error occurred in the validator. Review Messages tab or validator service logs for more information.'
         
     | 
| 
       130 
139 
     | 
    
         
             
                    end
         
     | 
| 
       131 
140 
     | 
    
         | 
| 
       132 
141 
     | 
    
         
             
                    # @private
         
     | 
| 
         @@ -134,6 +143,17 @@ module Inferno 
     | 
|
| 
       134 
143 
     | 
    
         
             
                      message_hashes.reject! { |message| exclude_message.call(Entities::Message.new(message)) } if exclude_message
         
     | 
| 
       135 
144 
     | 
    
         
             
                    end
         
     | 
| 
       136 
145 
     | 
    
         | 
| 
      
 146 
     | 
    
         
            +
                    # @private
         
     | 
| 
      
 147 
     | 
    
         
            +
                    def message_hashes_from_outcome(outcome, resource, profile_url)
         
     | 
| 
      
 148 
     | 
    
         
            +
                      message_hashes = outcome.issue&.map { |issue| message_hash_from_issue(issue, resource) } || []
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                      message_hashes.concat(additional_validation_messages(resource, profile_url))
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                      filter_messages(message_hashes)
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                      message_hashes
         
     | 
| 
      
 155 
     | 
    
         
            +
                    end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
       137 
157 
     | 
    
         
             
                    # @private
         
     | 
| 
       138 
158 
     | 
    
         
             
                    def message_hash_from_issue(issue, resource)
         
     | 
| 
       139 
159 
     | 
    
         
             
                      {
         
     | 
| 
         @@ -171,12 +191,33 @@ module Inferno 
     | 
|
| 
       171 
191 
     | 
    
         
             
                    #
         
     | 
| 
       172 
192 
     | 
    
         
             
                    # @param resource [FHIR::Model]
         
     | 
| 
       173 
193 
     | 
    
         
             
                    # @param profile_url [String]
         
     | 
| 
       174 
     | 
    
         
            -
                    # @ 
     | 
| 
       175 
     | 
    
         
            -
                     
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
                         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
      
 194 
     | 
    
         
            +
                    # @param runnable [Inferno::Entities::Test]
         
     | 
| 
      
 195 
     | 
    
         
            +
                    # @return [[Array(FHIR::OperationOutcome, Number)] the validation response and HTTP status code
         
     | 
| 
      
 196 
     | 
    
         
            +
                    def validate(resource, profile_url, runnable)
         
     | 
| 
      
 197 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 198 
     | 
    
         
            +
                        response = Faraday.new(
         
     | 
| 
      
 199 
     | 
    
         
            +
                          url,
         
     | 
| 
      
 200 
     | 
    
         
            +
                          params: { profile: profile_url }
         
     | 
| 
      
 201 
     | 
    
         
            +
                        ).post('validate', resource.source_contents)
         
     | 
| 
      
 202 
     | 
    
         
            +
                      rescue StandardError => e
         
     | 
| 
      
 203 
     | 
    
         
            +
                        runnable.add_message('error', e.message)
         
     | 
| 
      
 204 
     | 
    
         
            +
                        raise Inferno::Exceptions::ErrorInValidatorException, "Unable to connect to validator at #{url}."
         
     | 
| 
      
 205 
     | 
    
         
            +
                      end
         
     | 
| 
      
 206 
     | 
    
         
            +
                      outcome = operation_outcome_from_validator_response(response.body, runnable)
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
                      [outcome, response.status]
         
     | 
| 
      
 209 
     | 
    
         
            +
                    end
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
                    # @private
         
     | 
| 
      
 212 
     | 
    
         
            +
                    def operation_outcome_from_validator_response(response, runnable)
         
     | 
| 
      
 213 
     | 
    
         
            +
                      if response.start_with? '{'
         
     | 
| 
      
 214 
     | 
    
         
            +
                        FHIR::OperationOutcome.new(JSON.parse(response))
         
     | 
| 
      
 215 
     | 
    
         
            +
                      else
         
     | 
| 
      
 216 
     | 
    
         
            +
                        runnable.add_message('error', "Validator Response: #{response}")
         
     | 
| 
      
 217 
     | 
    
         
            +
                        raise Inferno::Exceptions::ErrorInValidatorException,
         
     | 
| 
      
 218 
     | 
    
         
            +
                              'Validator response was an unexpected format. '\
         
     | 
| 
      
 219 
     | 
    
         
            +
                              'Review Messages tab or validator service logs for more information.'
         
     | 
| 
      
 220 
     | 
    
         
            +
                      end
         
     | 
| 
       180 
221 
     | 
    
         
             
                    end
         
     | 
| 
       181 
222 
     | 
    
         
             
                  end
         
     | 
| 
       182 
223 
     | 
    
         | 
    
        data/lib/inferno/exceptions.rb
    CHANGED
    
    | 
         @@ -39,6 +39,16 @@ module Inferno 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  end
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
      
 42 
     | 
    
         
            +
                class ErrorInValidatorException < TestResultException
         
     | 
| 
      
 43 
     | 
    
         
            +
                  # This extends TestResultException instead of RuntimeError
         
     | 
| 
      
 44 
     | 
    
         
            +
                  # to bypass printing the stack trace in the UI.
         
     | 
| 
      
 45 
     | 
    
         
            +
                  # (The stack trace of this exception may not be useful,
         
     | 
| 
      
 46 
     | 
    
         
            +
                  # instead the message should point to where in the validator an error occurred)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  def result
         
     | 
| 
      
 48 
     | 
    
         
            +
                    'error'
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       42 
52 
     | 
    
         
             
                class ParentNotLoadedException < RuntimeError
         
     | 
| 
       43 
53 
     | 
    
         
             
                  def initialize(klass, id)
         
     | 
| 
       44 
54 
     | 
    
         
             
                    super("No #{klass.name.demodulize} found with id '#{id}'")
         
     |