From cff539af1a08b1e1c90174867571518f25755af7 Mon Sep 17 00:00:00 2001
From: jws52 <jws52@cam.ac.uk>
Date: Mon, 5 Feb 2024 12:40:49 +0000
Subject: [PATCH] feat: Consistent country names for newODK2 surveys

Requires the file of manual-surveys-to-add to have a consistent country column name and entries.
---
 coordinator/ProcessorSurveysnewODK2.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/coordinator/ProcessorSurveysnewODK2.py b/coordinator/ProcessorSurveysnewODK2.py
index 8591c47..02533a3 100644
--- a/coordinator/ProcessorSurveysnewODK2.py
+++ b/coordinator/ProcessorSurveysnewODK2.py
@@ -27,6 +27,27 @@ logger = logging.getLogger('Processor.Surveys.kobotoolbox')
 add_filters_to_sublogger(logger)
 
 
+# Downloads of the ODK form reports country descriptions as two letter codes.
+# The reason is unclear, as viewing online shows full country names. To be
+# consistent across all form types, this function is available for translating
+# two letter codes to full string names.
+# Only some have these have been checked explicitly against downloaded surveys.
+# Assuming the code is based on ISO 3166-1 alpha-2
+COUNTRY_ABBREVIATIONS_DICT = {
+        'AF' : 'Afghanistan',
+        'BD' : 'Bangladesh',
+        'BT' : 'Bhutan',
+        'ET' : 'Ethiopia',
+        'IN' : 'India',
+        'KE' : 'Kenya',
+        'NP' : 'Nepal',
+        'PK' : 'Pakistan',
+        'TZ' : 'Tanzania',
+        'UG' : 'Uganda',
+        'ZM' : 'Zambia',
+        'ZW' : 'Zimbabwe',
+        }
+
 def get_newODK2_form_as_csv(form_credentials: dict, jobPath: str, config: dict, status):
     '''Given a dict with a single kobotoolbox form to download from a kobotoolbox
     server, obtains it and converts to csv.'''
@@ -54,7 +75,7 @@ def get_newODK2_form_as_csv(form_credentials: dict, jobPath: str, config: dict,
             #'phonenumber' : 'None',
             'username' : 'username',
             'surveyor_information/region' : 'None',
-            'surveyor_information/country' : 'surveyor_infromation-country',
+            'surveyor_information/country' : ('parse_cases',(('name_out','surveyor_infromation-country'),('cases', COUNTRY_ABBREVIATIONS_DICT))),
             'surveyor_information/surveyor' : 'surveyor_infromation-surveyor_name',
             'surveyor_information/institution' : 'surveyor_infromation-institution',
             'survey_information/admin_level_1' : 'None',
-- 
GitLab