REST request to retrieve a value from an external source

I would like to issue a REST query to an external server to retrieve a value.

For example, after entering a name, I would like to check in our database if that name has already been stored. I have seen the REST examples, but most deal with sending, not with receiving data.

https://support.kobotoolbox.org/en/articles/978826-pull-data-functionality-in-kobotoolbox is similar, but it does not work for dynamic data.

Any hint would be welcome.

Hi,
I am not so sure whether that will work; I highly doubt. I however would suggest a workaround with a lag using following logic for collect based data collection.

  1. When using pull data- data is pulled to a CSV file which is essentially stored within a folder in the phone.
  2. If you were to use a folder sync application, you can sync that very folder to a cloud based folder.
  3. If you can automate the cloud based folder to be populated with the most recent CSV file, then you can easily sync your android folder using the automated folder sync.

I must admit this is rather crude, but so far this is the only logical approach that I have used previously to achieving near dynamism.

Stephane

Thanks, Stephane. I had thought of this already, but immediately dismissed it, because it would mean that I have to store the full patient database on the tablet, which is too much of a security risk when the tablet “disappears”.

For the simplified case I described (“patient exists”), a hash would be enough, but in the real application I need to retrieve the details of the patient as a feedback to the interviewer.

There are much more basic applications around (e.g. breezingforms in Joomla) that allow inserting JQuery Ajax into a field, but I am aware that this will not generalize well enough for the non-connected case.

Still thinking about some solution that would only transfer one patient’s data on request,

Just in case someone has another idea, here the full workflow:

  • Interviewer scans the patient’s barcode. No pull of data set
  • Barcode request patient’s details from server, and displays names, dob on all forms to give feedback to interviewer that she is adding additional data from the correct person.
1 Like

I tried your suggestion, but I could not get pulldata to work with an url-based media file. I also found no example. Do you know of on?

I have looked into this, and here is a workaround. It means that some of the suggestions posted here and in https://support.kobotoolbox.org/en/articles/978826-pull-data-functionality-in-kobotoolbox are not correct.

  • Pulldata from an URL is not supported. I am not sure about this, because it is tempting to use it when you upload a media csv file, but let’s wait for someone knowing better.
  • So we must try to use the “manual copy csv-method” by using a sync tool. I used SMBSyn2 on Android, which works nicely.
  • On Android, form media are stored in subdirectories of /storage/emulated/0/odk/forms. When you have several versions of a form, there are multiple directories disambiguated by (2), (3).
  • Use SMBSync2 to synchronize all files in this folder with all non-empty subfolders with some Samba-Share - with other apps you can also synchronize with some network share, but the Sambo-solution was good enough for me. Make sure you have selected the advanced options, with “do not overwrite newer files”. You need this step to find out how the directory structure is.
  • Do the synchronization. Edit the CSV.imported-file (but read the full text first), or replace it by a new one. You need to make sure that you realy picked the latest version of the subdirectory, some clever script could do this automatically.
  • Create another task in SmbSync2 to COPY newer files to the device. Do the sync.
  • Test by entering new data into a form. Be surprised that things have not changed, old file still active.

Why? Kobo does not care about the CSV.imported file, because it looks up what is in the SQlite database, without checking that the CSV.imported had been changed.

So do the following:

  • Do not edit the CSV.imported file on your Samba share, but edit the SQLite database xxx.db with a standard tool - I use https://sqlitestudio.pl/. Then copy the file back to your device. This means that you can restrict the synchronization to *.db files only.

This procedure is a mess, and will not work reliably in practice. Correct me when I am wrong, but please provide an example.

Some api tool to upload CSV files and update the database are required. Clearly some method to retrieve lookups from a REST API would be helpful, but that’s a major undertaking to handle the asynchronous task. I found a commercial solution (123 something) that looked right with “@javascript”, but alas, no HTTP, nothing asynchronous.

Frustrated…

After reading REST request to retrieve a value from an external source, I tried the same with ODK Collect 1…27.1 today: First, it does not create a file xx.csv.imported, but keeps the filename xx. Nice. In addition, it keeps a hash of the file in the database table externalMetadata, and updating the CSV file works; the app updates the database when the CSV file changes. Well done.

I hope this feature will carry over to the announce 1.27.1 of Kobo.

The location of the CSV file has change when you accepted the “Migration” request. It is now (don’t blame me when I mistyped the boa constrictor):

internal/android/data/ord.odk.collect.android/files/forms

2 Likes

Thanks for investigating all of this and documenting it for the benefit of the community.

Out of curiosity, is there something that KoBoCollect does for you that ODK Collect does not?

1 Like

Hi @dmenne,
I don’t know if you ever found a better solution to this, but I “worked around” this by building a custom android application that receives and passes intents to Collect.
Now I’m looking for some kind of solution that will work with Enketo.