Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-2015 GET requests added to fhir_operation #380

Merged
merged 22 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3acc04b
GET requests added to fhir_operation
360dgries Aug 4, 2023
43eac91
Updated function contract
360dgries Aug 4, 2023
82aed41
linting
360dgries Aug 4, 2023
a07f634
added tests for helper function
360dgries Aug 4, 2023
83d2ada
deferred affectsState detection to test author
360dgries Aug 29, 2023
354674c
linting
360dgries Aug 29, 2023
53276a3
package-lock from main
360dgries Aug 29, 2023
fc94781
adjusted body_to_path to take one argument
360dgries Aug 29, 2023
e7dfb4d
Merge branch 'main' into FI-2015-enable-get-request-fhir_operation
360dgries Aug 30, 2023
aa9d5e8
Repeated parameter support, contract updating, let changes in spec te…
360dgries Aug 31, 2023
c999f43
Linting and Cyclomatic complexity handling
360dgries Aug 31, 2023
5044914
Merge branch 'FI-2015-enable-get-request-fhir_operation' of https://g…
360dgries Aug 31, 2023
d4dc3c8
Reverted Package-lock.json to original state
360dgries Sep 11, 2023
ac8a754
bundle update
360dgries Oct 2, 2023
d77c0bf
reorganization of spec tests and changes to checking parameter for pr…
360dgries Oct 6, 2023
268a585
Merge branch 'main' into FI-2015-enable-get-request-fhir_operation
360dgries Oct 6, 2023
94600a2
Merge branch 'main' into FI-2015-enable-get-request-fhir_operation
360dgries Oct 6, 2023
4e7d126
conflict resolution
360dgries Oct 6, 2023
8ac86f9
Taking package and gemfile from Main Branch
360dgries Oct 9, 2023
ac83e98
Linting spec tests
360dgries Oct 9, 2023
25da3d6
added rspec test for unhandled REST methods
360dgries Oct 10, 2023
cd511f2
linting of rspec file
360dgries Oct 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 38 additions & 5 deletions lib/inferno/dsl/fhir_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,59 @@
@fhir_clients ||= {}
end

# Move parameters from body to the path for GET operations
360dgries marked this conversation as resolved.
Show resolved Hide resolved
#
# @param path [String]
# @param body [FHIR::Parameters] Must all be primitive if making GET request
# @private
def body_to_path(body)
query_hash = body.parameter.reduce({}) do |query, param|
360dgries marked this conversation as resolved.
Show resolved Hide resolved
valid = param.valid? && param.part.empty? && param.resource.nil? # Parameter is valid
param_val = param.to_hash.except('name') # should contain only one value if is a valid parameter
if valid && !param_val.empty? && FHIR.primitive?(datatype: param_val.keys[0][5..], value: param_val.values[0])
query.merge!({ param.name => param_val.values[0] })
query
else
# Handle the case of nonprimitive
Inferno::Application[:logger].error "Cannot use GET request with non-primitive datatype #{param.name}"
raise ArgumentError, "Cannot use GET request with non-primitive datatype #{param.name}"
end
end
query_hash.to_query
end

# Perform a FHIR operation
#
# @note This is a placeholder method until the FHIR::Client supports
# general operations
# general operations. Note that while both POST and GET methods are allowed,
# GET is only allowed when the operation does not affect the servers state.
# See https://build.fhir.org/operationdefinition-definitions.html#OperationDefinition.affectsState
#
# @param path [String]
# @param body [FHIR::Parameters]
# @param body [FHIR::Parameters] Must all be primitive if making GET request
# @param client [Symbol]
# @param name [Symbol] Name for this request to allow it to be used by
# other tests
# @param headers [Hash] custom headers for this operation
# @param search_method [Symbol] indicates which request type to use for the operation
360dgries marked this conversation as resolved.
Show resolved Hide resolved
# @return [Inferno::Entities::Request]
def fhir_operation(path, body: nil, client: :default, name: nil, headers: {})
def fhir_operation(path, body: nil, client: :default, name: nil, headers: {}, operation_method: :post)
store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
operation_headers = fhir_client(client).fhir_headers
operation_headers.merge!('Content-Type' => 'application/fhir+json') if body.present?
operation_headers.merge!(headers) if headers.present?

fhir_client(client).send(:post, path, body, operation_headers)
case operation_method
when :post
fhir_client(client).send(:post, path, body, operation_headers)
when :get
path = "#{path}?#{body_to_path(body)}" if body.present?
fhir_client(client).send(:get, path, operation_headers)
else
# Handle the case of non-supported operation_method
Inferno::Application[:logger].error "Cannot perform #{operation_method} requests, use GET or POST"
raise ArgumentError, "Cannot perform #{operation_method} requests, use GET or POST"

Check warning on line 114 in lib/inferno/dsl/fhir_client.rb

View check run for this annotation

Codecov / codecov/patch

lib/inferno/dsl/fhir_client.rb#L114

Added line #L114 was not covered by tests
end
end
end
end
Expand Down