29918/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-15 18:06:08 +00:00

610 lines
14 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Guardians = db.guardians;
const HealthMetrics = db.health_metrics;
const MedicationSchedules = db.medication_schedules;
const Patients = db.patients;
const Water = db.water;
const Groups = db.groups;
const GuardiansData = [
{
first_name: 'Michael',
last_name: 'Doe',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Emily',
last_name: 'Doe',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'David',
last_name: 'Johnson',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const HealthMetricsData = [
{
// type code here for "relation_one" field
date: new Date('2023-10-01T08:00:00Z'),
blood_pressure: 120.5,
glucose_level: 5.6,
physical_activity: 30,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-02T08:00:00Z'),
blood_pressure: 118,
glucose_level: 5.8,
physical_activity: 45,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
date: new Date('2023-10-01T08:00:00Z'),
blood_pressure: 115,
glucose_level: 5.5,
physical_activity: 60,
// type code here for "relation_one" field
},
];
const MedicationSchedulesData = [
{
// type code here for "relation_one" field
medication_name: 'Aspirin',
start_date: new Date('2023-10-01T08:00:00Z'),
end_date: new Date('2023-10-10T08:00:00Z'),
reminder: true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
medication_name: 'Metformin',
start_date: new Date('2023-10-05T08:00:00Z'),
end_date: new Date('2023-10-15T08:00:00Z'),
reminder: true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
medication_name: 'Lisinopril',
start_date: new Date('2023-10-01T08:00:00Z'),
end_date: new Date('2023-10-10T08:00:00Z'),
reminder: true,
// type code here for "relation_one" field
},
];
const PatientsData = [
{
first_name: 'John',
last_name: 'Doe',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Jane',
last_name: 'Smith',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Alice',
last_name: 'Johnson',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const WaterData = [
{
// type code here for "relation_one" field
name: 'Theodosius Dobzhansky',
description: 'John von Neumann',
},
{
// type code here for "relation_one" field
name: 'Ernst Mayr',
description: 'Nicolaus Copernicus',
},
{
// type code here for "relation_one" field
name: 'Rudolf Virchow',
description: 'John Dalton',
},
];
const GroupsData = [
{
name: 'Family A',
},
{
name: 'Family B',
},
{
name: 'Family C',
},
];
// Similar logic for "relation_many"
async function associateUserWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setGroup) {
await User0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setGroup) {
await User1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setGroup) {
await User2.setGroup(relatedGroup2);
}
}
// Similar logic for "relation_many"
async function associateGuardianWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Guardian0 = await Guardians.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Guardian0?.setGroup) {
await Guardian0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Guardian1 = await Guardians.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Guardian1?.setGroup) {
await Guardian1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Guardian2 = await Guardians.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Guardian2?.setGroup) {
await Guardian2.setGroup(relatedGroup2);
}
}
async function associateHealthMetricWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const HealthMetric0 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (HealthMetric0?.setPatient) {
await HealthMetric0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const HealthMetric1 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (HealthMetric1?.setPatient) {
await HealthMetric1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const HealthMetric2 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (HealthMetric2?.setPatient) {
await HealthMetric2.setPatient(relatedPatient2);
}
}
async function associateHealthMetricWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const HealthMetric0 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (HealthMetric0?.setGroup) {
await HealthMetric0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const HealthMetric1 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (HealthMetric1?.setGroup) {
await HealthMetric1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const HealthMetric2 = await HealthMetrics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (HealthMetric2?.setGroup) {
await HealthMetric2.setGroup(relatedGroup2);
}
}
async function associateMedicationScheduleWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicationSchedule0 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicationSchedule0?.setPatient) {
await MedicationSchedule0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicationSchedule1 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicationSchedule1?.setPatient) {
await MedicationSchedule1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicationSchedule2 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicationSchedule2?.setPatient) {
await MedicationSchedule2.setPatient(relatedPatient2);
}
}
async function associateMedicationScheduleWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const MedicationSchedule0 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicationSchedule0?.setGroup) {
await MedicationSchedule0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const MedicationSchedule1 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicationSchedule1?.setGroup) {
await MedicationSchedule1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const MedicationSchedule2 = await MedicationSchedules.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicationSchedule2?.setGroup) {
await MedicationSchedule2.setGroup(relatedGroup2);
}
}
async function associatePatientWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setGroup) {
await Patient0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setGroup) {
await Patient1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setGroup) {
await Patient2.setGroup(relatedGroup2);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associatePatientWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setGroup) {
await Patient0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setGroup) {
await Patient1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setGroup) {
await Patient2.setGroup(relatedGroup2);
}
}
async function associateWaterWithGroup() {
const relatedGroup0 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Water0 = await Water.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Water0?.setGroup) {
await Water0.setGroup(relatedGroup0);
}
const relatedGroup1 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Water1 = await Water.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Water1?.setGroup) {
await Water1.setGroup(relatedGroup1);
}
const relatedGroup2 = await Groups.findOne({
offset: Math.floor(Math.random() * (await Groups.count())),
});
const Water2 = await Water.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Water2?.setGroup) {
await Water2.setGroup(relatedGroup2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Guardians.bulkCreate(GuardiansData);
await HealthMetrics.bulkCreate(HealthMetricsData);
await MedicationSchedules.bulkCreate(MedicationSchedulesData);
await Patients.bulkCreate(PatientsData);
await Water.bulkCreate(WaterData);
await Groups.bulkCreate(GroupsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithGroup(),
// Similar logic for "relation_many"
await associateGuardianWithGroup(),
await associateHealthMetricWithPatient(),
await associateHealthMetricWithGroup(),
await associateMedicationScheduleWithPatient(),
await associateMedicationScheduleWithGroup(),
await associatePatientWithGroup(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associatePatientWithGroup(),
await associateWaterWithGroup(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('guardians', null, {});
await queryInterface.bulkDelete('health_metrics', null, {});
await queryInterface.bulkDelete('medication_schedules', null, {});
await queryInterface.bulkDelete('patients', null, {});
await queryInterface.bulkDelete('water', null, {});
await queryInterface.bulkDelete('groups', null, {});
},
};