Is it possible to create a unique id from implement phonetics such as soundex and doubleMetaphone in Kobo collect

Hello team
I want to implement soundex phonetic on firstname and doublemetaphone on lastname.Is this possible.Any help would really be appreciated

Many Thanks

Welcome to the community, @danoti! Could you provide an example that supports your issue so that the community would be able to help you if it’s possible?

Many thanks @Kal_Lam
I want to generate a unigue identifier from
<soundex(fname)><double_metaphone(lname)><dob(yyyymmdd)>
for example
gender=M
soundex(firstname)=J500
doubleMetaphone(lastname)=KHNT
dob(yyyymmdd)= 19990203
pkv=<soundex(fname)><double_metaphone(lname)><dob(yyyymmdd)>
pkv= MJ500KHNT19990203

You could do this by following the post discussed in our previous post:

many thanks @Kal_Lam

What I need is a specific unique identifier pkv
pkv=gender+soundex(firstname)+doubleMetaphone(lastname)+dob
pkv should be something like FA500AP19870615

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,
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

Many thanks @Kal_Lam
I need something like this
pkv

soundex(fname)=E520
doubleMetaphone(lname)=AK,AK

@danoti, did you try the workaround shared above? Let us know the place where you were stuck.

Am trying to find a code that would help me implement this in kobo collect
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

Link to guide on what I request help on

GitHub

words/double-metaphone

Fast Double Metaphone algorithm. Contribute to words/double-metaphone development by creating an account on GitHub.

A snippet of my case. I have hardcoded the variable data values but the expectation is that they be drawn from the participant through kobo collect
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

image

To get

image

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

image

Summary of what I want
I have kobo collect 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

Hi @danoti
I have seen you had asked the same question sometime back in 2020 within the ODK forum. I have done some extensive search to see if anyone has been able to implement this; unfortunately, there is very little information around the implementation of the same as a direct form function. I have also tried playing with the code on other environments and unfortunately, we are not able to execute this.

I will leave this for other users to potentially chime on it. Pinging some, for now, @wroos @Xiphware @Josh

Stephane

1 Like

Many many thanks @stephanealoo

1 Like

Hi @danoti, from what I understand, it doesn’t seem like your requirements are possible — I could be missing the point here. Unfortunately you are confined by the XLSForm standards in what you can do without the data leaving the device. Perhaps encrypting the data may help with the “privacy/data security concerns” and allow you to perform this transformation off-device? It seems like your proposed “phonetic” id could still be used to deanonymize patients if that’s something of concern.

2 Likes