Skip to content

Commit

Permalink
switched calculation of blocking traits to PIM library
Browse files Browse the repository at this point in the history
  • Loading branch information
kachok committed Dec 12, 2014
1 parent fc5c9d7 commit e389cea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 47 deletions.
54 changes: 8 additions & 46 deletions lib/models.js
Expand Up @@ -3,20 +3,22 @@
var DoubleMetaphone = require('doublemetaphone');
var encoder = new DoubleMetaphone();

var pim = require('blue-button-pim');

var mongoose = require('mongoose');

var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;

var storageColName = 'storage.files';

exports.models = function(connection, supportedSections) {
exports.models = function (connection, supportedSections) {
var result = {
merge: {},
clinical: {},
match: {}
};
supportedSections.forEach(function(secName) {
supportedSections.forEach(function (secName) {
var mergeColName = secName + 'merges';
var mergeSchema = new Schema({
entry_type: String,
Expand Down Expand Up @@ -64,51 +66,11 @@ exports.models = function(connection, supportedSections) {

//hook for demographics model only (to process PIM attributes)
if (secName === 'demographics') { //TODO: disabled for now
schema.pre('save', function(next) {
schema.pre('save', function (next) {
var self = this;

self.pim = {};

// do stuff

/*
The following is a list of blocking traits computed on entities for this matching module:
LNMPDOB (last name metaphone plus DOB)
LNMPFNPC (last name metaphone plus first name plus zip code)
LNFN (last name metaphone plus first name)
if SSN available: SMDSSN79 (sex, month of birth, day of birth, SSN digits 7-9)
else: SMDLASTNAME13 (sex, month of birth, day of birth, first 3 letters of last name)
*/

//encoder.setMaxCodeLen(7);
var lnmp = encoder.doubleMetaphone(self.data.name.last).primary;
var fn = self.data.name.first.toUpperCase();
var ln13 = self.data.name.last.substring(0, 3).toUpperCase(); //first 3 letters of last name

//TODO: better handling of zip in the future
var zip = "";
if (self.data.addresses && self.data.addresses[0] && self.data.addresses[0].zip) {
zip = self.data.addresses[0].zip;
}

var dob = "";
var mdb = "";
if (self.data.dob && self.data.dob.point && self.data.dob.point.date) {
dob = self.data.dob.point.date.substring(0, 10);
mdb = self.data.dob.point.date.substring(5, 10); //month and day of birth
}

var gender = "UNKNOWN";
if (self.data.gender) {
gender = self.data.gender.toUpperCase();
}

self.pim.lnmpdob = lnmp + dob;
self.pim.lnmpfnpc = lnmp + fn + zip;
self.pim.lnfn = lnmp + fn;
//this.save();

self.pim.smdlastname13 = gender + mdb + ln13;
//pre-calculate blocking traits
self.pim = pim.calculate_blockers(self.data);

next();
});
Expand All @@ -119,7 +81,7 @@ exports.models = function(connection, supportedSections) {
return result;
};

exports.storageModel = function(connection) {
exports.storageModel = function (connection) {
if (!connection) {
connection = mongoose;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Dmitry Kachaev, Matthew McCall and Afsin Ustundag",
"name": "blue-button-record",
"description": "Master Health Record and Data Reconciliation Engine Persistance Layer",
"version": "1.2.0-beta.19",
"version": "1.2.0-beta.20",
"repository": {
"type": "git",
"url": "git@github.com:amida-tech/blue-button-record.git"
Expand All @@ -19,6 +19,7 @@
"dependencies": {
"async": "0.9.x",
"blue-button-meta": "^1.1.0",
"blue-button-pim": "0.0.6",
"doublemetaphone": "^0.1.2",
"mongodb": "1.4.x",
"mongoose": "3.8.8",
Expand Down

0 comments on commit e389cea

Please sign in to comment.