Adding Instance to database

Hi,

We would like to get partially pre-filled forms on to devices, so a user
can see and complete them in Collect.
There are a number of requirements for this, including inspectors,
healthcare visitors, etc where information that is pertinent to the tasks
would be already available on the forms.

Looking at the structure of the ODK folders and database, it looks possible
to add a new form instance (that contained pre-filled data) to the instance
folder and to then add a reference to this in the instance table. We were
thinking of perhaps writing an application that would add a new data row to
the SqLite Instance table, and also create a folder and instance xml file
in the ODK folder on the device.

Is this possible to do or is there a better way to get pre-filled forms on
to the devices?

Cheers,

Paul.

The standard method for this would be to:

(1) register a form definition with the ODK Collect content provider:
FormsProvider
(2) register a form instance with the ODK Collect content provider:
InstanceProvider
(3) launch ODK Collect specifying the Uri of the form instance as returned
by the InstanceProvider. e.g.,
Uri insertUri
Intent intent = new Intent();
intent.setComponent(new ComponentName("org.odk.collect.android",
"org.odk.collect.android.activities.FormEntryActivity"));
intent.setAction(Intent.ACTION_EDIT);
intent.setData(insertUri);
startActivityForResult(intent);

If you create a form definition using Build or XLSForm, then (1) is
accomplished by downloading that form to the phone and opening Collect's
Fill-Blank-Form dialog (so that it is scanned and recorded as available).
You can also manually insert a form using the content provider, but you
will need to do some XML (javarosa) parsing or know a priori the needed
fields.

For (2) and (3), we have lightly tested code in ODK Tables that does this
in Controller.editRow(). See
http://code.google.com/p/opendatakit/source/browse/src/org/opendatakit/tables/activities/Controller.java?repo=tables#381

You want to look at the 2nd case where the formId is not null (where a
formId has already been supplied to Collect).

As an alternative to that codebase, for (2), the insert statement would be
something like that in the SaveToDiskTask.updateInstanceDatabase() code
here:
http://code.google.com/p/opendatakit/source/browse/src/org/odk/collect/android/tasks/SaveToDiskTask.java?repo=collect#107
In particular, the section starting at line 135, which accesses information
about the form (1) and inserts data into the instances database (at line
181).

Mitch

ยทยทยท On Tue, Dec 18, 2012 at 10:15 AM, Paul wrote:

Hi,

We would like to get partially pre-filled forms on to devices, so a user
can see and complete them in Collect.
There are a number of requirements for this, including inspectors,
healthcare visitors, etc where information that is pertinent to the tasks
would be already available on the forms.

Looking at the structure of the ODK folders and database, it looks
possible to add a new form instance (that contained pre-filled data) to the
instance folder and to then add a reference to this in the instance
table. We were thinking of perhaps writing an application that would add a
new data row to the SqLite Instance table, and also create a folder and
instance xml file in the ODK folder on the device.

Is this possible to do or is there a better way to get pre-filled forms on
to the devices?

Cheers,

Paul.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Hi Mitch,

Many thanks for your detailed response and sorry for the delay in
responding to you.
Your advice clearly shows what needs to be done.

Best regards,

Paul.

Paul,

would you like to share your code if you have managed to solve your problem?

Regards,
Joachim