@@ -126,41 +126,22 @@ export const subjectSummaryRule = async (rule, entity) => {
126126 return [ ] ;
127127} ;
128128
129- export const isEligibleForEncounter = async ( individual , encounterType ) => {
129+ export const isEligibleForEntityType = async ( individual , entityType , bundleRuleParams ) => {
130130 let eligible = true ;
131- const rulesFromTheBundle = await getAllRuleItemsFor ( encounterType . uuid , "EncounterEligibilityCheck" , "EncounterType" ) ;
132- if ( ! _ . isNil ( encounterType . entityEligibilityCheckRule ) && ! _ . isEmpty ( _ . trim ( encounterType . entityEligibilityCheckRule ) ) ) {
133- const code = removeStrictFromRuleCode ( encounterType . entityEligibilityCheckRule ) ;
131+ const rulesFromTheBundle = await getAllRuleItemsFor ( entityType . uuid , bundleRuleParams . ruleType , entityType ) ;
132+ if ( ! _ . isNil ( entityType . entityEligibilityCheckRule ) && ! _ . isEmpty ( _ . trim ( entityType . entityEligibilityCheckRule ) ) ) {
133+ const code = removeStrictFromRuleCode ( entityType . entityEligibilityCheckRule ) ;
134134 const ruleFunc = eval ( code ) ;
135135 eligible = ruleFunc ( {
136136 params : { entity : individual , services} ,
137137 imports : { rulesConfig, lodash, moment}
138138 } ) ;
139139 } else if ( ! _ . isEmpty ( rulesFromTheBundle ) ) {
140- eligible = runRuleAndSaveFailure ( _ . last ( rulesFromTheBundle ) , 'Encounter' , { individual} , true ) ;
140+ eligible = runRuleAndSaveFailure ( _ . last ( rulesFromTheBundle ) , bundleRuleParams . entityName , { individual} , true ) ;
141141 }
142142 return {
143143 "isEligible" : eligible ,
144- "typeUUID" : encounterType . uuid ,
145- } ;
146- } ;
147-
148- export const isEligibleForProgramEnrolment = async ( individual , program ) => {
149- let eligible = true ;
150- const rulesFromTheBundle = await getAllRuleItemsFor ( program . uuid , "EnrolmentEligibilityCheck" , "Program" ) ;
151- if ( ! _ . isNil ( program . entityEligibilityCheckRule ) && ! _ . isEmpty ( _ . trim ( program . entityEligibilityCheckRule ) ) ) {
152- const code = removeStrictFromRuleCode ( program . entityEligibilityCheckRule ) ;
153- const ruleFunc = eval ( code ) ;
154- eligible = ruleFunc ( {
155- params : { entity : individual , services} ,
156- imports : { rulesConfig, lodash, moment}
157- } ) ;
158- } else if ( ! _ . isEmpty ( rulesFromTheBundle ) ) {
159- eligible = runRuleAndSaveFailure ( _ . last ( rulesFromTheBundle ) , 'Program' , { individual} , true ) ;
160- }
161- return {
162- "isEligible" : eligible ,
163- "typeUUID" : program . uuid ,
144+ "typeUUID" : entityType . uuid ,
164145 } ;
165146} ;
166147
0 commit comments