forked from solid-lines/dhis2-metadata-checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_programRules_without_programRuleActions.py
30 lines (21 loc) · 1.23 KB
/
check_programRules_without_programRuleActions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import utils
import os
if __name__ == "__main__":
credentials = utils.get_credentials()
check_name = os.path.basename(__file__).replace(".py", "")
logger = utils.get_logger(credentials, check_name)
server_url = credentials["server"]
############################################################################
PARENT_RESOURCE = "programRules"
CHILD_RESOURCE = "programRuleActions" # Watch out singular and plural.
#retrieve all metadata_resources
metadata_resources = utils.get_resources_from_online(credentials=credentials, resource_type=PARENT_RESOURCE, fields="id,name,program[name,id]", param_filter="filter="+CHILD_RESOURCE+":empty")
#check condition
#check if all programStageSections are associated to a programStage
for resource in metadata_resources[PARENT_RESOURCE]:
if (not CHILD_RESOURCE in resource):
metadata_url = server_url+PARENT_RESOURCE+"/"+resource["id"]
message = f"In Program '{resource['program']['name']}' ({resource['program']['id']}), the Program Rule '{resource['name']}' ({resource['id']}) has not Program Rule Actions associated. See {metadata_url}"
logger.error(message)