forked from solid-lines/dhis2-metadata-checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_programIndicators_without_expression.py
31 lines (21 loc) · 1.2 KB
/
check_programIndicators_without_expression.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
31
#!/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 = "programIndicators"
CHILD_RESOURCE = "expression" # 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[id,name]", param_filter="filter="+CHILD_RESOURCE+":null")
#check condition
#check if all programIndicators has a expression
for resource in metadata_resources[PARENT_RESOURCE]:
if CHILD_RESOURCE not in resource:
metadata_url = server_url+PARENT_RESOURCE+"/"+resource["id"]
message = f"In Program '{resource['program']['name']}' ({resource['program']['id']}), the programIndicator '{resource['name']}' ({resource['id']}) has not an expression. See {metadata_url}"
logger.error(message)