From 5d6913872b551bf839cf221f76215a595ff3aa80 Mon Sep 17 00:00:00 2001 From: vicwere Date: Thu, 11 Apr 2024 13:54:25 +0300 Subject: [PATCH] updated endpoints with additional variables - waittime --- models/admissions_test.js | 1 + models/waittime_test.js | 31 +++++++++++++++++++++++++++++++ routes/receiver_test.js | 25 +++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 models/waittime_test.js diff --git a/models/admissions_test.js b/models/admissions_test.js index 699307a..92b1f2b 100644 --- a/models/admissions_test.js +++ b/models/admissions_test.js @@ -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 diff --git a/models/waittime_test.js b/models/waittime_test.js new file mode 100644 index 0000000..aafe9c6 --- /dev/null +++ b/models/waittime_test.js @@ -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; \ No newline at end of file diff --git a/routes/receiver_test.js b/routes/receiver_test.js index a2446eb..6fe5de8 100644 --- a/routes/receiver_test.js +++ b/routes/receiver_test.js @@ -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) { @@ -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; } @@ -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 @@ -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 }); + } + @@ -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,