I am working on a project in which we will need to define certain types of statuses for a large number of people stored in a database. The business rules for defining these statuses are quite complex and subject to change.
For instance,
if a person is part of group X and (if they have attribute O) has either attribute P or attribute Q, or (if they don't have attribute O) has attribute P but not Q, and don't have attribute R, and aren't part of group Y (unless they also are part of group Z), then status A is true.
Multiply dozens of statuses and possibly hundreds of groups and attributes. People, groups, and attributes are in the database.
Although this will be consumed by the Java application, we also want to be able to run reports directly with the database, so it would be better if the set of calculated statuses were available at the data level.
Thus, our current design plan should have a table or view consisting of a set of Boolean flags (hasStatusA? HasStatusB? HasStatusC?) For each person. Thus, if I want to ask everyone who has C status, I don’t need to know all the rules for calculating C state; I just check the flag.
(Note that in real life, flags will have more meaningful names: isEligibleForReview ?, isPastDueForReview ?, etc.).
So, a) this is a reasonable approach, and b) if so, what is the best way to compute these flags?
Some parameters that we consider for calculating flags:
Make the flag set a representation and calculate the flag values from the underlying data in real time using SQL or PL-SQL (this is Oracle DB). Thus, the values are always accurate, but performance may suffer, and the rules must be supported by the developer.
Make a set of flags consisting of static data and use the mechanism of some types of rules to update these flags as the underlying data changes. Thus, rules can be supported more easily, but flags may be inaccurate at a given time. (If we go with this approach, is there a rule mechanism that can easily manipulate data in a database this way?)