30721/backend/src/db/models/patients.js
2025-04-14 21:29:31 +00:00

82 lines
1.5 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 patients = sequelize.define(
'patients',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
species: {
type: DataTypes.TEXT,
},
breed: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
patients.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.patients.belongsTo(db.clients, {
as: 'owner',
foreignKey: {
name: 'ownerId',
},
constraints: false,
});
db.patients.belongsTo(db.clinics, {
as: 'clinic',
foreignKey: {
name: 'clinicId',
},
constraints: false,
});
db.patients.belongsTo(db.clinics, {
as: 'clinics',
foreignKey: {
name: 'clinicsId',
},
constraints: false,
});
db.patients.belongsTo(db.users, {
as: 'createdBy',
});
db.patients.belongsTo(db.users, {
as: 'updatedBy',
});
};
return patients;
};