38833-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-02-28 10:41:15 +00:00

3654 lines
67 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const PatientProfiles = db.patient_profiles;
const DoctorProfiles = db.doctor_profiles;
const CareTeams = db.care_teams;
const GlucoseReadings = db.glucose_readings;
const DailyAdherence = db.daily_adherence;
const CgmSensors = db.cgm_sensors;
const Alerts = db.alerts;
const MealRecommendations = db.meal_recommendations;
const PatientMealLogs = db.patient_meal_logs;
const PatientProfilesData = [
{
// type code here for "relation_one" field
"diabetes_type": "prediabetes",
"target_glucose_min_mgdl": 80.0,
"target_glucose_max_mgdl": 140.0,
"a1c_percent": 6.8,
"diagnosis_date": new Date('2021-05-18T00:00:00Z'),
"preferred_units": "mmol_l",
"notifications_enabled": true,
"alert_sensitivity": "high",
},
{
// type code here for "relation_one" field
"diabetes_type": "prediabetes",
"target_glucose_min_mgdl": 70.0,
"target_glucose_max_mgdl": 160.0,
"a1c_percent": 7.3,
"diagnosis_date": new Date('2008-09-02T00:00:00Z'),
"preferred_units": "mmol_l",
"notifications_enabled": true,
"alert_sensitivity": "low",
},
{
// type code here for "relation_one" field
"diabetes_type": "other",
"target_glucose_min_mgdl": 85.0,
"target_glucose_max_mgdl": 150.0,
"a1c_percent": 7.0,
"diagnosis_date": new Date('2016-02-11T00:00:00Z'),
"preferred_units": "mmol_l",
"notifications_enabled": true,
"alert_sensitivity": "high",
},
{
// type code here for "relation_one" field
"diabetes_type": "other",
"target_glucose_min_mgdl": 80.0,
"target_glucose_max_mgdl": 130.0,
"a1c_percent": 5.9,
"diagnosis_date": new Date('2020-10-01T00:00:00Z'),
"preferred_units": "mmol_l",
"notifications_enabled": false,
"alert_sensitivity": "low",
},
];
const DoctorProfilesData = [
{
// type code here for "relation_one" field
"specialty": "Endocrinology",
"license_number": "CA-ENDO-49210",
"clinic_name": "Bayview Diabetes Clinic",
"clinic_phone": "+14155550301",
"clinic_address": "200 Market Street, Suite 500, San Francisco, CA",
"accepting_new_patients": true,
},
{
// type code here for "relation_one" field
"specialty": "Family Medicine",
"license_number": "CA-FM-38814",
"clinic_name": "Sunrise Primary Care",
"clinic_phone": "+14155550302",
"clinic_address": "18 Mission Avenue, San Francisco, CA",
"accepting_new_patients": true,
},
{
// type code here for "relation_one" field
"specialty": "Endocrinology",
"license_number": "CA-ENDO-49210-A",
"clinic_name": "Northside Metabolic Center",
"clinic_phone": "+14155550303",
"clinic_address": "77 Lombard Street, San Francisco, CA",
"accepting_new_patients": true,
},
{
// type code here for "relation_one" field
"specialty": "Internal Medicine",
"license_number": "CA-IM-38814-B",
"clinic_name": "Harbor Internal Medicine",
"clinic_phone": "+14155550304",
"clinic_address": "515 Embarcadero Road, San Francisco, CA",
"accepting_new_patients": true,
},
];
const CareTeamsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "paused",
"invited_at": new Date('2026-01-10T10:00:00Z'),
"started_at": new Date('2026-01-12T09:00:00Z'),
"ended_at": new Date('2026-12-31T00:00:00Z'),
"notes": "Routine follow-ups every 3 months.",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "invited",
"invited_at": new Date('2026-01-08T16:00:00Z'),
"started_at": new Date('2026-01-09T10:30:00Z'),
"ended_at": new Date('2026-12-31T00:00:00Z'),
"notes": "Focus on overnight trends and exercise adjustments.",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "ended",
"invited_at": new Date('2026-02-01T12:15:00Z'),
"started_at": new Date('2026-02-03T08:45:00Z'),
"ended_at": new Date('2026-12-31T00:00:00Z'),
"notes": "Medication review and dietary coaching.",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "paused",
"invited_at": new Date('2026-01-20T11:00:00Z'),
"started_at": new Date('2026-01-22T09:15:00Z'),
"ended_at": new Date('2026-06-30T00:00:00Z'),
"notes": "Paused while patient transitions providers.",
},
];
const GlucoseReadingsData = [
{
// type code here for "relation_one" field
"glucose_value": 112.0,
"unit": "mg_dl",
"measured_at": new Date('2026-02-26T07:40:00Z'),
"source": "manual",
"context": "unknown",
"device_label": "Manual Entry",
"trend_rate": 0.0,
"trend_direction": "fall",
"note": "Slept well and hydrated.",
"is_alert": false,
},
{
// type code here for "relation_one" field
"glucose_value": 168.0,
"unit": "mg_dl",
"measured_at": new Date('2026-02-26T13:10:00Z'),
"source": "cgm",
"context": "unknown",
"device_label": "Manual Entry",
"trend_rate": 0.0,
"trend_direction": "steady",
"note": "Lunch included rice.",
"is_alert": true,
},
{
// type code here for "relation_one" field
"glucose_value": 95.0,
"unit": "mg_dl",
"measured_at": new Date('2026-02-26T06:55:00Z'),
"source": "cgm",
"context": "before_meal",
"device_label": "CGM Patch A1",
"trend_rate": -1.2,
"trend_direction": "rise",
"note": "Morning drop observed.",
"is_alert": true,
},
{
// type code here for "relation_one" field
"glucose_value": 62.0,
"unit": "mg_dl",
"measured_at": new Date('2026-02-26T22:35:00Z'),
"source": "manual",
"context": "bedtime",
"device_label": "CGM Patch A1",
"trend_rate": -2.0,
"trend_direction": "fall",
"note": "Treated with 15g carbs.",
"is_alert": true,
},
];
const DailyAdherenceData = [
{
// type code here for "relation_one" field
"day_start_at": new Date('2026-02-22T00:00:00Z'),
"day_end_at": new Date('2026-02-22T23:59:59Z'),
"measurement_count": 2,
"measured_today": true,
"summary": "Measured 2 times",
},
{
// type code here for "relation_one" field
"day_start_at": new Date('2026-02-23T00:00:00Z'),
"day_end_at": new Date('2026-02-23T23:59:59Z'),
"measurement_count": 1,
"measured_today": true,
"summary": "Measured 1 time",
},
{
// type code here for "relation_one" field
"day_start_at": new Date('2026-02-24T00:00:00Z'),
"day_end_at": new Date('2026-02-24T23:59:59Z'),
"measurement_count": 6,
"measured_today": true,
"summary": "CGM active day",
},
{
// type code here for "relation_one" field
"day_start_at": new Date('2026-02-25T00:00:00Z'),
"day_end_at": new Date('2026-02-25T23:59:59Z'),
"measurement_count": 0,
"measured_today": true,
"summary": "No measurements logged",
},
];
const CgmSensorsData = [
{
// type code here for "relation_one" field
"sensor_name": "CGM Patch A1",
"manufacturer": "GlucoSense",
"model": "GS-Patch-2",
"serial_number": "GS2-AX19-44821",
"bluetooth_identifier": "BLE-GS2-44821",
"connection_status": "disconnected",
"last_connected_at": new Date('2026-02-26T22:40:00Z'),
"paired_at": new Date('2026-02-01T10:05:00Z'),
"sensor_started_at": new Date('2026-02-01T10:10:00Z'),
"sensor_expires_at": new Date('2026-03-01T10:10:00Z'),
"battery_level_percent": 62.0,
"firmware_version": "2.3.1",
},
{
// type code here for "relation_one" field
"sensor_name": "CGM Patch B2",
"manufacturer": "GlucoSense",
"model": "GS-Patch-2",
"serial_number": "GS2-BK44-12009",
"bluetooth_identifier": "BLE-GS2-12009",
"connection_status": "error",
"last_connected_at": new Date('2026-02-20T18:20:00Z'),
"paired_at": new Date('2026-02-10T09:00:00Z'),
"sensor_started_at": new Date('2026-02-10T09:10:00Z'),
"sensor_expires_at": new Date('2026-03-10T09:10:00Z'),
"battery_level_percent": 18.0,
"firmware_version": "2.3.1",
},
{
// type code here for "relation_one" field
"sensor_name": "Clinic Demo Sensor",
"manufacturer": "MedPatch",
"model": "MP-CGM-1",
"serial_number": "MP1-DEMO-33018",
"bluetooth_identifier": "BLE-MP1-33018",
"connection_status": "connected",
"last_connected_at": new Date('2026-02-26T08:05:00Z'),
"paired_at": new Date('2026-02-26T08:00:00Z'),
"sensor_started_at": new Date('2026-02-26T08:00:00Z'),
"sensor_expires_at": new Date('2026-03-26T08:00:00Z'),
"battery_level_percent": 95.0,
"firmware_version": "1.8.0",
},
{
// type code here for "relation_one" field
"sensor_name": "Backup Sensor Kit",
"manufacturer": "GlucoSense",
"model": "GS-Patch-2",
"serial_number": "GS2-AX19-55107",
"bluetooth_identifier": "BLE-GS2-55107",
"connection_status": "pairing",
"last_connected_at": new Date('2026-01-30T09:10:00Z'),
"paired_at": new Date('2026-01-15T10:00:00Z'),
"sensor_started_at": new Date('2026-01-15T10:05:00Z'),
"sensor_expires_at": new Date('2026-02-14T10:05:00Z'),
"battery_level_percent": 0.0,
"firmware_version": "2.2.9",
},
];
const AlertsData = [
{
// type code here for "relation_one" field
"alert_type": "missed_measurement",
"severity": "critical",
"title_text": "Low glucose detected",
"message": "Glucose dropped below target range. Consider fast-acting carbs and recheck.",
"triggered_at": new Date('2026-02-26T22:35:00Z'),
"acknowledged_at": new Date('2026-02-26T22:38:00Z'),
"is_resolved": true,
},
{
// type code here for "relation_one" field
"alert_type": "hypoglycemia",
"severity": "critical",
"title_text": "High post-meal glucose",
"message": "Glucose above target after meal. Review meal carbs and consider a walk.",
"triggered_at": new Date('2026-02-26T13:10:00Z'),
"acknowledged_at": new Date('2026-02-26T13:25:00Z'),
"is_resolved": true,
},
{
// type code here for "relation_one" field
"alert_type": "rapid_change",
"severity": "critical",
"title_text": "No reading logged yet",
"message": "Remember to log at least one glucose reading today.",
"triggered_at": new Date('2026-02-25T16:00:00Z'),
"acknowledged_at": new Date('2026-02-25T18:10:00Z'),
"is_resolved": true,
},
{
// type code here for "relation_one" field
"alert_type": "rapid_change",
"severity": "critical",
"title_text": "CGM disconnected",
"message": "Sensor connection lost. Try reconnecting via Bluetooth.",
"triggered_at": new Date('2026-02-20T18:25:00Z'),
"acknowledged_at": new Date('2026-02-20T18:30:00Z'),
"is_resolved": true,
},
];
const MealRecommendationsData = [
{
"meal_name": "Grilled Salmon and Roasted Vegetables",
"recommendation_type": "snack",
"glucose_condition": "in_range",
"description": "High-protein dinner with non-starchy vegetables.",
"ingredients": "Salmon, zucchini, bell pepper, olive oil, lemon, herbs",
"instructions": "Season salmon and roast vegetables. Grill salmon until cooked and serve with vegetables.",
"estimated_carbs_g": 18.0,
"estimated_sugar_g": 5.0,
"estimated_fiber_g": 7.0,
"estimated_calories": 520,
// type code here for "images" field
"is_active": true,
},
{
"meal_name": "Greek Yogurt with Chia and Berries",
"recommendation_type": "hydration",
"glucose_condition": "high",
"description": "Balanced snack with protein and fiber.",
"ingredients": "Plain Greek yogurt, chia seeds, blueberries, cinnamon",
"instructions": "Mix chia into yogurt and top with berries and cinnamon.",
"estimated_carbs_g": 22.0,
"estimated_sugar_g": 10.0,
"estimated_fiber_g": 8.0,
"estimated_calories": 240,
// type code here for "images" field
"is_active": true,
},
{
"meal_name": "Vegetable Omelet",
"recommendation_type": "hydration",
"glucose_condition": "low",
"description": "Low-carb breakfast option with vegetables.",
"ingredients": "Eggs, spinach, mushrooms, tomato, olive oil",
"instructions": "Saute vegetables, add beaten eggs, cook until set.",
"estimated_carbs_g": 10.0,
"estimated_sugar_g": 4.0,
"estimated_fiber_g": 3.0,
"estimated_calories": 310,
// type code here for "images" field
"is_active": true,
},
{
"meal_name": "Apple Slices with Peanut Butter",
"recommendation_type": "balanced",
"glucose_condition": "low",
"description": "Quick snack combining carbs and fat for recovery.",
"ingredients": "Apple, natural peanut butter",
"instructions": "Slice apple and dip into peanut butter.",
"estimated_carbs_g": 28.0,
"estimated_sugar_g": 17.0,
"estimated_fiber_g": 5.0,
"estimated_calories": 260,
// type code here for "images" field
"is_active": true,
},
];
const PatientMealLogsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"logged_at": new Date('2026-02-25T15:30:00Z'),
"meal_type": "lunch",
"notes": "Used unsweetened yogurt.",
"followed_recommendation": true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"logged_at": new Date('2026-02-26T22:40:00Z'),
"meal_type": "dinner",
"notes": "Used as low treatment snack.",
"followed_recommendation": true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"logged_at": new Date('2026-02-26T12:10:00Z'),
"meal_type": "snack",
"notes": "Added extra greens.",
"followed_recommendation": true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"logged_at": new Date('2026-02-24T19:00:00Z'),
"meal_type": "lunch",
"notes": "Kept portion moderate.",
"followed_recommendation": true,
},
];
// Similar logic for "relation_many"
async function associatePatientProfileWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientProfile0 = await PatientProfiles.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PatientProfile0?.setUser)
{
await
PatientProfile0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientProfile1 = await PatientProfiles.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PatientProfile1?.setUser)
{
await
PatientProfile1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientProfile2 = await PatientProfiles.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PatientProfile2?.setUser)
{
await
PatientProfile2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientProfile3 = await PatientProfiles.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (PatientProfile3?.setUser)
{
await
PatientProfile3.
setUser(relatedUser3);
}
}
async function associateDoctorProfileWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DoctorProfile0 = await DoctorProfiles.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DoctorProfile0?.setUser)
{
await
DoctorProfile0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DoctorProfile1 = await DoctorProfiles.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DoctorProfile1?.setUser)
{
await
DoctorProfile1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DoctorProfile2 = await DoctorProfiles.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DoctorProfile2?.setUser)
{
await
DoctorProfile2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DoctorProfile3 = await DoctorProfiles.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (DoctorProfile3?.setUser)
{
await
DoctorProfile3.
setUser(relatedUser3);
}
}
async function associateCareTeamWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam0 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CareTeam0?.setPatient)
{
await
CareTeam0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam1 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CareTeam1?.setPatient)
{
await
CareTeam1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam2 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CareTeam2?.setPatient)
{
await
CareTeam2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam3 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CareTeam3?.setPatient)
{
await
CareTeam3.
setPatient(relatedPatient3);
}
}
async function associateCareTeamWithDoctor() {
const relatedDoctor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam0 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CareTeam0?.setDoctor)
{
await
CareTeam0.
setDoctor(relatedDoctor0);
}
const relatedDoctor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam1 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CareTeam1?.setDoctor)
{
await
CareTeam1.
setDoctor(relatedDoctor1);
}
const relatedDoctor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam2 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CareTeam2?.setDoctor)
{
await
CareTeam2.
setDoctor(relatedDoctor2);
}
const relatedDoctor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CareTeam3 = await CareTeams.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CareTeam3?.setDoctor)
{
await
CareTeam3.
setDoctor(relatedDoctor3);
}
}
async function associateGlucoseReadingWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GlucoseReading0 = await GlucoseReadings.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GlucoseReading0?.setPatient)
{
await
GlucoseReading0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GlucoseReading1 = await GlucoseReadings.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GlucoseReading1?.setPatient)
{
await
GlucoseReading1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GlucoseReading2 = await GlucoseReadings.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GlucoseReading2?.setPatient)
{
await
GlucoseReading2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GlucoseReading3 = await GlucoseReadings.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (GlucoseReading3?.setPatient)
{
await
GlucoseReading3.
setPatient(relatedPatient3);
}
}
async function associateDailyAdherenceWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DailyAdherence0 = await DailyAdherence.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DailyAdherence0?.setPatient)
{
await
DailyAdherence0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DailyAdherence1 = await DailyAdherence.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DailyAdherence1?.setPatient)
{
await
DailyAdherence1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DailyAdherence2 = await DailyAdherence.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DailyAdherence2?.setPatient)
{
await
DailyAdherence2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DailyAdherence3 = await DailyAdherence.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (DailyAdherence3?.setPatient)
{
await
DailyAdherence3.
setPatient(relatedPatient3);
}
}
async function associateCgmSensorWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CgmSensor0 = await CgmSensors.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CgmSensor0?.setPatient)
{
await
CgmSensor0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CgmSensor1 = await CgmSensors.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CgmSensor1?.setPatient)
{
await
CgmSensor1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CgmSensor2 = await CgmSensors.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CgmSensor2?.setPatient)
{
await
CgmSensor2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const CgmSensor3 = await CgmSensors.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (CgmSensor3?.setPatient)
{
await
CgmSensor3.
setPatient(relatedPatient3);
}
}
async function associateAlertWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Alert0 = await Alerts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Alert0?.setPatient)
{
await
Alert0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Alert1 = await Alerts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Alert1?.setPatient)
{
await
Alert1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Alert2 = await Alerts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Alert2?.setPatient)
{
await
Alert2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Alert3 = await Alerts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Alert3?.setPatient)
{
await
Alert3.
setPatient(relatedPatient3);
}
}
async function associatePatientMealLogWithPatient() {
const relatedPatient0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientMealLog0 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PatientMealLog0?.setPatient)
{
await
PatientMealLog0.
setPatient(relatedPatient0);
}
const relatedPatient1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientMealLog1 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PatientMealLog1?.setPatient)
{
await
PatientMealLog1.
setPatient(relatedPatient1);
}
const relatedPatient2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientMealLog2 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PatientMealLog2?.setPatient)
{
await
PatientMealLog2.
setPatient(relatedPatient2);
}
const relatedPatient3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const PatientMealLog3 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (PatientMealLog3?.setPatient)
{
await
PatientMealLog3.
setPatient(relatedPatient3);
}
}
async function associatePatientMealLogWithRecommendation() {
const relatedRecommendation0 = await MealRecommendations.findOne({
offset: Math.floor(Math.random() * (await MealRecommendations.count())),
});
const PatientMealLog0 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (PatientMealLog0?.setRecommendation)
{
await
PatientMealLog0.
setRecommendation(relatedRecommendation0);
}
const relatedRecommendation1 = await MealRecommendations.findOne({
offset: Math.floor(Math.random() * (await MealRecommendations.count())),
});
const PatientMealLog1 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (PatientMealLog1?.setRecommendation)
{
await
PatientMealLog1.
setRecommendation(relatedRecommendation1);
}
const relatedRecommendation2 = await MealRecommendations.findOne({
offset: Math.floor(Math.random() * (await MealRecommendations.count())),
});
const PatientMealLog2 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (PatientMealLog2?.setRecommendation)
{
await
PatientMealLog2.
setRecommendation(relatedRecommendation2);
}
const relatedRecommendation3 = await MealRecommendations.findOne({
offset: Math.floor(Math.random() * (await MealRecommendations.count())),
});
const PatientMealLog3 = await PatientMealLogs.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (PatientMealLog3?.setRecommendation)
{
await
PatientMealLog3.
setRecommendation(relatedRecommendation3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await PatientProfiles.bulkCreate(PatientProfilesData);
await DoctorProfiles.bulkCreate(DoctorProfilesData);
await CareTeams.bulkCreate(CareTeamsData);
await GlucoseReadings.bulkCreate(GlucoseReadingsData);
await DailyAdherence.bulkCreate(DailyAdherenceData);
await CgmSensors.bulkCreate(CgmSensorsData);
await Alerts.bulkCreate(AlertsData);
await MealRecommendations.bulkCreate(MealRecommendationsData);
await PatientMealLogs.bulkCreate(PatientMealLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associatePatientProfileWithUser(),
await associateDoctorProfileWithUser(),
await associateCareTeamWithPatient(),
await associateCareTeamWithDoctor(),
await associateGlucoseReadingWithPatient(),
await associateDailyAdherenceWithPatient(),
await associateCgmSensorWithPatient(),
await associateAlertWithPatient(),
await associatePatientMealLogWithPatient(),
await associatePatientMealLogWithRecommendation(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('patient_profiles', null, {});
await queryInterface.bulkDelete('doctor_profiles', null, {});
await queryInterface.bulkDelete('care_teams', null, {});
await queryInterface.bulkDelete('glucose_readings', null, {});
await queryInterface.bulkDelete('daily_adherence', null, {});
await queryInterface.bulkDelete('cgm_sensors', null, {});
await queryInterface.bulkDelete('alerts', null, {});
await queryInterface.bulkDelete('meal_recommendations', null, {});
await queryInterface.bulkDelete('patient_meal_logs', null, {});
},
};