IntegrationsHL7 (Old Flow)Outbound

Outbound HL7 Overview

Overview of outbound HL7 message generation APIs and message-type documentation.

👤 Development Team📅 Updated: May 22, 2026📁 Integrations🏷️ HL7🏷️ Outbound🏷️ Overview🏷️ ADT🏷️ ORM🏷️ ORU🏷️ OUL🏷️ DFT

HL7 Outbound Overview

Outbound HL7 integrations generate billing, order, patient, specimen, and result messages from LiveHealth/Crelio data. The detailed configuration for each message family now lives in its own page.

Scope

This section documents the legacy outbound HL7 APIs implemented in livehealthapp/labs/views.py. The APIs are used by SFTP/webhook-style integrations where LiveHealth prepares an HL7 message and optionally pushes it to a downstream listener such as Mirth over TCP.

The documentation focuses on two high-use endpoints:

EndpointFunctionPurpose
/integration/sftp/hl7/2_3/send_hl7_data/sftp_HL7_payload_generation_functionReport-wise HL7 generation for DFT, ORM, OUL, ADT, and ORUR01.
/integration/sftp/hl7/2_3/send_billwise_hl7_data/sftp_billwise_HL7_payload_generation_functionBill-wise ORUR01 generation and bill-wise DFT forwarding.

These endpoints are legacy in naming, but still contain the active compatibility behavior for multiple vendor integrations. They combine HL7 generation, vendor-specific mapping, socket delivery, activity logging, and response rendering in one flow.

Mental Model

A request to these APIs is not a raw HL7 payload. It is a JSON request that identifies a report or bill, includes the serialized report/result data, and supplies integrationDetails flags. The API then reloads canonical database records, builds the HL7 segments, normalizes the message, and either returns it or sends it to the configured TCP destination.

Data Sources Used During Generation

The API reloads most business context from the database even when similar values are present in the request. The request is primarily used to choose the flow, supply result arrays/base64 payloads, and override integration behavior.

Data areaSource used by the APIUsed for
Report identitylabReportId, labReportDetails, or testDetailsResolving the first labReportRelation record for report-wise generation.
Bill identitybill_idLoading all synced, non-dismissed reports for bill-wise ORU and creating bill-wise DFT forwarding payloads.
Patient demographicslabReportRelation.userDetailsId and selected request fallbacksPID, contact, address, DOB, gender, race, ethnicity, national id, passport, patient ids.
Bill/order datalabReportRelation.billId, billingInfo, BillingICDORC, OBR, FT1, DG1, visit id, order number, bill source, ICD and procedure mapping.
Organization/provider dataorgId, docId, branch recordsSending/ordering facility, provider identifiers, organization address/contact, branch override behavior.
ResultsreportFormatAndValues, reportDetails, report format metadataOBX, NTE, abnormal flags, reference ranges, result status, base64 report blocks.
InsurancePatientInsurance or UserBillInsuranceIN1 segments and insurance-required validation.
Attachments/TRFAttachment models and TRF endpointsED OBX blocks for PDF/image/base64 documents.

Runtime Contract

StepBehavior
Request parsingsftp_HL7_payload_generation_function accepts either a JSON object or a one-item JSON array and uses the first object when an array is received.
Message control idA 14-digit value is derived from uuid.uuid4().int; processingId defaults to P.
Timestamp formatHL7 timestamps are built as YYYYMMDDHHMMSS; some branches convert report, bill, sample, and accession dates to the lab timezone.
Message cleanupBefore return/send, line breaks and selected HTML tokens are normalized; <br> tags are removed or converted depending on branch.
ID enrichmentupdate_message_with_ids(jsonData, message, "HL7") is applied before final response/send in the main outbound paths.
TransportIf a non-zero port is resolved, the message is sent to host:port by TCP socket. If not, the generated HL7 is returned with sent_to_mirth: false.
LoggingSuccessful generation writes activity log entries for webhook triggering and generated HL7 text.
Error handlingUnhandled exceptions return status 500 with the generated message-so-far and traceback text.

