This repo is the Polio plugin for IASO. It is not part of the IASO git tree. Clone it into plugins/polio and enable it with PLUGINS=polio.
- Clone IASO:
git clone git@github.com:BLSQ/iaso.git- Inside the IASO repo, clone this repo into
plugins/:
cd plugins
git clone git@github.com:BLSQ/polio.git polioThe folder name must be polio. Django loads the app as plugins.polio.
- In the IASO
.env(copy.env.distto.envfirst if you do not have one):
PLUGINS=polio
Add polio to the list if other plugins are already set, for example PLUGINS=polio,snt_malaria.
- Start IASO:
docker compose upWebpack bundles plugins/polio/js/config.tsx with the rest of the app. There is no separate frontend dev server. The Polio menu shows on accounts that have the Polio module enabled.
Vaccination Round require some amount of preparation at different regional level before its start. The status of these preparations is encoded in a shared Google Spreadsheet per campaign/round by the different actors.
This Spreadsheet contains different metrics at the national level, and then for each region and district concerned.
Iaso has different features around these Preparedness SpreadSheet:
- Automatically Import data from the SpreadSheet associated to a campaign.
- Associate a Spreadsheet to a Campaign in the Iaso user interface. It can be a sheet generated by Iaso or a previously existing one. At the moment only one Spreadsheet per campaign is allowed in Iaso, but normally it should be one per round.
- Generate a Spreadsheet for a campaign inside Google Drive with a sharable url. This Spreadsheet can then be shared to actors outside of Iaso to fill the preparation status for the zone they are responsible for. It will use the list of districts in the campaign scope (configured inside Iaso) to automatically add the sheet and columns to be filled.
- Keep a history of previous version of the spreadsheet (one per day)
- Manually launch an Import of the data via a button in the interface
- Provide a summary of the data in the spreadsheets for a campaign (by parsing
its content)
- and expose it in API for PowerBI.
- and display it in the interface.
Since the format of the spread is prone to change and human mistake, there is a few heuristics in the code to try to deal with them appropriately.
The Polio Campaign app has integration with the Google Sheet API used to populate the preparedness data and generate new google sheet. This integration requires a JSON API Key with the Sheet API Enabled, see section below or the Google Sheet API documentation for how to create an API key and enable the Sheet API.
Introduction: This documentation will guide you through the process of creating credentials to access the Google Spreadsheet API using a service principal. Service principals are a type of identity that represent applications or services rather than individual users. By following the steps below, you'll be able to obtain the necessary credentials to authenticate your application and access the Google Spreadsheet API programmatically.
Step 1: Set up a Google Cloud Platform (GCP) Project:
- Go to the Google Cloud Console (https://console.cloud.google.com/) and sign in with your Google account.
- Create a new project by clicking on the project dropdown menu at the top of the console and selecting "New Project." Provide a name for your project and click "Create."
- Once the project is created, ensure that it is selected in the project dropdown menu.
Step 2: Enable the Google Spreadsheet API:
- In the Google Cloud Console, navigate to the "APIs & Services" -> "Library" section using the left sidebar.
- Search for "Google Spreadsheet API" in the library search bar.
- Click on the "Google Spreadsheet API" from the search results.
- On the API details page, click the "Enable" button to enable the API for your project.
Step 3: Create a Service Account
- Open the Google Cloud Console (console.cloud.google.com).
- Select your desired project from the project selector.
- In the left sidebar, navigate to "IAM & Admin" -> "Service accounts."
- Click on the "Create Service Account" button.
- Provide a name and optional description for the service account.
- Click on the "Create" button.
- On the "Service account permissions" page, assign the necessary roles for accessing the Google Spreadsheet API. Consider granting the "Editor" role if you require read and write access to spreadsheets.
- Click on the "Continue" button.
- Skip the "Grant users access to this service account" section, unless specific users need to be granted access.
- Click on the "Done" button.
Step 4: Generate a Private Key
- Locate the newly created service account in the list and click on the "Manage Keys" button in the "Actions" column.
- Click on the "Add Key" button and select the "Create new key" option.
- Choose the key type as "JSON" and click on the "Create" button.
- A JSON file containing the private key and other details will be downloaded to your computer. Make sure to store it securely.
Step 6: Configure it in Iaso
Go to the Django admin at /admin and go to Polio -> Config and create a
olio.Config object with the slug google_api_key and copy the key file (json)
inside the content field.
For the generation of Preparedness template you will also need a
Config preparedness_template_id with keys fr and en.
The file is generated for a campaign's round in particular.
- Find the template according to the lang of the country where the Campaign occur
- Make a copy of it in a new file
- Share readable to all
- Change the title and meta data according to the campaign
- Make a copy of the Regional sheet per region in the scope
- Add a column per district in the region.
- Update the named ranges and protected ranges `` Organizatin wise we save the templates on a folder in the Google drive.
Configuration, in Polio config /admin/polio/config/:
google_api_keyA google api key with access to the drive api that the backend can use to read and create google sheetemails_for_preparedness_alertList of Email to send alert when a google sheet don't parse properlypreparedness_template_idTemplate per language used in the generation of the Google sheet. It is versionned so we can configure new version on the server before the code is deployed. Redacted example:
{
"v2": {
"en": "1qUTT4nWvKWxDvAbw....",
"fr": "1lQzK8o9gDuCrUAuP...."
},
"v3": {
"en": "1WS6hEtNdZ_nLjDV3azU0...",
"fr": "1nh4sKKwtoaphSEs0bdaf...."
}
}- Make a copy of the last template file in the folder for each language
- Make modifications
- Update the Named Ranges, this is how the location of information is determined during the import, so it's primordial that they are correct.
- Modify the protected ranges as well if lines have been added or deleted.
- Do not forget to make similar modifications in all the language
- Share the templates, so they are readable by everyone (with link, non-searchable)
- Test them
Do it on the staging polio staging.poliooutbreaks.com
- Go to admin. Polio > config > preparedness_template_id, replace the ids of the last version of the Google Sheets with yours. (keep a copy of the old ones under another name)
- Generate a new sheet in a campaign with several regions and districts
- Modify the values
- Try to re-import it, check if the values for each preparedness category correspond to what you have entered
- Repeat for each language. The language is configured on the country.
- Implement the modifications in prod by updating the config similarly to how it is done in production.
The above procedure work only for minor modifications like updating title or swapping line, more invasive modification require consideration and code change to not break everything.
Preparedness spreadsheets configured on campaigns are imported once a day via a cron.yaml scheduled task.
A copy of the whole spreadsheet is done as JSON in a SpreadSheetImport instance. It is then parsed and filed in the cache.
An e-mail is sent if value are found outside the range.
To control who receive the e-mail create/edit a polio.Config object with the slug emails_for_preparedness_alert and containing a list of e-mail as json.
e.g. ['test@bluesquarehub.com']
The file need to be readable to all.
Note that the timeout in the AWS task system needed to be increased because the import take around an hour, otherwise the task got run in a loop. The schedule is refresh_preparedness_data_task in plugins/polio/cron.yaml. CI merges that file into the root cron.yaml deployed to the worker.
This is now implemented via the background task system. Schedules are in plugins/polio/cron.yaml. CI merges plugin cron files into the root cron.yaml the worker reads. See https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-cron-job-worker-tier/
- To create a
/launch_task/<task_name>/<user_name>/url that will be called by EBS native cron job management, where : task_nameis a fully qualified task_name = module path + task fn name, example : 'plugins.polio.tasks.refresh_preparedness_data.refresh_data'user_nameis the username of the user that will be associated with the task (we decided onpolio_cron_task_userfor this case)
For testing locally, generate your own google api key ! don't use the one in prod or bad things will happen to you. See above on how to generate one.
- Add the Spreadsheet url in the Preparedness tab of a campaign.
- Press the refresh data button
- The parsed data will get displayed.
This way doesn't require the task worker to be running.
- Create a campaign with round dates in the future
- Either use the preparedness sheet linked in the ticket, or generate a new one
- If generating a new one: delete data in several cells
- Call the url
/tasks/launch_task/plugins.polio.tasks.weekly_email.send_email/polio_cron_task_user/ - in the terminal launch the task worker tasks_worker, run
docker compose run iaso manage tasks_worker - The output should show you an email with no errors (see screenshot). Such emails are printed out in the console, but not sent. If the list of errors is not empty, there's a bug in this PR.
Contributions are welcome. See CONTRIBUTING.md for how to contribute, including the required DCO sign-off on every commit.