32141/backend/src/db/seeders/20231127130745-sample-data.js
2025-06-10 17:49:29 +00:00

300 lines
6.5 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const ConditionSuggestions = db.condition_suggestions;
const Doctors = db.doctors;
const HealthReports = db.health_reports;
const SymptomLogs = db.symptom_logs;
const ConditionSuggestionsData = [
{
// type code here for "relation_one" field
possible_conditions: 'Migraine, Flu',
confidence_scores: '80%, 60%',
urgency_level: 'Low',
suggested_at: new Date('2023-10-01T15:00:00Z'),
},
{
// type code here for "relation_one" field
possible_conditions: 'Common Cold, Strep Throat',
confidence_scores: '70%, 50%',
urgency_level: 'High',
suggested_at: new Date('2023-10-02T16:00:00Z'),
},
{
// type code here for "relation_one" field
possible_conditions: 'Chronic Fatigue Syndrome, Muscle Strain',
confidence_scores: '75%, 65%',
urgency_level: 'Medium',
suggested_at: new Date('2023-10-03T17:00:00Z'),
},
];
const DoctorsData = [
{
name: 'Dr. Alice Green',
specialization: 'Cardiology',
contact: '6789012345',
email: 'alice.green@example.com',
// type code here for "relation_many" field
},
{
name: 'Dr. Bob White',
specialization: 'Neurology',
contact: '7890123456',
email: 'bob.white@example.com',
// type code here for "relation_many" field
},
{
name: 'Dr. Carol Black',
specialization: 'Pediatrics',
contact: '8901234567',
email: 'carol.black@example.com',
// type code here for "relation_many" field
},
];
const HealthReportsData = [
{
// type code here for "relation_one" field
report_text: 'Patient exhibits symptoms of migraine.',
summary: 'Migraine suspected.',
doctor_notes: 'Prescribed pain relief medication.',
},
{
// type code here for "relation_one" field
report_text: 'Symptoms consistent with common cold.',
summary: 'Common cold diagnosis.',
doctor_notes: 'Advised rest and hydration.',
},
{
// type code here for "relation_one" field
report_text: 'Chronic fatigue symptoms observed.',
summary: 'Chronic Fatigue Syndrome suspected.',
doctor_notes: 'Recommended lifestyle changes.',
},
];
const SymptomLogsData = [
{
// type code here for "relation_one" field
symptoms: 'Headache, fever',
mood: 'Happy',
pain_level: 5,
logged_at: new Date('2023-10-01T10:00:00Z'),
},
{
// type code here for "relation_one" field
symptoms: 'Cough, sore throat',
mood: 'Sad',
pain_level: 3,
logged_at: new Date('2023-10-02T11:00:00Z'),
},
{
// type code here for "relation_one" field
symptoms: 'Back pain, fatigue',
mood: 'Sad',
pain_level: 6,
logged_at: new Date('2023-10-03T12:00:00Z'),
},
];
// Similar logic for "relation_many"
async function associateConditionSuggestionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ConditionSuggestion0 = await ConditionSuggestions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ConditionSuggestion0?.setUser) {
await ConditionSuggestion0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ConditionSuggestion1 = await ConditionSuggestions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ConditionSuggestion1?.setUser) {
await ConditionSuggestion1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ConditionSuggestion2 = await ConditionSuggestions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ConditionSuggestion2?.setUser) {
await ConditionSuggestion2.setUser(relatedUser2);
}
}
// Similar logic for "relation_many"
async function associateHealthReportWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HealthReport0 = await HealthReports.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (HealthReport0?.setUser) {
await HealthReport0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HealthReport1 = await HealthReports.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (HealthReport1?.setUser) {
await HealthReport1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const HealthReport2 = await HealthReports.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (HealthReport2?.setUser) {
await HealthReport2.setUser(relatedUser2);
}
}
async function associateSymptomLogWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SymptomLog0 = await SymptomLogs.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (SymptomLog0?.setUser) {
await SymptomLog0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SymptomLog1 = await SymptomLogs.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (SymptomLog1?.setUser) {
await SymptomLog1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SymptomLog2 = await SymptomLogs.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (SymptomLog2?.setUser) {
await SymptomLog2.setUser(relatedUser2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await ConditionSuggestions.bulkCreate(ConditionSuggestionsData);
await Doctors.bulkCreate(DoctorsData);
await HealthReports.bulkCreate(HealthReportsData);
await SymptomLogs.bulkCreate(SymptomLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associateConditionSuggestionWithUser(),
// Similar logic for "relation_many"
await associateHealthReportWithUser(),
await associateSymptomLogWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('condition_suggestions', null, {});
await queryInterface.bulkDelete('doctors', null, {});
await queryInterface.bulkDelete('health_reports', null, {});
await queryInterface.bulkDelete('symptom_logs', null, {});
},
};