390 lines
8.8 KiB
JavaScript
390 lines
8.8 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Appointments = db.appointments;
|
|
|
|
const Patients = db.patients;
|
|
|
|
const Receipts = db.receipts;
|
|
|
|
const Reviews = db.reviews;
|
|
|
|
const AppointmentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
reminder_sent: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-02T11:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-02T12:00:00Z'),
|
|
|
|
reminder_sent: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-03T14:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-03T15:00:00Z'),
|
|
|
|
reminder_sent: true,
|
|
},
|
|
];
|
|
|
|
const PatientsData = [
|
|
{
|
|
first_name: 'Juan',
|
|
|
|
last_name: 'Perez',
|
|
|
|
date_of_birth: new Date('1985-06-15T00:00:00Z'),
|
|
|
|
contact_number: '5551234567',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Maria',
|
|
|
|
last_name: 'Lopez',
|
|
|
|
date_of_birth: new Date('1990-08-22T00:00:00Z'),
|
|
|
|
contact_number: '5559876543',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Carlos',
|
|
|
|
last_name: 'Gomez',
|
|
|
|
date_of_birth: new Date('1978-11-30T00:00:00Z'),
|
|
|
|
contact_number: '5552345678',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ReceiptsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
receipt_number: 'R001',
|
|
|
|
issue_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
total_amount: 150,
|
|
|
|
payment_status: 'paid',
|
|
|
|
payment_date: new Date('2023-10-02T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
receipt_number: 'R002',
|
|
|
|
issue_date: new Date('2023-10-05T00:00:00Z'),
|
|
|
|
total_amount: 200,
|
|
|
|
payment_status: 'paid',
|
|
|
|
payment_date: new Date(Date.now()),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
receipt_number: 'R003',
|
|
|
|
issue_date: new Date('2023-10-10T00:00:00Z'),
|
|
|
|
total_amount: 175,
|
|
|
|
payment_status: 'paid',
|
|
|
|
payment_date: new Date('2023-10-11T00:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const ReviewsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
review_text: 'Excellent service, very professional.',
|
|
|
|
rating: 5,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
review_text: 'Good experience, but room for improvement.',
|
|
|
|
rating: 4,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
review_text: 'Average service, expected more.',
|
|
|
|
rating: 3,
|
|
},
|
|
];
|
|
|
|
// 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 associateAppointmentWithProfessional() {
|
|
const relatedProfessional0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment0 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appointment0?.setProfessional) {
|
|
await Appointment0.setProfessional(relatedProfessional0);
|
|
}
|
|
|
|
const relatedProfessional1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment1 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appointment1?.setProfessional) {
|
|
await Appointment1.setProfessional(relatedProfessional1);
|
|
}
|
|
|
|
const relatedProfessional2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment2 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appointment2?.setProfessional) {
|
|
await Appointment2.setProfessional(relatedProfessional2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateReceiptWithPatient() {
|
|
const relatedPatient0 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Receipt0 = await Receipts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Receipt0?.setPatient) {
|
|
await Receipt0.setPatient(relatedPatient0);
|
|
}
|
|
|
|
const relatedPatient1 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Receipt1 = await Receipts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Receipt1?.setPatient) {
|
|
await Receipt1.setPatient(relatedPatient1);
|
|
}
|
|
|
|
const relatedPatient2 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Receipt2 = await Receipts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Receipt2?.setPatient) {
|
|
await Receipt2.setPatient(relatedPatient2);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithPatient() {
|
|
const relatedPatient0 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setPatient) {
|
|
await Review0.setPatient(relatedPatient0);
|
|
}
|
|
|
|
const relatedPatient1 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setPatient) {
|
|
await Review1.setPatient(relatedPatient1);
|
|
}
|
|
|
|
const relatedPatient2 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setPatient) {
|
|
await Review2.setPatient(relatedPatient2);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithAppointment() {
|
|
const relatedAppointment0 = await Appointments.findOne({
|
|
offset: Math.floor(Math.random() * (await Appointments.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setAppointment) {
|
|
await Review0.setAppointment(relatedAppointment0);
|
|
}
|
|
|
|
const relatedAppointment1 = await Appointments.findOne({
|
|
offset: Math.floor(Math.random() * (await Appointments.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setAppointment) {
|
|
await Review1.setAppointment(relatedAppointment1);
|
|
}
|
|
|
|
const relatedAppointment2 = await Appointments.findOne({
|
|
offset: Math.floor(Math.random() * (await Appointments.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setAppointment) {
|
|
await Review2.setAppointment(relatedAppointment2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Appointments.bulkCreate(AppointmentsData);
|
|
|
|
await Patients.bulkCreate(PatientsData);
|
|
|
|
await Receipts.bulkCreate(ReceiptsData);
|
|
|
|
await Reviews.bulkCreate(ReviewsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateAppointmentWithPatient(),
|
|
|
|
await associateAppointmentWithProfessional(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateReceiptWithPatient(),
|
|
|
|
await associateReviewWithPatient(),
|
|
|
|
await associateReviewWithAppointment(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('appointments', null, {});
|
|
|
|
await queryInterface.bulkDelete('patients', null, {});
|
|
|
|
await queryInterface.bulkDelete('receipts', null, {});
|
|
|
|
await queryInterface.bulkDelete('reviews', null, {});
|
|
},
|
|
};
|