154 lines
3.2 KiB
JavaScript
154 lines
3.2 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 hospitals = sequelize.define(
|
|
'hospitals',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
hospitals.associate = (db) => {
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
db.hospitals.hasMany(db.users, {
|
|
as: 'users_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.chats, {
|
|
as: 'chats_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.clinical_procedures, {
|
|
as: 'clinical_procedures_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.imaging_studies, {
|
|
as: 'imaging_studies_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.interconsultations, {
|
|
as: 'interconsultations_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.lab_tests, {
|
|
as: 'lab_tests_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.medical_histories, {
|
|
as: 'medical_histories_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.medications, {
|
|
as: 'medications_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.notifications, {
|
|
as: 'notifications_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.patients, {
|
|
as: 'patients_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.referrals, {
|
|
as: 'referrals_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.triage_categories, {
|
|
as: 'triage_categories_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.hospitals.hasMany(db.vital_signs, {
|
|
as: 'vital_signs_hospitals',
|
|
foreignKey: {
|
|
name: 'hospitalsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
//end loop
|
|
|
|
db.hospitals.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.hospitals.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return hospitals;
|
|
};
|