-
Notifications
You must be signed in to change notification settings - Fork 141
WHO_TuberculosisBacteriologicallyConfirmedPercentage #1939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shvngisingh
wants to merge
11
commits into
datacommonsorg:master
Choose a base branch
from
shvngisingh:tuberculosis_percentage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
034f892
tuberculosis_percentage
shvngisingh 46594cf
input_file name change
shvngisingh d0e525b
updated the pvmap
shvngisingh 176f26a
new files generated as per new pvmap
shvngisingh a791cdc
Update tuberculosisPercentage_input.csv
shvngisingh 99ebc22
Update tuberculosisPercentage_output.csv
shvngisingh 74573a3
Update manifest.json
shvngisingh 9e0ab50
Update tuberculosisPercentage_output.csv
shvngisingh 6fc5e72
Update manifest.json
shvngisingh cdc8a48
Update README.md
shvngisingh 2bb7804
Update README.md
shvngisingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # WHO Tuberculosis Percentage Dataset | ||
| ## Overview | ||
| This dataset provides the percentage of people diagnosed with a new episode of pulmonary TB whose disease was bacteriologically confirmed, sourced from the World Health Organization (WHO) Global Tuberculosis Programme. | ||
|
|
||
| ## Data Source | ||
|
|
||
| **Source URL:** | ||
| https://data.who.int/indicators/i/1891124/449F55C | ||
|
|
||
| The data is fetched from the WHO's official Global Tuberculosis Database via their public API. | ||
|
|
||
| ## How To Download Input Data | ||
| To download the latest data, use the provided download script `download_who_tuberculosis.py`. This script fetches the data from the WHO API and merges it with country ISO3 codes to generate `tuberculosisPercentage_input.csv`. | ||
|
|
||
| **Type of place:** Country. | ||
|
|
||
| **Statvars:** Tuberculosis - Bacteriologically Confirmed Percentage. | ||
|
|
||
| **Years:** 1999 to 2024. | ||
|
|
||
| ## Processing Instructions | ||
| To process the Tuberculosis data and generate statistical variables, use the following commands from the project's root `data` directory: | ||
|
|
||
| **Download input file** | ||
| ```bash | ||
| python3 statvar_imports/tuberculosis_percentage/download_who_tuberculosis.py | ||
| ``` | ||
|
|
||
| **For Test Data Run** | ||
| ```bash | ||
| python3 tools/statvar_importer/stat_var_processor.py \ | ||
| --input_data=statvar_imports/tuberculosis_percentage/test_data/tuberculosisPercentage_input.csv \ | ||
| --pv_map=statvar_imports/tuberculosis_percentage/test_data/tuberculosisPercentage_pvmap.csv \ | ||
| --output_path=statvar_imports/tuberculosis_percentage/test_data/tuberculosisPercentage_output \ | ||
| --config_file=statvar_imports/tuberculosis_percentage/test_data/tuberculosisPercentage_metadata.csv \ | ||
| --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf | ||
| ``` | ||
|
|
||
| **For Main data run** | ||
| ```bash | ||
| python3 tools/statvar_importer/stat_var_processor.py \ | ||
| --input_data=statvar_imports/tuberculosis_percentage/source_files/tuberculosisPercentage_input.csv \ | ||
| --pv_map=statvar_imports/tuberculosis_percentage/tuberculosisPercentage_pvmap.csv \ | ||
| --output_path=statvar_imports/tuberculosis_percentage/tuberculosisPercentage_output \ | ||
| --config_file=statvar_imports/tuberculosis_percentage/tuberculosisPercentage_metadata.csv \ | ||
| --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf | ||
| ``` |
58 changes: 58 additions & 0 deletions
58
statvar_imports/tuberculosis_percentage/download_who_tuberculosis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import os | ||
| import requests | ||
| import io | ||
| import pandas as pd | ||
|
|
||
| def download_tb_percentage_data(): | ||
| # 1. Get the Clean Data from the API using the new Indicator ID | ||
| api_url = "https://xmart-api-public.who.int/DATA_/RELAY_TB_DATA" | ||
| params = { | ||
| "$filter": "IND_ID eq '1891124449F55C'", | ||
| "$select": "IND_ID,INDICATOR_NAME,YEAR,COUNTRY,VALUE", | ||
| "$format": "csv" | ||
| } | ||
|
|
||
| print("1. Fetching clean percentage data from WHO API...") | ||
| api_response = requests.get(api_url, params=params) | ||
|
|
||
| if api_response.status_code != 200: | ||
| print(f"Failed to fetch API data. HTTP {api_response.status_code}") | ||
| return | ||
|
|
||
| # Load the clean API data into a pandas table | ||
| api_df = pd.read_csv(io.StringIO(api_response.text)) | ||
|
|
||
| # 2. Get ONLY the iso3 code from the master database | ||
| print("2. Fetching country iso3 codes from WHO master database...") | ||
| master_url = "https://extranet.who.int/tme/generateCSV.asp?ds=notifications" | ||
|
|
||
| # We only pull the 'country' (for matching) and 'iso3' columns | ||
| geo_columns = ['country', 'iso3'] | ||
| master_df = pd.read_csv(master_url, usecols=geo_columns).drop_duplicates() | ||
|
shvngisingh marked this conversation as resolved.
|
||
|
|
||
| # 3. Merge the two datasets together based on the country name | ||
| print("3. Merging data and formatting...") | ||
| # The API uses uppercase 'COUNTRY', the master uses lowercase 'country' | ||
| merged_df = pd.merge(api_df, master_df, left_on='COUNTRY', right_on='country', how='left') | ||
|
|
||
| # Drop the duplicate lowercase 'country' column used for joining | ||
| merged_df = merged_df.drop(columns=['country']) | ||
|
|
||
| # Reorder columns so the iso3 code sits right next to the Country name | ||
| final_columns = [ | ||
| 'IND_ID', 'INDICATOR_NAME', 'YEAR', 'COUNTRY', 'iso3', 'VALUE' | ||
| ] | ||
| merged_df = merged_df[final_columns] | ||
|
|
||
| # 4. Save to CSV in a new folder | ||
| output_dir = "statvar_imports/tuberculosis_percentage/input_files" | ||
| filename = os.path.join(output_dir, "tuberculosisPercentage_input.csv") | ||
|
|
||
| os.makedirs(output_dir, exist_ok=True) | ||
|
|
||
| # Save without the pandas index column | ||
| merged_df.to_csv(filename, index=False) | ||
| print(f"Success! Data saved locally as '{filename}'") | ||
|
|
||
| if __name__ == "__main__": | ||
| download_tb_percentage_data() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "import_specifications": [ | ||
| { | ||
| "import_name": "WHO_TuberculosisBacteriologicallyConfirmedPercentage", | ||
| "curator_emails": [ | ||
| "support@datacommons.org" | ||
| ], | ||
| "provenance_url": "https://data.who.int/indicators/i/1891124/449F55C", | ||
| "provenance_description": "Percentage of people diagnosed with a new episode of pulmonary TB whose disease was bacteriologically confirmed", | ||
| "scripts": [ | ||
| "download_who_tuberculosis.py", | ||
| "../../tools/statvar_importer/stat_var_processor.py --input_data=tuberculosisPercentage_input.csv --pv_map=tuberculosisPercentage_pvmap.csv --config_file=tuberculosisPercentage_metadata.csv --output_path=tuberculosisPercentage_output" | ||
| ], | ||
| "source_files": [ | ||
| "input_files/*" | ||
| ], | ||
| "import_inputs": [ | ||
| { | ||
| "template_mcf": "tuberculosisPercentage_output.tmcf", | ||
| "cleaned_csv": "tuberculosisPercentage_output.csv", | ||
| "stat_var_mcf": "tuberculosisPercentage_output_stat_vars.mcf" | ||
| } | ||
| ], | ||
| "cron_schedule": "0 0 1 1,4,7,10 *" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.