Report-Wise vs Bill-Wise Behavior

BehaviorReport-wise endpointBill-wise endpoint
Primary identifierlabReportId for ORUR01/OUL; first labReportDetails[].labReportId or testDetails[].labReportId for others.bill_id.
Supported payloadsDFT, ORM, OUL, ADT, ORUR01.ORUR01 and DFT.
Report selectionStarts from one report and often uses its bill context.Loads all reports on the bill where dismissed=0, sampleRedrawFlag=0, and isSynced=1.
DFT behaviorBuilds DFT in-process for the report/bill context.Builds a webhook payload and forwards it to the configured DFT URL; it does not directly build the final DFT message in this function.
ORU behaviorBuilds one report-oriented result message.Builds a consolidated bill-wise ORU from the supplied/report-derived result details.

Response Shape

Successful generation returns JSON similar to:

{
  "status": 200,
  "message": "MSH|^~\\&|...",
  "file Name": "",
  "sent_to_mirth": true
}

For report-wise generation the response may also include MSH_1 and MSH_2. Bill-wise DFT forwarding returns the generated forwarding payload instead of the final HL7 text:

{
  "status": 200,
  "message": "DFT HL7 sent successfully",
  "sent_to_mirth": false,
  "payload": {
    "Status": "Bill Generation HL7 for SFTP",
    "bill_id": 12345,
    "payloadType": "DFT"
  }
}

Operational Cautions

  • The DFT branch in the report-wise SFTP endpoint reads host and port from the root request, while most other branches read them from integrationDetails.
  • integration_name is case-normalized in many branches and activates destination-specific behavior. Treat it as a behavior switch, not only a label.
  • segments is an allow-list for optional segment groups. Some base segments are always produced even if the list is empty.
  • Some branches return status 200 for business skips, for example no insurance in the DFT SFTP branch. Consumers should inspect both HTTP status and response body.
  • Because socket delivery happens synchronously in the request, an unreachable host or port can raise an exception and return status 500.

Integration Name Specifications

The outbound generators use integration_name as a compatibility switch for receiver-specific HL7 structure. ORU flows may also derive an integration_identifier from the order number with integration_differentiator; that identifier is mainly used for dynamic port selection and a few receiver-specific ORU layouts.

