Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The rules for the Formal Sector can be complex and evolving. Therefore, the "Formal Sector" solution should bring flexibility, to avoid complete redesign and databases change when a parameter to define the contribution value is changed.
To bring that flexibility, the solution described here uses a Calculation Rule (the Calculation Rules are defined in additional openIMIS modules extending the Calculation Module). This module is defining a framework to design calculations and to manage their activation and versioning in openIMIS. This solution will deliver a Calculation Module that takes the income (on the level of the Contract’s insuree) and a rate (on the level of the Contribution Plan) as parameters, make the calculation and updates the payment value of the Contract’s insuree.

This module will have two way of working, either listening to event or/and proactively checking for calculation; the later approach is to improve performance when at least one calculation rule is expected (no additional database access, no concurent access to database …)
The value of the parameters will be saved as a JSON string in the json_ext field.
Later, this module could be used as a framework to create event-based actions or plug additional calculation to existing process.

Business process

This module will use a "generic contribution" to get the required parameters and the json_ext database field will be used to save the parameters (generic backend feature). Finally, a signal will trigger the calculation action. 

Plantumlcloud
filenameprocess.png
datazVbbattAEP0aUechoNrpBxglBT8UAsbQPpXV7sjeeLW77MWOzVbbjtowEP0aVHhYicL2AxBsJR4qrYSQ2qfK2AN4cezIF9j8fcfj3CDJbqlWq0oRcuK5nDlnxmb0OHWeWR8yNZouGPfGjmZTemYbfoQMcL0QmdT4AZfM4Q9nHdsn7S3kVrpov1RgTy174GgP2ktfJGuTg17/r4zK8mWYilN6UMLxoyluZw5Z2Zw9pD7wFyItcryNePBuGyZp89yyw9QA9prUUuND9BkHr84uWG/F90sGBddKTf6HAHQfwbW+wNEfdJChab2NBb35ttnir8oZHUCL9kUfYWQF8zEl48eJkJJC8LN3Jlp88giV1IQnHCChVjwqFqTRVDeBb98UCMHJMnavnhXTmAa7XOb399nqqQe0WqdiXu71NXaU1UWVChpypJrjzJYyIN9qBF2qg8jNzDsM+ovhWbK6D3aZxkOl2TWGRF5oODUngUnjUAsqfwQTdmh8ewEvO8VOPyy664HOwJuT4ZQV7qSMefwRCrXhQzEujY14Cn3aWCMHKXSi3nhXTGAarnE0fHkbz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LT32XLAAX2KI3CjJi5a2j1Nc4H/CPw==
width
compressedtrue
revision57

Use cases

UC14-1: add a new Calculation rule (needs to change the openimis.json).
UC14-2: use the frontend contribution to select a calculation rule.
UC14-3: use the fronend contribution to display the parameters required by multiple calculation for an object.
UC14-4: replace a calculation rule.
UC14-5: remove a calculation rule.

...

  • UUID (char(24) )

  • CalculationClassName(varchar)

  • Status (int)

  • Description (varchar)

  • Version (int)

  • Json_ext (json)

  • DateCreated(date)

  • DateUpdate(date)

  • UserUpdateUUID(fk users)

  • UserCreateUUID (fk users)

  • DateValidFrom (date)

  • DateValidTo (date)

  • Priority (int)

sub table CalculationRulesDetails

...

The backend management code will be used to register the calculation sub-module parameters, the sub-module status and the ReadUpdate right management on the database.
This code should have a function to clean the table from the remove calculation
This code should manage the uniqueness of the active version for a given UUID

...

runCalculation(object obj, string context, bool stopAtFirst)

This function will be used to look for a suitable calculation for the object provided,

this function will look in all active calculation (highest priority first) to check if the object is part of a “main class“ (See member objects). if the object is from a “main class“ then it will execute the activeForObject(obj, context) to see if the calculation concerns this instance.

In case the stopAtFirst is “true” then once a calculation is valid for the object instance then it will stop looking for other calcualtions

absCalculationRule class

The calculation module will be composed of an abstract class "absCalculation" that will have those methods and members.
This class should be imported as a module in the subclass definition (inside the "hat" modules)

...

This method makes sure the calculation is registered in the calculation table (if not the line should be added with "inactive status") and register the signals only if it is active

activeForObject(object, context)

this method will contains the checks if the calculation need to be executed for the object on that context. the default context will be:

  • create

  • update

  • delete

  • submit

  • amend

  • replace

  • check

  • validate

This function is required because the same class can have different calculation based on the object members values (like product ….)

calculateEvent(sender, **kwargs)
  • This method runs the calculation based on the object sending the signal, this means that the relationship with the other item required for the calculation could be found from the object sending the signal. (e.g., link to the product can be found in the policy as foreign key.)

  • This function should call first the activeForObject method, the context will depend on the calling event, if the fuction return true the calcuation needs to be run, in other case the even handling will stop

  • the calculate(*args) function

  • Signal need to be set up on the ready function to call it

calculateUUID(*UUID)

Function that fetches the args from the UUID [order specific ?] then run the calculate(*args) function.

...

Return the data contained on the JSON so the frontend can ask the parameters for a new object of the ClassName.

Events

ContributionPlanUpdated -

Calculations Frontend Module

...