diff --git a/lib/parser/cms/cmsObjConverter.js b/lib/parser/cms/cmsObjConverter.js index ac48122f..d304a397 100644 --- a/lib/parser/cms/cmsObjConverter.js +++ b/lib/parser/cms/cmsObjConverter.js @@ -29,7 +29,8 @@ var bbDocumentModel = { "immunizations": [], "socialHistory": [], "problems": [], - "procedures": [] + "procedures": [], + "insurance": [] }, "meta": { "type" : "cms", diff --git a/lib/parser/cms/sections/commonFunctions.js b/lib/parser/cms/sections/commonFunctions.js index 9542d8a8..38fddd81 100644 --- a/lib/parser/cms/sections/commonFunctions.js +++ b/lib/parser/cms/sections/commonFunctions.js @@ -1,24 +1,55 @@ //these are common models that must be hardcoded... //might want to modify later so that HERE it also takes in custom default values. - -var sections = { - 'cda_name': cda_name, - 'cda_concept': cda_concept, - 'cda_id': cda_id, - 'cda_coded_entry': cda_coded_entry -}; -var special = { +var functions = { 'cda_name': cda_name, 'cda_concept': cda_concept, 'cda_id': cda_id, 'cda_date': cda_date, 'cda_coded_entry': cda_coded_entry, 'cda_phone': cda_phone, - 'cda_email': cda_email + 'cda_email': cda_email, + 'cda_line_address': cda_line_address, }; + + + +//later on, this functions might become MUCH more complicated, because +//cities are not necessarily one word entries +function cda_line_address(addressString) { + var addressObj = { + "use": "primary", + "streetLines": [], + "city": "", + "state": "", + "zip": "", + "country": "United States"}; + var addressArray = addressString.trim().split(','); + if(addressArray.length == 2){ + var streetAndCity = addressArray[0].trim(); + var stateAndZip = addressArray[1].trim(); + + var street = streetAndCity.substring(0, streetAndCity.lastIndexOf(' ')); + var city = streetAndCity.substring(streetAndCity.lastIndexOf(' ')+1, streetAndCity.length); + + stateAndZip = stateAndZip.split(' '); + var state = stateAndZip[0]; + var zip = stateAndZip[1]; + addressObj.streetLines.push(street); + addressObj.city = city; + addressObj.state = state; + addressObj.zip = zip; + return addressObj; + } + return null; + + +} + + + function cda_phone(numberString, type) { var phoneObj = {}; phoneObj.number = numberString; @@ -166,34 +197,15 @@ function writeValue(value, obj, key){ obj[key] = value; } - - -//gets a common model function if it's defined in the section -var getCommonModelFunction = function(commonModelName, type) { - - //sectionName = keyMap[sectionName]; - if (commonModelName in sections && arguments[1] === undefined) { - if (sections[commonModelName] !== null) { - return sections[commonModelName]; - } - } else if (type == 'special') { - return special[commonModelName]; - } else { - return null; - } -}; - var getFunction = function(commonModelName) { - if (commonModelName in special) { - if (special[commonModelName] !== null) { - return special[commonModelName]; + if (commonModelName in functions) { + if (functions[commonModelName] !== null) { + return functions[commonModelName]; } } return null; }; -module.exports.getCommonModelFunction = getCommonModelFunction; -module.exports.sections = sections; module.exports.writeValue = writeValue; module.exports.getFunction = getFunction; module.exports.getValueType = getValueType; diff --git a/lib/parser/cms/sections/insurance.js b/lib/parser/cms/sections/insurance.js index 3f738bce..2f7a4fe1 100644 --- a/lib/parser/cms/sections/insurance.js +++ b/lib/parser/cms/sections/insurance.js @@ -5,7 +5,6 @@ var commonFunctions = require('./commonFunctions'); function parseInsurance(intObj, sectionType) { var result = []; var resultChild; - console.log('section type ' + sectionType); for(var x in intObj){ var child = intObj[x]; console.log(child); @@ -107,7 +106,6 @@ function processEmployerChild(childObj){ returnChildObj.name = value; } else if(key.indexOf('date') >= 0){ - //console.log(key); var processDate = commonFunctions.getFunction('cda_date'); var dateObj = processDate(value); dateArray.push(dateObj); @@ -135,9 +133,10 @@ function processInsuranceChild(childObj){ var emailArray = []; var phoneArray = []; var typeArray = []; + var addressArray = []; for(var key in childObj){ var key = key.toLowerCase(); - var value = childObj[key].toLowerCase(); + var value = childObj[key]; if(key.indexOf('msp type') >= 0 && value.length > 0){ returnChildObj.type = 'medicare msp:' + value; } @@ -150,10 +149,12 @@ function processInsuranceChild(childObj){ else if(key.indexOf('insurer name') >= 0){ returnChildObj.payer_name = value; } - else if(key.indexOf('insurer address') >= 9){ + else if(key.indexOf('insurer address') >= 0){ //needs to be updated to an address object //try to split by state name first. - returnChildObj.address = value; + var processLineAddr = commonFunctions.getFunction('cda_line_address'); + var addressObj = processLineAddr(value); + addressArray.push(addressObj); } else if(key.indexOf('date') >= 0){ var processDate = commonFunctions.getFunction('cda_date'); @@ -175,6 +176,9 @@ function processInsuranceChild(childObj){ if(dateArray.length > 0){ returnChildObj.date = dateArray; } + if(addressArray.length > 0){ + returnChildObj.addresses = addressArray; + } return returnChildObj; } diff --git a/test/fixtures/cms/bbModel.json b/test/fixtures/cms/bbModel.json index 7674cc1a..a73b4688 100644 --- a/test/fixtures/cms/bbModel.json +++ b/test/fixtures/cms/bbModel.json @@ -245,6 +245,123 @@ } ] } + ], + "insurance": [ + { + "plan_id": "H9999/9999", + "name": "HealthCare Payer", + "type": [ + "medicare", + "A Medicare Plan Plus (HMO)", + "3 - Coordinated Care Plan (HMO, PPO, PSO, SNP)" + ] + }, + { + "plan_id": "S9999/000", + "name": "Another HealthCare Payer", + "type": [ + "medicare", + "A Medicare Rx Plan (PDP)", + "11 - Medicare Prescription Drug Plan" + ] + }, + { + "name": "STATE HEALTH BENEFITS PROGRAM", + "type": [ + "employer subsidy" + ], + "date": [ + { + "date": "2011-01-01T00:00:00.000Z", + "precision": "day" + }, + { + "date": "2011-12-31T00:00:00.000Z", + "precision": "day" + } + ] + }, + { + "type": "medicare msp:End stage Renal Disease (ESRD)", + "policy_number": "1234567890", + "payer_name": "Insurer1", + "date": [ + { + "date": "2011-01-01T00:00:00.000Z", + "precision": "day" + }, + { + "date": "2011-09-30T00:00:00.000Z", + "precision": "day" + } + ], + "addresses": [ + { + "use": "primary", + "streetLines": [ + "PO BOX 0000" + ], + "city": "Anytown", + "state": "CO", + "zip": "00002-0000", + "country": "United States" + } + ] + }, + { + "type": "medicare msp:End stage Renal Disease (ESRD)", + "policy_number": "12345678901", + "payer_name": "Insurer2", + "date": [ + { + "date": "2010-01-01T00:00:00.000Z", + "precision": "day" + }, + { + "date": "2010-12-31T00:00:00.000Z", + "precision": "day" + } + ], + "addresses": [ + { + "use": "primary", + "streetLines": [ + "0000 Any ROAD" + ], + "city": "ANYWHERE", + "state": "VA", + "zip": "00000-0000", + "country": "United States" + } + ] + }, + { + "type": "medicare msp", + "policy_number": "00001", + "payer_name": "Insurer", + "date": [ + { + "date": "1984-10-01T00:00:00.000Z", + "precision": "day" + }, + { + "date": "2008-11-30T00:00:00.000Z", + "precision": "day" + } + ], + "addresses": [ + { + "use": "primary", + "streetLines": [ + "00 Address STREET" + ], + "city": "ANYWHERE", + "state": "PA", + "zip": "00000", + "country": "United States" + } + ] + } ] }, "meta": { diff --git a/test/test-cms-parser.js b/test/test-cms-parser.js index 688dbf4b..da32621e 100644 --- a/test/test-cms-parser.js +++ b/test/test-cms-parser.js @@ -289,6 +289,7 @@ describe.only('Test file parsing beginning to end', function () { var outputFilename = __dirname+ '/fixtures/cms/bbModel.json'; var intObj = txtToIntObj.getIntObj(this.txtdata); var bbModel = objConverter.convertToBBModel(intObj); + console.log(bbModel); fs.writeFile(outputFilename, JSON.stringify(bbModel, null, 4), function(err) { if(err) {