Create and update Entities from repeats

Developers may be interested in the companion ODK XForms spec proposal.

Background

Repeats make it possible to capture data about multiple things of the same kind within the context of a single form. This means capturing the item data can be embedded in a broader flow and there can be logic used to perform validation between those items.

Users want to create Entities from those repeat so that they can follow up with them. Some practical examples:

  • In an agricultural context, it's common to have to capture information about many fields in the same farm. See @dast's Insiders lightning talk and showcase post.
  • Household surveys often involve capturing info about individual household members associated with that household. See Form linking

Currently, a single form submission can only create or update a single Entity. We propose making it possible for a submission to either create or update a single Entity OR create/update multiple Entities in a single Entity List from a repeat.

XLSForm spec

entities sheet:

We propose adding a repeat column in which a reference to a repeat can be specified. All other references used in other columns such as label, create_if, entity_id, etc, would be evaluated in the context of that repeat.

For now, exactly one Entity declaration would be allowed.

list_name repeat label
trees ${tree} ${species}

survey sheet:

When an Entity declaration is specified on the entities sheet, save_to values would only be allowed in that repeat.

type name label save_to
begin_repeat tree Tree
geopoint location Get tree location geometry
text species Species species
end_repeat

Future work

In the future, we expect to further expand to the following:

  • create/update multiple Entities in a single Entity List from a repeat AND a parent Entity in the same or a different Entity List
  • create/update multiple different Entities from the top level and from multiple repeats

Please let us know if you have any feedback!

1 Like

Absolutely in support of this — great initiative!

This would be a great step forward. Do I understand correctly that this is not yet implemented and that only one entity from one repeat could be populated with data from the submission?

To bridge the gap until this feature is properly implemented in ODK we have developed a script for pyodk to retrieve selected data from repeats of a given form, save it in a csv which then is uploaded to Central to populate the form the next time the dataset is used. Would that be worth to share in a showcase?

1 Like

You can also do this with QuODK - you can load the submission data (repeats) into QGIS then use that as the layer to create (or update) an entity list (exported as a CSV). Followed by a pyODK script to talk to Central.

So certainly not as simple as your tool, but there is the opportunity to adjust any geometry [or any other attributes] if needed, so it has some 'strength'. You can also be selective as to which attributes to include in the entity list.

I'd like to say that I'd thought of this specific use case when designing QuODK, but I confess that I only realised it was applicable when I read your post. :slight_smile:

I would find that useful - any 'grown up' scripts for pyODK would be really useful. My kindergarten scripts are a little wobbly so I find examples a good way to learn.

1 Like