Create New Order
Inbound HL7/SFTP documentation for creating a new Crelio bill from an ORM order message.
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:
authKeyshould 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 billworkflow.
Implementation Path
| Step | Function | Description |
|---|---|---|
| Validate request | hl7/2_3/createOrder/ | Validates token and integration configuration. |
| Parse HL7 | orm_hl7_parsing_api_corrohealth or orm_hl7_parsing_function_tox | Converts HL7 segments into the inbound order payload. |
| Enqueue downstream create | Fusion.webhook | Posts the inbound order payload to /create_order_in_crelio/. |
| Create patient and bill | create_order_in_crelio | Creates or updates patient, resolves org/referral/tests, and creates bill. |
| Create billing records | commonBillingMasterFunction | Creates 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 field | HL7 source | Downstream use |
|---|---|---|
fullName | PID-5 | Patient name. |
firstName | PID-5.2 | Patient first name. |
middleName | PID-5.3 | Patient middle name. |
lastName | PID-5.1 | Patient last name. |
gender | PID-8 | Patient gender. |
dob | PID-7 | Patient date of birth. |
mobile | PID-13 | Patient contact number. |
labPatientId | PID-2 | External patient identifier. |
nationalId | PID-19 | National identity number. |
passportNo | PID-20 | Passport number. |
insurance_details | IN1 | Patient insurance creation/update. |
aoe_data | OBX, when is_aoe_store is enabled | AOE question values. |
test_aoe_mapping | OBX values grouped by current OBR test code | AOE-to-test mapping. |
bill_attachment_details | OBX attachment data | Bill attachment upload. |
shared_providers | OBX question REFERRED_TO_DOCTOR | Shared provider records. |
orderNumber | OBR/ORC-derived order identifier | Saved on the bill and used for future matching. |
orgCode | PV1/MSH/vendor-specific | Organization lookup. |
doctorCode | OBR-16 or PV1-7 for ADT | Referral lookup. |
testList | OBR-4 | Tests to bill. |
billDate | OBR-7 | Bill date. |
sampleDate | OBR-7, when collectionTime = 1 | Collection date/time. |
comments | NTE | Bill comments. |
icd_details | DG1 | Bill 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:
organizationIdLHorgCodeorganizationNameororganisationName- Lab default organization fallback
Referral is resolved from:
doctorCodereferralIdLHreferralName- 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:
testCodetestIDtestName
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:
- Organization price list, when available.
- Doctor price list, when no organization price applies.
- Master test amount.
- 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
| Response | Meaning |
|---|---|
Invalid auth key | Downstream payload did not contain a valid token. |
Mandatory fields are Missing e.g. Name, Gender, Age/DOB, Test Details etc | Patient or test data required for registration/billing is incomplete. |
Wrong Organisation or Referral details | Organization/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. |