IntegrationsHL7 (Old Flow)Inbound

Create New Order

Inbound HL7/SFTP documentation for creating a new Crelio bill from an ORM order message.

👤 Development Team📅 Updated: May 5, 2026📁 Integrations🏷️ HL7🏷️ SFTP🏷️ Inbound🏷️ Create Order

Create New Order

This page documents the new-order path of hl7/2_3/createOrder/. Related operations are documented separately:

When This Flow Runs

A new order is created when the inbound message is parsed successfully and the router does not handle it as a duplicate, add-test, or cancellation request.

Typical conditions:

  • authKey should be valid.
  • An enabled integration exists with actionCategoryListId = 51.
  • The HL7 data should be valid.
  • No active bill is found for orderNumber, or no order number is parsed.
  • The HL7 status should not contain bill cancellation status (CA in ORC).
  • The HL7 data should not contains same order Number with non billed Tests that means Add test to bill workflow.

Implementation Path

StepFunctionDescription
Validate requesthl7/2_3/createOrder/Validates token and integration configuration.
Parse HL7orm_hl7_parsing_api_corrohealth or orm_hl7_parsing_function_toxConverts HL7 segments into the inbound order payload.
Enqueue downstream createFusion.webhookPosts the inbound order payload to /create_order_in_crelio/.
Create patient and billcreate_order_in_crelioCreates or updates patient, resolves org/referral/tests, and creates bill.
Create billing recordscommonBillingMasterFunctionCreates bill, billing info, reports, samples, payments, and related records.

Router Response

The router does not create the bill directly. It enqueues a Fusion job and returns the accepted order reference.

{
  "status": 200,
  "jobId": "<fusion-job-id>",
  "orderNumber": "<external-order-number>"
}

The jobId means the request was accepted for downstream processing. It does not by itself guarantee that bill creation succeeded.

Parsed Payload Used For Creation

Parsed fieldHL7 sourceDownstream use
fullNamePID-5Patient name.
firstNamePID-5.2Patient first name.
middleNamePID-5.3Patient middle name.
lastNamePID-5.1Patient last name.
genderPID-8Patient gender.
dobPID-7Patient date of birth.
mobilePID-13Patient contact number.
labPatientIdPID-2External patient identifier.
nationalIdPID-19National identity number.
passportNoPID-20Passport number.
insurance_detailsIN1Patient insurance creation/update.
aoe_dataOBX, when is_aoe_store is enabledAOE question values.
test_aoe_mappingOBX values grouped by current OBR test codeAOE-to-test mapping.
bill_attachment_detailsOBX attachment dataBill attachment upload.
shared_providersOBX question REFERRED_TO_DOCTORShared provider records.
orderNumberOBR/ORC-derived order identifierSaved on the bill and used for future matching.
orgCodePV1/MSH/vendor-specificOrganization lookup.
doctorCodeOBR-16 or PV1-7 for ADTReferral lookup.
testListOBR-4Tests to bill.
billDateOBR-7Bill date.
sampleDateOBR-7, when collectionTime = 1Collection date/time.
commentsNTEBill comments.
icd_detailsDG1Bill ICD details.

Patient Handling

create_order_in_crelio first attempts to match an existing patient by labPatientId. When patient_strict_check = 1, the match also includes first name, middle name, last name, date of birth, and gender.

If a patient is found, selected demographics are updated from the inbound payload. If no patient is found, the downstream function validates required fields and creates a patient through commonPatientRegistrationFunction.

Required patient fields for a new patient:

  • Patient name
  • Gender
  • Age or date of birth
  • Valid organization/referral context

Organization And Referral Handling

Organization is resolved from:

  1. organizationIdLH
  2. orgCode
  3. organizationName or organisationName
  4. Lab default organization fallback

Referral is resolved from:

  1. doctorCode
  2. referralIdLH
  3. referralName
  4. Lab default referral fallback

When a non-empty organization or referral name is supplied and no matching record exists, the downstream function can create a new organization or referral using the existing billing helpers.

Test Handling And Pricing

Each inbound test is matched against active allTests records in this order:

  1. testCode
  2. testID
  3. testName

For matched tests, the downstream payload includes the internal test ID, resolved amount, quantity, concession, sample ID, sample type, report comments, report-level tags, and ICD code ID.

Pricing priority:

  1. Organization price list, when available.
  2. Doctor price list, when no organization price applies.
  3. Master test amount.
  4. If orgPriceList = 1, organization price-list priority is explicitly used.

Unmatched tests are returned as unbilled_tests. If no inbound test matches master data, the bill is not created.

Bill Creation Side Effects

After commonBillingMasterFunction creates the bill:

  • Home collection can be booked when isHomeCollection = 1.
  • AOE values are saved through create_question_values_from_aoe_data.
  • Test-level clinical information is saved through create_test_clinical_info.
  • Shared providers are created when provided in the inbound message.
  • Accession/manual sample update is attempted unless test_wise_accession = 1.
  • Base64 bill attachments are uploaded when present.
  • Tox/micro orders enqueue drug setup through /integration/tox/add_drugs_into_report/.

Downstream Success Response

{
  "code": 200,
  "is_tox": 0,
  "unbilled_tests": [],
  "Message": "Bill Generated successfully with billId Id : <labBillId>"
}

For tox/micro orders:

{
  "code": 200,
  "unbilled_tests": [],
  "Message": "Tox Bill Generated successfully with billId Id : <labBillId>"
}

Common Failure Responses

ResponseMeaning
Invalid auth keyDownstream payload did not contain a valid token.
Mandatory fields are Missing e.g. Name, Gender, Age/DOB, Test Details etcPatient or test data required for registration/billing is incomplete.
Wrong Organisation or Referral detailsOrganization/referral lookup failed during patient creation.
Patient not registered. Combination Mismatched of Patient ID / Contact No.Existing patient matching failed and registration did not complete.
Test codes are not available in master data - ...None of the inbound tests matched active master tests.

On this page