31153/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-01 19:13:38 +00:00

1228 lines
32 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Appointments = db.appointments;
const BillingRecords = db.billing_records;
const Departments = db.departments;
const EmrRecords = db.emr_records;
const LabResults = db.lab_results;
const Patients = db.patients;
const PharmacyOrders = db.pharmacy_orders;
const Organizations = db.organizations;
const AppointmentsData = [
{
start_time: new Date('2023-11-01T09:00:00Z'),
end_time: new Date('2023-11-01T09: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-11-02T10:00:00Z'),
end_time: new Date('2023-11-02T10: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-11-03T11:00:00Z'),
end_time: new Date('2023-11-03T11: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
},
];
const BillingRecordsData = [
{
// type code here for "relation_one" field
amount: 150,
status: 'paid',
billing_date: new Date('2023-10-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: 'pending',
billing_date: new Date('2023-10-02T00: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: 'overdue',
billing_date: new Date('2023-10-03T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const DepartmentsData = [
{
name: 'Cardiology',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Radiology',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Pediatrics',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const EmrRecordsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
notes: 'Patient shows improvement in blood pressure.',
recorded_at: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
notes: 'Prescribed medication for diabetes management.',
recorded_at: new Date('2023-10-02T11:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
notes: 'Follow-up required for cholesterol levels.',
recorded_at: new Date('2023-10-03T12:00:00Z'),
// type code here for "relation_one" field
},
];
const LabResultsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
test_name: 'Complete Blood Count',
result: 'Normal',
recorded_at: new Date('2023-10-01T10:00: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
test_name: 'Lipid Panel',
result: 'High cholesterol',
recorded_at: new Date('2023-10-02T11:00: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
test_name: 'Blood Glucose',
result: 'Elevated',
recorded_at: new Date('2023-10-03T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const PatientsData = [
{
first_name: 'Ali',
last_name: 'Al-Farsi',
national_id: '1234567890',
date_of_birth: new Date('1985-06-15T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Fatima',
last_name: 'Al-Mutairi',
national_id: '0987654321',
date_of_birth: new Date('1990-11-20T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Mohammed',
last_name: 'Al-Qahtani',
national_id: '1122334455',
date_of_birth: new Date('1978-03-05T00:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const PharmacyOrdersData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
medication: 'Atorvastatin',
prescribed_at: new Date('2023-10-01T10:00: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
medication: 'Metformin',
prescribed_at: new Date('2023-10-02T11:00: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
medication: 'Lisinopril',
prescribed_at: new Date('2023-10-03T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Riyadh Health Center',
},
{
name: 'Jeddah Medical Complex',
},
{
name: 'Dammam Clinic',
},
];
// Similar logic for "relation_many"
async function associateUserWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setOrganization) {
await User0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setOrganization) {
await User1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setOrganization) {
await User2.setOrganization(relatedOrganization2);
}
}
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 associateAppointmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setOrganization) {
await Appointment0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setOrganization) {
await Appointment1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setOrganization) {
await Appointment2.setOrganization(relatedOrganization2);
}
}
async function associateAppointmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment0 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Appointment0?.setOrganization) {
await Appointment0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment1 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Appointment1?.setOrganization) {
await Appointment1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Appointment2 = await Appointments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Appointment2?.setOrganization) {
await Appointment2.setOrganization(relatedOrganization2);
}
}
async function associateBillingRecordWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const BillingRecord0 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (BillingRecord0?.setPatient) {
await BillingRecord0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const BillingRecord1 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (BillingRecord1?.setPatient) {
await BillingRecord1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const BillingRecord2 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (BillingRecord2?.setPatient) {
await BillingRecord2.setPatient(relatedPatient2);
}
}
async function associateBillingRecordWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord0 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (BillingRecord0?.setOrganization) {
await BillingRecord0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord1 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (BillingRecord1?.setOrganization) {
await BillingRecord1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord2 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (BillingRecord2?.setOrganization) {
await BillingRecord2.setOrganization(relatedOrganization2);
}
}
async function associateBillingRecordWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord0 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (BillingRecord0?.setOrganization) {
await BillingRecord0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord1 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (BillingRecord1?.setOrganization) {
await BillingRecord1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const BillingRecord2 = await BillingRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (BillingRecord2?.setOrganization) {
await BillingRecord2.setOrganization(relatedOrganization2);
}
}
// Similar logic for "relation_many"
async function associateDepartmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department0 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Department0?.setOrganization) {
await Department0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department1 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Department1?.setOrganization) {
await Department1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department2 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Department2?.setOrganization) {
await Department2.setOrganization(relatedOrganization2);
}
}
async function associateDepartmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department0 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Department0?.setOrganization) {
await Department0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department1 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Department1?.setOrganization) {
await Department1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Department2 = await Departments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Department2?.setOrganization) {
await Department2.setOrganization(relatedOrganization2);
}
}
async function associateEmrRecordWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const EmrRecord0 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (EmrRecord0?.setPatient) {
await EmrRecord0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const EmrRecord1 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (EmrRecord1?.setPatient) {
await EmrRecord1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const EmrRecord2 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (EmrRecord2?.setPatient) {
await EmrRecord2.setPatient(relatedPatient2);
}
}
async function associateEmrRecordWithDoctor() {
const relatedDoctor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmrRecord0 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (EmrRecord0?.setDoctor) {
await EmrRecord0.setDoctor(relatedDoctor0);
}
const relatedDoctor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmrRecord1 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (EmrRecord1?.setDoctor) {
await EmrRecord1.setDoctor(relatedDoctor1);
}
const relatedDoctor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmrRecord2 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (EmrRecord2?.setDoctor) {
await EmrRecord2.setDoctor(relatedDoctor2);
}
}
async function associateEmrRecordWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmrRecord0 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (EmrRecord0?.setOrganization) {
await EmrRecord0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmrRecord1 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (EmrRecord1?.setOrganization) {
await EmrRecord1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmrRecord2 = await EmrRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (EmrRecord2?.setOrganization) {
await EmrRecord2.setOrganization(relatedOrganization2);
}
}
async function associateLabResultWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const LabResult0 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LabResult0?.setPatient) {
await LabResult0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const LabResult1 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LabResult1?.setPatient) {
await LabResult1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const LabResult2 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LabResult2?.setPatient) {
await LabResult2.setPatient(relatedPatient2);
}
}
async function associateLabResultWithTechnician() {
const relatedTechnician0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LabResult0 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LabResult0?.setTechnician) {
await LabResult0.setTechnician(relatedTechnician0);
}
const relatedTechnician1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LabResult1 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LabResult1?.setTechnician) {
await LabResult1.setTechnician(relatedTechnician1);
}
const relatedTechnician2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const LabResult2 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LabResult2?.setTechnician) {
await LabResult2.setTechnician(relatedTechnician2);
}
}
async function associateLabResultWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult0 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LabResult0?.setOrganization) {
await LabResult0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult1 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LabResult1?.setOrganization) {
await LabResult1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult2 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LabResult2?.setOrganization) {
await LabResult2.setOrganization(relatedOrganization2);
}
}
async function associateLabResultWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult0 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (LabResult0?.setOrganization) {
await LabResult0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult1 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (LabResult1?.setOrganization) {
await LabResult1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const LabResult2 = await LabResults.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (LabResult2?.setOrganization) {
await LabResult2.setOrganization(relatedOrganization2);
}
}
async function associatePatientWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setOrganization) {
await Patient0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setOrganization) {
await Patient1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setOrganization) {
await Patient2.setOrganization(relatedOrganization2);
}
}
async function associatePatientWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setOrganization) {
await Patient0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setOrganization) {
await Patient1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setOrganization) {
await Patient2.setOrganization(relatedOrganization2);
}
}
async function associatePharmacyOrderWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const PharmacyOrder0 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (PharmacyOrder0?.setPatient) {
await PharmacyOrder0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const PharmacyOrder1 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (PharmacyOrder1?.setPatient) {
await PharmacyOrder1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const PharmacyOrder2 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (PharmacyOrder2?.setPatient) {
await PharmacyOrder2.setPatient(relatedPatient2);
}
}
async function associatePharmacyOrderWithDoctor() {
const relatedDoctor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PharmacyOrder0 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (PharmacyOrder0?.setDoctor) {
await PharmacyOrder0.setDoctor(relatedDoctor0);
}
const relatedDoctor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PharmacyOrder1 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (PharmacyOrder1?.setDoctor) {
await PharmacyOrder1.setDoctor(relatedDoctor1);
}
const relatedDoctor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PharmacyOrder2 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (PharmacyOrder2?.setDoctor) {
await PharmacyOrder2.setDoctor(relatedDoctor2);
}
}
async function associatePharmacyOrderWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder0 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (PharmacyOrder0?.setOrganization) {
await PharmacyOrder0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder1 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (PharmacyOrder1?.setOrganization) {
await PharmacyOrder1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder2 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (PharmacyOrder2?.setOrganization) {
await PharmacyOrder2.setOrganization(relatedOrganization2);
}
}
async function associatePharmacyOrderWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder0 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (PharmacyOrder0?.setOrganization) {
await PharmacyOrder0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder1 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (PharmacyOrder1?.setOrganization) {
await PharmacyOrder1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const PharmacyOrder2 = await PharmacyOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (PharmacyOrder2?.setOrganization) {
await PharmacyOrder2.setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Appointments.bulkCreate(AppointmentsData);
await BillingRecords.bulkCreate(BillingRecordsData);
await Departments.bulkCreate(DepartmentsData);
await EmrRecords.bulkCreate(EmrRecordsData);
await LabResults.bulkCreate(LabResultsData);
await Patients.bulkCreate(PatientsData);
await PharmacyOrders.bulkCreate(PharmacyOrdersData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateAppointmentWithPatient(),
await associateAppointmentWithDoctor(),
await associateAppointmentWithOrganization(),
await associateAppointmentWithOrganization(),
await associateBillingRecordWithPatient(),
await associateBillingRecordWithOrganization(),
await associateBillingRecordWithOrganization(),
// Similar logic for "relation_many"
await associateDepartmentWithOrganization(),
await associateDepartmentWithOrganization(),
await associateEmrRecordWithPatient(),
await associateEmrRecordWithDoctor(),
await associateEmrRecordWithOrganization(),
await associateLabResultWithPatient(),
await associateLabResultWithTechnician(),
await associateLabResultWithOrganization(),
await associateLabResultWithOrganization(),
await associatePatientWithOrganization(),
await associatePatientWithOrganization(),
await associatePharmacyOrderWithPatient(),
await associatePharmacyOrderWithDoctor(),
await associatePharmacyOrderWithOrganization(),
await associatePharmacyOrderWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('appointments', null, {});
await queryInterface.bulkDelete('billing_records', null, {});
await queryInterface.bulkDelete('departments', null, {});
await queryInterface.bulkDelete('emr_records', null, {});
await queryInterface.bulkDelete('lab_results', null, {});
await queryInterface.bulkDelete('patients', null, {});
await queryInterface.bulkDelete('pharmacy_orders', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};