Skip to content

Commit 740a8fe

Browse files
authored
Merge pull request #362 from bcgov/Application-score-fix
Updated code to calculate app score on the basis of total op capacity
2 parents b3cc198 + 1773c7c commit 740a8fe

File tree

3 files changed

+34
-81
lines changed

3 files changed

+34
-81
lines changed

OFM.Infrastructure.WebAPI/Models/ApplicationScore/AppicationScore.cs

Lines changed: 27 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -212,81 +212,33 @@ public static class DataverseQueries
212212

213213

214214
//Total Operational Spaces
215-
public const string TotalOperationSpaces = @$"ofm_licence_details?fetchXml=
216-
<fetch aggregate=""true"">
217-
<entity name=""ofm_licence_detail"">
218-
<attribute name=""ofm_operational_spaces"" alias=""TotalSpaces"" aggregate=""sum"" />
219-
<filter>
220-
<condition attribute=""statecode"" operator=""eq"" value=""0"" />
221-
<condition attribute=""ofm_licence_type"" operator=""in"">
222-
<value>1</value>
223-
<value>2</value>
224-
<value>4</value>
225-
<value>5</value>
226-
<value>6</value>
227-
<value>12</value>
228-
<value>3</value>
229-
<value>7</value>
230-
<value>8</value>
231-
<value>9</value>
232-
<value>10</value>
233-
<value>11</value>
234-
<value>12</value>
235-
</condition>
236-
</filter>
237-
<link-entity name=""ofm_licence"" from=""ofm_licenceid"" to=""ofm_licence"" alias=""f"">
238-
<filter>
239-
<condition attribute=""ofm_facility"" operator=""eq"" value=""{{0}}"" />
240-
<condition attribute=""statecode"" operator=""eq"" value=""0"" />
241-
<filter type=""or"">
242-
<filter type=""and"">
243-
<condition attribute=""ofm_start_date"" operator=""on-or-before"" value=""{{1}}"" />
244-
<condition attribute=""ofm_end_date"" operator=""null"" />
245-
</filter>
246-
<filter type=""and"">
247-
<condition attribute=""ofm_start_date"" operator=""on-or-before"" value=""{{1}}"" />
248-
<condition attribute=""ofm_end_date"" operator=""on-or-after"" value=""{{1}}"" />
249-
</filter>
250-
</filter>
251-
</filter>
252-
</link-entity>
253-
</entity>
254-
</fetch>
255-
";
215+
public const string TotalOperationSpaces = @$"ofm_applications?fetchXml=
216+
<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
217+
<entity name=""ofm_application"">
218+
<attribute name=""ofm_applicationid"" />
219+
<attribute name=""ofm_application"" />
220+
<attribute name=""createdon"" />
221+
<attribute name=""ofm_total_operational_spaces"" alias=""TotalSpaces"" />
222+
<order attribute=""ofm_application"" descending=""false"" />
223+
<filter type=""and"">
224+
<condition attribute=""ofm_applicationid"" operator=""eq"" uitype=""ofm_application"" value=""{{0}}"" />
225+
</filter>
226+
</entity>
227+
</fetch>";
256228
////0-5 Age Group Childcare Category Operational Spaces
257-
public const string MaxChildSpaces = @$"ofm_licence_details?fetchXml=
258-
<fetch aggregate=""true"">
259-
<entity name=""ofm_licence_detail"">
260-
<attribute name=""ofm_operational_spaces"" alias=""MaxSpaces"" aggregate=""sum"" />
261-
<filter>
262-
<condition attribute=""statecode"" operator=""eq"" value=""0"" />
263-
<condition attribute=""ofm_licence_type"" operator=""in"">
264-
<value>1</value>
265-
<value>2</value>
266-
<value>4</value>
267-
<value>5</value>
268-
<value>6</value>
269-
<value>12</value>
270-
</condition>
271-
</filter>
272-
<link-entity name=""ofm_licence"" from=""ofm_licenceid"" to=""ofm_licence"" alias=""f"">
273-
<filter>
274-
<condition attribute=""ofm_facility"" operator=""eq"" value=""{{0}}"" />
275-
<condition attribute=""statecode"" operator=""eq"" value=""0"" />
276-
<filter type=""or"">
277-
<filter type=""and"">
278-
<condition attribute=""ofm_start_date"" operator=""on-or-before"" value=""{{1}}"" />
279-
<condition attribute=""ofm_end_date"" operator=""null"" />
280-
</filter>
281-
<filter type=""and"">
282-
<condition attribute=""ofm_start_date"" operator=""on-or-before"" value=""{{1}}"" />
283-
<condition attribute=""ofm_end_date"" operator=""on-or-after"" value=""{{1}}"" />
284-
</filter>
285-
</filter>
286-
</filter>
287-
</link-entity>
288-
</entity>
289-
</fetch>";
229+
public const string MaxChildSpaces = @$"ofm_applications?fetchXml=
230+
<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
231+
<entity name=""ofm_application"">
232+
<attribute name=""ofm_applicationid"" />
233+
<attribute name=""ofm_preschool_4_hours_op"" />
234+
<attribute name=""ofm_group_child_care_30_months_school_age_op"" />
235+
<attribute name=""ofm_group_child_care_under_36_months_op"" />
236+
<order attribute=""ofm_application"" descending=""false"" />
237+
<filter type=""and"">
238+
<condition attribute=""ofm_applicationid"" operator=""eq"" uitype=""ofm_application"" value=""{{0}}"" />
239+
</filter>
240+
</entity>
241+
</fetch>";
290242

