forked from solid-lines/dhis2-metadata-checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_de_ps_pss.py
39 lines (27 loc) · 1.71 KB
/
check_de_ps_pss.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
32
33
34
35
36
37
38
39
#!/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"]
############################################################################
PROGRAM_STAGES = "programStages"
metadata_resources = utils.get_resources_from_online(credentials=credentials, resource_type=PROGRAM_STAGES, fields="name,id,program[id,name],programStageDataElements[dataElement],programStageSections[dataElements]", param_filter="filter=formType:eq:SECTION&filter=program:!null")
programs_data = {}
for programStage in metadata_resources[PROGRAM_STAGES]:
program_uid = programStage["program"]["id"]
program_name = programStage["program"]["name"]
programStage_uid = programStage["id"]
programStage_name = programStage["name"]
programStageDataElements = [x["dataElement"]["id"] for x in programStage["programStageDataElements"]]
programStageSectionsDE = list()
for pss in programStage["programStageSections"]:
programStageSectionsDE = programStageSectionsDE + [x["id"] for x in pss["dataElements"]]
a = set(programStageDataElements)
b = set(programStageSectionsDE)
url_ui = utils.get_url_maintenance(server_url, "programs", program_uid)
if a != b:
logger.warning(f"The DE assigned to this Program Stage is not included in the program Stage Section. Check the programStage '{programStage_name}' ({programStage_uid}) of the program '{program_name}' ({program_uid}). See {url_ui}")