Integration name / identifierApplies toSpecification
ATHENADFT, report-wise ORUR01, bill-wise ORUR01DFT uses Athena-aware insurance relation handling and can split comma-separated report integration codes into multiple FT1 rows. ORU validates that the derived/configured identifier belongs to Athena, allows sender/facility overrides, formats provider name as last/first, applies Athena-specific result/specimen behavior, and can route bill-wise output through athena_port.
EMEDDFT, report-wise ORUR01, bill-wise ORUR01DFT prefers report integration code and falls back to procedure/test code. ORU uses the configured lab name as the sending application, maps sending facility to the ordering facility, and uses the sending facility as the receiving facility in the bill-wise branch.
CERNERORM, ADTORM uses Cerner-specific patient, visit, order, and observation identifiers including MRN/CMRN/FIN-style fields, collection/cancel/dispatch statuses, and optional HLA/outsourced message routing through HLA_port. ADT uses Cerner-specific PID/PV1 construction and can add medical history, height, and weight observations.
CPLORMSets billing type as insurance, credit, or patient pay based on insurance and bill-payment context, and adds configured order comments as NTE content.
SIGLOORMPrefixes patient contact with country code and prefers national id/SSN formatting expected by the destination.
TRIBALORMUpdates the bill order number from the manual sample/accession identifier and changes OBR placer/filler ordering for the receiver.
EMDEONreport-wise ORUR01Builds an EMDEON/DOH-style ORU with receiving application FILE, sending application fallback ECL, CLIA-aware sending facility values, dynamic port lookup by integration identifier, and optional secondary DOH routing through doh_port.
expirity identifierreport-wise ORUR01Uses a derived/configured integration_identifier to change ORC placement and report-order formatting inside the EMDEON-style ORU flow.
ellkay identifierreport-wise ORUR01Uses a derived/configured integration_identifier to change OBR layout and method/comment handling inside the EMDEON-style ORU flow.
CALREDIEreport-wise ORUR01Applies public-health style MSH/PID/ORC/OBR formatting with CLIA/LIMS identifiers, provider NPI formatting, normalized race/ethnicity fields, and public-health OBX/SPM construction.
LOUSIANAreport-wise ORUR01Uses the same public-health branch as CALREDIE with Louisiana-specific contact formatting, address shaping, LOINC suffixing, and abnormal-flag vocabulary. The code uses the spelling LOUSIANA; configuration must match that value unless the implementation is changed.
ILLINOISreport-wise ORUR01Adjusts CLIA/facility formatting and can emit SFT software details when configured.
TEXASreport-wise ORUR01Uses Texas-specific MSH/PID/ORC/OBR structure, CLIA/OID identifier placement, provider/contact formatting, and LOINC-oriented test descriptions.
MARYLANDreport-wise ORUR01Prefixes sending application with organization context and uses Maryland-specific PID, ORC, OBR, and LOINC/test-description formatting.
NABIDHreport-wise ORUR01Uses integration code as the test code where present, sends nationality/national-id visit context, formats sample type with code/name pairs, and has special base64/CAP-accreditation OBX behavior.
CATALYSTreport-wise ORUR01, bill-wise ORUR01Uses the lab bill id as the placer/order identifier in ORU segments where this receiver expects bill-level identifiers instead of report-level ids.
ECWreport-wise ORUR01, bill-wise ORUR01Appends pathologist name and report comments as NTE content after result/document OBX generation.
default / blankAll supported payloadsUses the generic outbound segment templates and direct host/port routing from the applicable request location. Configure explicit integration names only when the receiver needs one of the behaviors above.

Configuration Guidance

FieldGuidance
integration_nameUse the exact receiver switch expected by the branch. The implementation compares most values case-insensitively, but spelling still matters for values such as LOUSIANA.
integration_identifierUse when one integration setup needs dynamic ORU routing by destination identifier. If blank, the report-wise ORU branch derives it from the order number prefix before integration_differentiator.
integration_differentiatorDefaults to -; use it only when order numbers encode destination routing, for example ATHENA-12345.
<identifier> port keysORU dynamic routing can look up integrationDetails[integration_identifier]; some branches also use dedicated keys such as athena_port, doh_port, and HLA_port.
sendingApplication / sendingFacilityThese are normal MSH fields, but several integration names override them. Verify the generated MSH after enabling a receiver-specific branch.

Message Type Pages

Payload typeHL7 messageDocumentationTypical trigger
ADTADTADTPatient/event information outbound
ORMORM^O01ORMOrder creation, update, cancellation, or resend
ORUR01ORU^R01 by defaultORUR01Result submission
OULOUL result/specimen messageOULSpecimen/result outbound with OUL formatting
DFTDFT^P03DFTBilling/charge outbound

Outbound Routing Flow

Purpose

This document describes the outbound HL7 generation APIs used by the livehealthapp repository for billing, order, patient, specimen, and result transmission.

It covers the following implementation entry points:

APIFunctionFilePrimary use
/integration/sftp/hl7/2_3/send_hl7_data/sftp_HL7_payload_generation_functionlabs/views.pySFTP-triggered HL7 generation for DFT, ORM, OUL, ADT, and ORUR01.
/integration/sftp/hl7/2_3/send_billwise_hl7_data/sftp_billwise_HL7_payload_generation_functionlabs/views.pyBill-wise ORU generation and bill-wise DFT forwarding.
/integration/hl7/send_dft_hl7_data/DFT_HL7_payload_generation_functionlabs/integration_functions.pyDirect DFT P03 generation for HL7 2.3 style billing integrations.
/integration/hl7/2_4/send_dft_hl7_data/DFT_HL7_2_4_payload_generation_functionlabs/integration_functions.pyDirect DFT P03 generation for HL7 2.4 style billing integrations and vendor-specific DFT behavior.

