Hospital Invoice Creation Flow

Automations: 02. Hospital Invoice Creation Flow

Objective

To automatically generate a Hospital Invoice when a reception record meets all discharge criteria: 

  • Patient is Discharged 
  • Payment is Paid 
  • Discount is Approved 

 

Flow Type 

  • Type: Record-Triggered Flow 
  • Trigger Object: Reception 
  • Trigger Conditions: 
  • Trigger the flow when a record is updated 
  • Entry Conditions: 
  • Patient Status = Discharged 
  • Payment Status = Paid 
  • Discount Approval Status = Approved 
  • Run flow: Only when record is updated to meet the condition requirements 
  • Optimize For: Actions and Related Records (to allow creation and data manipulation) 

2. Get Conflicting Room Bookings

Step 2: Calculate Total Amount 

At this stage, we calculate the full hospital charges before discount. 

🧮 Formula Resource: CalculateAllAmount 

Property Value
API Name API Name CalculateAllAmount
Description Calculates total charges before discount
Data Type Number (Decimal)
Decimal Places 2
Formula Doctor__r.Consultation_Fees__c + LabChargesAmount + Prescriptioncharges + RoomCharges + VisitChargeAmount

Variables Used in Formula 

Variable Name Description Type/ Decimal Note
LabChargesAmount Lab test total charge Number/1 Fetched from Lab Test object
Prescriptioncharges Prescription total charge Number/2 from Prescription object
RoomCharges Total room charges Number/3 From Room object
VisitChargeAmount Paid charges from visit Number/4 From Visit of Patient object

Step 3: Apply Discount and Compute Final Paid Amount 

🧮 Formula Resource: DiscountPercent 

| API Name | DiscountPercent | 
| Data Type | Number (Decimal) | 
| Formula | 

 

plaintext 

CopyEdit 

 

CASE(Discount_Type__c, 

  “Army”, 25, 

  “Normal”, 15, 

  “Management”, 30, 

  “Chairman”, 50, 

  0 

) 

🎯 This maps the selected discount type to a percentage. 

 

🧮 Formula Resource: AmountPaid 

| API Name | AmountPaid | 
| Data Type | Number (Decimal) | 
| Formula | 

plaintext 

CopyEdit 

CalculateAllAmount – (CalculateAllAmount * DiscountPercent / 100) 

This calculates the net payable amount after applying the selected discount. 

 

📅 Formula Resource: TodayDate 

| API Name | TodayDate | 
| Data Type | Date | 
| Formula | TODAY() | 

Used to auto-fill the invoice date. 

 

Step 4: Create Get record. 

1.1 Get Visit of Patient Record 

  • Object: Visit of Patient 
  • Filter: 
  • Patient = {!$Record.Patient__c} 
  • Store: Only first record 
  • Variable: VisitChargeAmount = Amount_Paid__c 

1.2 Get Room Charges 

  • Object: Room 
  • Filter: 
  • Patient = {!$Record.Patient__c} 
  • Store: Only first record 
  • Variable: RoomCharges = Total_Room_Charges__c 

1.3 Get Lab Charges 

  • Object: Lab Test 
  • Filter: 
  • Patient = {!$Record.Patient__c} 
  • Store: Only first record 
  • Variable: LabChargesAmount = Charges__c 

1.4 Get Prescription Charges 

  • Object: Prescription 
  • Filter: 
  • Patient = {!$Record.Patient__c} 
  • Store: Only first record 
  • Variable: Prescriptioncharges = Prescription_Total_Charges__c 

 

Step 5: Assignment 

Label: Assign all the record 

In this step, all charges are summed into a final calculation variable (e.g., CalculateAllAmount). 

You may need to calculate: 

plaintext 

CopyEdit 

CalculateAllAmount = LabChargesAmount + Prescriptioncharges + RoomCharges + VisitChargeAmount + ConsultationFees – Discount 

(You can use a formula resource or another Assignment step) 

 

Course Video