Class: Inferno::DSL::FhirpathEvaluation::Evaluator
- Inherits:
-
Object
- Object
- Inferno::DSL::FhirpathEvaluation::Evaluator
- Defined in:
- lib/inferno/dsl/fhirpath_evaluation.rb
Instance Method Summary collapse
-
#call_fhirpath_service(fhir_resource, fhirpath_expression) ⇒ Object
-
#evaluate_fhirpath(fhir_resource, fhirpath_expression, runnable) ⇒ Array<Hash>
Evaluates a fhirpath expression for a given FHIR resource.
-
#url(fhirpath_url = nil) ⇒ String
Set/Get the url of the fhirpath service.
Instance Method Details
#call_fhirpath_service(fhir_resource, fhirpath_expression) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/inferno/dsl/fhirpath_evaluation.rb', line 96 def call_fhirpath_service(fhir_resource, fhirpath_expression) Faraday.new( url, request: { timeout: 600 } ).post( "evaluate?path=#{fhirpath_expression}", fhir_resource.to_json, content_type: 'application/json' ) end |
#evaluate_fhirpath(fhir_resource, fhirpath_expression, runnable) ⇒ Array<Hash>
Note:
the element
field can either be a primitive value (string, boolean, etc.) or a FHIR::Model.
Evaluates a fhirpath expression for a given FHIR resource
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/inferno/dsl/fhirpath_evaluation.rb', line 63 def evaluate_fhirpath(fhir_resource, fhirpath_expression, runnable) begin response = call_fhirpath_service(fhir_resource, fhirpath_expression) rescue StandardError => e # This could be a complete failure to connect (fhirpath service isn't running) # or a timeout (fhirpath service took too long to respond). runnable.('error', e.) raise Inferno::Exceptions::ErrorInFhirpathException, "Unable to connect to FHIRPath service at #{url}." end sanitized_body = remove_invalid_characters(response.body) return transform_fhirpath_results(JSON.parse(sanitized_body)) if response.status.to_s.start_with? '2' runnable.('error', "FHIRPath service Response: HTTP #{response.status}\n#{sanitized_body}") raise Inferno::Exceptions::ErrorInFhirpathException, 'FHIRPath service call failed. Review Messages tab for more information.' rescue JSON::ParserError runnable.('error', "Invalid FHIRPath service response format:\n#{sanitized_body}") raise Inferno::Exceptions::ErrorInFhirpathException, 'Error occurred in the FHIRPath service. Review Messages tab for more information.' end |
#url(fhirpath_url = nil) ⇒ String
Set/Get the url of the fhirpath service
50 51 52 |
# File 'lib/inferno/dsl/fhirpath_evaluation.rb', line 50 def url(fhirpath_url = nil) @url ||= fhirpath_url || default_fhirpath_url end |