Message Types

Payload typeHL7 messageTypical triggerMain segments
ADTADTPatient/event information outboundMSH, PID, optional PV1, OBX, NTE
ORMORM^O01Order creation, update, cancellation, or resendMSH, PID, PV1, ORC, OBR, optional AL1, IN1, GT1, RXO, OBX, FT1, DG1, CST, NTE
ORUR01ORU^R01 by defaultResult submissionMSH, PID, ORC, OBR, OBX, SPM, optional PV1, AL1, IN1, FT1, DG1, RXO, CST, NTE
OULOUL result/specimen messageSpecimen/result outbound with OUL formattingMSH, specimen and result segments, optional SPM, OBX, NTE, CST
DFTDFT^P03Billing/charge outboundMSH, EVN, PID, PV1, FT1, DG1, optional IN1, GT1, OBX, custom vendor segments

Request Shape

Most outbound calls expect JSON in the request body. The common structure is:

{
  "payloadType": "ORUR01",
  "labReportId": 123456,
  "labReportDetails": [],
  "reportDetails": [],
  "dictionaryId": 0,
  "integrationDetails": {
    "host": "127.0.0.1",
    "port": 5000,
    "versionId": "2.4"
  }
}

Bill-wise ORU/DFT uses bill_id as the primary identifier:

{
  "payloadType": "ORUR01",
  "bill_id": 12345,
  "billId": 1001,
  "reportDetails": [],
  "integrationDetails": {
    "host": "127.0.0.1",
    "port": 5000
  }
}

Common Runtime Behavior

  • If port is configured and non-zero, the generated HL7 is sent over TCP socket to host:port.
  • If port is missing or zero, the API can still return the generated HL7 message without sending it to Mirth or another TCP listener.
  • update_message_with_ids(jsonData, message, "HL7") is applied before final return/send in the main outbound paths.
  • HTML line break tags and some report formatting tokens are normalized before sending.
  • integrationDetails is the main configuration object for flags.
  • Some functions read host and port from the root payload, while others read them from integrationDetails. See the API-specific notes below.

API-Specific Notes

/integration/sftp/hl7/2_3/send_hl7_data/

Function: sftp_HL7_payload_generation_function

Supported payloadType values:

  • DFT
  • ORM
  • OUL
  • ADT
  • ORUR01

Identifier rules:

  • ORUR01 and OUL read labReportId from the root payload.
  • Other payloads read the first labReportId from labReportDetails; if empty, testDetails is used as a fallback.
  • If no report id can be resolved, the API returns 400 with labReportId is not valid.

Transport rules:

  • ORM, OUL, ADT, and ORUR01 primarily read host and port from integrationDetails.
  • The DFT branch in this function reads host and port from the root payload.

/integration/sftp/hl7/2_3/send_billwise_hl7_data/

Function: sftp_billwise_HL7_payload_generation_function

Supported bill-wise behavior:

  • ORUR01: Generates one bill-wise ORU message using all synced, non-dismissed reports for the bill.
  • DFT: Builds a bill-wise payload and forwards it to a configured URL, defaulting to /integration/hl7/send_dft_hl7_data/.

Identifier rules:

  • Requires bill_id.
  • If bill_id is missing, the API returns 400 with bill_id is not valid.

DFT forwarding rules:

  • Reads host, port, and optional url from integrationDetails.
  • Sends a webhook payload containing patient, billing, order, report, and integration details to the configured DFT URL.

/integration/hl7/send_dft_hl7_data/

Function: DFT_HL7_payload_generation_function

Supported payload:

  • payloadType: "DFT"

Behavior:

  • Generates DFT^P03.
  • Uses HL7 version 2.3.1 by default.
  • Supports insurance validation, bill-level insurance, timezone conversion, and NextGen-specific segment ordering/formatting.
  • Reads host and port from the root payload.

