Am still stuck with implementation of double metaphone and soundex on names

Am still stuck with implementation of double metaphone and soundex on names. Anyone who has implemented doublemetaphone and soundex with odk-x or someone who wants to challenge himself or herself.Please I seriously need this implementation

Data must leave the facility/ or tablet as it goes to the central server with identifiers such as names anonymized
I need this help
Please please

1 Like

Please be more specific by doing the following:

  1. Provide a link to double metaphone and soundex code you need to use
  2. Provide the name of which ODK-X tools you want them to integrate with.
  3. Provide an example of the input that would be received
1 Like

Many many thanks @W_Brunette
I am so grateful

Link to guide on what I request help on

A snippet of my case. I have hardcoded the variable data values but the expectation is that they be drawn from the participant through odk-x survey
var soundex = require(‘soundex-code’) //include the soundex library
var doubleMet= require(‘double-metaphone’) //include the double metaphone library
var gender=“M” //gender can be Male M, Female F, or Other O, or Unknown U
var dob=“19990203” //date of birth is in YMD format
var fname=soundex(‘john’) //apply soundex to the first name
var lname=doubleMet(“achieng”) //apply double-metaphone to the last name
var PKV1=gender+fname+lname[0]+dob //use the first metaphone for the last name
var PKV2=gender+fname+lname[1]+dob //use the second metaphone for the last name

You can test your code on runkit (RunKit)

From the odk-x survey a user inputs this data
First Name Last Name Gender DOB gender
JOHN KAHINDI M 1999-02-03 M

The input is subjected to the phonetic algorithmn


To get

The PKV flag potential duplicates at facility level and merge multiple records from the same individual at central level. It’s used for deduplication
The database should have

Summary of what I want
I have an odk-x survey configured with these variables( firstname, lastname, gender, DOB).Identifiers such as name should be anonymized such that the data leaving the facility(data on the tablet) should bear phonetics rather than the actual names. patient PII (name) should not leave the health facility for privacy/data security concerns

My request is that if my explanation above is not explicit then please accept that we have a zoom call

The doublemetaphone library can be downloaded

The soundex library can be downloaded

2 Likes

@Duncan_Otieno thanks for providing the information. I should have time to work on this next week.

1 Like

Many many thanks @W_Brunette
I will be very grateful
Thanks once again

1 Like

@Duncan_Otieno

The best starting point is to create a JavaScript file that does what you want as an example.

Since npm is not supported by default on the ODK-X Android side (it is supported on the PC tools side), I recommend the following steps.

Create a isolated folder with an index.html that calls your custom JavaScript file. This custom JavaScript file should then call the soundex-code and metaphone-code in JavaScript directly. Basically all dependencies are in their purest form as JavaScript in a single folder. Once it’s all JavaScript it’s easier to understand how to properly put it into the ODK-X JavaScript framework.

I am happy to have a Zoom call. Private message me to set it up.

1 Like

Many many thanks @W_Brunette

Attached is the JavaScript file that is able to implement the phonetics from the PC side.
Since npm is not supported by default on the ODK-X android side. How then can it be invoked?
In ODK-X, Where can I snap variables are they are being written to the database? Which file implements this?
Many many thanks once again
dmapi.zip (15.9 KB)

@Duncan_Otieno

When rendering, the ODK-X framework’s JavaScript libraries are listed here (in progress):
https://docs.odk-x.org/injected-interfaces/

One method for assigning your variables could be to use a Custom Prompt in Survey. Custom prompts are implemented in JavaScript. See:
https://docs.odk-x.org/xlsx-converter-using/#customizing-prompts

General Steps I see:

  1. Figure out what is the minimum number of JavaScript libraries are required to get metaphone and soundex code to run.
  2. Include the proper JavaScript files in the form’s directory for the custom prompt type that does not conflict with the JavaScript libraries Survey uses. Hopefully ODK-X already is including most of the JavaScript libraries that metaphone and soundex needs.
  3. Use ODK-X’s JavaScript interfaces to call metaphone and soundex custom prompt type.

NPM manages you JavaScript libraries for you, what we need to do is understand what dependencies are already included and what JavaScript libraries need to be added to the ODK-X framework on the mobile device.

Again, happy to have a Zoom call. Private Message me to setup a time and we can discuss.

I would try to make a custom prompt that calls the JavaScript libraries that you download the JavaScript file yourself to be with the formDef and don’t use NPM.

1 Like

Many many thanks once again @W_Brunette

