const db = require('../models'); const Users = db.users; const Appointments = db.appointments; const Messages = db.messages; const Patients = db.patients; const Prescriptions = db.prescriptions; const Services = db.services; const WaitingRooms = db.waiting_rooms; 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'), status: 'cancelled', }, { // 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'), status: 'scheduled', }, { // 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'), status: 'cancelled', }, ]; const MessagesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field content: 'Please review the latest reports.', sent_at: new Date('2023-10-01T08:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field content: 'Meeting scheduled for tomorrow.', sent_at: new Date('2023-10-01T09:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field content: 'Patient records updated.', sent_at: new Date('2023-10-01T10:00:00Z'), }, ]; const PatientsData = [ { first_name: 'John', last_name: 'Doe', date_of_birth: new Date('1980-05-15T00:00:00Z'), contact_number: '1234567890', // type code here for "relation_many" field }, { first_name: 'Jane', last_name: 'Smith', date_of_birth: new Date('1990-07-20T00:00:00Z'), contact_number: '0987654321', // type code here for "relation_many" field }, { first_name: 'Alice', last_name: 'Johnson', date_of_birth: new Date('1975-03-10T00:00:00Z'), contact_number: '1122334455', // type code here for "relation_many" field }, ]; const PrescriptionsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field medication: 'Paracetamol 500mg', date_issued: new Date('2023-10-01T00:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field medication: 'Ibuprofen 200mg', date_issued: new Date('2023-10-02T00:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field medication: 'Amoxicillin 250mg', date_issued: new Date('2023-10-03T00:00:00Z'), }, ]; const ServicesData = [ { service_name: 'General Consultation', price: 50, }, { service_name: 'Dental Checkup', price: 75, }, { service_name: 'Eye Examination', price: 60, }, ]; const WaitingRoomsData = [ { // type code here for "relation_many" field status: 'completed', }, { // type code here for "relation_many" field status: 'completed', }, { // type code here for "relation_many" field status: 'in_consultation', }, ]; // Similar logic for "relation_many" 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); } } async function associateAppointmentWithDoctor() { const relatedDoctor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment0 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Appointment0?.setDoctor) { await Appointment0.setDoctor(relatedDoctor0); } const relatedDoctor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment1 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Appointment1?.setDoctor) { await Appointment1.setDoctor(relatedDoctor1); } const relatedDoctor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment2 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Appointment2?.setDoctor) { await Appointment2.setDoctor(relatedDoctor2); } } async function associateMessageWithSender() { const relatedSender0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message0 = await Messages.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Message0?.setSender) { await Message0.setSender(relatedSender0); } const relatedSender1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message1 = await Messages.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Message1?.setSender) { await Message1.setSender(relatedSender1); } const relatedSender2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message2 = await Messages.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Message2?.setSender) { await Message2.setSender(relatedSender2); } } async function associateMessageWithReceiver() { const relatedReceiver0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message0 = await Messages.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Message0?.setReceiver) { await Message0.setReceiver(relatedReceiver0); } const relatedReceiver1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message1 = await Messages.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Message1?.setReceiver) { await Message1.setReceiver(relatedReceiver1); } const relatedReceiver2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message2 = await Messages.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Message2?.setReceiver) { await Message2.setReceiver(relatedReceiver2); } } // Similar logic for "relation_many" async function associatePrescriptionWithPatient() { const relatedPatient0 = await Patients.findOne({ offset: Math.floor(Math.random() * (await Patients.count())), }); const Prescription0 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Prescription0?.setPatient) { await Prescription0.setPatient(relatedPatient0); } const relatedPatient1 = await Patients.findOne({ offset: Math.floor(Math.random() * (await Patients.count())), }); const Prescription1 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Prescription1?.setPatient) { await Prescription1.setPatient(relatedPatient1); } const relatedPatient2 = await Patients.findOne({ offset: Math.floor(Math.random() * (await Patients.count())), }); const Prescription2 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Prescription2?.setPatient) { await Prescription2.setPatient(relatedPatient2); } } async function associatePrescriptionWithDoctor() { const relatedDoctor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription0 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Prescription0?.setDoctor) { await Prescription0.setDoctor(relatedDoctor0); } const relatedDoctor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription1 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Prescription1?.setDoctor) { await Prescription1.setDoctor(relatedDoctor1); } const relatedDoctor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Prescription2 = await Prescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Prescription2?.setDoctor) { await Prescription2.setDoctor(relatedDoctor2); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Appointments.bulkCreate(AppointmentsData); await Messages.bulkCreate(MessagesData); await Patients.bulkCreate(PatientsData); await Prescriptions.bulkCreate(PrescriptionsData); await Services.bulkCreate(ServicesData); await WaitingRooms.bulkCreate(WaitingRoomsData); await Promise.all([ // Similar logic for "relation_many" await associateAppointmentWithPatient(), await associateAppointmentWithDoctor(), await associateMessageWithSender(), await associateMessageWithReceiver(), // Similar logic for "relation_many" await associatePrescriptionWithPatient(), await associatePrescriptionWithDoctor(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('appointments', null, {}); await queryInterface.bulkDelete('messages', null, {}); await queryInterface.bulkDelete('patients', null, {}); await queryInterface.bulkDelete('prescriptions', null, {}); await queryInterface.bulkDelete('services', null, {}); await queryInterface.bulkDelete('waiting_rooms', null, {}); }, };