Codified Address
Create a new Business Rules File
/// <reference path="../.ref/js/santedb-bre.js" />
/// <reference path="../.ref/js/santedb-model.js" />
/// <reference path="../.ref/js/santedb.js" />
/**
* Elbonia MPI / SanteMPI Rules for Codifying Address
* --
*/
Write Address Lookup Function
/**
* Business rule - Add address information
*/
function appendAddress(patient) {
// Fill out addresses
if (patient.address) {
// Use the reflector tool instead of Object.keys here
var keys = reflector.properties(patient.address);
// Iterate over the types of addresses
for (var k in keys) {
var addrType = keys[k];
var addr = patient.address[addrType];
if (addr.component) { // address has component
var censusTract = addr.component.CensusTract;
if (censusTract) continue; // already has census tract
// Lookup the place by address components
var att = 0;
// Attempt to search for places with the same name - search up the hierarchy
while (!addr.component.CensusTract && att < 3) {
var query = {
"_count": 2
};
if (addr.component.State && att < 3) { // attempt state res
query["address.component[State].value"] = addr.component.State;
query["classConcept.mnemonic"] = 'State';
}
if (addr.component.County && att < 2) { // attempt township res
query["address.component[County].value"] = addr.component.County;
query["classConcept.mnemonic"] = 'County';
}
if (addr.component.City && att < 1 && addr.component.City != "?") { // attempt full res
query["address.component[City].value"] = addr.component.City;
query["classConcept.mnemonic"] = 'City';
}
att++;
try {
var r = SanteDB.resources.place.find(query);
if (r.totalResults == 1 && r.resource && r.resource.length == 1) {
var correctAddr = r.resource[0].address['Direct'];
if (correctAddr != null)
addr.component.CensusTract = correctAddr.component.CensusTract;
}
} catch(e) {
console.error("Error correcting address: " + e);
};
}
}
}
}
return patient;
}Attach the Business Rule
Last updated
Was this helpful?