How can one search a table in odk-x survey using more than one parameter e.g the 3 names

I wanted to know if it is possible to do a search on a table created from odk-x survey form using multiple parameters e.g the 3 names.

Problem I want to solve.Registration at the clinic poses many challenges.Clients may pose as new clients and so a search on the 3 names and a mothers first name may help
Any help on this is greatly appreciated

1 Like

Hello,

There are multiple ways to solve this, but what I find easiest is to use the “ODK-X Tables” app to display the search screen (i.e. the text entry fields and a search button) and then use javascript to do the lookup in the database based on SQL. That way you have full control of the SQL query (if you want to experiment I recommend that you copy the sqlite.db file from the device (/sdcard/opendatakit/data/webDb) to your computer and uses something like DB Browser to test/build your SQL…

So basically there are three steps;

  • use javascript to construct the SQL based on user input
  • Call the function to execute the SQL:
odkData.arbitraryQuery('YOUR_TABLE', sql, null, null, null, successFn, failureFn);
  • Define the successFn and failureFn. In the successFn you can iterate through the results produced by the SQL like this;
             var successFn = function( result ) {
                var persons = []; // this array will hold the persons found by the sql query
                for (var row = 0; row < result.getCount(); row++) {
                    var id = result.getData(row,"_id"); 
                    var temperatura = result.getData(row,"temperatura");
                    var febre = result.getData(row,"febre");                   
                    var p = {
                        id,
                        temperatura,
                        febre,
                    }
                    persons.push(p); // This adds the "person" to the array 
                }
                populateList(persons);
                return;
            }
  • Finally you can the display the persons and hook it up so that when you click a person, you open a new form instance for that person…

We have solved a similar problem, so you can have a look at the complete (unpolished) solution for a “Centro” (i.e. Clinic) page out here:

Let us know how that works out - I will be happy to help if you get stuck somewhere :slight_smile:

/emil

1 Like

Many many thanks @Emil
Let me try this and keep you posted
Attached is the form am working on.Please check it and see how best to offer other insights
Once again Thanks CBS_Case_Report.xlsx (28.2 KB)

1 Like

Many thanks @Emil
I tried this out but on opening Odk-x survey am getting the error message that odk-x survey has stopped working

1 Like

Hi Duncan,
Does that mean that you got your search page working in ODK-X Tables and the results displayed correctly? And then, once you click on one of the results, and tries to open a new form in ODK-X Survey with some parameters passed on from javascript ODK-X Survey crashes? If so, I think that can sometimes happen if you include some parameters in the json-object you pass on to ODK-X Survey that Survey does not expect… Have you checked that all the variables that you pass along exist in the form’s model? :thinking:
E.g. both variable_01 and variable_02 must be ‘known’ by the form in Survey and of the correct type (i.e. be mentioned on the model sheet of the excel workbook)

var my_data = {
   variable_01: 'some value',
   variable_02: 'something else'
}
odkTables.addRowWithSurvey(null, 'my_table', 'my_form', null, my_data);
1 Like