/integration/hl7/2_4/send_dft_hl7_data/

Function: DFT_HL7_2_4_payload_generation_function

Supported payload:

  • payloadType: "DFT"

Behavior:

  • Generates DFT^P03.
  • Supports vendor-specific DFT behavior for integrations such as PGM, ATHENA, CERMAK, and custom dynamic segment sequencing.
  • Reads host, port, and dynamic integration-specific port keys from integrationDetails.
  • Supports additional DFT options such as outsource mapping, custom segment order, base64 result attachment, profile ICD mapping, and drug-wise FT1 generation.

Configuration Key Naming

Different branches expect different key styles.

BranchExpected styleExamples
ORM, ADT, ORUR01, DFTcamelCase and mixed legacy keyssendingApplication, receivingFacility, labName, BillingInsurance
OULsnake_casesending_application, receiving_facility, lab_name
DFT 2.4 dynamic portintegration name as keyPGM, ATHENA, or any configured integration_name
ORU bill-wise dynamic portlower-case integration identifier as keyintegrationDetails[integration_identifier]

If the wrong key style is sent, the code usually falls back to blank/default values.

Common Configuration Keys

KeyTypeDefaultUsed byDescription
integration_namestring""All major branchesEnables vendor-specific formatting and validation.
sendingApplicationstringvariesDFT, ORM, ADT, ORUR01Populates MSH-3.
sending_applicationstring""OULOUL snake_case equivalent of sending application.
sendingFacilitystringorg code / ""DFT, ORM, ADT, ORUR01Populates MSH-4 or related sending facility fields.
sending_facilitystring""OULOUL snake_case equivalent of sending facility.
receivingApplicationstring""DFT, ORM, ADT, ORUR01Populates MSH-5.
receiving_applicationstring""OULOUL snake_case equivalent of receiving application.
receivingFacilitystring""DFT, ORM, ADT, ORUR01Populates MSH-6.
receiving_facilitystring""OULOUL snake_case equivalent of receiving facility.
hoststring""Most outbound pathsTCP destination host.
portnumber/string0 or ""Most outbound pathsTCP destination port.
versionIdstring2.3.1 or 2.4Most outbound pathsHL7 version populated in MSH-12.
segmentslistvariesORM, OUL, ADT, ORUR01Optional segment inclusion list.
lab_time_zoneboolean0DFT, ORM, ORUR01Converts dates to the configured lab timezone before HL7 formatting.
BillingInsuranceboolean0DFT, ORM, ORUR01Uses bill-level insurance mapping instead of default patient insurance records.
is_insurance_enableboolean0DFT, ORUR01Requires insurance data before generating HL7.

Use the smallest segment list required by the receiving system.

Use caseSuggested segment list
Basic ORM order["PV1"] or default mandatory segments only
ORM with insurance and diagnoses["PV1", "IN1", "DG1"]
ORM with medications["PV1", "RXO"] plus prescribed_drugs: 1
ORM with custom operational metadata["PV1", "CST"]
Basic ORU result[] plus default ORC/OBR/OBX/SPM behavior
ORU with visit and insurance["PV1", "IN1"]
ORU with attachments/TRFattachments: 1 and/or trf_flag: 1
DFT with insuranceis_insurance_enable: 1, BillingInsurance as required

Validation and Failure Cases

CaseBehavior
Missing labReportId in report-wise endpointReturns HTTP 400.
Missing bill_id in bill-wise endpointReturns HTTP 400.
is_insurance_enable enabled and no insurance is availableDFT/ORU branches return a failure response and do not generate/send HL7.
testCodes configured for ORM but no matching tests are eligibleORM can return status 209 with "Test codes are not configured."
Disabled DFT integration identifier in DFT 2.4Returns status 209 and skips DFT generation.
Athena ORU with mismatched integration identifierReturns status 209 and skips generation for non-Athena data.
port empty or zeroMessage is generated and returned where supported, but TCP send is skipped.

On this page