Skip to main content

Module hl7v2

Module hl7v2 

Source
Expand description

Bridge HL7 v2 messages to and from the FHIR server.

The receiver is an MLLP listener: it accepts framed HL7 v2 messages, converts each one to FHIR with a Jinja template, submits the result, and answers the sender with an HL7 ACK.

§What “production ready” means here

An interface engine is not a browser. It keeps one socket open for hours, sends thousands of messages down it, retries anything it does not see an ACK for, and treats a missing or malformed acknowledgement as a failure to deliver. The properties that follow from that:

  • Every message is answered. A parse failure, a template failure and a write failure each produce an ACK with the appropriate MSA-1, never a dropped connection. A sender that gets silence retries forever.
  • AR vs AE is chosen deliberately. AR (reject) means the sender should not retry – the message itself is wrong. AE (error) means it should – we could not store a message that may well be fine. Getting this backwards either loses data or produces an infinite retry loop.
  • One message cannot take down the listener. Each connection is its own task and each message its own error scope.
  • Every wait is bounded. A half-open socket, a sender that stops mid-frame, or a frame that never terminates are all survivable.
  • Shutdown drains. On SIGINT/SIGTERM the listener stops accepting and lets in-flight messages finish, so a message is not acknowledged and then lost, or lost without being acknowledged.

Re-exports§

use crate::cli::state::CliState; 🔒
use clap::Subcommand; 🔒
use haste_fhir_client::FHIRClient; 🔒
use haste_fhir_converter::Input; 🔒
use haste_fhir_model::r4::generated::resources::Resource; 🔒
use haste_fhir_model::r4::generated::terminology::BundleType; 🔒
use haste_fhir_model::r4::generated::terminology::IssueType; 🔒
use haste_fhir_operation_error::OperationOutcomeError; 🔒
use haste_hl7v2::ack::AckCode; 🔒
use haste_hl7v2::ack::InboundHeader; 🔒
use haste_hl7v2::ack::build_ack; 🔒
use haste_hl7v2::mllp_async::FrameEnd; 🔒
use haste_hl7v2::mllp_async::encode_frame; 🔒
use haste_hl7v2::mllp_async::read_frame; 🔒
use std::collections::HashMap; 🔒
use std::net::SocketAddr; 🔒
use std::sync::Arc; 🔒
use std::time::Duration; 🔒
use tokio::io::AsyncWriteExt; 🔒
use tokio::net::TcpListener; 🔒
use tokio::net::TcpStream; 🔒
use tokio::sync::Mutex; 🔒
use tokio::sync::Semaphore; 🔒

Structs§

MessageOutcome 🔒
What handling one message produced.
ReceiverConfig 🔒
Settings a connection task needs, resolved once at startup.

Enums§

HL7v2Commands 🔒
Bridge HL7v2 messages to and from the FHIR server.

Functions§

ack_was_accepted 🔒
Whether MSA-1 is AA (or CA, its commit-level equivalent).
handle_connection 🔒
Serves one sender until it disconnects, idles out, or breaks framing.
handle_message 🔒
Converts one message and submits it.
normalize_segment_separators 🔒
Rewrites bare newlines to carriage returns, leaving \r\n intact.
run 🔒
Runs the hl7v2 command group.
send_message 🔒
Sends one message and waits for its acknowledgement.
serve 🔒
Accepts connections until shutdown is signalled.
shutdown_signal 🔒
Resolves when the process is asked to stop.
submit 🔒
Writes the converted resource to the server.
timestamp 🔒
MSH-7 format: YYYYMMDDHHMMSS.