mbs-importer-jps
Advanced tools
Comparing version 1.0.0-2 to 1.0.0-3
@@ -46,8 +46,12 @@ "use strict"; | ||
handleError(fileName) { | ||
fs_1.default.copyFileSync(`${this.importPath}${fileName}`, `${this.errorPath}${fileName}`); | ||
fs_1.default.rmSync(`${this.importPath}${fileName}`); | ||
if (fs_1.default.existsSync(`${this.importPath}${fileName}`)) { | ||
fs_1.default.copyFileSync(`${this.importPath}${fileName}`, `${this.errorPath}${fileName}`); | ||
fs_1.default.rmSync(`${this.importPath}${fileName}`); | ||
} | ||
} | ||
handleCompleted(fileName) { | ||
fs_1.default.copyFileSync(`${this.importPath}${fileName}`, `${this.processedPath}${fileName}`); | ||
fs_1.default.rmSync(`${this.importPath}${fileName}`); | ||
if (fs_1.default.existsSync(`${this.importPath}${fileName}`)) { | ||
fs_1.default.copyFileSync(`${this.importPath}${fileName}`, `${this.processedPath}${fileName}`); | ||
fs_1.default.rmSync(`${this.importPath}${fileName}`); | ||
} | ||
} | ||
@@ -60,136 +64,141 @@ importWithConnection(fileName, db) { | ||
let data = fs_1.default.readFileSync(`${this.importPath}${fileName}`); | ||
parser.parseString(data, (err, result) => { | ||
if (err) { | ||
this.handleError(fileName); | ||
console.log(err); | ||
reject(err); | ||
} | ||
try { | ||
let processedItems = []; | ||
const allItems = result.MBS_XML.Data; | ||
allItems.forEach((itemData) => { | ||
let item = { | ||
_id: itemData.ItemNum[0], | ||
startDate: converters.dateConverter(itemData.ItemStartDate[0]), | ||
endDate: converters.dateConverter(itemData.ItemEndDate[0]), | ||
category: itemData.Category[0], | ||
group: itemData.Group[0], | ||
itemType: itemData.ItemType[0], | ||
feeType: itemData.FeeType[0], | ||
isNewItem: converters.isTrue(itemData.NewItem[0]), | ||
isChanged: converters.isTrue(itemData.ItemChange[0]), | ||
isAnaestheticChange: converters.isTrue(itemData.AnaesChange[0]), | ||
isDescriptionChange: converters.isTrue(itemData.DescriptorChange[0]), | ||
isFeeChange: converters.isTrue(itemData.FeeChange[0]), | ||
isEMSNChange: converters.isTrue(itemData.EMSNChange[0]), | ||
benefitType: itemData.BenefitType[0], | ||
benefitStartDate: converters.dateConverter(itemData.BenefitStartDate[0]), | ||
basicUnits: itemData.BasicUnits[0], | ||
descriptionStartDate: converters.dateConverter(itemData.DescriptionStartDate[0]), | ||
description: itemData.Description[0], | ||
}; | ||
if (itemData.FeeStartDate) { | ||
item.feeStartDate = converters.dateConverter(itemData.FeeStartDate[0]); | ||
} | ||
if (itemData.ScheduleFee) { | ||
item.scheduleFee = converters.floatConverter(itemData.ScheduleFee[0]); | ||
} | ||
if (itemData.Benefit100) { | ||
item.benefit100 = converters.floatConverter(itemData.Benefit100[0]); | ||
} | ||
if (itemData.Benefit75) { | ||
item.benefit75 = converters.floatConverter(itemData.Benefit75[0]); | ||
} | ||
if (itemData.Benefit85) { | ||
item.benefit85 = converters.floatConverter(itemData.Benefit85[0]); | ||
} | ||
if (itemData.DerivedFee) { | ||
item.derivedFeeDescription = itemData.DerivedFee[0]; | ||
item.isDerived = true; | ||
} | ||
else { | ||
item.isDerived = false; | ||
} | ||
processedItems.push(item); | ||
}); | ||
db.collection(this.collection).deleteMany({}).then((result) => { | ||
db.collection(this.collection).insertMany(processedItems).then((result) => { | ||
// now we need to calculated the derived values | ||
db.collection(this.collection).find({ isDerived: true }).toArray().then((derivedItems) => { | ||
/* | ||
compute the derived fee | ||
if (data) { | ||
parser.parseString(data, (err, result) => { | ||
if (err) { | ||
this.handleError(fileName); | ||
console.log(err); | ||
reject(err); | ||
} | ||
try { | ||
let processedItems = []; | ||
const allItems = result.MBS_XML.Data; | ||
allItems.forEach((itemData) => { | ||
let item = { | ||
_id: itemData.ItemNum[0], | ||
startDate: converters.dateConverter(itemData.ItemStartDate[0]), | ||
endDate: converters.dateConverter(itemData.ItemEndDate[0]), | ||
category: itemData.Category[0], | ||
group: itemData.Group[0], | ||
itemType: itemData.ItemType[0], | ||
feeType: itemData.FeeType[0], | ||
isNewItem: converters.isTrue(itemData.NewItem[0]), | ||
isChanged: converters.isTrue(itemData.ItemChange[0]), | ||
isAnaestheticChange: converters.isTrue(itemData.AnaesChange[0]), | ||
isDescriptionChange: converters.isTrue(itemData.DescriptorChange[0]), | ||
isFeeChange: converters.isTrue(itemData.FeeChange[0]), | ||
isEMSNChange: converters.isTrue(itemData.EMSNChange[0]), | ||
benefitType: itemData.BenefitType[0], | ||
benefitStartDate: converters.dateConverter(itemData.BenefitStartDate[0]), | ||
basicUnits: itemData.BasicUnits[0], | ||
descriptionStartDate: converters.dateConverter(itemData.DescriptionStartDate[0]), | ||
description: itemData.Description[0], | ||
}; | ||
if (itemData.FeeStartDate) { | ||
item.feeStartDate = converters.dateConverter(itemData.FeeStartDate[0]); | ||
} | ||
if (itemData.ScheduleFee) { | ||
item.scheduleFee = converters.floatConverter(itemData.ScheduleFee[0]); | ||
} | ||
if (itemData.Benefit100) { | ||
item.benefit100 = converters.floatConverter(itemData.Benefit100[0]); | ||
} | ||
if (itemData.Benefit75) { | ||
item.benefit75 = converters.floatConverter(itemData.Benefit75[0]); | ||
} | ||
if (itemData.Benefit85) { | ||
item.benefit85 = converters.floatConverter(itemData.Benefit85[0]); | ||
} | ||
if (itemData.DerivedFee) { | ||
item.derivedFeeDescription = itemData.DerivedFee[0]; | ||
item.isDerived = true; | ||
} | ||
else { | ||
item.isDerived = false; | ||
} | ||
processedItems.push(item); | ||
}); | ||
db.collection(this.collection).deleteMany({}).then((result) => { | ||
db.collection(this.collection).insertMany(processedItems).then((result) => { | ||
// now we need to calculated the derived values | ||
db.collection(this.collection).find({ isDerived: true }).toArray().then((derivedItems) => { | ||
/* | ||
compute the derived fee | ||
the derived fee has the form "The fee for item d, plus $dd.dd divided by the number of patients seen, up to a maximum of six patients. For seven or more patients - the fee for item x plus $dd.dd per patient" OR | ||
"An amount equal to $dd.dd, plus $dd.dd divided by the number of patients seen, up to a maximum of six patients. For sever or more patients - an amount equal to $dd.dd plus $dd.dd per patient." | ||
*/ | ||
const regex1 = /The fee for item (\d+), plus \$(\d*\.\d+) divided by the number of patients seen, up to a maximum of six patients\.\sFor seven or more patients - the fee for item (\d+) plus \$(\d*\.\d+) per patient/; | ||
const regex2 = /An amount equal to \$(\d+\.\d+), plus \$(\d+\.\d+) divided by the number of patients seen, up to a maximum of six patients\.\sFor seven or more patients - an amount equal to \$(\d*\.\d+) plus \$(\d*\.\d+) per patient/; | ||
const regex3 = /The fee for item (\d+) plus for each field in excess of 1, an amount of \$(\d+\.\d+)/; | ||
const regex4 = /The fee for item (\d+) plus \$(\d+\.\d+) for each additional 15 minutes or part thereof beyond the first hour of attendance by the medical practitioner/; | ||
derivedItems.forEach((item) => { | ||
let matches = item.derivedFeeDescription.match(regex1); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additionalForUpToSixPatients = converters.floatConverter(matches[2]); | ||
const additionalForSevenOrMorePatients = converters.floatConverter(matches[4]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
the derived fee has the form "The fee for item d, plus $dd.dd divided by the number of patients seen, up to a maximum of six patients. For seven or more patients - the fee for item x plus $dd.dd per patient" OR | ||
"An amount equal to $dd.dd, plus $dd.dd divided by the number of patients seen, up to a maximum of six patients. For sever or more patients - an amount equal to $dd.dd plus $dd.dd per patient." | ||
*/ | ||
const regex1 = /The fee for item (\d+), plus \$(\d*\.\d+) divided by the number of patients seen, up to a maximum of six patients\.\sFor seven or more patients - the fee for item (\d+) plus \$(\d*\.\d+) per patient/; | ||
const regex2 = /An amount equal to \$(\d+\.\d+), plus \$(\d+\.\d+) divided by the number of patients seen, up to a maximum of six patients\.\sFor seven or more patients - an amount equal to \$(\d*\.\d+) plus \$(\d*\.\d+) per patient/; | ||
const regex3 = /The fee for item (\d+) plus for each field in excess of 1, an amount of \$(\d+\.\d+)/; | ||
const regex4 = /The fee for item (\d+) plus \$(\d+\.\d+) for each additional 15 minutes or part thereof beyond the first hour of attendance by the medical practitioner/; | ||
derivedItems.forEach((item) => { | ||
let matches = item.derivedFeeDescription.match(regex1); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additionalForUpToSixPatients = converters.floatConverter(matches[2]); | ||
const additionalForSevenOrMorePatients = converters.floatConverter(matches[4]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additionalForUpToSixPatients; | ||
item.additionalFeeMaxPatientNumber = 6; | ||
item.additionalFeePerPatientOverMaxNumber = additionalForSevenOrMorePatients; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additionalForUpToSixPatients; | ||
item.additionalFeeMaxPatientNumber = 6; | ||
item.additionalFeePerPatientOverMaxNumber = additionalForSevenOrMorePatients; | ||
} | ||
matches = item.derivedFeeDescription.match(regex2); | ||
if (matches) { | ||
const baseFee = converters.floatConverter(matches[1]); | ||
const additionalForUpToSixPatients = converters.floatConverter(matches[2]); | ||
const additionalForSevenOrMorePatients = converters.floatConverter(matches[4]); | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additionalForUpToSixPatients; | ||
item.additionalFeeMaxPatientNumber = 6; | ||
item.additionalFeePerPatientOverMaxNumber = additionalForSevenOrMorePatients; | ||
} | ||
matches = item.derivedFeeDescription.match(regex3); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additional = converters.floatConverter(matches[2]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
matches = item.derivedFeeDescription.match(regex2); | ||
if (matches) { | ||
const baseFee = converters.floatConverter(matches[1]); | ||
const additionalForUpToSixPatients = converters.floatConverter(matches[2]); | ||
const additionalForSevenOrMorePatients = converters.floatConverter(matches[4]); | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additionalForUpToSixPatients; | ||
item.additionalFeeMaxPatientNumber = 6; | ||
item.additionalFeePerPatientOverMaxNumber = additionalForSevenOrMorePatients; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additional; | ||
item.additionalFeeMaxPatientNumber = -1; | ||
} | ||
matches = item.derivedFeeDescription.match(regex4); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additional = converters.floatConverter(matches[2]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
matches = item.derivedFeeDescription.match(regex3); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additional = converters.floatConverter(matches[2]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additional; | ||
item.additionalFeeMaxPatientNumber = -1; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additional; | ||
item.additionalFeeMaxPatientNumber = -1; | ||
} | ||
db.collection(this.collection).replaceOne({ _id: item._id }, item); | ||
matches = item.derivedFeeDescription.match(regex4); | ||
if (matches) { | ||
let baseFee = 0; | ||
const itemNumberAsBaseFee = matches[1]; | ||
const additional = converters.floatConverter(matches[2]); | ||
// find the base fee | ||
const foundIndex = processedItems.findIndex((processedItem) => processedItem._id === itemNumberAsBaseFee); | ||
if (foundIndex >= 0) { | ||
baseFee = processedItems[foundIndex].scheduleFee; | ||
} | ||
item.scheduleFee = baseFee; | ||
item.additionalFee = additional; | ||
item.additionalFeeMaxPatientNumber = -1; | ||
} | ||
db.collection(this.collection).replaceOne({ _id: item._id }, item); | ||
}); | ||
resolve(processedItems.length); | ||
}); | ||
resolve(processedItems.length); | ||
}); | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
else { | ||
resolve(0); | ||
} | ||
} | ||
@@ -196,0 +205,0 @@ else { |
{ | ||
"name": "mbs-importer-jps", | ||
"version": "1.0.0-2", | ||
"version": "1.0.0-3", | ||
"description": "A patient management web application", | ||
@@ -5,0 +5,0 @@ "main": "dist/XMLImporter.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41227
502