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

HANS-298: HL7v2 Improvements #6

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

mkpsc
Copy link
Collaborator

@mkpsc mkpsc commented Apr 14, 2023

No description provided.

Copy link

@regularfry regularfry left a comment

Choose a reason for hiding this comment

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

Three main things:

  1. We need to document how to run the tests locally.
  2. Timezones will bite us on the ankle if we let them. I've had far too many experiences where tests pass for a team in one country but fail for those in another to let there be ambiguity there.
  3. Getting the NHS number out of the HL7 message feels really fragile to me.

Wider point: it feels like we want an abstraction between hl7.parse and the HL7MessageController. I'd much rather the controller was calling self.hl7_message.family_name() than self._extract_field("PID", 0, 5, 0, 0). Feels like having the knowledge about how to pull the hl7 message apart separated from translating it into FHIR will make things easier to test and understand.

):
"""https://hl7-definition.caristix.com/v2/HL7v2.8/Segments/MSH"""

timestamp = datetime.now().strftime("%Y%m%d%H%M%S")

Choose a reason for hiding this comment

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

I don't think this format is right.. We're not specifying a timezone, which according to the spec means it defaults to being interpreted by anything that speaks HL7v2 as the local timezone. That means if we pass the output of this method to to_fhir_datetime below, which formats everything as UTC, we're actually an hour wrong for half the year. If we specify +0000 on the tail of the format string I think that removes any potential ambiguity.

+ ":"
+ hl7_DTM[12:14]
+ "Z"
return datetime.strptime(hl7_datetime, "%Y%m%d%H%M%S").strftime(

Choose a reason for hiding this comment

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

See above. I'm pretty sure we do need to care about the timezone here.

name
for name in (
self._extract_field("PID", 0, 5, 0, 1),
self._extract_field("PID", 0, 5, 0, 2),

Choose a reason for hiding this comment

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

Possibly stupid question, but do we know we're only getting two given names?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah that's a good spot - we need to space separate the result of _extract_field("PID", 0, 5, 0, 2) (if it exists)

These could be space separated according to the spec on Caristix

raise MissingNHSNumberError

try:
return next(

Choose a reason for hiding this comment

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

This feels fragile. We're identifying whether NHSNMBR appears anywhere in the pid_segment then scanning for any 10-digit sequence that might be anywhere else in the pid_segment - there's no reason for the two to be coming from the same place. In our example below if the SIMULATOR MRN value happened to pass the NHS number checksum calculation, that's what we'd get returned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep this is definitely not what we want - @michal-kras can you look at the current get_nhs_number() method and extract the logic from there?

It's in the current version of the code on the repo

@henrywrightPSC
Copy link
Collaborator

Some additional functionality that needs fixing from current version to do with which fields to complain about when missing might be worth dealing with now too (as appropriate) and adding in regression tests:

@mkpsc
Copy link
Collaborator Author

mkpsc commented Apr 18, 2023

Wider point: it feels like we want an abstraction between hl7.parse and the HL7MessageController. I'd much rather the controller was calling self.hl7_message.family_name() than self._extract_field("PID", 0, 5, 0, 0). Feels like having the knowledge about how to pull the hl7 message apart separated from translating it into FHIR will make things easier to test and understand.

@regularfry

I think this is really good idea, I am jumping right on it.

@mkpsc mkpsc marked this pull request as draft April 25, 2023 16:18
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.

3 participants