30241/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-27 15:18:44 +00:00

572 lines
13 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Admissions = db.admissions;
const Discharges = db.discharges;
const MedicalHistories = db.medical_histories;
const Patients = db.patients;
const AdmissionsData = [
{
// type code here for "relation_one" field
admission_date: new Date('2023-10-01T10:00:00Z'),
admission_type: 'Involuntary',
legal_status: 'Discharged',
consent_signed: true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
admission_date: new Date('2023-10-02T11:00:00Z'),
admission_type: 'Involuntary',
legal_status: 'UnderCare',
consent_signed: true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
admission_date: new Date('2023-10-03T12:00:00Z'),
admission_type: 'Voluntary',
legal_status: 'Discharged',
consent_signed: true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
admission_date: new Date('2023-10-04T13:00:00Z'),
admission_type: 'Involuntary',
legal_status: 'UnderCare',
consent_signed: false,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
admission_date: new Date('2023-10-05T14:00:00Z'),
admission_type: 'Voluntary',
legal_status: 'UnderCare',
consent_signed: true,
// type code here for "relation_one" field
},
];
const DischargesData = [
{
// type code here for "relation_one" field
discharge_date: new Date('2023-10-10T10:00:00Z'),
discharge_against_medical_advice: true,
},
{
// type code here for "relation_one" field
discharge_date: new Date('2023-10-11T11:00:00Z'),
discharge_against_medical_advice: true,
},
{
// type code here for "relation_one" field
discharge_date: new Date('2023-10-12T12:00:00Z'),
discharge_against_medical_advice: false,
},
{
// type code here for "relation_one" field
discharge_date: new Date('2023-10-13T13:00:00Z'),
discharge_against_medical_advice: true,
},
{
// type code here for "relation_one" field
discharge_date: new Date('2023-10-14T14:00:00Z'),
discharge_against_medical_advice: true,
},
];
const MedicalHistoriesData = [
{
// type code here for "relation_one" field
psychiatric_history: 'History of anxiety and depression.',
medical_history: 'Diabetes and hypertension.',
},
{
// type code here for "relation_one" field
psychiatric_history: 'Bipolar disorder diagnosis.',
medical_history: 'Asthma and allergies.',
},
{
// type code here for "relation_one" field
psychiatric_history: 'Schizophrenia treatment ongoing.',
medical_history: 'No significant medical history.',
},
{
// type code here for "relation_one" field
psychiatric_history: 'PTSD from past trauma.',
medical_history: 'Chronic back pain.',
},
{
// type code here for "relation_one" field
psychiatric_history: 'Major depressive disorder.',
medical_history: 'Heart disease.',
},
];
const PatientsData = [
{
full_name: 'John Doe',
age: 45,
gender: 'Other',
residence: 'Nairobi',
marital_status: 'Divorced',
nationality: 'Other',
// type code here for "relation_one" field
},
{
full_name: 'Jane Smith',
age: 30,
gender: 'Other',
residence: 'Mombasa',
marital_status: 'Widowed',
nationality: 'Kenyan',
// type code here for "relation_one" field
},
{
full_name: 'Michael Johnson',
age: 50,
gender: 'Female',
residence: 'Kisumu',
marital_status: 'Married',
nationality: 'Other',
// type code here for "relation_one" field
},
{
full_name: 'Emily Davis',
age: 28,
gender: 'Female',
residence: 'Nakuru',
marital_status: 'Divorced',
nationality: 'Other',
// type code here for "relation_one" field
},
{
full_name: 'David Brown',
age: 60,
gender: 'Other',
residence: 'Eldoret',
marital_status: 'Single',
nationality: 'Kenyan',
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateAdmissionWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Admission0 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Admission0?.setPatient) {
await Admission0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Admission1 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Admission1?.setPatient) {
await Admission1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Admission2 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Admission2?.setPatient) {
await Admission2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Admission3 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Admission3?.setPatient) {
await Admission3.setPatient(relatedPatient3);
}
const relatedPatient4 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Admission4 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Admission4?.setPatient) {
await Admission4.setPatient(relatedPatient4);
}
}
async function associateAdmissionWithRecommended_doctor() {
const relatedRecommended_doctor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Admission0 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Admission0?.setRecommended_doctor) {
await Admission0.setRecommended_doctor(relatedRecommended_doctor0);
}
const relatedRecommended_doctor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Admission1 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Admission1?.setRecommended_doctor) {
await Admission1.setRecommended_doctor(relatedRecommended_doctor1);
}
const relatedRecommended_doctor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Admission2 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Admission2?.setRecommended_doctor) {
await Admission2.setRecommended_doctor(relatedRecommended_doctor2);
}
const relatedRecommended_doctor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Admission3 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Admission3?.setRecommended_doctor) {
await Admission3.setRecommended_doctor(relatedRecommended_doctor3);
}
const relatedRecommended_doctor4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Admission4 = await Admissions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Admission4?.setRecommended_doctor) {
await Admission4.setRecommended_doctor(relatedRecommended_doctor4);
}
}
async function associateDischargeWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Discharge0 = await Discharges.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Discharge0?.setPatient) {
await Discharge0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Discharge1 = await Discharges.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Discharge1?.setPatient) {
await Discharge1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Discharge2 = await Discharges.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Discharge2?.setPatient) {
await Discharge2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Discharge3 = await Discharges.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Discharge3?.setPatient) {
await Discharge3.setPatient(relatedPatient3);
}
const relatedPatient4 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const Discharge4 = await Discharges.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Discharge4?.setPatient) {
await Discharge4.setPatient(relatedPatient4);
}
}
async function associateMedicalHistoryWithPatient() {
const relatedPatient0 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalHistory0 = await MedicalHistories.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicalHistory0?.setPatient) {
await MedicalHistory0.setPatient(relatedPatient0);
}
const relatedPatient1 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalHistory1 = await MedicalHistories.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicalHistory1?.setPatient) {
await MedicalHistory1.setPatient(relatedPatient1);
}
const relatedPatient2 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalHistory2 = await MedicalHistories.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicalHistory2?.setPatient) {
await MedicalHistory2.setPatient(relatedPatient2);
}
const relatedPatient3 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalHistory3 = await MedicalHistories.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MedicalHistory3?.setPatient) {
await MedicalHistory3.setPatient(relatedPatient3);
}
const relatedPatient4 = await Patients.findOne({
offset: Math.floor(Math.random() * (await Patients.count())),
});
const MedicalHistory4 = await MedicalHistories.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (MedicalHistory4?.setPatient) {
await MedicalHistory4.setPatient(relatedPatient4);
}
}
async function associatePatientWithAdmitted_by() {
const relatedAdmitted_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Patient0 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Patient0?.setAdmitted_by) {
await Patient0.setAdmitted_by(relatedAdmitted_by0);
}
const relatedAdmitted_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Patient1 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Patient1?.setAdmitted_by) {
await Patient1.setAdmitted_by(relatedAdmitted_by1);
}
const relatedAdmitted_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Patient2 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Patient2?.setAdmitted_by) {
await Patient2.setAdmitted_by(relatedAdmitted_by2);
}
const relatedAdmitted_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Patient3 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Patient3?.setAdmitted_by) {
await Patient3.setAdmitted_by(relatedAdmitted_by3);
}
const relatedAdmitted_by4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Patient4 = await Patients.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Patient4?.setAdmitted_by) {
await Patient4.setAdmitted_by(relatedAdmitted_by4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Admissions.bulkCreate(AdmissionsData);
await Discharges.bulkCreate(DischargesData);
await MedicalHistories.bulkCreate(MedicalHistoriesData);
await Patients.bulkCreate(PatientsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAdmissionWithPatient(),
await associateAdmissionWithRecommended_doctor(),
await associateDischargeWithPatient(),
await associateMedicalHistoryWithPatient(),
await associatePatientWithAdmitted_by(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('admissions', null, {});
await queryInterface.bulkDelete('discharges', null, {});
await queryInterface.bulkDelete('medical_histories', null, {});
await queryInterface.bulkDelete('patients', null, {});
},
};