Files
administracionHospital/patch.cjs
T

59 lines
3.9 KiB
JavaScript

const fs = require('fs');
let code = fs.readFileSync('src/sections/HistoriaClinica.tsx', 'utf8');
code = code.replace("import { useState } from 'react';", "import { useState } from 'react';\nimport { createPortal } from 'react-dom';");
const portalState = "const [tabActivo, setTabActivo] = useState('evoluciones');\n const [portalNode, setPortalNode] = useState<HTMLDivElement | null>(null);";
code = code.replace("const [tabActivo, setTabActivo] = useState('evoluciones');", portalState);
const tabsListRegex = /<ScrollArea className="w-full rounded-md border bg-background whitespace-nowrap">([\s\S]*?)<\/ScrollArea>/;
const newTabsList = `
<div className="flex flex-col sm:flex-row sm:items-center gap-4 mb-4">
<Select value={tabActivo} onValueChange={setTabActivo}>
<SelectTrigger className="w-full sm:w-[280px] font-semibold bg-gray-50 border-gray-300">
<SelectValue placeholder="Menú de Secciones" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Menú</SelectLabel>
<SelectItem value="evoluciones">Evoluciones ({evoluciones.length})</SelectItem>
<SelectItem value="indicaciones">Indicaciones ({indicacionesActivas.length})</SelectItem>
<SelectItem value="glucemias">Glucemias ({glucemias.length})</SelectItem>
<SelectItem value="laboratorios">Laboratorio ({laboratorios.length})</SelectItem>
<SelectItem value="acidobase">EAB ({acidosBase.length})</SelectItem>
<SelectItem value="cultivos">Cultivos ({cultivos.length})</SelectItem>
<SelectItem value="atb">ATB ({atb.length})</SelectItem>
<SelectItem value="estudios">Estudios ({estudiosComplementarios.length})</SelectItem>
<SelectItem value="interconsultas">Interconsultas ({interconsultas.length})</SelectItem>
<SelectItem value="pendientes">Pendientes ({pendientesActivos.length})</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<div ref={setPortalNode} id="menu-actions" className="flex flex-1 items-center gap-2 overflow-x-auto min-h-[40px]"></div>
</div>
`;
code = code.replace(tabsListRegex, newTabsList.trim());
// We also need to add portalNode={portalNode} to all SeccionXXX components
code = code.replace(/<SeccionGlucemias (.*?)\/>/g, '<SeccionGlucemias portalNode={portalNode} $1/>');
code = code.replace(/<SeccionLaboratorios (.*?)\/>/g, '<SeccionLaboratorios portalNode={portalNode} $1/>');
code = code.replace(/<SeccionEvoluciones (.*?)\/>/g, '<SeccionEvoluciones portalNode={portalNode} $1/>');
code = code.replace(/<SeccionAcidosBase (.*?)\/>/g, '<SeccionAcidosBase portalNode={portalNode} $1/>');
code = code.replace(/<SeccionCultivos (.*?)\/>/g, '<SeccionCultivos portalNode={portalNode} $1/>');
code = code.replace(/<SeccionATB (.*?)\/>/g, '<SeccionATB portalNode={portalNode} $1/>');
code = code.replace(/<SeccionIndicaciones (.*?)\/>/g, '<SeccionIndicaciones portalNode={portalNode} $1/>');
code = code.replace(/<SeccionEstudiosComplementarios (.*?)\/>/g, '<SeccionEstudiosComplementarios portalNode={portalNode} $1/>');
code = code.replace(/<SeccionInterconsultas (.*?)\/>/g, '<SeccionInterconsultas portalNode={portalNode} $1/>');
code = code.replace(/<SeccionPendientes (.*?)\/>/g, '<SeccionPendientes portalNode={portalNode} $1/>');
// Update signatures
function updateSignature(name) {
const regex = new RegExp(`function ${name}\\(\\{ (.*?)canEdit \\}: \\{([\\s\\S]*?)canEdit\\?: boolean;([\\s\\S]*?)\\}\\) \\{`, 'g');
// Wait, some might not have canEdit?: boolean optional.
}
// Actually, it's easier to do this individually or just with a regex
fs.writeFileSync('src/sections/HistoriaClinica.tsx', code);