def get_value_from_url(self, url, group_key, value_key): request = RequestFactory().get(url) view = JsonDataView() view.im.category_option_combos = { "Number Positive, Under 5 years": "PT9vhPUpxc4", "Number Positive, 5 years and above": "Li89EZS6Jss", "Days out of stock": "Avvv8JaSwGR" } view.im.data_elements = { "105-7.3 Lab Malaria RDTs": "fOZ2QUjRSB7", "105-6 Artemether/ Lumefantrine 100/20mg tablet": "IBuhlkMrwqY", } result = json.loads(view.get(request).getvalue()) print result return result[group_key][value_key]
def handle(self, *args, **options): data_set = "Cm5cTKifbLA" period = "201603" dhis2_total = 0 print ">>>> Fetching Data Set Report from DHIS2" report = dhis2_request('dataSetReport.json?ds=%s&pe=%s&ou=akV6429SUqu' % (data_set, period), False) soup = BeautifulSoup(report, 'html.parser') dhis2_inpatient_malaria_deaths = self.get_total("malaria total", soup, [3, 4, 7, 8]) dhis2_malaria_admissions = self.get_total("malaria total", soup, [1, 2, 5, 6]) dhis2_total_inpatient_deaths = self.get_total("(D) Deaths", soup, [19]) print ">>>> Fetching Dashboard Data" url = "path?from_date=201603&to_date=201604&group=period®ion=0&district=0" request = RequestFactory().get(url) view = JsonDataView() result = json.loads(view.get(request).getvalue()) dashboard_inpatient_malaria_deaths = float(result[period]['inpatient_malaria_deaths']) dashboard_malaria_admissions = float(result[period]['malaria_admissions']) dashboard_total_inpatient_deaths = float(result[period]['total_inpatient_deaths']) print "Inpatient Malaria deaths: DHIS2 (%s), Dashboard (%s)" % (dhis2_inpatient_malaria_deaths, dashboard_inpatient_malaria_deaths) print "Malaria Admissions: DHIS2 (%s), Dashboard (%s)" % (dhis2_malaria_admissions, dashboard_malaria_admissions) print "Total Inpatient Deaths: DHIS2 (%s), Dashboard (%s)" % (dhis2_total_inpatient_deaths, dashboard_total_inpatient_deaths) assert dhis2_inpatient_malaria_deaths == dashboard_inpatient_malaria_deaths assert dhis2_malaria_admissions == dashboard_malaria_admissions assert dhis2_total_inpatient_deaths == dashboard_total_inpatient_deaths