From 36c2a1fa71d4633fe51755002557a2d9e415e311 Mon Sep 17 00:00:00 2001 From: Pallvi Grover Date: Thu, 28 Nov 2024 16:48:50 -0800 Subject: [PATCH] Funding validations --- .../OFM.Infrastructure.WebAPI.xml | 181 ++++++++++++++++++ .../Processes/Fundings/FundingCalculator.cs | 6 +- .../Processes/Fundings/IFundingValidator.cs | 120 ++++++++++++ 3 files changed, 306 insertions(+), 1 deletion(-) diff --git a/OFM.Infrastructure.WebAPI/OFM.Infrastructure.WebAPI.xml b/OFM.Infrastructure.WebAPI/OFM.Infrastructure.WebAPI.xml index ae4ab09..8b0c959 100644 --- a/OFM.Infrastructure.WebAPI/OFM.Infrastructure.WebAPI.xml +++ b/OFM.Infrastructure.WebAPI/OFM.Infrastructure.WebAPI.xml @@ -763,6 +763,11 @@ Gets a binding to the set of all entities. + + + Gets a binding to the set of all entities. + + Gets a binding to the set of all entities. @@ -12532,6 +12537,162 @@ LINQ anonymous type. + + + MyCCS Statutory Holiday Record + + + + + Available fields, a the time of codegen, for the ofm_stat_holiday entity + + + + + Default Constructor. + + + + + Unique identifier of the user who created the record. + + + + + Date and time when the record was created. + + + + + Unique identifier of the delegate user who created the record. + + + + + Sequence number of the import that created this record. + + + + + Unique identifier of the user who modified the record. + + + + + Date and time when the record was modified. + + + + + Unique identifier of the delegate user who modified the record. + + + + + MyCCS Statutory Holiday record + + + + + Date Observed (if holiday falls on weekend) + + + + + Stat Day + + + + + Type + + + + + Holiday Name + + + + + Selected Year + + + + + Unique identifier for entity instances + + + + + Date and time that the record was migrated. + + + + + Owner Id + + + + + Name of the owner + + + + + Yomi name of the owner + + + + + Unique identifier for the business unit that owns the record + + + + + Unique identifier for the team that owns the record. + + + + + Unique identifier for the user that owns the record. + + + + + Status of the Statutory Holiday + + + + + Reason for the status of the Statutory Holiday + + + + + For internal use only. + + + + + Time zone code that was in use when the record was created. + + + + + Version Number + + + + + N:1 team_ofm_stat_holiday + + + + + Constructor for populating via LINQ queries given a LINQ anonymous type + LINQ anonymous type. + + Available fields, a the time of codegen, for the ofm_subcategory entity @@ -13910,6 +14071,11 @@ 1:N team_ofm_standing_history + + + 1:N team_ofm_stat_holiday + + 1:N team_ofm_subcategory @@ -15318,6 +15484,11 @@ Health Authorities + + + Holiday Type + + Inclusion Policies @@ -17928,6 +18099,16 @@ Reason for the status of the Standing History + + + Status of the Statutory Holiday + + + + + Reason for the status of the Statutory Holiday + + Status of the Sub-Category diff --git a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs index 75fe74f..2204134 100644 --- a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs +++ b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs @@ -209,7 +209,11 @@ public async Task CalculateAsync() .NextValidator(new MustHaveValidApplicationStatusRule()) .NextValidator(new MustHaveValidOwnershipTypeRule()) .NextValidator(new MustHaveValidLicenceRule()) - .NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule()); + .NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule()) + .NextValidator(new MustHaveAtLeastOneOperationalSpaceRule()) + .NextValidator(new MustHaveWeeksInOperationRule()) + .NextValidator(new MustHaveHoursOfOperationRule()) + .NextValidator(new MustHaveDaysOfWeekRule()); try { fundingRules.Validate(_funding); diff --git a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs index ed66927..e06c139 100644 --- a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs +++ b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs @@ -202,6 +202,126 @@ public bool Validate(Funding funding) return true; } + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveAtLeastOneOperationalSpaceRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var operationalSpaces = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && (licDetail.ofm_operational_spaces + < 1 || licDetail.ofm_operational_spaces == null)).Count(); + + if (operationalSpaces > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Operational Spaces.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveWeeksInOperationRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var weeksInOperation = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && (licDetail.ofm_weeks_in_operation + < 1 || licDetail.ofm_weeks_in_operation == null)).Count(); + + if (weeksInOperation > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Weeks in Operation.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveHoursOfOperationRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var operationHoursFrom = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_from + == null).Count(); + var operationHoursTo = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_to + == null).Count(); + + if (operationHoursFrom > 0 || operationHoursTo > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Operation Hours.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveDaysOfWeekRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var weekDays = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_week_days + == null).Count(); + + if (weekDays > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Week Days when the ChildCare is operating.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + public IFundingValidator NextValidator(IFundingValidator? next) { _next = next;