Billing check assistant
A nurse-procedure billing audit built from two exports that didn't talk to each other
- Role
- Billing and revenue audit
- When
- 2026
- Built with
- Excel, Office Scripts (TypeScript), Dynamic-array formulas
- Format
- Working demo
Which charges need a second look?
Every “Nursing Procedure” on the billing export is a charge. Most are routine, but some need a person to check them and a few have no attendance behind them at all. Telling them apart means opening a second system, the scheduling system’s clinic-list printout, which shows which clinics each patient was booked into that day. That printout was made for reading, though: schedule names sit on their own line, dates are buried in session headers, and patients are listed underneath.
The Office Script
I wrote an Office Script that turns both exports into an audit anyone can keep running in Excel.
It starts by wiping names, phone numbers, titles and dates of birth from the clinic list and keeps only the patient number for matching. Helper columns then carry each schedule name down to its patients, read the date out of the session header (so any date range works) and build a key from patient and date.
The rules live in yellow cells, not in formulas. They say which clinic lists mean “To review” and which mean “Not needed”, which appointment names never need review, and that a health-screening patient who also had bloods or a treatment-room visit that day doesn’t need checking. Changing a rule never means touching a formula.
Each billed line then runs through the rules in a fixed order and comes out with a flag and a reason in plain English. The flag that matters most is “Not found in schedule - check”: a nursing charge for a patient who wasn’t on any clinic list that day.
Try it
The demo runs the same rules, in the same order, on an invented week at Hospital X. Change a rule on the left and the flags update; click a line to see the path it took through the rules and the clinic lists that patient was on. If you’d rather see it in Excel, the faux workbook has the same formulas working, with the script on its own tab.
About the dataHospital X is fictional, and so is every patient number, clinician, room and charge in the demo and the workbook. Names, phone numbers and dates of birth are blank because the script clears them, just as it did on the real reports.
Try the demo
Billing export, audited
See the Office Script that does this in Excel
function main(workbook: ExcelScript.Workbook) {
const CLINIC_SHEET = "Sheet1";
const EXPORT_SHEET = "Export";
// Capacity of the editable rule tables on the Export tab (rows 2..RULE_LAST)
const RULE_LAST = 20;
const HS_LAST = 6;
const clinic = workbook.getWorksheet(CLINIC_SHEET);
const exp = workbook.getWorksheet(EXPORT_SHEET);
if (!clinic || !exp) {
throw new Error(`Could not find sheets '${CLINIC_SHEET}' and '${EXPORT_SHEET}'.`);
}
const q = (n: string) => (/[^A-Za-z0-9_]/.test(n) ? `'${n}'` : n);
const CS = q(CLINIC_SHEET);
const ES = q(EXPORT_SHEET);
const headerFill = "#DDEBF7";
const inputFill = "#FFFF00";
const inputFont = "#0000FF";
// ---------- 1. Anonymise appointment rows on the clinic list ----------
const clinicUsed = clinic.getUsedRange();
const clinicLast = clinicUsed.getRowIndex() + clinicUsed.getRowCount();
const colA = clinic.getRange(`A1:A${clinicLast}`).getValues();
let cleared = 0;
for (let i = 0; i < colA.length; i++) {
if (typeof colA[i][0] === "number") {
clinic.getRangeByIndexes(i, 2, 1, 11).clear(ExcelScript.ClearApplyTo.contents);
cleared++;
}
}
// ---------- 2. Helper columns on the clinic list (any date range) ----------
const helperLast = clinicLast + 20;
const hdr = clinic.getRange("V1:Y1");
hdr.setValues([["Schedule", "Schedule Date", "Key (PatientNo|Date)", "Review-trigger? (1/0)"]]);
hdr.getFormat().getFont().setBold(true);
hdr.getFormat().getFill().setColor(headerFill);
// Schedule name = the row directly above a "Ddd dd/mm/yyyy ..." session row
clinic.getRange(`V2:V${helperLast}`).setFormulaR1C1(
`=IF(AND(ISTEXT(R[1]C1),MID(R[1]C1,7,1)="/",MID(R[1]C1,10,1)="/"),TRIM(RC1),R[-1]C)`
);
// Session date parsed from the session row itself, so any day/month/year works
const wRange = clinic.getRange(`W2:W${helperLast}`);
wRange.setFormulaR1C1(
`=IF(AND(ISTEXT(RC1),MID(RC1,7,1)="/",MID(RC1,10,1)="/"),DATE(MID(RC1,11,4),MID(RC1,8,2),MID(RC1,5,2)),R[-1]C)`
);
wRange.setNumberFormatLocal("dd/mm/yyyy");
clinic.getRange(`X2:X${helperLast}`).setFormulaR1C1(
`=IF(AND(RC14<>"",RC14<>"Patient No."),TRIM(RC14)&"|"&TEXT(INT(RC23),"0"),"")`
);
clinic.getRange(`Y2:Y${helperLast}`).setFormulaR1C1(
`=IF(RC24="","",IF(IFERROR(INDEX(${ES}!R2C16:R${RULE_LAST}C16,MATCH(RC22,${ES}!R2C15:R${RULE_LAST}C15,0)),"")="To review",1,0))`
);
clinic.getRange("V:Y").getFormat().setColumnWidth(140);
// ---------- 3. Rule tables on the Export tab ----------
const rulesHdr = exp.getRange("O1:R1");
rulesHdr.setValues([[
"Schedule (exactly as on clinic list)",
"Outcome if patient is on it that day",
"",
"Appointment names always Not needed"
]]);
rulesHdr.getFormat().getFont().setBold(true);
exp.getRange("O1:P1").getFormat().getFill().setColor(headerFill);
exp.getRange("R1").getFormat().getFill().setColor(headerFill);
const blockEmpty = exp.getRange(`O2:P${RULE_LAST}`).getValues().every(r => r.every(v => v === "" || v === null));
if (blockEmpty) {
exp.getRange("O2:P8").setValues([
["Pathology", "Not needed"],
["Pre ass minor op", "Not needed"],
["Theatre", "Not needed"],
["Smear Test Clinic", "Not needed"],
["Treatment Room", "To review"],
["Wound Care", "To review"],
["Skin Patch/Prick Testing", "To review"]
]);
exp.getRange("R2").setValue("Spirometry");
}
// NEW: Health Screening rule table (T = screening schedule, U = paired schedules)
const hsHdr = exp.getRange("T1:U1");
hsHdr.setValues([["Health Screening schedule", "Paired schedules (same day = Not needed)"]]);
hsHdr.getFormat().getFont().setBold(true);
hsHdr.getFormat().getFill().setColor(headerFill);
const hsEmpty = exp.getRange(`T2:U${HS_LAST}`).getValues().every(r => r.every(v => v === "" || v === null));
if (hsEmpty) {
exp.getRange("T2").setValue("Health Screening Nurse 1");
exp.getRange("U2:U3").setValues([["Pathology"], ["Treatment Room"]]);
}
const inputs = [
exp.getRange(`O2:P${RULE_LAST}`),
exp.getRange(`R2:R${RULE_LAST}`),
exp.getRange(`T2:T${HS_LAST}`),
exp.getRange(`U2:U${HS_LAST}`)
];
inputs.forEach(r => r.getFormat().getFont().setColor(inputFont));
exp.getRange(`P2:P${RULE_LAST}`).getFormat().getFill().setColor(inputFill);
exp.getRange(`R2:R${RULE_LAST}`).getFormat().getFill().setColor(inputFill);
exp.getRange(`T2:U${HS_LAST}`).getFormat().getFill().setColor(inputFill);
exp.getRange("O:O").getFormat().setColumnWidth(170);
exp.getRange("P:P").getFormat().setColumnWidth(180);
exp.getRange("R:R").getFormat().setColumnWidth(190);
exp.getRange("T:T").getFormat().setColumnWidth(170);
exp.getRange("U:U").getFormat().setColumnWidth(230);
// ---------- 4. Audit columns on the Export tab ----------
const colB = exp.getRange("B:B").getUsedRange().getValues();
let expLast = 2;
for (let i = colB.length - 1; i >= 0; i--) {
if (colB[i][0] !== "" && colB[i][0] !== null) { expLast = i + 1; break; }
}
expLast += 5;
const audHdr = exp.getRange("I1:M1");
audHdr.setValues([[
"Schedules Found (Nursing)",
"Review-trigger appts that day",
"Audit Flag",
"Reason",
"Health Screening + Path/TR same day (1/0)"
]]);
audHdr.getFormat().getFont().setBold(true);
audHdr.getFormat().getFill().setColor(headerFill);
const key = `TRIM(RC2)&"|"&TEXT(INT(RC4),"0")`;
const RS = `R2C15:R${RULE_LAST}C15`;
const RX = `R2C18:R${RULE_LAST}C18`;
const HS = `R2C20:R${HS_LAST}C20`;
exp.getRange(`I2:I${expLast}`).setFormulaR1C1(
`=IF(RC2="","",TEXTJOIN(", ",TRUE,` +
`IF((${RS}<>"")*(COUNTIFS(${CS}!C24,${key},${CS}!C22,${RS})>0),${RS},""),` +
// NEW: when the Health Screening rule is true (col M = 1), list the screening schedule too
`IF(RC13=1,IF((${HS}<>"")*(COUNTIFS(${CS}!C24,${key},${CS}!C22,${HS})>0),${HS},""),"")))`
);
exp.getRange(`J2:J${expLast}`).setFormulaR1C1(
`=IF(RC2="","",COUNTIFS(${CS}!C24,${key},${CS}!C25,1))`
);
// NEW: 1 if patient is on a Health Screening schedule AND on Pathology/Treatment Room that day
exp.getRange(`M2:M${expLast}`).setFormulaR1C1(
`=IF(RC2="","",IF(AND(` +
`SUMPRODUCT((R2C20:R${HS_LAST}C20<>"")*COUNTIFS(${CS}!C24,${key},${CS}!C22,R2C20:R${HS_LAST}C20))>0,` +
`SUMPRODUCT((R2C21:R${HS_LAST}C21<>"")*COUNTIFS(${CS}!C24,${key},${CS}!C22,R2C21:R${HS_LAST}C21))>0),1,0))`
);
// Rule order: excluded appointment name -> NEW Health Screening rule -> existing Nursing Procedure rules
exp.getRange(`K2:K${expLast}`).setFormulaR1C1(
`=IF(RC2="","",IF(COUNTIF(${RX},RC3)>0,"Not needed",` +
`IF(RC13=1,"Not needed",` +
`IF(ISNUMBER(SEARCH("Nursing Procedure",RC3)),IF(RC10>0,"To review",` +
`IF(RC9="","Not found in schedule - check","Not needed")),"To review"))))`
);
exp.getRange(`L2:L${expLast}`).setFormulaR1C1(
`=IF(RC2="","",IF(COUNTIF(${RX},RC3)>0,"Appointment name excluded from audit",` +
`IF(RC13=1,"Health Screening patient also on Pathology/Treatment Room that day",` +
`IF(ISNUMBER(SEARCH("Nursing Procedure",RC3)),IF(RC10>0,"On a review-trigger schedule that day",` +
`IF(RC9="","Patient No. not on any clinic list for this date","Only on Not-needed schedules that day")),` +
`"Not a Nursing Procedure appointment"))))`
);
exp.getRange("I:I").getFormat().setColumnWidth(250);
exp.getRange("J:J").getFormat().setColumnWidth(110);
exp.getRange("K:K").getFormat().setColumnWidth(170);
exp.getRange("L:L").getFormat().setColumnWidth(320);
exp.getRange("M:M").getFormat().setColumnWidth(150);
exp.getRange("J:J").setColumnHidden(true);
exp.getRange("L:L").setColumnHidden(true);
exp.getRange("M:M").setColumnHidden(true);
exp.getAutoFilter().remove();
exp.getAutoFilter().apply(exp.getRange(`A1:M${expLast}`));
console.log(`Done. ${cleared} appointment rows anonymised; helpers to row ${helperLast}; audit to Export row ${expLast}.`);
}