Use this tool to calculate anion gap and osmolar gap.
The source code is available open source here.