openIMIS Backend calcrule_validations reference module
How we can configure strategy for validation?
- The schema within the
Benefit Plan/Programmeentity holds a crucial role in this process. - For instance,
validationCalculationin the schema triggers a specific validation strategy. Similarly, in the duplications section of the schema, settinguniqueness: truesignifies the need for duplication checks based on the record's field value. - Based on the provided schema below (from
programme/benefit plan), it indicates that validations will run for theemailfield (validationCalculation), and duplication checks will be performed fornational_id(uniqueness: true)
{
"$id":"https://example.com/beneficiares.schema.json",
"type":"object",
"title":"Record of beneficiares",
"$schema":"http://json-schema.org/draft-04/schema#",
"properties":{
"email":{
"type":"string",
"description":"email address to contact with beneficiary",
"validationCalculation":{
"name":"EmailValidationStrategy"
}
},
"able_bodied":{
"type":"boolean",
"description":"Flag determining whether someone is able bodied or not"
},
"national_id":{
"type":"string",
"uniqueness":true,
"description":"national id"
},
"educated_level":{
"type":"string",
"description":"The level of person when it comes to the school/education/studies"
},
"chronic_illness":{
"type":"boolean",
"description":"Flag determining whether someone has such kind of illness or not"
},
"national_id_type":{
"type":"string",
"description":"A type of national id"
},
"number_of_elderly":{
"type":"integer",
"description":"Number of elderly"
},
"number_of_children":{
"type":"integer",
"description":"Number of children"
},
"beneficiary_data_source":{
"type":"string",
"description":"The source from where such beneficiary comes"
}
},
"description":"This document records the details beneficiares"
}
- In essence, to create a custom validation rule applicable to a schema field,
you'll need to define a class in python file within the
strategiesfolder (The filename should conclude with_validation_strategy.py). - The example of validation class implementation:
from dataclasses import asdict
from calcrule_validations.strategies.base_strategy import BaseValidationsStrategy
from calcrule_validations.strategies.validation_strategy_interface import ValidationResult
class YourCustomValidationStrategy(BaseValidationsStrategy):
VALIDATION_CLASS = "YourCustomValidationStrategy"
@classmethod
def validate(cls, field_name, field_value, **kwargs):
return asdict(ValidationResult(
success=False,
field_name=field_name,
note="<YOUR VALIDATION NOTE>"
))
- The
VALIDATION_CLASSproperty plays a significant role in defining the value for thevalidationCalculation: nameproperty within the JSON schema of the schema for theBenefit Plan/Programmeentity. - The validation implementation needs to be executed within the
validatemethod. It's expected to return aValidationResultas a dictionary structured as follows:
return asdict(ValidationResult(
success=False,
field_name=field_name,
note="<YOUR VALIDATION NOTE>"
))
- For a valid condition, the expected return should resemble the following:
return asdict(ValidationResult(
success=True,
field_name=field_name,
note="Ok"
))
- The signature of
validatemethod isdef validate(cls, field_name, field_value, **kwargs)
Metadata
Release files for openimis-be-calcrule-validations 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openimis_be_calcrule_validations-1.2.0.tar.gz | 9.2 kB | Without provenance | Details for openimis_be_calcrule_validations-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openimis_be_calcrule_validations-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for openimis_be_calcrule_validations-1.2.0-py3-none-any.whl |
Total release size: 22.6 kB
Release files / openimis_be_calcrule_validations-1.2.0.tar.gz
| Download URL | openimis_be_calcrule_validations-1.2.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86ca86a70c8af76f6d9ae1bdaef8d9f62a4ba0f4b54e94b223ec5c5c570406b1
|
|
BLAKE2b-256 checksum How to use checksums |
a48ebde9bfaaf0f8226216e9756394d20d8eca2bd5488e537e6ebe5acd75c1d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / openimis_be_calcrule_validations-1.2.0-py3-none-any.whl
| Download URL | openimis_be_calcrule_validations-1.2.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
626bedd2f1c60a3a9a61f57ebe2de481e0cb7d71b1baaf63394c3dccb5219485
|
|
BLAKE2b-256 checksum How to use checksums |
f0d0ba8d1407d012f8cc4f957e989224a3db41347691b1854b9e30b17b4c1eb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for openimis-be-calcrule-validations 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.