Skip to content

Commit

Permalink
Bump HL7 to 0.7 (#78)
Browse files Browse the repository at this point in the history
- Updated MLLP.Ack to import new sigil for use with get_part/2
- Updated tests to reflect updates between 0.6.2 and 0.7.0
  • Loading branch information
starbelly authored Oct 13, 2023
1 parent f87b2eb commit d7d9069
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
4 changes: 3 additions & 1 deletion lib/mllp/ack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule MLLP.Ack do
# # AR - Application Reject
# # AE – Application Error

import HL7.Query, only: :macros

defstruct acknowledgement_code: nil,
text_message: "",
hl7_ack_message: nil
Expand Down Expand Up @@ -74,7 +76,7 @@ defmodule MLLP.Ack do
|> List.replace_at(6, sending_facility)
|> List.replace_at(3, receiving_application)
|> List.replace_at(5, sending_application)
|> List.replace_at(9, "ACK^#{HL7.Query.get_part(hl7, "MSH-9.2")}^ACK")
|> List.replace_at(9, "ACK^#{HL7.Query.get_part(hl7, ~g{MSH-9.2})}^ACK")

msa = ["MSA", code, message_control_id, text_message]

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule MLLP.MixProject do
[
{:telemetry, "~> 1.0"},
{:ranch, "~> 1.8.0"},
{:elixir_hl7, "~> 0.6.0"},
{:elixir_hl7, "~> 0.7.0"},
{:backoff, "~> 1.1.6"},
{:ex_doc, "~> 0.24.2", only: :dev, runtime: false},
{:dialyxir, "~> 1.1.0", only: [:dev, :test], runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.17", "6f3c7e94170377ba45241d394389e800fb15adc5de51d0a3cd52ae766aafd63f", [:mix], [], "hexpm", "f93ac89c9feca61c165b264b5837bf82344d13bebc634cd575cb711e2e342023"},
"elixir_hl7": {:hex, :elixir_hl7, "0.6.2", "b066608f2e63258da596d99794745ab42cb4e62ac9b363014d1611b49146da07", [:mix], [], "hexpm", "43db06b2f9333581b02a03ada7a22c3406088cd9b4564a60b2ab63e2191e5ee9"},
"elixir_hl7": {:hex, :elixir_hl7, "0.7.0", "10ec8cc7ace7da2ab7c977d86d8b5e21a116cdd5c740224b01fa2c72eec8f0bf", [:mix], [], "hexpm", "98ecfeedfef5adc68744c7c8ef861989454b152f4439dfd55fe93960e52533a7"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
"excoveralls": {:hex, :excoveralls, "0.14.6", "610e921e25b180a8538229ef547957f7e04bd3d3e9a55c7c5b7d24354abbba70", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "0eceddaa9785cfcefbf3cd37812705f9d8ad34a758e513bb975b081dce4eb11e"},
Expand Down
44 changes: 23 additions & 21 deletions test/ack_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,87 @@ defmodule AckTest do
|> HL7.Message.new()

ack = Ack.get_ack_for_message(bad_message, "AA")
assert "AR" == ack |> get_part("MSA-1")
assert "AR" == ack |> get_part(~g{MSA-1})
assert "ACK" == ack.header.message_type
assert ack |> get_part("MSA-3") =~ "missing_header_or_encoding"
assert ack |> get_part(~g{MSA-3}) =~ "missing_header"
end

test "for an invalid HL7 string" do
bad_message = "Bad Message"

ack = Ack.get_ack_for_message(bad_message, "AA")
assert "AR" == ack |> get_part("MSA-1")
assert "AR" == ack |> get_part(~g{MSA-1})
assert "ACK" == ack.header.message_type
assert ack |> get_part("MSA-3") =~ "missing_header_or_encoding"

assert ack |> get_part(~g{MSA-3}) ==
"Message was not parsable as HL7. Reason: missing_header"
end

test "with code `application_accepted`" do
hl7_ack = get_ack_for_wikipedia_example(:application_accept)
assert "AA" == hl7_ack |> get_part("MSA-1")
assert "AA" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `AA`" do
hl7_ack = get_ack_for_wikipedia_example("AA")
assert "AA" == hl7_ack |> get_part("MSA-1")
assert "AA" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `CA`" do
hl7_ack = get_ack_for_wikipedia_example("CA")
assert "CA" == hl7_ack |> get_part("MSA-1")
assert "CA" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `application_reject`" do
hl7_ack = get_ack_for_wikipedia_example(:application_reject)
assert "AR" == hl7_ack |> get_part("MSA-1")
assert "AR" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `AR`" do
hl7_ack = get_ack_for_wikipedia_example("AR")
assert "AR" == hl7_ack |> get_part("MSA-1")
assert "AR" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `CR`" do
hl7_ack = get_ack_for_wikipedia_example("CR")
assert "CR" == hl7_ack |> get_part("MSA-1")
assert "CR" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `application_error`" do
hl7_ack = get_ack_for_wikipedia_example(:application_error)
assert "AE" == hl7_ack |> get_part("MSA-1")
assert "AE" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `AE`" do
hl7_ack = get_ack_for_wikipedia_example("AE")
assert "AE" == hl7_ack |> get_part("MSA-1")
assert "AE" == hl7_ack |> get_part(~g{MSA-1})
end

test "with code `CE`" do
hl7_ack = get_ack_for_wikipedia_example("CE")
assert "CE" == hl7_ack |> get_part("MSA-1")
assert "CE" == hl7_ack |> get_part(~g{MSA-1})
end

test "returns an ACK message with the proper message_type" do
hl7_ack = get_ack_for_wikipedia_example(:application_accept)
assert "ACK" == hl7_ack.header.message_type
assert "A01" == hl7_ack.header.trigger_event
assert "ACK" == HL7.Query.get_part(hl7_ack, "MSH-9.3")
assert "ACK" == HL7.Query.get_part(hl7_ack, ~g{MSH-9.3})
end

test "return an ACK message with a matching message_control_id" do
hl7_ack = get_ack_for_wikipedia_example(:application_accept)

assert "01052901" == hl7_ack |> new() |> get_part("MSA-2")
assert "01052901" == hl7_ack |> new() |> get_part(~g{MSA-2})
end

test "returns an ACK message with the sender and receiver fields properly reversed" do
hl7_ack = get_ack_for_wikipedia_example(:application_accept)

assert "MegaReg" == hl7_ack |> get_part("MSH-5")
assert "XYZHospC" == hl7_ack |> get_part("MSH-6")
assert "SuperOE" == hl7_ack |> get_part("MSH-3")
assert "XYZImgCtr" == hl7_ack |> get_part("MSH-4")
assert "MegaReg" == hl7_ack |> get_part(~g{MSH-5})
assert "XYZHospC" == hl7_ack |> get_part(~g{MSH-6})
assert "SuperOE" == hl7_ack |> get_part(~g{MSH-3})
assert "XYZImgCtr" == hl7_ack |> get_part(~g{MSH-4})
end
end

Expand Down Expand Up @@ -203,7 +205,7 @@ defmodule AckTest do

ack = ""

assert {:error, :invalid_message, "missing_header_or_encoding"} ==
assert {:error, :invalid_message, "missing_header"} ==
Ack.verify_ack_against_message(message, ack)
end

Expand All @@ -212,7 +214,7 @@ defmodule AckTest do

bad_ack = "Nothing like a valid ACK message"

assert {:error, :invalid_ack_message, "missing_header_or_encoding"} ==
assert {:error, :invalid_ack_message, "missing_header"} ==
Ack.verify_ack_against_message(message, bad_ack)
end
end
Expand Down

0 comments on commit d7d9069

Please sign in to comment.