Skip to content

Instantly share code, notes, and snippets.

@SLaks
Last active July 12, 2021 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SLaks/e5fdd24cceed605868ba921a8bfbb6b0 to your computer and use it in GitHub Desktop.
Save SLaks/e5fdd24cceed605868ba921a8bfbb6b0 to your computer and use it in GitHub Desktop.
Export services from Castlight

Console script to export claims and services from Castlight

This script helps manage medical bills via https://us.castlighthealth.com/ in a spreadsheet.

Setup

This script populates a spreadsheet with one row per service.

  • Each claim has multiple services, which you can see in Castlight by opening the claim details.
  • Each service corresponds to a single line item in a bill from a provider.
  • This helps make sure that EOBs from insurance match bills from provider.
  • This script was built for the following column headers; you can also change them and edit the fields in the array.
    ID	Person	Date of service	Service Provider	Description	Type	Original Amount	Deductible	Coinsurance	To pay amount	Statement/bill date	Date Paid	Payment type	Notes
    

Usage

  1. Log into Castlight.
  2. Open the dev tools console.
  3. Paste the entire script into the console and run it. It will copy TSV data to the clipboard.
  4. Paste the copied data into the spreadsheet.
    • If the spreadsheet is not empty, paste it over the last existing row. It will copy starting from the last row of the previous copy (this is stored in localStorage). If that last row changes, that means you're missing some rows and should investigate.
    • If the localStorage is cleared (or if you use a different browser), you can copy the ID from the last row of the spreadsheet into the first line of the script.

Warning: Firefox doesn't seem to support copy(await ...). On Firefox, run this command to copy the result of the previous command to the clipboard: copy(rows.map(r => r.join('\t')).reverse().join('\n'))

copy(await (async () => {
var lastId = localStorage.SLaks___lastExportedId || /* Paste the last ID from the spreadsheet here: */ "";
function takeWhile(cb) {
let found = false;
return x => {
if (found) return false;
if (cb(x)) return true;
found = true;
return true;
}
}
async function getRows() {
console.info('Loading...')
const claims = (await fetch("https://us.castlighthealth.com/api/pastcare/for_session?fil=year%7C2021&ppg=40").then(res => res.json())).serviceGroups;
return claims.flatMap(c => c.services.map((s, sIndex) => ([
`${c.guid}#${sIndex}`,
c.patientName,
c.serviceBeginDate,
c.providerDisplayName,
s.description,
s.type,
s.chargedAmount / 100,
s.deductibleAmount / 100,
s.coinsuranceAmount / 100,
s.patientResponsibleAmount / 100,
])));
}
rows = (await getRows()).filter(takeWhile(r => r[0] !== lastId));
if (!rows.length) {
console.log(`No claims found starting from ID ${lastId}!`);
return '';
}
if (lastId && rows.length === 1) {
console.warn(`Didn't find any rows after the last row from the previous dump.
Paste over the last row in the spreadsheet and make sure it's the same.`);
} else if (lastId) {
console.info(`NOTE: This includes the last row from the previous dump.
Paste over the last row in the spreadsheet and verify that it didn't change.`);
} else {
console.warn(`There is no recorded last row from the previous dump.
If your spreadsheet is not empty, copy the ID from its last row to the first line of this script and run it again.`);
}
console.log(`Copied to clipboard!
After pasting into the spreadsheet, click below to save the last row copied for next time.`);
console.log({'Click to': 'expand!', 'Rows found': rows.length, 'Last ID': lastId, get [`Click here to save ${rows[0][2]} as the last saved claim!`]() { localStorage.SLaks___lastExportedId = rows[0][0]; return 'Saved!'; }});
return rows.map(r => r.join('\t')).reverse().join('\n');
})());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment