From efd24f0f87e08d2e072295704141c5b26e3f1c20 Mon Sep 17 00:00:00 2001 From: Kipchirchir Sigei Date: Fri, 17 Jan 2025 16:04:11 +0100 Subject: [PATCH] Update DHIS geojson with properties Signed-off-by: Kipchirchir Sigei --- afpolgis.py | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/afpolgis.py b/afpolgis.py index 37f25e7..571689b 100644 --- a/afpolgis.py +++ b/afpolgis.py @@ -754,7 +754,7 @@ def fetch_dhis_org_units(self, api_url, username, password): while hasData: params = [ - ("fields", "id,name,children[id,name],dataSets[id,name],geometry"), + ("fields", "id,name,lastUpdated,dimensionItemType,shortName,displayName,children[id,name],dataSets[id,name],geometry"), ("filter", f"level:eq:{cleaned_adm_lvl}"), ("filter", "children:gte:0"), ("page", page), @@ -781,7 +781,13 @@ def fetch_dhis_org_units(self, api_url, username, password): { "type": "Feature", "geometry": geometry, - "properties": {}, + "properties": { + "name": datum.get("name"), + "lastUpdated": datum.get("lastUpdated"), + "dimensionItemType": datum.get("dimensionItemType"), + "shortName": datum.get("shortName"), + "displayName": datum.get("displayName") + }, } ) elif not pager.get("nextPage"): @@ -824,6 +830,7 @@ def fetch_gts_tracking_rounds_data_handler(self): # Disable OK button self.dlg.gtsOkButton.setEnabled(False) + self.dlg.gtsOkButton.repaint() selected_tracking_round = self.dlg.comboGTSTrackingRounds.currentData() @@ -879,18 +886,7 @@ def fetch_gts_tracking_rounds_data_handler(self): ) else: hasData = False - self.dlg.gtsProgressBar.setValue(100) - if ( - feature_collection["features"] - and len(feature_collection["features"]) == 0 - ): - self.dlg.gtsProgressBar.setValue(0) - self.iface.messageBar().pushMessage( - "Notice", - "No Data Found", - level=Qgis.Warning, - duration=15, - ) + self.dlg.gtsProgressBar.setValue(0) self.dlg.gtsOkButton.setEnabled(True) else: hasData = False @@ -899,7 +895,7 @@ def fetch_gts_tracking_rounds_data_handler(self): "Error", f"Error fetching data: {response.status_code}", level=Qgis.Critical, - duration=15, + duration=10, ) self.dlg.gtsOkButton.setEnabled(True) @@ -913,6 +909,18 @@ def fetch_gts_tracking_rounds_data_handler(self): feature_collection, "gts", "_".join(single_round_name.split(" ")) ) self.dlg.gtsProgressBar.setValue(0) + else: + self.dlg.app_logs.appendPlainText(f"No available Geo Data for Selected Tracking Round") + self.iface.messageBar().pushMessage( + "Notice", + f"No available Geo Data for Selected Tracking Round", + level=Qgis.Warning, + duration=10, + ) + self.dlg.gtsOkButton.setEnabled(True) + self.dlg.gtsOkButton.repaint() + + self.dlg.gtsProgressBar.setValue(0) def handle_gts_cancel_btn(self): self.dlg.gtsProgressBar.setValue(0) @@ -1272,6 +1280,10 @@ def fetch_and_save_kobo_data( self.load_data_to_qgis(feature_collection, cleaned_asset_name, geo_field) self.dlg.koboPorgressBar.setValue(0) else: + self.dlg.app_logs.appendPlainText( + "The selected geo field doesn't have geo data" + ) + self.iface.messageBar().pushMessage( "Notice", f"The selected geo field doesn't have geo data", @@ -2236,6 +2248,13 @@ def handle_data_fetched(self, data): self.dlg.app_logs.appendPlainText( "The selected geo field doesn't have geo data" ) + + self.iface.messageBar().pushMessage( + "Notice", + f"The selected geo field doesn't have geo data", + level=Qgis.Warning, + duration=10, + ) if not self.ona_sync_timer.isActive(): self.dlg.onaOkButton.setEnabled(True)