Closed aleksa-krolls closed 3 years ago
A bunch of questions here:
"type":"select_one"
, "type":"note"
). Could we consider the type as varchar
?type
and constraint
needed to build the table.@lakhassane responses...
varchar
for any string values. afCPRfan8JdBt9sy9q48Jp
in your development (the form you pulled is not a wcs form) , and (ii) we will also need to ensure we can map form metadata like id
, _submission_time
, etc. Are you able to extract the list of metadata fields from the Kobo API? (Or will we need to pre-identify these?)@aleksa-krolls Those metadata fields are not extracted. So we might need to ID them.
@lakhassane Can you please get me a list of all standard metadata fields Kobo adds to the xForm definition (i.e., _submission_time
, id
, uuid
, _xform_id
)? (Fetch an actual form submission to see these.) I can then get sign-off from the client regarding which ones are important to build into the jobs.
cc @taylordowns2000
@aleksa-krolls I have fetched one from Kobo and have seen :
version_id
, start
, end
, device_id
, _version__001
, info_recall_date
, _version_
, __version__
today
, date_constraint_calc
@lakhassane What about other fields like _submission_time
, id
, uuid
, _xform_id
? I know these exist in every Kobo form submission. See example Kobo response to a GET request for form data here. Ideally we want all of these uploaded to the destination DB.
From Slack:
{q1, q2, q3, etc.}
_id
, _uuid
, etc. (edited) Taylor 3 minutes ago
(a) one might have {q1, q2, q3, more}
(b) and the other (the submission) might have {start, q1, q2, q3, _id, _version, more}
your job is to get a list of the things that appear in b
but not a
Taylor 2 minutes ago
here's the data url: https://kf.kobotoolbox.org/api/v2/assets/afCPRfan8JdBt9sy9q48Jp/data/?format=json
to compare against the form url: https://kf.kobotoolbox.org/api/v2/assets/afCPRfan8JdBt9sy9q48Jp/
WCS Postgres Table Management Jobs
Background
WCS collects research data across several sites and surveys, which are managed by a number of staff. To ensure that all Kobo survey data can be securely and centrally captured for easier access and analysis, WCS would like to automate the process of integrating Kobo surveys and creating database tables to centrally store the data.
The specific request
Goal is to identify an automated or semi-automated process for going from a new or updated Kobo form to a Postgres set of holding tables. This will require an automated metadata and data sync between Kobo Toolbox and Postgresql.
state.json
Source: Kobo
openfn_kobo
in LPDestination: Postgresql
adaptor
Assume the destination database will be Postgres - use language-postgresql.
expression.js
See original design notes for initial solution outline and questions. In sum, we'll need the following jobs:
(1) Metadata sync (upserts tables and columns)
N
jobs in OpenFn (/api/jobs/new)(2) Data sync (upserts records)
(1) Metadata Integration
Job to automate the creation of the Postgres destination table based on Kobo xForm.
Metadata mapping rules:
resource.name
(form name -i.e., "Rural Consumption").kobo_payload
JSONB column that captures the entire raw Message payload."group_scores":[...]"
) should be captured in another table with a foreign key relationship to the parent table. Therefore any survey with a repeat group will map to 2 tables, one parent and one child (i.e.,tbl_survey
andtbl_survey_char
).(2) Data IntegrationJobs to automatically create and update the mappings from the Kobo form to the db table created in the above flow.N
jobs in OpenFn (/api/jobs/new). ~~Data mapping rules:
uuid
is needed for upserting Kobo survey data, use_id + _xform_id_string
. This will ensure uniqueness across Kobo servers if WCS is hoping to connect multiple accounts._kobo_payload
column created in job 1.output.json
Fetching this Kobo Rural Consumption survey for the first time should:
tbl_wcs_rural_consumption_test
and childtbl_wcs_rural_consumption_test_char
for capturing repeat group data2. Create 1 job to map the Kobo survey data to the Postgres tables createdAssume OpenFn will fetch all Kobo survey forms and submissions on a cron-timer (i.e., every 3 hours).
Toggl
Please log your time to the WCS - Automated Kobo-Postgres Sync project.