Skip to content

Commit 98dac4a

Browse files
authored
Merge pull request #656 from bcgov/ccfri-4568-application-update-facility
CCFRI-4568 - Application Update Facility Info page
2 parents 61bbe94 + fa7b3a9 commit 98dac4a

File tree

8 files changed

+375
-242
lines changed

8 files changed

+375
-242
lines changed

backend/src/components/facility.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ function buildNewFacilityPayload(req) {
3030
function mapFacilityObjectForBack(data) {
3131
const facilityForBack = new MappableObjectForBack(data, FacilityMappings).toJSON();
3232

33-
if (facilityForBack.ccof_facilitystartdate) {
34-
facilityForBack.ccof_facilitystartdate = `${facilityForBack.ccof_facilitystartdate}-01-01`;
35-
}
33+
facilityForBack.ccof_facilitystartdate = facilityForBack.ccof_facilitystartdate ? `${facilityForBack.ccof_facilitystartdate}-01-01` : null;
3634
if (facilityForBack.ccof_licensestartdate) {
3735
facilityForBack.ccof_licensestartdate = facilityForBack.ccof_licensestartdate + 'T12:00:00-07:00';
3836
}
@@ -80,7 +78,7 @@ function mapCCFRIObjectForFront(data) {
8078
}
8179

8280
async function getFacilityByFacilityId(facilityId) {
83-
const operation = `accounts(${facilityId})?$select=ccof_accounttype,name,ccof_facilitystartdate,address1_line1,address1_city,address1_stateorprovince,address1_postalcode,ccof_position,emailaddress1,address1_primarycontactname,telephone1,ccof_facilitylicencenumber,ccof_licensestartdate,ccof_formcomplete,ccof_everreceivedfundingundertheccofprogram,ccof_facilityreceived_ccof_funding,accountnumber,ccof_facilitystatus,ccof_is_facility_address_entered_manually`;
81+
const operation = `accounts(${facilityId})?$select=ccof_accounttype,name,ccof_facilitystartdate,address1_line1,address1_city,address1_stateorprovince,address1_postalcode,ccof_position,emailaddress1,address1_primarycontactname,telephone1,ccof_facilitylicencenumber,ccof_licensestartdate,ccof_formcomplete,ccof_everreceivedfundingundertheccofprogram,ccof_facilityreceived_ccof_funding,accountnumber,ccof_facilitystatus,ccof_is_facility_address_entered_manually,ccof_is_facility_address_same_as_org,ccof_is_facility_contact_same_as_org,ccof_healthauthority`;
8482
const facility = await getOperation(operation);
8583

8684
if (ACCOUNT_TYPE.FACILITY != facility?.ccof_accounttype) {

backend/src/components/lookup.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const cache = require('memory-cache');
66
const { PROGRAM_YEAR_STATUS_CODES, ORGANIZATION_PROVIDER_TYPES, CHANGE_REQUEST_TYPES } = require('../util/constants');
77
const { ProgramYearMappings, SystemMessagesMappings } = require('../util/mapping/Mappings');
88
const { MappableObjectForFront } = require('../util/mapping/MappableObject');
9+
const log = require('./logger');
910

1011
const lookupCache = new cache.Cache();
12+
const ONE_HOUR_MS = 60 * 60 * 1000; // Cache timeout set for one hour
1113

1214
const organizationType = [
1315
{
@@ -75,7 +77,7 @@ async function getLicenseCategory() {
7577
.sort((a, b) => {
7678
return a.ccof_categorynumber - b.ccof_categorynumber;
7779
});
78-
lookupCache.put('licenseCategory', resData, 60 * 60 * 1000);
80+
lookupCache.put('licenseCategory', resData, ONE_HOUR_MS);
7981
}
8082
return resData;
8183
}
@@ -137,7 +139,7 @@ async function getLookupInfo(req, res) {
137139
return _.pick(item, ['ccof_childcarecategorynumber', 'ccof_name', 'ccof_description', 'ccof_childcare_categoryid']);
138140
});
139141

140-
const licenseCategory = await getLicenseCategory();
142+
const [licenseCategory, healthAuthorities] = await Promise.all([getLicenseCategory(), getGlobalOptionsData('ccof_healthauthority')]);
141143
resData = {
142144
programYear: programYears,
143145
childCareCategory: childCareCategory,
@@ -146,8 +148,9 @@ async function getLookupInfo(req, res) {
146148
groupLicenseCategory: licenseCategory.groupLicenseCategory,
147149
familyLicenseCategory: licenseCategory.familyLicenseCategory,
148150
'changeRequestTypes:': CHANGE_REQUEST_TYPES,
151+
healthAuthorities: healthAuthorities,
149152
};
150-
lookupCache.put('lookups', resData, 60 * 60 * 1000);
153+
lookupCache.put('lookups', resData, ONE_HOUR_MS);
151154
}
152155
return res.status(HttpStatus.OK).json(resData);
153156
}
@@ -159,11 +162,25 @@ async function getSystemMessages(req, res) {
159162
systemMessages = [];
160163
const resData = await getOperation(`ccof_systemmessages?$filter=(ccof_startdate le ${currentTime} and ccof_enddate ge ${currentTime})`);
161164
resData?.value.forEach((message) => systemMessages.push(new MappableObjectForFront(message, SystemMessagesMappings).data));
162-
lookupCache.put('systemMessages', systemMessages, 60 * 60 * 1000);
165+
lookupCache.put('systemMessages', systemMessages, ONE_HOUR_MS);
163166
}
164167
return res.status(HttpStatus.OK).json(systemMessages);
165168
}
166169

170+
async function getGlobalOptionsData(operationName) {
171+
try {
172+
const response = await getOperation(`GlobalOptionSetDefinitions(Name='${operationName}')`);
173+
const data =
174+
response?.Options?.map((item) => ({
175+
id: Number(item.Value),
176+
description: item.Label?.LocalizedLabels?.[0]?.Label ?? null,
177+
})) || [];
178+
return data;
179+
} catch (error) {
180+
log.error(`Error getting global options data for ${operationName}:`, error);
181+
}
182+
}
183+
167184
module.exports = {
168185
getLookupInfo,
169186
getLicenseCategory,

backend/src/util/mapping/Mappings.js

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ const FacilityMappings = [
4242
{ back: 'accountnumber', front: 'facilityAccountNumber' },
4343
{ back: '_ccof_change_request_value', front: 'changeRequestId' }, //likely won't stay here
4444
{ back: 'ccof_is_facility_address_entered_manually', front: 'isFacilityAddressEnteredManually' },
45+
{ back: 'ccof_is_facility_address_same_as_org', front: 'isFacilityAddressSameAsOrgStreetAddress' },
46+
{ back: 'ccof_is_facility_contact_same_as_org', front: 'isFacilityContactSameAsOrgContact' },
47+
{ back: 'ccof_healthauthority', front: 'healthAuthority' },
4548
];
4649

4750
const CCFRIFacilityMappings = [

0 commit comments

Comments
 (0)