Collection Calculations

Hi all,

In a collection named “docjobs”, I have two columns (“docCoverageDay” and “paNpCoverageDay”) with numbers which I would like to add, and then insert the sum into a new column (“totalCoverageDay”).
The following code works to simply add 5 to the docCoverageDay:

export function docjobs_afterQuery(item,) {
	//TODO: 
	item.totalCoverageDay = tcd(item.docCoverageDay);
	
	return item;
}

function tcd(docCoverageDay, paNpCoverageDay) {
	
	let tcd = docCoverageDay + 5;
	return tcd;
	
	//let tcd = docCoverageDay + paNpCoverageDay;
	//return tcd;
	
	
}

but the following code does NOT work when trying to add the two columns together as desired:

export function docjobs_afterQuery(item,) {
	//TODO: 
	item.totalCoverageDay = tcd(item.docCoverageDay);
	
	return item;
}

function tcd(docCoverageDay, paNpCoverageDay) {
	
	//let tcd = docCoverageDay + 5;
	//return tcd;
	
	let tcd = docCoverageDay + paNpCoverageDay;
	return tcd;
	
	
}

I followed the basic idea of this tutorial but I’m a noob, with a noob problem, and am hoping for a noob solution (o:
thanks so much!
G

Solved!

Here’s what I figured out:

export function docjobs_afterQuery(item,context) {
item.totalCoverageDay = item.docCoverageDay + item.paNpCoverageDay
var numb = (item.deptAnnualVolume / 365) / item.totalCoverageDay 
item.patientsHrDoc = +numb.toFixed(1)
var payper = (item.basePay / item.patientsHrDoc)
item.patient = payper.toFixed(2)
return item;
}

where:

  1. docjobs is my database
  2. “totalCoverageDay”, “docCoverageDay”, “paNpCoverageDay”, “deptAnnualVolume”, “patientsHrDoc”, “basePay”, and “patient” are all titles of columns in the database
  3. “numb” and “payPer” are just randomly titled variable names
  4. before returning results for “patientsHrDoc” and “patient” I round the values to 1 and 2 decimal places respectively.

These 7 lines of code (8 including the " } ") took WAY more time to figure out than it looks like they should have required, so hopefully my investment of time can help someone else out there. (o:

see it in action at WhiteCoatWork.com and let me know what you think!

cheers n’ blessings,
G