291243
public static string AllSchoolDistrictQuery = $@"ofm_school_districts?$select=ofm_school_district_fullname,ofm_school_district_number,ofm_school_district_name,ofm_postal_code,ofm_name&$filter=statecode eq 0 and _ofm_application_score_calculator_value eq '{{0}}'";
292244
public static string AllScoreCategoryQuery = "ofm_application_score_categories?$filter=_ofm_application_score_calculator_value eq '{0}'&$select=ofm_name,ofm_maximum_score,ofm_description,ofm_category_display_name,ofm_application_score_group";
@@ -447,7 +399,7 @@ public LicenseSpaces(JsonObject data)
447399
{
448400
_data = data ?? throw new ArgumentNullException(nameof(data));
449401
}
450-
public decimal? MaxPreSchoolChildCareSpaces => _data.GetPropertyValue<decimal>("MaxSpaces");
402+
public decimal? MaxPreSchoolChildCareSpaces => _data.GetPropertyValue<decimal>("ofm_group_child_care_under_36_months_op") + _data.GetPropertyValue<decimal>("ofm_preschool_4_hours_op") + _data.GetPropertyValue<decimal>("ofm_group_child_care_30_months_school_age_op");
451403
public decimal? TotalChildCareSpaces => _data.GetPropertyValue<decimal>("TotalSpaces");
452404

453405
}

OFM.Infrastructure.WebAPI/Services/Processes/ApplicationScore/DataverseRepository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface IDataverseRepository
4848
/// <param name="facilityId">GUID of the facility</param>
4949
/// <param name="submittedOn">Application submitted date</param>
5050
/// <returns></returns>
51-
Task<LicenseSpaces> GetLicenseDataAsync(Guid facilityId, DateTime? submittedOn);
51+
Task<LicenseSpaces> GetLicenseDataAsync(Guid applicationId);
5252
/// <summary>
5353
/// Get the ACCB data
5454
/// </summary>
@@ -208,21 +208,22 @@ public async Task<Facility> GetFacilityDataAsync(Guid facilityId)
208208
return new Facility(json["value"]?.AsArray()?.First()?.AsObject());
209209
}
210210

211-
public async Task<LicenseSpaces?> GetLicenseDataAsync(Guid facilityId, DateTime? submittedOn)
211+
public async Task<LicenseSpaces?> GetLicenseDataAsync(Guid applicationId)
212212
{
213213

214214
var output = new JsonObject();
215215
var outputObjects = new List<JsonObject>();
216216
List<Task<HttpResponseMessage>> taks = new List<Task<HttpResponseMessage>>();
217-
taks.Add(d365WebApiService.SendRetrieveRequestAsync(appUserService.AZSystemAppUser, $"{string.Format(DataverseQueries.TotalOperationSpaces, facilityId, submittedOn)}"));
218-
taks.Add(d365WebApiService.SendRetrieveRequestAsync(appUserService.AZSystemAppUser, $"{string.Format(DataverseQueries.MaxChildSpaces, facilityId, submittedOn)}"));
217+
218+
taks.Add(d365WebApiService.SendRetrieveRequestAsync(appUserService.AZSystemAppUser, $"{string.Format(DataverseQueries.TotalOperationSpaces,applicationId)}"));
219+
taks.Add(d365WebApiService.SendRetrieveRequestAsync(appUserService.AZSystemAppUser, $"{string.Format(DataverseQueries.MaxChildSpaces, applicationId)}"));
219220
var responses = await Task.WhenAll(taks.ToArray());
220221
responses.ToList().ForEach(async r =>
221222
{
222223
if (!r.IsSuccessStatusCode)
223224
{
224225
var responseBody = await r.Content.ReadAsStringAsync();
225-
throw new Exception($"GetLicenseDataAsync(Guid {facilityId}, DateTime? {submittedOn}):HTTP Failure: {responseBody}");
226+
throw new Exception($"GetLicenseDataAsync(Guid {applicationId}):HTTP Failure: {responseBody}");
226227
}
227228
var json = await r.Content.ReadFromJsonAsync<JsonObject>();
228229
outputObjects.Add(json["value"].AsArray().First().AsObject());

OFM.Infrastructure.WebAPI/Services/Processes/ApplicationScore/P800ScoreCalculatorProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private IComparisonHandler comparisonChain
100100
if (!scoreParameters.Any()) return (applicationId, false, "No score parameters found.");
101101
var facilityData = await dataverseRepository.GetFacilityDataAsync(facilityId);
102102
if (facilityData == null) { return (applicationId, false, $"ofm_application with Id = {applicationId} is missing a facility"); }
103-
var licenseData = await dataverseRepository.GetLicenseDataAsync(facilityId, application.SubmittedOn);
103+
var licenseData = await dataverseRepository.GetLicenseDataAsync(applicationId);
104104
var incomeData = await dataverseRepository.GetIncomeDataAsync(facilityData.PostalCode, calculatorId);
105105
var feeData = await dataverseRepository.GetFeeDataAsync(facilityId);
106106
var thresholdData = await dataverseRepository.GetThresholdDataAsync(calculatorId);

0 commit comments

Comments
 (0)