30202/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-26 14:26:34 +00:00

903 lines
22 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Appointments = db.appointments;
const Invoices = db.invoices;
const MedicalRecords = db.medical_records;
const Patients = db.patients;
const Tenants = db.tenants;
const AppointmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-10T09:00:00Z'),
end_time: new Date('2023-10-10T09:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-11T10:00:00Z'),
end_time: new Date('2023-10-11T10:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-12T11:00:00Z'),
end_time: new Date('2023-10-12T11:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
start_time: new Date('2023-10-13T12:00:00Z'),
end_time: new Date('2023-10-13T12:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const InvoicesData = [
{
// type code here for "relation_one" field
amount: 150,
status: 'unpaid',
issue_date: new Date('2023-09-01T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
amount: 200,
status: 'unpaid',
issue_date: new Date('2023-09-05T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
amount: 250,
status: 'paid',
issue_date: new Date('2023-09-10T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
amount: 300,
status: 'unpaid',
issue_date: new Date('2023-09-15T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const MedicalRecordsData = [
{
// type code here for "relation_one" field
notes: 'Patient has a history of hypertension.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
notes: 'Patient is allergic to penicillin.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
notes: 'Patient requires regular check-ups for diabetes.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
notes: 'Patient has a family history of heart disease.',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const PatientsData = [
{
first_name: 'John',
last_name: 'Doe',
date_of_birth: new Date('1985-06-15T00:00:00Z'),
email: 'john.doe@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Jane',
last_name: 'Smith',
date_of_birth: new Date('1990-09-25T00:00:00Z'),
email: 'jane.smith@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Emily',
last_name: 'Johnson',
date_of_birth: new Date('1978-03-12T00:00:00Z'),
email: 'emily.johnson@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Michael',
last_name: 'Brown',
date_of_birth: new Date('1982-11-30T00:00:00Z'),
email: 'michael.brown@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const TenantsData = [
{
name: 'Health Clinic A',
},
{
name: 'Health Clinic B',
},
{
name: 'Health Clinic C',
},
{
name: 'Health Clinic D',
},
];
// Similar logic for "relation_many"
async function associateUserWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setTenant) {
await User0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setTenant) {
await User1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setTenant) {
await User2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setTenant) {
await User3.setTenant(relatedTenant3);
}
}
async function associateAppointmentWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setPatient) {
await Appointment0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setPatient) {
await Appointment1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setPatient) {
await Appointment2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Appointment3 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Appointment3?.setPatient) {
await Appointment3.setPatient(relatedPatient3);
}
}
async function associateAppointmentWithHealth_professional() {
const relatedHealth_professional0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setHealth_professional) {
await Appointment0.setHealth_professional(relatedHealth_professional0);
}
const relatedHealth_professional1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setHealth_professional) {
await Appointment1.setHealth_professional(relatedHealth_professional1);
}
const relatedHealth_professional2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setHealth_professional) {
await Appointment2.setHealth_professional(relatedHealth_professional2);
}
const relatedHealth_professional3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Appointment3 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Appointment3?.setHealth_professional) {
await Appointment3.setHealth_professional(relatedHealth_professional3);
}
}
async function associateAppointmentWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setTenant) {
await Appointment0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setTenant) {
await Appointment1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setTenant) {
await Appointment2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment3 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Appointment3?.setTenant) {
await Appointment3.setTenant(relatedTenant3);
}
}
async function associateAppointmentWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setTenant) {
await Appointment0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setTenant) {
await Appointment1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setTenant) {
await Appointment2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Appointment3 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Appointment3?.setTenant) {
await Appointment3.setTenant(relatedTenant3);
}
}
async function associateInvoiceWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setPatient) {
await Invoice0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setPatient) {
await Invoice1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setPatient) {
await Invoice2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setPatient) {
await Invoice3.setPatient(relatedPatient3);
}
}
async function associateInvoiceWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setTenant) {
await Invoice0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setTenant) {
await Invoice1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setTenant) {
await Invoice2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setTenant) {
await Invoice3.setTenant(relatedTenant3);
}
}
async function associateInvoiceWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice0 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Invoice0?.setTenant) {
await Invoice0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice1 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Invoice1?.setTenant) {
await Invoice1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice2 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Invoice2?.setTenant) {
await Invoice2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Invoice3 = await Invoices.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Invoice3?.setTenant) {
await Invoice3.setTenant(relatedTenant3);
}
}
async function associateMedicalRecordWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalRecord0 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicalRecord0?.setPatient) {
await MedicalRecord0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalRecord1 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicalRecord1?.setPatient) {
await MedicalRecord1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalRecord2 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicalRecord2?.setPatient) {
await MedicalRecord2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalRecord3 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MedicalRecord3?.setPatient) {
await MedicalRecord3.setPatient(relatedPatient3);
}
}
async function associateMedicalRecordWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord0 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicalRecord0?.setTenant) {
await MedicalRecord0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord1 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicalRecord1?.setTenant) {
await MedicalRecord1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord2 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicalRecord2?.setTenant) {
await MedicalRecord2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord3 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MedicalRecord3?.setTenant) {
await MedicalRecord3.setTenant(relatedTenant3);
}
}
async function associateMedicalRecordWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord0 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicalRecord0?.setTenant) {
await MedicalRecord0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord1 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicalRecord1?.setTenant) {
await MedicalRecord1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord2 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicalRecord2?.setTenant) {
await MedicalRecord2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const MedicalRecord3 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MedicalRecord3?.setTenant) {
await MedicalRecord3.setTenant(relatedTenant3);
}
}
async function associatePatientWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setTenant) {
await Patient0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setTenant) {
await Patient1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setTenant) {
await Patient2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient3 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Patient3?.setTenant) {
await Patient3.setTenant(relatedTenant3);
}
}
async function associatePatientWithTenant() {
const relatedTenant0 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setTenant) {
await Patient0.setTenant(relatedTenant0);
}
const relatedTenant1 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setTenant) {
await Patient1.setTenant(relatedTenant1);
}
const relatedTenant2 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setTenant) {
await Patient2.setTenant(relatedTenant2);
}
const relatedTenant3 = await Tenants.findOne({
offset: Math.floor(Math.random() * (await Tenants.count())),
});
const Patient3 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Patient3?.setTenant) {
await Patient3.setTenant(relatedTenant3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Appointments.bulkCreate(AppointmentsData);
await Invoices.bulkCreate(InvoicesData);
await MedicalRecords.bulkCreate(MedicalRecordsData);
await Patients.bulkCreate(PatientsData);
await Tenants.bulkCreate(TenantsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithTenant(),
await associateAppointmentWithPatient(),
await associateAppointmentWithHealth_professional(),
await associateAppointmentWithTenant(),
await associateAppointmentWithTenant(),
await associateInvoiceWithPatient(),
await associateInvoiceWithTenant(),
await associateInvoiceWithTenant(),
await associateMedicalRecordWithPatient(),
await associateMedicalRecordWithTenant(),
await associateMedicalRecordWithTenant(),
await associatePatientWithTenant(),
await associatePatientWithTenant(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('appointments', null, {});
await queryInterface.bulkDelete('invoices', null, {});
await queryInterface.bulkDelete('medical_records', null, {});
await queryInterface.bulkDelete('patients', null, {});
await queryInterface.bulkDelete('tenants', null, {});
},
};