Skip to content

Commit

Permalink
updated endpoints with additional variables - waittime
Browse files Browse the repository at this point in the history
  • Loading branch information
vicwere committed Apr 11, 2024
1 parent f527f96 commit 5d69138
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions models/admissions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Admissions = sequelize.sequelize.define(
capacity: Sequelize.BIGINT,
occupancy: Sequelize.BIGINT,
new_admissions: Sequelize.BIGINT,
discharges: Sequelize.BIGINT,
record_pk: {
type: Sequelize.STRING,
unique: true // Ensure uniqueness of record
Expand Down
31 changes: 31 additions & 0 deletions models/waittime_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const sequelize = require("../db_config_test");
const Sequelize = require("sequelize");

const Waittime = sequelize.sequelize.define(
"waittime", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
timestamp: Sequelize.TEXT,
mfl_code: Sequelize.INTEGER,
county: Sequelize.TEXT,
sub_county: Sequelize.TEXT,
facility_name:Sequelize.TEXT,

queue: Sequelize.TEXT,
average_wait_time: Sequelize.FLOAT,
record_pk: {
type: Sequelize.STRING,
unique: true // Ensure uniqueness of usernames
},
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "waittime"
}
);
exports.Waittime = Waittime;
25 changes: 23 additions & 2 deletions routes/receiver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const {Visits} = require("../models/visits_test");
const {Workload} = require("../models/workload_test");
const {Mortality} = require("../models/mortality_test");

const {Waittime} = require("../models/waittime_test");



//Check Empty Json
function isEmptyJSON(jsonObject) {
Expand Down Expand Up @@ -95,6 +98,9 @@ function addNewElement(jsonData, mfl_code,facility_name,county, sub_county, time
case 'mortality':
record.record_pk = base64.encode(mfl_code+timestamp_unix+record.cause_of_death);
break;
case 'waittime':
record.record_pk = base64.encode(mfl_code+timestamp_unix+record.queue);
break;


}
Expand All @@ -104,7 +110,7 @@ function addNewElement(jsonData, mfl_code,facility_name,county, sub_county, time
}

//Function To Create Data
async function visualizer_records(facility_data, visits_data, workload_data, payments_data, inventory_data, diagnosis_data, billing_data, admissions_data, mortality_data) {
async function visualizer_records(facility_data, visits_data, workload_data, payments_data, inventory_data, diagnosis_data, billing_data, admissions_data, mortality_data, waittime_data) {
let transaction;
try {
// Start a transaction
Expand Down Expand Up @@ -167,6 +173,13 @@ async function visualizer_records(facility_data, visits_data, workload_data, pay
}, { transaction });
}


if (_.isEmpty(waittime_data) == false) {
const waittime_created = await Waittime.bulkCreate(waittime_data, {
updateOnDuplicate: ['queue', 'average_wait_time']// Update the 'Total' field if the timestamp and visit type is same
}, { transaction });
}




Expand Down Expand Up @@ -293,13 +306,21 @@ console.log(facility_attributes);
var mortality = {};
}

if(_.isEmpty(req.body.wait_time) == false)
{
var waittime = addNewElement(req.body.wait_time, mfl_code, facility_name,county, sub_county,timestamp, timestamp_unix, 'waittime');
} else {
var waittime = {};
}








visualizer_records(facility_attributes, visits,workload, payments, inventory,diagnosis,billing, admissions, mortality )
visualizer_records(facility_attributes, visits,workload, payments, inventory,diagnosis,billing, admissions, mortality, waittime )
.then(
facility_attributes => {
return res.status(200).json({success: true,
Expand Down

0 comments on commit 5d69138

Please sign in to comment.