Let me private message you to setup a time for a zoom call

2 Likes

Hello Team,
I am trying to snap the point where variables are written to the databases but not successful.
Any help with be highly appreciated.
How do I reference the variables that already exists in the database from a JavaScript file

Hello
Am trying to find a code that would help me implement this in the odk-x survey
Any help will highly be appreciated

const express = require(‘express’)
const app = express()
const morgan = require(‘morgan’)
const bodyParser = require(‘body-parser’)

app.use(morgan(‘short’))
app.use(express.static(‘./public’))
app.use(bodyParser.urlencoded({extended: false}))

const sqlite = require(‘sqlite3’).verbose()
let db = new sqlite.Database(‘./encode.db’)

let soundex = require(‘soundex-code’) //include the soundex library
let doubleMet= require(‘double-metaphone’) //include the double metaphone library

app.post(‘/create’, (req, res) =>{
let gender = req.body.gender
let dob = req.body.dob
//let fname = soundex(‘req.body.fname’)
//let lname = doubleMet(‘req.body.lname’)
let fname = soundex(req.body.fname)
let lname = doubleMet(req.body.lname)
let pkv1 = gender+fname+lname[0]+dob
let pkv2 = gender+fname+lname[1]+dob

db.run("INSERT into customer(gender, dob, fname, lname, pkv1, pkv2) values('"+gender+"', '"+dob+"', '"+fname+"','"+lname+"', '"+pkv1+"','"+pkv2+"')",function(err,row){
    if(err){
        console.log(err.message)
    }
    console.log("Entry added to table")
    res.send("New Customer has ben added")
});
res.end()

})

app.get(“/”, (req, res)=> {
console.log(“Responding to root route”)
res.send(“Hello from Rooot”)
})

app.get(“/users”, (req, res) => {
let db = new sqlite.Database(‘./encode.db’)
db.all(“SELECT * FROM customer”, (err, rows, fields) =>{
console.log(“I think the data was Fetched”)
res.json(rows)
})

})

app.listen(3003, () => {
console.log(“Server is up and listening on 3003…”)
})

//npm install double-metaphone

// npm install soundex-code
// npm i body-parser
// npm install sqlite3
// sudo npm i -g nodemon
// npm install express
// npm init -y
// node app.js

Hi,

I made a form that should do what you want. You can download it here phonetic_example.zip (18.0 KB)

There are 2 parts to using soundex-code and double-metaphone. (If you wish to use other libraries in the future the procedure should be similar.)

  1. Prepare and load the libraries into Survey
  2. Call the library in the xlsx form

Part 1 is handled as follows

  1. Download soundex-code and double-metaphone using npm.
  2. Convert the 2 libraries into a format that could be loaded by Survey
    The 2 libraries were written in the CommonJS style but Survey requires them in AMD. So I converted them using RequireJS’s r.js, see CommonJS Notes for more detail. I named the converted soundex-code library soundex.js and the converted double-metaphone library doublemetaphone.js. These 2 libraries have no dependencies and don’t use Node.js features so this is all you need to do. For more complex libraries you might want to consider using a bundler like webpack.
  3. Load the 2 libraries using a custom prompt type. See forms/phonetic_example/customPromptTypes.js. See Using ODK-X XLSX Converter — ODK-X Docs for more information.
  4. The custom prompt type hooks the 2 libraries into the formulaFunctions object, as soundex and doubleMetaphone, to make them available in xlsx forms.

Part 2 is handled as follows

  1. The 2 libraries are now available in the xlsx form anywhere JS expressions are allowed, e.g. calculation or constraint.
  2. Use assign to write pkv1 and pkv2. See line 8 and line 9 on the survey sheet of phonetic_example.xlsx.

Let me know if you have questions.

3 Likes

@linl33
Many many thanks. Golden buzzer performance. You are my hero

Attached is the output

I am really impressed.
Just asking what about instead of the exact names we have their corresponding phonetics instead
instead of james we have soundex(james)=J520
and
instead of okoth we have doublemetaphone(okoth)=[AK0,AKT]
But all the same Many many thanks

1 Like

Here’s a version that stores only the phonetics. phonetic_example.xlsx (8.3 KB)

I added session variables to store the raw first and last name. Session variables are variables scoped to a Survey instances and discarded on exit. See ODK-X XLSX Converter Reference — ODK-X Docs for more on session variables.

1 Like

Thank you very much @linl33
This works magic
Thanks a million

1 Like