Skip to content

Comments

Adding empty? Predicate to HL7 API#83

Open
Chase-Callahan wants to merge 1 commit intoHCA-Healthcare:mainfrom
Chase-Callahan:cc/hl7_empty
Open

Adding empty? Predicate to HL7 API#83
Chase-Callahan wants to merge 1 commit intoHCA-Healthcare:mainfrom
Chase-Callahan:cc/hl7_empty

Conversation

@Chase-Callahan
Copy link

@Chase-Callahan Chase-Callahan commented Oct 3, 2025

Resolves #76

There are often times when consumers need to know whether the path they are selecting from the HL7 contains data. This concept of the data returned being "empty" is currently undefinded in the HL7 library and is left up to interpretation of the users.

This provides an implementaiton for determining if a given path is empty of data or not.

Testing Instructions

  1. Start application iex -S mix
  2. Create an HL7 message for testing:
import HL7

hl7 = HL7.Examples.wikipedia_sample_hl7() |> new!()
  1. Check if a populated field returns false:
empty?(hl7, ~p"MSH-4")
  1. Check if a non-existant field returns true:
empty?(hl7, ~p"PID-999")
  1. Check if a field with an empty string as a value returns true:
hl7 |> put(~p"PID-20", "") |> empty?(~p"PID-20")
  1. Check if a non-existant segment returns true:
empty?(hl7, ~p"ZZZ")
  1. Check if an existant segment returns false:
empty?(hl7, ~p"MSH")
  1. Check if returning empty repetitions returns true
empty?(hl7, ~p"OBX[*]-999[*]")
  1. Check any other condition you can think of. Also review the unit tests and ensure enough conditions are tested

@Chase-Callahan Chase-Callahan marked this pull request as ready for review October 3, 2025 18:44
@Chase-Callahan
Copy link
Author

Hey @DarkMarmot, was wondering if you might be able to take a look at this if you get a chance?


## Examples

iex> hl7 = HL7.Examples.wikipedia_sample_hl7() |> new!()
Copy link
Contributor

@DarkMarmot DarkMarmot Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you not have to import HL7 here for the sigil? Otherwise, looks good!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if you change the doctest macro to doctest HL7, import: true! Matt showed me that one the other day :).

If you think it makes the example more difficult to follow, then I am happy to add it back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chase-Callahan oh that's a great trick! I wonder if we should show the import for the first example in a series (so people realize it was needed0, and then drop it for the rest since we could with that macro?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point @DarkMarmot, perhaps it is better to stick with convention in this module. I have updated examples to use import!

There are often times when consumers need to know whether the path
they are selecting from the HL7 contains data. This concept of the
data returned being "empty" is currently undefinded in the HL7
library and is left up to interpretation of the users.

This provides an implementaiton for determining if a given path
is empty of data or not.
@Chase-Callahan
Copy link
Author

@DarkMarmot, we have found that having this same function availible but as a 1 arity function that takes a value in directly is also useful. I opened a PR to this PR if you like the idea and want to merge it. If not, happy to carryout a discussion there. Didn't want to hold up this PR though :)

Chase-Callahan#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Predicate for Checking Empty/Populated fields.

2 participants