-
Notifications
You must be signed in to change notification settings - Fork 138
Tuberculosis: Estimated incidence rate per 100 000 population #1945
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
smarthg-gi
wants to merge
4
commits into
datacommonsorg:master
Choose a base branch
from
smarthg-gi:who_tuberculosis_estimated_incidence_rate
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
4 commits
Select commit
Hold shift + click to select a range
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
76 changes: 76 additions & 0 deletions
76
statvar_imports/who/tuberculosis_estimated_incidence_rate/README.md
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,76 @@ | ||
| # WHO Tuberculosis Estimated Incidence Rate Import | ||
|
|
||
| ## Overview | ||
| This dataset contains national-level statistics for the Estimated Tuberculosis Incidence Rate (per 100,000 population). | ||
| Specifically, it provides incidence rates for two categories: | ||
| - Overall TB incidence | ||
| - HIV-positive TB incidence | ||
|
|
||
| The generated statistical variables capture the incidence rate for these conditions. | ||
| Examples of the statvars generated: | ||
| - `dcid:Count_MedicalConditionIncident_ConditionTuberculosis_AsAFractionOf_Count_Person` | ||
| - `dcid:Count_MedicalConditionIncident_ConditionTuberculosisAndHIV_AsAFractionOf_Count_Person` | ||
|
|
||
| **type of place:** Country, Region (M49 codes), WHO Regions, Overseas Territory, Special Administrative Regions | ||
| **years:** 2000 to 2024 | ||
| **place_resolution:** Resolved to DCIDs (e.g., dcid:country/FRA, dcid:country/IND) | ||
|
|
||
| ## Data Source | ||
| **Source URL:** | ||
| https://data.who.int/indicators/i/EB68992/2674B39 | ||
|
|
||
| **Provenance Description:** | ||
| The data comes from the World Health Organization (WHO) master database and the public API. It tracks the estimated TB incidence rate globally (Indicator ID: `EB689922674B39`). | ||
|
|
||
| ## Refresh Type | ||
| Automatic Refresh | ||
|
|
||
| For refresh of the data, the import includes a Python script (`tb_data_download.py`) to automatically fetch the data from the WHO API, join it with ISO3 geographic identifiers, and save the formatted CSV. | ||
|
|
||
| ## Data Publish Frequency | ||
| Release Frequency = Annual | ||
|
|
||
| ## How To Download Input Data | ||
| To download the data, run the provided script: | ||
| ```bash | ||
| python3 tb_data_download.py | ||
| ``` | ||
| This will fetch the latest full dataset, process the ISO3 codes, and save it locally as `input_files/Estimated_incidence_rate_per_100_000_population.csv` making it available for stat var processing. | ||
|
|
||
| ## Processing Instructions | ||
| To process the WHO Tuberculosis Incidence Rate data and generate statistical variables, use the following command from the import directory: | ||
|
|
||
| **For Data Run** | ||
| ```bash | ||
| python3 ../../../tools/statvar_importer/stat_var_processor.py \ | ||
| --input_data=input_files/* \ | ||
| --pv_map=tuberculosis_estimated_incidence_rate_pvmap.csv \ | ||
| --output_path=tuberculosis_estimated_incidence_rate_output \ | ||
| --config_file=tuberculosis_estimated_incidence_rate_metadata.csv | ||
| ``` | ||
|
|
||
| This generates the following output files: | ||
| - tuberculosis_estimated_incidence_rate_output.csv | ||
| - tuberculosis_estimated_incidence_rate_output_stat_vars_schema.mcf | ||
| - tuberculosis_estimated_incidence_rate_output_stat_vars.mcf | ||
| - tuberculosis_estimated_incidence_rate_output.tmcf | ||
|
|
||
| **For Data Quality Checks and validation** | ||
| Validation of the data is done using the lint flag in the DataCommons import tool. | ||
|
|
||
| ```bash | ||
| java -jar datacommons-import-tool-0.1-jar-with-dependencies.jar lint tuberculosis_estimated_incidence_rate_output_stat_vars_schema.mcf tuberculosis_estimated_incidence_rate_output.csv tuberculosis_estimated_incidence_rate_output.tmcf tuberculosis_estimated_incidence_rate_output_stat_vars.mcf | ||
| ``` | ||
|
|
||
| This generates the following output files: | ||
| - report.json | ||
| - summary_report.csv | ||
| - summary_report.html | ||
|
|
||
| The report files can be analyzed to check for errors and warnings. Further, linting is performed on the generated output files using the DataCommons import tool. | ||
|
|
||
| ## Testing | ||
| Testing is performed using the provided `test_data` directory: | ||
| - Input: `test_data/tuberculosis_estimated_incidence_rate_input.csv` | ||
| - Output (expected): `test_data/tuberculosis_estimated_incidence_rate_output.csv` | ||
| - MCF (expected): `test_data/tuberculosis_estimated_incidence_rate_output.tmcf` |
22 changes: 22 additions & 0 deletions
22
statvar_imports/who/tuberculosis_estimated_incidence_rate/manifest.json
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,22 @@ | ||
| { | ||
| "import_specifications": [ | ||
| { | ||
| "import_name": "WHO_TuberculosisEstimatedIncidenceRate", | ||
| "curator_emails": ["support@datacommons.org"], | ||
| "provenance_url": "https://data.who.int/indicators/i/EB68992/2674B39", | ||
| "provenance_description": "Estimated number of new episodes of TB cases arising in a given year per 100 000 population.", | ||
| "scripts": ["tb_data_download.py", | ||
| "../../tools/statvar_importer/stat_var_processor.py --input_data=gs://unresolved_mcf/who/TB_Estimated_Incidence_Rate/input_files/* --pv_map=gs://unresolved_mcf/who/TB_Estimated_Incidence_Rate/tuberculosis_estimated_incidence_rate_pvmap.csv --config_file=gs://unresolved_mcf/who/TB_Estimated_Incidence_Rate/tuberculosis_estimated_incidence_rate_metadata.csv --output_path=gs://unresolved_mcf/who/TB_Estimated_Incidence_Rate/tuberculosis_estimated_incidence_rate_output --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf" | ||
| ], | ||
| "import_inputs": [ | ||
| { | ||
| "template_mcf": "tuberculosis_estimated_incidence_rate_output.tmcf", | ||
| "cleaned_csv": "tuberculosis_estimated_incidence_rate_output.csv" | ||
| } | ||
| ], | ||
| "source_files": ["input_files/*.csv"], | ||
| "cron_schedule": "15 22 15 12 *" | ||
| } | ||
| ] | ||
| } | ||
|
|
57 changes: 57 additions & 0 deletions
57
statvar_imports/who/tuberculosis_estimated_incidence_rate/tb_data_download.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,57 @@ | ||
| import os | ||
| import requests | ||
| import io | ||
| import pandas as pd | ||
|
|
||
| def download_who_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 'EB689922674B39'", | ||
| "$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() | ||
|
|
||
| # 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') | ||
smarthg-gi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # 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', 'DISAGGR_1', 'VALUE' | ||
| ] | ||
| merged_df = merged_df[final_columns] | ||
|
|
||
| # 4. Save to CSV in a new folder | ||
| output_dir = "input_files" | ||
| filename = os.path.join(output_dir, "Estimated_incidence_rate_per_100_000_population.csv") | ||
smarthg-gi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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_who_data() | ||
Oops, something went wrong.
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.