import mysql from "mysql2/promise"; import * as dotenv from "dotenv"; dotenv.config(); const BLOCS = [ "SI RH","SI Finance","SI Métier","SI Collaboratif","Site internet", "SI Achat","SI Support","SI Infrastructure","SI Sécurité","SI Qualité", "SI Immobilier","SI Décisionnel" ]; const EDITEURS_DEMO = [ "Cerner","Oracle Health","Dedalus","Mediware","Infor","SAP","Microsoft", "Sage","Cegid","Berger-Levrault","Maincare","Hopital Manager","Softway Medical", "Medasys","Enovacom","Xperis","Mipih","Sephira","Cegedim","Autre" ]; const SOLUTIONS_DEMO = [ { nom: "DPI (Dossier Patient Informatisé)", editeur: "Dedalus", bloc: "SI Métier" }, { nom: "SIRH", editeur: "Cegid", bloc: "SI RH" }, { nom: "Logiciel de paie", editeur: "Sage", bloc: "SI RH" }, { nom: "Comptabilité générale", editeur: "Sage", bloc: "SI Finance" }, { nom: "Messagerie sécurisée", editeur: "Enovacom", bloc: "SI Collaboratif" }, { nom: "Intranet", editeur: "Microsoft", bloc: "Site internet" }, { nom: "GMAO", editeur: "Infor", bloc: "SI Immobilier" }, { nom: "Système de gestion des achats", editeur: "Berger-Levrault", bloc: "SI Achat" }, { nom: "BI / Reporting", editeur: "Microsoft", bloc: "SI Décisionnel" }, { nom: "Antivirus / EDR", editeur: "Microsoft", bloc: "SI Sécurité" }, ]; const ETABLISSEMENTS_DEMO = [ { nom: "Clinique Saint-Joseph", finess: "750123456", region: "Île-de-France", typeActivite: "MCO", tailleEffectifs: "200 - 500 salariés" }, { nom: "EHPAD Les Jardins", finess: "690234567", region: "Auvergne-Rhône-Alpes", typeActivite: "EHPAD", tailleEffectifs: "50 - 200 salariés" }, { nom: "Centre Hospitalier de Bretagne", finess: "290345678", region: "Bretagne", typeActivite: "MCO", tailleEffectifs: "500 - 1000 salariés" }, { nom: "HAD Nouvelle-Aquitaine", finess: "330456789", region: "Nouvelle-Aquitaine", typeActivite: "HAD", tailleEffectifs: "< 50 salariés" }, { nom: "IME Les Pins", finess: "130567890", region: "Provence-Alpes-Côte d'Azur", typeActivite: "IME", tailleEffectifs: "50 - 200 salariés" }, ]; async function seed() { const conn = await mysql.createConnection(process.env.DATABASE_URL); console.log("Seeding blocs fonctionnels..."); for (const nom of BLOCS) { await conn.execute("INSERT IGNORE INTO blocs_fonctionnels (nom, estValide) VALUES (?, 1)", [nom]); } console.log("Seeding editeurs..."); for (const nom of EDITEURS_DEMO) { await conn.execute("INSERT IGNORE INTO editeurs (nom, estValide) VALUES (?, 1)", [nom]); } console.log("Seeding solutions..."); for (const s of SOLUTIONS_DEMO) { const [editeurRows] = await conn.execute("SELECT id FROM editeurs WHERE nom = ? LIMIT 1", [s.editeur]); const [blocRows] = await conn.execute("SELECT id FROM blocs_fonctionnels WHERE nom = ? LIMIT 1", [s.bloc]); const editeurId = editeurRows[0]?.id; const blocId = blocRows[0]?.id; if (editeurId) { await conn.execute( "INSERT IGNORE INTO solutions (nom, editeurId, blocFonctionnelId, estValide) VALUES (?, ?, ?, 1)", [s.nom, editeurId, blocId ?? null] ); } } console.log("Seeding etablissements demo..."); for (const e of ETABLISSEMENTS_DEMO) { await conn.execute( "INSERT IGNORE INTO etablissements (finess, nom, region, typeActivite, tailleEffectifs, visibilite, accepteMiseEnRelation) VALUES (?, ?, ?, ?, ?, 'tous', 1)", [e.finess, e.nom, e.region, e.typeActivite, e.tailleEffectifs] ); } console.log("Seed termine !"); await conn.end(); } seed().catch(console.error);