1910 lines
48 KiB
JavaScript
1910 lines
48 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Appointments = db.appointments;
|
|
|
|
const Departments = db.departments;
|
|
|
|
const EmrRecords = db.emr_records;
|
|
|
|
const ImagingOrders = db.imaging_orders;
|
|
|
|
const Invoices = db.invoices;
|
|
|
|
const LabOrders = db.lab_orders;
|
|
|
|
const Patients = db.patients;
|
|
|
|
const PharmacyOrders = db.pharmacy_orders;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
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: 'scheduled',
|
|
|
|
type: 'new',
|
|
|
|
// 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'),
|
|
|
|
status: 'checked_in',
|
|
|
|
type: 'new',
|
|
|
|
// 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'),
|
|
|
|
status: 'completed',
|
|
|
|
type: 'follow_up',
|
|
|
|
// 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'),
|
|
|
|
status: 'checked_in',
|
|
|
|
type: 'follow_up',
|
|
|
|
// 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-14T13:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-14T13:30:00Z'),
|
|
|
|
status: 'scheduled',
|
|
|
|
type: 'new',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const DepartmentsData = [
|
|
{
|
|
name: 'Cardiology',
|
|
|
|
description: 'Heart and vascular care department.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Radiology',
|
|
|
|
description: 'Imaging and diagnostic services department.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Pediatrics',
|
|
|
|
description: 'Child healthcare services department.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Orthopedics',
|
|
|
|
description: 'Bone and joint care department.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Dermatology',
|
|
|
|
description: 'Skin care and treatment department.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const EmrRecordsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
symptoms: 'Chest pain and shortness of breath.',
|
|
|
|
diagnosis: 'Angina pectoris.',
|
|
|
|
medications: 'Aspirin, Nitroglycerin.',
|
|
|
|
lab_tests: 'ECG, Blood test.',
|
|
|
|
imaging_investigations: 'Chest X-ray.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
symptoms: 'Fever and cough.',
|
|
|
|
diagnosis: 'Viral infection.',
|
|
|
|
medications: 'Paracetamol, Cough syrup.',
|
|
|
|
lab_tests: 'CBC, Throat swab.',
|
|
|
|
imaging_investigations: 'None.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
symptoms: 'Back pain and stiffness.',
|
|
|
|
diagnosis: 'Lumbar strain.',
|
|
|
|
medications: 'Ibuprofen, Muscle relaxant.',
|
|
|
|
lab_tests: 'None.',
|
|
|
|
imaging_investigations: 'MRI of the lumbar spine.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
symptoms: 'Rash and itching.',
|
|
|
|
diagnosis: 'Allergic dermatitis.',
|
|
|
|
medications: 'Antihistamine, Corticosteroid cream.',
|
|
|
|
lab_tests: 'Allergy test.',
|
|
|
|
imaging_investigations: 'None.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
symptoms: 'Knee pain and swelling.',
|
|
|
|
diagnosis: 'Osteoarthritis.',
|
|
|
|
medications: 'Acetaminophen, Glucosamine.',
|
|
|
|
lab_tests: 'Joint fluid analysis.',
|
|
|
|
imaging_investigations: 'Knee X-ray.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ImagingOrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
investigations: 'Chest X-ray',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
investigations: 'None',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
investigations: 'MRI of the lumbar spine',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
investigations: 'None',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
investigations: 'Knee X-ray',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InvoicesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 150,
|
|
|
|
status: 'paid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 200,
|
|
|
|
status: 'paid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 250,
|
|
|
|
status: 'unpaid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 100,
|
|
|
|
status: 'unpaid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 300,
|
|
|
|
status: 'paid',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const LabOrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
tests: 'ECG, Blood test',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
tests: 'CBC, Throat swab',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
tests: 'None',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
tests: 'Allergy test',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
tests: 'Joint fluid analysis',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PatientsData = [
|
|
{
|
|
full_name: 'John Doe',
|
|
|
|
date_of_birth: new Date('1985-06-15T00:00:00Z'),
|
|
|
|
gender: 'male',
|
|
|
|
nationality: 'Saudi',
|
|
|
|
national_id: '1234567890',
|
|
|
|
contact_information: 'john.doe@example.com',
|
|
|
|
emergency_contact: 'Jane Doe',
|
|
|
|
address: '123 Main St, Riyadh, Saudi Arabia',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Fatima Al-Farsi',
|
|
|
|
date_of_birth: new Date('1990-11-20T00:00:00Z'),
|
|
|
|
gender: 'male',
|
|
|
|
nationality: 'Saudi',
|
|
|
|
national_id: '0987654321',
|
|
|
|
contact_information: 'fatima.alfarsi@example.com',
|
|
|
|
emergency_contact: 'Ali Al-Farsi',
|
|
|
|
address: '456 Elm St, Jeddah, Saudi Arabia',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Ahmed Khan',
|
|
|
|
date_of_birth: new Date('1978-03-05T00:00:00Z'),
|
|
|
|
gender: 'female',
|
|
|
|
nationality: 'Pakistani',
|
|
|
|
national_id: '1122334455',
|
|
|
|
contact_information: 'ahmed.khan@example.com',
|
|
|
|
emergency_contact: 'Sara Khan',
|
|
|
|
address: '789 Oak St, Dammam, Saudi Arabia',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Sara Ibrahim',
|
|
|
|
date_of_birth: new Date('1995-08-30T00:00:00Z'),
|
|
|
|
gender: 'female',
|
|
|
|
nationality: 'Egyptian',
|
|
|
|
national_id: '6677889900',
|
|
|
|
contact_information: 'sara.ibrahim@example.com',
|
|
|
|
emergency_contact: 'Mohamed Ibrahim',
|
|
|
|
address: '321 Pine St, Mecca, Saudi Arabia',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Mohamed Ali',
|
|
|
|
date_of_birth: new Date('1982-12-12T00:00:00Z'),
|
|
|
|
gender: 'female',
|
|
|
|
nationality: 'Jordanian',
|
|
|
|
national_id: '5566778899',
|
|
|
|
contact_information: 'mohamed.ali@example.com',
|
|
|
|
emergency_contact: 'Layla Ali',
|
|
|
|
address: '654 Cedar St, Medina, Saudi Arabia',
|
|
|
|
// 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
|
|
|
|
medications: 'Aspirin, Nitroglycerin',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
medications: 'Paracetamol, Cough syrup',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
medications: 'Ibuprofen, Muscle relaxant',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
medications: 'Antihistamine, Corticosteroid cream',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
medications: 'Acetaminophen, Glucosamine',
|
|
|
|
status: 'completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Riyadh Health Clinic',
|
|
},
|
|
|
|
{
|
|
name: 'Jeddah Medical Center',
|
|
},
|
|
|
|
{
|
|
name: 'Dammam General Hospital',
|
|
},
|
|
|
|
{
|
|
name: 'Mecca Family Health',
|
|
},
|
|
|
|
{
|
|
name: 'Medina Wellness Hospital',
|
|
},
|
|
];
|
|
|
|
// 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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setOrganization) {
|
|
await User3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setOrganization) {
|
|
await User4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Appointment4 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Appointment4?.setPatient) {
|
|
await Appointment4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedDoctor3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment3 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Appointment3?.setDoctor) {
|
|
await Appointment3.setDoctor(relatedDoctor3);
|
|
}
|
|
|
|
const relatedDoctor4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment4 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Appointment4?.setDoctor) {
|
|
await Appointment4.setDoctor(relatedDoctor4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Appointment3 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Appointment3?.setOrganization) {
|
|
await Appointment3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Appointment4 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Appointment4?.setOrganization) {
|
|
await Appointment4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Department3 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Department3?.setOrganization) {
|
|
await Department3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Department4 = await Departments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Department4?.setOrganization) {
|
|
await Department4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedPatient3 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const EmrRecord3 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (EmrRecord3?.setPatient) {
|
|
await EmrRecord3.setPatient(relatedPatient3);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const EmrRecord4 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (EmrRecord4?.setPatient) {
|
|
await EmrRecord4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedDoctor3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EmrRecord3 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (EmrRecord3?.setDoctor) {
|
|
await EmrRecord3.setDoctor(relatedDoctor3);
|
|
}
|
|
|
|
const relatedDoctor4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EmrRecord4 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (EmrRecord4?.setDoctor) {
|
|
await EmrRecord4.setDoctor(relatedDoctor4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EmrRecord3 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (EmrRecord3?.setOrganization) {
|
|
await EmrRecord3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EmrRecord4 = await EmrRecords.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (EmrRecord4?.setOrganization) {
|
|
await EmrRecord4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateImagingOrderWithPatient() {
|
|
const relatedPatient0 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const ImagingOrder0 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ImagingOrder0?.setPatient) {
|
|
await ImagingOrder0.setPatient(relatedPatient0);
|
|
}
|
|
|
|
const relatedPatient1 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const ImagingOrder1 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ImagingOrder1?.setPatient) {
|
|
await ImagingOrder1.setPatient(relatedPatient1);
|
|
}
|
|
|
|
const relatedPatient2 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const ImagingOrder2 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ImagingOrder2?.setPatient) {
|
|
await ImagingOrder2.setPatient(relatedPatient2);
|
|
}
|
|
|
|
const relatedPatient3 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const ImagingOrder3 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ImagingOrder3?.setPatient) {
|
|
await ImagingOrder3.setPatient(relatedPatient3);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const ImagingOrder4 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ImagingOrder4?.setPatient) {
|
|
await ImagingOrder4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
async function associateImagingOrderWithImaging_technician() {
|
|
const relatedImaging_technician0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ImagingOrder0 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ImagingOrder0?.setImaging_technician) {
|
|
await ImagingOrder0.setImaging_technician(relatedImaging_technician0);
|
|
}
|
|
|
|
const relatedImaging_technician1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ImagingOrder1 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ImagingOrder1?.setImaging_technician) {
|
|
await ImagingOrder1.setImaging_technician(relatedImaging_technician1);
|
|
}
|
|
|
|
const relatedImaging_technician2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ImagingOrder2 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ImagingOrder2?.setImaging_technician) {
|
|
await ImagingOrder2.setImaging_technician(relatedImaging_technician2);
|
|
}
|
|
|
|
const relatedImaging_technician3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ImagingOrder3 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ImagingOrder3?.setImaging_technician) {
|
|
await ImagingOrder3.setImaging_technician(relatedImaging_technician3);
|
|
}
|
|
|
|
const relatedImaging_technician4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ImagingOrder4 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ImagingOrder4?.setImaging_technician) {
|
|
await ImagingOrder4.setImaging_technician(relatedImaging_technician4);
|
|
}
|
|
}
|
|
|
|
async function associateImagingOrderWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ImagingOrder0 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ImagingOrder0?.setOrganization) {
|
|
await ImagingOrder0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ImagingOrder1 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ImagingOrder1?.setOrganization) {
|
|
await ImagingOrder1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ImagingOrder2 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ImagingOrder2?.setOrganization) {
|
|
await ImagingOrder2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ImagingOrder3 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ImagingOrder3?.setOrganization) {
|
|
await ImagingOrder3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ImagingOrder4 = await ImagingOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ImagingOrder4?.setOrganization) {
|
|
await ImagingOrder4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const Invoice4 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Invoice4?.setPatient) {
|
|
await Invoice4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setOrganization) {
|
|
await Invoice0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setOrganization) {
|
|
await Invoice1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setOrganization) {
|
|
await Invoice2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice3 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Invoice3?.setOrganization) {
|
|
await Invoice3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice4 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Invoice4?.setOrganization) {
|
|
await Invoice4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateLabOrderWithPatient() {
|
|
const relatedPatient0 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const LabOrder0 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (LabOrder0?.setPatient) {
|
|
await LabOrder0.setPatient(relatedPatient0);
|
|
}
|
|
|
|
const relatedPatient1 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const LabOrder1 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (LabOrder1?.setPatient) {
|
|
await LabOrder1.setPatient(relatedPatient1);
|
|
}
|
|
|
|
const relatedPatient2 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const LabOrder2 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (LabOrder2?.setPatient) {
|
|
await LabOrder2.setPatient(relatedPatient2);
|
|
}
|
|
|
|
const relatedPatient3 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const LabOrder3 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (LabOrder3?.setPatient) {
|
|
await LabOrder3.setPatient(relatedPatient3);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const LabOrder4 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (LabOrder4?.setPatient) {
|
|
await LabOrder4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
async function associateLabOrderWithLab_technician() {
|
|
const relatedLab_technician0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LabOrder0 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (LabOrder0?.setLab_technician) {
|
|
await LabOrder0.setLab_technician(relatedLab_technician0);
|
|
}
|
|
|
|
const relatedLab_technician1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LabOrder1 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (LabOrder1?.setLab_technician) {
|
|
await LabOrder1.setLab_technician(relatedLab_technician1);
|
|
}
|
|
|
|
const relatedLab_technician2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LabOrder2 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (LabOrder2?.setLab_technician) {
|
|
await LabOrder2.setLab_technician(relatedLab_technician2);
|
|
}
|
|
|
|
const relatedLab_technician3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LabOrder3 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (LabOrder3?.setLab_technician) {
|
|
await LabOrder3.setLab_technician(relatedLab_technician3);
|
|
}
|
|
|
|
const relatedLab_technician4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LabOrder4 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (LabOrder4?.setLab_technician) {
|
|
await LabOrder4.setLab_technician(relatedLab_technician4);
|
|
}
|
|
}
|
|
|
|
async function associateLabOrderWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const LabOrder0 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (LabOrder0?.setOrganization) {
|
|
await LabOrder0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const LabOrder1 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (LabOrder1?.setOrganization) {
|
|
await LabOrder1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const LabOrder2 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (LabOrder2?.setOrganization) {
|
|
await LabOrder2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const LabOrder3 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (LabOrder3?.setOrganization) {
|
|
await LabOrder3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const LabOrder4 = await LabOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (LabOrder4?.setOrganization) {
|
|
await LabOrder4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Patient3 = await Patients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Patient3?.setOrganization) {
|
|
await Patient3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Patient4 = await Patients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Patient4?.setOrganization) {
|
|
await Patient4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Patient3 = await Patients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Patient3?.setOrganization) {
|
|
await Patient3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Patient4 = await Patients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Patient4?.setOrganization) {
|
|
await Patient4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedPatient3 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const PharmacyOrder3 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (PharmacyOrder3?.setPatient) {
|
|
await PharmacyOrder3.setPatient(relatedPatient3);
|
|
}
|
|
|
|
const relatedPatient4 = await Patients.findOne({
|
|
offset: Math.floor(Math.random() * (await Patients.count())),
|
|
});
|
|
const PharmacyOrder4 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (PharmacyOrder4?.setPatient) {
|
|
await PharmacyOrder4.setPatient(relatedPatient4);
|
|
}
|
|
}
|
|
|
|
async function associatePharmacyOrderWithPharmacist() {
|
|
const relatedPharmacist0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const PharmacyOrder0 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (PharmacyOrder0?.setPharmacist) {
|
|
await PharmacyOrder0.setPharmacist(relatedPharmacist0);
|
|
}
|
|
|
|
const relatedPharmacist1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const PharmacyOrder1 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (PharmacyOrder1?.setPharmacist) {
|
|
await PharmacyOrder1.setPharmacist(relatedPharmacist1);
|
|
}
|
|
|
|
const relatedPharmacist2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const PharmacyOrder2 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (PharmacyOrder2?.setPharmacist) {
|
|
await PharmacyOrder2.setPharmacist(relatedPharmacist2);
|
|
}
|
|
|
|
const relatedPharmacist3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const PharmacyOrder3 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (PharmacyOrder3?.setPharmacist) {
|
|
await PharmacyOrder3.setPharmacist(relatedPharmacist3);
|
|
}
|
|
|
|
const relatedPharmacist4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const PharmacyOrder4 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (PharmacyOrder4?.setPharmacist) {
|
|
await PharmacyOrder4.setPharmacist(relatedPharmacist4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PharmacyOrder3 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (PharmacyOrder3?.setOrganization) {
|
|
await PharmacyOrder3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const PharmacyOrder4 = await PharmacyOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (PharmacyOrder4?.setOrganization) {
|
|
await PharmacyOrder4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Appointments.bulkCreate(AppointmentsData);
|
|
|
|
await Departments.bulkCreate(DepartmentsData);
|
|
|
|
await EmrRecords.bulkCreate(EmrRecordsData);
|
|
|
|
await ImagingOrders.bulkCreate(ImagingOrdersData);
|
|
|
|
await Invoices.bulkCreate(InvoicesData);
|
|
|
|
await LabOrders.bulkCreate(LabOrdersData);
|
|
|
|
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(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateDepartmentWithOrganization(),
|
|
|
|
await associateEmrRecordWithPatient(),
|
|
|
|
await associateEmrRecordWithDoctor(),
|
|
|
|
await associateEmrRecordWithOrganization(),
|
|
|
|
await associateImagingOrderWithPatient(),
|
|
|
|
await associateImagingOrderWithImaging_technician(),
|
|
|
|
await associateImagingOrderWithOrganization(),
|
|
|
|
await associateInvoiceWithPatient(),
|
|
|
|
await associateInvoiceWithOrganization(),
|
|
|
|
await associateLabOrderWithPatient(),
|
|
|
|
await associateLabOrderWithLab_technician(),
|
|
|
|
await associateLabOrderWithOrganization(),
|
|
|
|
await associatePatientWithOrganization(),
|
|
|
|
await associatePatientWithOrganization(),
|
|
|
|
await associatePharmacyOrderWithPatient(),
|
|
|
|
await associatePharmacyOrderWithPharmacist(),
|
|
|
|
await associatePharmacyOrderWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('appointments', null, {});
|
|
|
|
await queryInterface.bulkDelete('departments', null, {});
|
|
|
|
await queryInterface.bulkDelete('emr_records', null, {});
|
|
|
|
await queryInterface.bulkDelete('imaging_orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('invoices', null, {});
|
|
|
|
await queryInterface.bulkDelete('lab_orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('patients', null, {});
|
|
|
|
await queryInterface.bulkDelete('pharmacy_orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|