Skip to content

Commit c34c82f

Browse files
committed
add some params/endpoints, include parameters in response struct
1 parent aabe724 commit c34c82f

File tree

7 files changed

+72
-7
lines changed

7 files changed

+72
-7
lines changed

.iex.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Supervisor.start_link(children, opts)
1414

1515
defmodule ReplHelpers do
1616
def search(term) do
17-
with {:ok, %{data: %{"results" => results}}} when length(results) > 0 <- Ribbonex.search_insurances(search: term) do
17+
with {:ok, %{data: %{"results" => results}}} when results != [] > 0 <- Ribbonex.search_insurances(search: term) do
1818
results
1919
|> Enum.sort_by(& &1["confidence"])
2020
|> Enum.reverse()

lib/insurances.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ defmodule Ribbonex.Insurances do
55
[Ribbon Docs](https://ribbon.readme.io/docs/insurances-reference-endpoint)
66
"""
77

8+
def get_insurance(uuid, params \\ []) when is_binary(uuid) do
9+
path = "/v1/custom/insurances/#{uuid}"
10+
Ribbonex.Client.authd_get(path, params: params)
11+
end
12+
813
@insurances_search_params [
14+
page: [type: :non_neg_integer],
915
search: [
1016
type: :string,
1117
doc: "Fuzzy search across all information within an insurance object."

lib/locations.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule Ribbonex.Locations do
2+
@location_search_params [
3+
page: [type: :non_neg_integer],
4+
name: [
5+
type: :string,
6+
doc: "Fuzzy search on name."
7+
],
8+
fields: [
9+
type: {:list, :string},
10+
doc: "Fields to include in response."
11+
]
12+
]
13+
14+
def search(params \\ []) do
15+
with {:ok, params} <- NimbleOptions.validate(Enum.into(params, []), @location_search_params) do
16+
path = "/v1/custom/locations"
17+
Ribbonex.Client.authd_get(path, params: params)
18+
end
19+
end
20+
end

lib/providers.ex

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ defmodule Ribbonex.Providers do
1919
"""
2020

2121
@provider_search_params [
22+
page: [type: :non_neg_integer],
23+
npi: [
24+
type: :string,
25+
doc: ""
26+
],
27+
name: [
28+
type: :string,
29+
doc: "String input of a full, first, last, or partial name."
30+
],
2231
address: [
2332
type: :string,
2433
doc: "String input of an address that will be interpreted and geocoded in real time."
@@ -33,13 +42,17 @@ defmodule Ribbonex.Providers do
3342
doc:
3443
"Comma separated list of desired specialty uuids. See all providers who specialize in the given specialties."
3544
],
45+
insurance_ids: [
46+
type: {:list, :string},
47+
doc: "List of desired insurance uuids. See all providers who accept a given insurance(s)."
48+
],
3649
fields: [
3750
type: {:list, :string},
38-
doc: "Fields to include"
51+
doc: "Fields to include in response."
3952
],
4053
_excl_fields: [
4154
type: {:list, :string},
42-
doc: "Fields to exclude"
55+
doc: "Fields to exclude in response."
4356
]
4457
]
4558

@@ -50,8 +63,8 @@ defmodule Ribbonex.Providers do
5063
end
5164
end
5265

53-
def get_provider(npi) when is_binary(npi) do
66+
def get_provider(npi, params \\ []) when is_binary(npi) do
5467
path = "/v1/custom/providers/" <> npi
55-
Ribbonex.Client.authd_get(path)
68+
Ribbonex.Client.authd_get(path, params: params)
5669
end
5770
end

lib/response.ex

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ defmodule Ribbonex.Response do
22
defstruct [
33
:status,
44
:http_response,
5+
:parameters,
56
:data,
7+
:end_of_list,
68
:request,
79
:additional_properties
810
]
@@ -21,8 +23,14 @@ defmodule Ribbonex.Response do
2123
def parse({:ok, http_response}, additional_properties) do
2224
body = decode(http_response)
2325
data = extract_data(body)
26+
parameters = extract_parameters(body)
2427

25-
{:ok, build_response(http_response, data, additional_properties)}
28+
response =
29+
build_response(http_response, data, additional_properties)
30+
|> Map.put(:parameters, parameters)
31+
|> Map.put(:end_of_list, end_of_list?(parameters))
32+
33+
{:ok, response}
2634
end
2735

2836
defp decode(%Finch.Response{body: ""}), do: nil
@@ -31,6 +39,9 @@ defmodule Ribbonex.Response do
3139
defp extract_data(%{"data" => data}), do: data
3240
defp extract_data(data), do: data
3341

42+
defp extract_parameters(%{"parameters" => parameters}), do: parameters
43+
defp extract_parameters(_), do: nil
44+
3445
defp build_response(http_response, data, additional_properties) do
3546
_headers = Enum.into(http_response.headers, %{})
3647
additional_properties = Enum.into(additional_properties, %{})
@@ -48,4 +59,15 @@ defmodule Ribbonex.Response do
4859
defp json_decode!(nil), do: nil
4960
defp json_decode!(%{} = body), do: body
5061
defp json_decode!(body) when is_binary(body), do: Jason.decode!(body)
62+
63+
defp end_of_list?(nil), do: true
64+
defp end_of_list?(%{"total_count" => 0}), do: true
65+
66+
defp end_of_list?(parameters) when is_map(parameters) do
67+
page = Map.get(parameters, "page", 1)
68+
page_size = Map.get(parameters, "page_size", 25)
69+
total_count = Map.get(parameters, "total_count", 0)
70+
71+
page * page_size >= total_count
72+
end
5173
end

lib/ribbonex.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ defmodule Ribbonex do
33
to: Ribbonex.Providers,
44
as: :search
55

6-
defdelegate get_provider(npi),
6+
defdelegate get_provider(npi, params \\ []),
77
to: Ribbonex.Providers
88

99
defdelegate search_specialties(params \\ []),
1010
to: Ribbonex.Specialties,
1111
as: :search
1212

13+
defdelegate get_insurance(uuid, params \\ []),
14+
to: Ribbonex.Insurances
15+
1316
defdelegate search_insurances(params \\ []),
1417
to: Ribbonex.Insurances,
1518
as: :search

lib/specialties.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule Ribbonex.Specialties do
1616
"""
1717

1818
@specialties_search_params [
19+
page: [type: :non_neg_integer],
1920
search: [
2021
type: :string,
2122
doc: "String input for fuzzy matching specialties"

0 commit comments

Comments
 (0)