Skip to content

Commit

Permalink
Merge branch 'main' into FI-2040-json-parse-error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyssaWang authored Aug 2, 2023
2 parents 0e31884 + 990a1ab commit 3c34375
Show file tree
Hide file tree
Showing 3 changed files with 441 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/writing-tests/making-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ The following methods are currently available for making FHIR requests:
- `fhir_get_capability_statement`
- `fhir_operation`
- `fhir_read`
- `fhir_vread`
- `fhir_update`
- `fhir_patch`
- `fhir_search`
- `fhir_history`
- `fhir_transaction`
For more details on these methods, see the [FHIR Client API
documentation](/inferno-core/docs/Inferno/DSL/FHIRClient.html). If you need to
Expand Down
82 changes: 79 additions & 3 deletions lib/inferno/dsl/fhir_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,78 @@ def fhir_read(resource_type, id, client: :default, name: nil)
end
end

# Perform a FHIR vread interaction.
#
# @param resource_type [String, Symbol, Class]
# @param id [String]
# @param version_id [String]
# @param client [Symbol]
# @param name [Symbol] Name for this request to allow it to be used by
# other tests
# @return [Inferno::Entities::Request]
def fhir_vread(resource_type, id, version_id, client: :default, name: nil)
store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
fhir_client(client).vread(fhir_class_from_resource_type(resource_type), id, version_id)
end
end
end

# Perform a FHIR update interaction.
#
# @param resource [FHIR::Model]
# @param id [String]
# @param client [Symbol]
# @param name [Symbol] Name for this request to allow it to be used by
# other tests
# @return [Inferno::Entities::Request]
def fhir_update(resource, id, client: :default, name: nil)
store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
fhir_client(client).update(resource, id)
end
end
end

# Perform a FHIR patch interaction.
#
# @param resource_type [String, Symbol, Class]
# @param id [String]
# @param patchset [Array]
# @param client [Symbol]
# @param name [Symbol] Name for this request to allow it to be used by
# other tests
# @return [Inferno::Entities::Request]
def fhir_patch(resource_type, id, patchset, client: :default, name: nil)
store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
fhir_client(client).partial_update(fhir_class_from_resource_type(resource_type), id, patchset)
end
end
end

# Perform a FHIR history interaction.
#
# @param resource_type [String, Symbol, Class]
# @param id [String]
# @param client [Symbol]
# @param name [Symbol] Name for this request to allow it to be used by
# other tests
# @return [Inferno::Entities::Request]
def fhir_history(resource_type = nil, id = nil, client: :default, name: nil)
store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
if id
fhir_client(client).resource_instance_history(fhir_class_from_resource_type(resource_type), id)
elsif resource_type
fhir_client(client).resource_history(fhir_class_from_resource_type(resource_type))
else
fhir_client(client).all_history
end
end
end
end

# Perform a FHIR search interaction.
#
# @param resource_type [String, Symbol, Class]
Expand All @@ -139,7 +211,7 @@ def fhir_read(resource_type, id, client: :default, name: nil)
# other tests
# @param search_method [Symbol] Use `:post` to search via POST
# @return [Inferno::Entities::Request]
def fhir_search(resource_type, client: :default, params: {}, name: nil, search_method: :get)
def fhir_search(resource_type = nil, client: :default, params: {}, name: nil, search_method: :get)
search =
if search_method == :post
{ body: params }
Expand All @@ -149,8 +221,12 @@ def fhir_search(resource_type, client: :default, params: {}, name: nil, search_m

store_request_and_refresh_token(fhir_client(client), name) do
tcp_exception_handler do
fhir_client(client)
.search(fhir_class_from_resource_type(resource_type), { search: })
if resource_type
fhir_client(client)
.search(fhir_class_from_resource_type(resource_type), { search: })
else
fhir_client(client).search_all({ search: })
end
end
end
end
Expand Down
Loading

0 comments on commit 3c34375

Please sign in to comment.