In my TypeScript class, I have a method that retrieves a list of organizations and their roles. The method looks like this:
getOrgList(oo: fhir.Organization) {
var olist: orgRoles[] = [];
var filtered = oo.extension.filter(this.getRoleExt);
filtered.forEach(function (value) {
var org = new orgRoles();
value.extension.forEach(function (innerValue) {
switch (innerValue.url) {
case 'role':
org.roleName = innerValue.valueCoding.display;
break;
case 'primaryRole':
org.primaryRole = innerValue.valueBoolean;
break;
case 'activePeriod':
var periodType = innerValue.valuePeriod.extension[0].valueString;
var periodExt = innerValue.valuePeriod;
var periodDisplay= this.getPeriodDisplay(periodExt);
break;
case 'status':
org.activeStatus = innerValue.valueString;
break;
}
});
olist.push(org);
});
return olist;
}
The issue I am facing is an error that occurs on this line:
var periodDisplay= this.getPeriodDisplay(periodExt);
The error message reads:
ERROR TypeError: Cannot read property 'getPeriodDisplay' of undefined
Interestingly, the getPeriodDisplay method is indeed defined in the same class as follows:
getPeriodDisplay(pp) {
return "++++";
}
While I am able to call getPeriodDisplay from other parts of the code, it seems to cause a problem when called from within a different method of the same class.
Any suggestions on how to resolve this issue?