mbs-importer-jps
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -25,2 +25,3 @@ "use strict"; | ||
const moment_1 = __importDefault(require("moment")); | ||
const data_source_controller_1 = require("data-source-controller"); | ||
require('dotenv').config(); | ||
@@ -64,9 +65,9 @@ const converters = require('./util/fieldConverters'); | ||
} | ||
importWithConnection(fileName, db) { | ||
import(fileName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
let parser = new xml2js_1.default.Parser(); | ||
const fullFileName = `${this.importPath}${fileName}`; | ||
if (fs_1.default.existsSync(fullFileName)) { | ||
let data = fs_1.default.readFileSync(fullFileName); | ||
const importFile = `${this.importPath}${fileName}`; | ||
if (fs_1.default.existsSync(importFile)) { | ||
let data = fs_1.default.readFileSync(importFile); | ||
if (data) { | ||
@@ -127,6 +128,6 @@ parser.parseString(data, (err, result) => { | ||
}); | ||
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) => { | ||
data_source_controller_1.DataSourceController.getInstance().deleteAll(this.collection).then((result) => { | ||
data_source_controller_1.DataSourceController.getInstance().insertMany(this.collection, processedItems).then((result) => { | ||
// now we need to calculate the derived values | ||
data_source_controller_1.DataSourceController.getInstance().find(this.collection, { isDerived: true }).then((derivedItems) => { | ||
/* | ||
@@ -197,3 +198,3 @@ compute the derived fee | ||
} | ||
db.collection(this.collection).replaceOne({ _id: item._id }, item); | ||
data_source_controller_1.DataSourceController.getInstance().replaceOne(this.collection, item); | ||
}); | ||
@@ -211,7 +212,7 @@ resolve(processedItems.length); | ||
else { | ||
reject(`No data in file ${fullFileName}`); | ||
reject({ message: `${importFile} no data` }); | ||
} | ||
} | ||
else { | ||
reject(`File ${fullFileName} not present`); | ||
reject({ message: `${importFile} does not exist` }); | ||
} | ||
@@ -221,37 +222,19 @@ }); | ||
} | ||
import(fileName) { | ||
this.fileName = fileName; | ||
} | ||
databaseConnected(db) { | ||
this.db = db; | ||
} | ||
executeJob(runId) { | ||
if (this.db) { | ||
this.importWithConnection(this.fileName, this.db).then((result) => { | ||
this.handleCompleted(this.fileName); | ||
if (this.cb) | ||
this.cb(runId, this.getConfig(), server_socket_framework_jps_1.JobStatus.completed, null); | ||
}) | ||
.catch((err) => { | ||
const error = { | ||
errorPriority: server_socket_framework_jps_1.JobErrorPriority.severe, | ||
jobName: "MBS XML Importer", | ||
message: err.message, | ||
runId: runId | ||
}; | ||
this.handleError(this.fileName); | ||
if (this.cb) | ||
this.cb(runId, this.getConfig(), server_socket_framework_jps_1.JobStatus.failed, [error]); | ||
}); | ||
} | ||
else { | ||
this.import(this.fileName).then((result) => { | ||
this.handleCompleted(this.fileName); | ||
if (this.cb) | ||
this.cb(runId, this.getConfig(), server_socket_framework_jps_1.JobStatus.completed, null); | ||
}) | ||
.catch((err) => { | ||
const error = { | ||
errorPriority: server_socket_framework_jps_1.JobErrorPriority.severe, | ||
jobName: "MBS XML Importer", | ||
message: "database not available", | ||
message: err.message, | ||
runId: runId | ||
}; | ||
this.handleError(this.fileName); | ||
if (this.cb) | ||
this.cb(runId, this.getConfig(), server_socket_framework_jps_1.JobStatus.failed, [error]); | ||
} | ||
}); | ||
} | ||
@@ -258,0 +241,0 @@ getConfig() { |
{ | ||
"name": "mbs-importer-jps", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "A patient management web application", | ||
@@ -5,0 +5,0 @@ "main": "dist/MBSXMLImporter.js", |
Sorry, the diff of this file is not supported yet
31814
340