2026-03-25 01:24:53 +00:00

221 lines
2.6 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const denials = sequelize.define(
'denials',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
denial_at: {
type: DataTypes.DATE,
},
denial_type: {
type: DataTypes.ENUM,
values: [
"medical_necessity",
"administrative",
"eligibility",
"coding",
"duplicate",
"other"
],
},
denial_reason_text: {
type: DataTypes.TEXT,
},
denial_code: {
type: DataTypes.TEXT,
},
dollars_denied: {
type: DataTypes.DECIMAL,
},
status: {
type: DataTypes.ENUM,
values: [
"new",
"triaged",
"appeal_needed",
"appeal_in_progress",
"overturned",
"upheld",
"closed"
],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
denials.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.denials.hasMany(db.appeals, {
as: 'appeals_denial',
foreignKey: {
name: 'denialId',
},
constraints: false,
});
//end loop
db.denials.belongsTo(db.organizations, {
as: 'organization',
foreignKey: {
name: 'organizationId',
},
constraints: false,
});
db.denials.belongsTo(db.locations, {
as: 'location',
foreignKey: {
name: 'locationId',
},
constraints: false,
});
db.denials.belongsTo(db.authorization_cases, {
as: 'authorization_case',
foreignKey: {
name: 'authorization_caseId',
},
constraints: false,
});
db.denials.belongsTo(db.submissions, {
as: 'submission',
foreignKey: {
name: 'submissionId',
},
constraints: false,
});
db.denials.belongsTo(db.users, {
as: 'owner_user',
foreignKey: {
name: 'owner_userId',
},
constraints: false,
});
db.denials.belongsTo(db.users, {
as: 'createdBy',
});
db.denials.belongsTo(db.users, {
as: 'updatedBy',
});
};
return denials;
};