181 lines
2.6 KiB
JavaScript
181 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 appointment_requests = sequelize.define(
|
|
'appointment_requests',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
requested_start_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
requested_end_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"pending",
|
|
|
|
|
|
"approved",
|
|
|
|
|
|
"declined",
|
|
|
|
|
|
"rescheduled",
|
|
|
|
|
|
"cancelled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
patient_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
internal_notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
decision_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
appointment_requests.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.appointment_requests.hasMany(db.appointments, {
|
|
as: 'appointments_appointment_request',
|
|
foreignKey: {
|
|
name: 'appointment_requestId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.appointment_requests.belongsTo(db.locations, {
|
|
as: 'location',
|
|
foreignKey: {
|
|
name: 'locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.appointment_requests.belongsTo(db.patients, {
|
|
as: 'patient',
|
|
foreignKey: {
|
|
name: 'patientId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.appointment_requests.belongsTo(db.services, {
|
|
as: 'service',
|
|
foreignKey: {
|
|
name: 'serviceId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.appointment_requests.belongsTo(db.dentist_profiles, {
|
|
as: 'preferred_dentist',
|
|
foreignKey: {
|
|
name: 'preferred_dentistId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.appointment_requests.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.appointment_requests.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.appointment_requests.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return appointment_requests;
|
|
};
|
|
|
|
|