Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Prossima revisione
Revisione precedente
docuneo:programma_npt [2025/07/29 17:47] – creata - modifica esterna 127.0.0.1docuneo:programma_npt [2025/08/02 21:46] (versione attuale) neoadmin
Linea 3: Linea 3:
     <meta charset="UTF-8">     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Programma NPT Neonatale v2.0 con BUN</title>+    <title>Programma NPT Neonatale v3.0 - Versione Unificata</title
 +    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
     <style>     <style>
         body {         body {
Linea 26: Linea 27:
             border-bottom: 3px solid #3498db;             border-bottom: 3px solid #3498db;
             padding-bottom: 10px;             padding-bottom: 10px;
 +        }
 +
 +        .version-info {
 +            text-align: center;
 +            font-size: 12px;
 +            color: #7f8c8d;
 +            margin-bottom: 20px;
         }         }
  
Linea 165: Linea 173:
         }         }
  
-        .phase-transition {+        .phase-transizione {
             background-color: #fff3cd;             background-color: #fff3cd;
             color: #856404;             color: #856404;
         }         }
  
-        .phase-stabilization {+        .phase-stabilizzazione {
             background-color: #d1ecf1;             background-color: #d1ecf1;
             color: #0c5460;             color: #0c5460;
         }         }
  
-        .phase-growth {+        .phase-crescita {
             background-color: #d4edda;             background-color: #d4edda;
             color: #155724;             color: #155724;
Linea 213: Linea 221:
         }         }
  
-        /* CSS TAB ORIZZONTALI CORRETTO */+        /* CSS TAB ORIZZONTALI CORRETTI */
         .tabs {         .tabs {
             display: flex;             display: flex;
Linea 222: Linea 230:
  
         .tab {         .tab {
-            padding: 10px 20px;+            padding: 8px 15px;
             background-color: #ecf0f1;             background-color: #ecf0f1;
             border: 1px solid #ddd;             border: 1px solid #ddd;
Linea 230: Linea 238:
             transition: all 0.3s ease;             transition: all 0.3s ease;
             text-align: center;             text-align: center;
-            min-width: 120px;+            min-width: 100px;
             flex: 1;             flex: 1;
-            max-width: 200px;+            max-width: 160px; 
 +            font-size: 12px;
         }         }
  
Linea 336: Linea 345:
             background-color: #f8f9fa;             background-color: #f8f9fa;
             text-align: left !important;             text-align: left !important;
 +        }
 +
 +        /* SEZIONE NUOVA PER TAB 5 CONFIGURAZIONE AVANZATA */
 +        .config-advanced {
 +            background-color: #f8f9fa;
 +            border: 2px solid #17a2b8;
 +            border-radius: 10px;
 +            padding: 20px;
 +            margin: 20px 0;
 +        }
 +
 +        .config-advanced h3 {
 +            color: #0c5460;
 +            margin-top: 0;
 +            border-bottom: 2px solid #17a2b8;
 +            padding-bottom: 10px;
 +        }
 +
 +        .monitoring-table {
 +            width: 100%;
 +            border-collapse: collapse;
 +            margin: 15px 0;
 +            font-size: 12px;
 +        }
 +
 +        .monitoring-table th, .monitoring-table td {
 +            border: 1px solid #17a2b8;
 +            padding: 8px;
 +            text-align: left;
 +        }
 +
 +        .monitoring-table th {
 +            background-color: #17a2b8;
 +            color: white;
 +        }
 +
 +        .alert-critical {
 +            background-color: #721c24;
 +            color: white;
 +            padding: 15px;
 +            border-radius: 5px;
 +            margin: 15px 0;
 +            font-weight: bold;
 +        }
 +
 +        /* REPORT SECTION */
 +        .report-output {
 +            border: 2px solid #3498db;
 +            border-radius: 10px;
 +            padding: 30px;
 +            margin-top: 30px;
 +            background-color: white;
 +            font-family: 'Times New Roman', serif;
 +            line-height: 1.6;
 +        }
 +
 +        .medical-header {
 +            text-align: center;
 +            border-bottom: 3px solid #2c3e50;
 +            padding-bottom: 15px;
 +            margin-bottom: 25px;
 +        }
 +
 +        .medical-header h1 {
 +            font-size: 24px;
 +            color: #2c3e50;
 +            margin: 5px 0;
 +        }
 +
 +        .medical-header h2 {
 +            font-size: 18px;
 +            color: #34495e;
 +            margin: 3px 0;
 +        }
 +
 +        .medical-header p {
 +            font-size: 14px;
 +            color: #7f8c8d;
 +            margin: 2px 0;
 +        }
 +
 +        .no-print { 
 +            display: block; 
 +        }
 +
 +        @media print {
 +            .no-print { 
 +                display: none !important; 
 +            }
 +            body { 
 +                background: white; 
 +            }
 +            .container { 
 +                box-shadow: none; 
 +            }
         }         }
     </style>     </style>
Linea 342: Linea 446:
  
 <div class="container"> <div class="container">
-    <h1>Programma NPT Neonatale v2.0</h1>+    <h1>Programma NPT Neonatale v3.0 - Versione Unificata</h1
 +    <div class="version-info"> 
 +        <strong>Versione:</strong> 3.0 UNIFIED | <strong>Data creazione:</strong> 02 Agosto 2025 | <strong>Ora:</strong> 20:00 | <strong>Sistema:</strong> NPT Calculator Advanced UNIFIED 
 +    </div>
          
     <!-- TAB ORIZZONTALI CORRETTI -->     <!-- TAB ORIZZONTALI CORRETTI -->
     <div class="tabs">     <div class="tabs">
         <div class="tab active" onclick="showTab('patient-data')">         <div class="tab active" onclick="showTab('patient-data')">
-            <span style="font-size: 18px;">1</span><br>Dati Paziente+            <span style="font-size: 16px;">1</span><br>Dati Paziente
         </div>         </div>
 +        
 +        <!-- SEZIONE CONFIGURAZIONE COMPONENTI (DA VERSIONE 17) -->
         <div class="tab" onclick="showTab('enteral')">         <div class="tab" onclick="showTab('enteral')">
-            <span style="font-size: 18px;">2</span><br>Nutrizione Enterale+            <span style="font-size: 16px;">2</span><br>Nutrizione Enterale
         </div>         </div>
         <div class="tab" onclick="showTab('nutrition-calc')">         <div class="tab" onclick="showTab('nutrition-calc')">
-            <span style="font-size: 18px;">3</span><br>Calcolo Fabbisogni+            <span style="font-size: 16px;">3</span><br>Calcolo Fabbisogni
         </div>         </div>
         <div class="tab" onclick="showTab('parenteral')">         <div class="tab" onclick="showTab('parenteral')">
-            <span style="font-size: 18px;">4</span><br>Nutrizione Parenterale+            <span style="font-size: 16px;">4</span><br>Nutrizione Parenterale 
 +        </div> 
 +        <div class="tab" onclick="showTab('report')"> 
 +            <span style="font-size: 16px;">5</span><br>Report Finale
         </div>         </div>
         <div class="tab" onclick="showTab('config')">         <div class="tab" onclick="showTab('config')">
-            <span style="font-size: 18px;">5</span><br>Configurazione+            <span style="font-size: 16px;">6</span><br>Configurazione
         </div>         </div>
     </div>     </div>
  
-    <!-- TAB 1: DATI PAZIENTE -->+    <!-- TAB 1: DATI PAZIENTE (VERSIONE 17 ORIGINALE) -->
     <div id="patient-data" class="tab-content active">     <div id="patient-data" class="tab-content active">
         <div class="info">         <div class="info">
Linea 369: Linea 481:
             <strong>Obiettivo:</strong> Inserire i dati antropometrici ed ematochimici del neonato             <strong>Obiettivo:</strong> Inserire i dati antropometrici ed ematochimici del neonato
         </div>         </div>
 +        <div class="section">
 +            <h2>Dati Prescrizione</h2>
 +            <div class="form-row">
 +                <div class="form-col">
 +                    <div class="input-group">
 +                        <label for="prescriptionDate">Data di prescrizione:</label>
 +                        <input type="date" id="prescriptionDate" style="width: 180px;">
 +                    </div>
 +                    <div class="input-group">
 +                        <label for="prescribingDoctor">Medico prescrittore:</label>
 +                        <select id="prescribingDoctor" style="width: 200px;">
 +                            <!-- Popolato dinamicamente -->
 +                        </select>
 +                    </div>
 +                </div>
 +                <div class="form-col">
 +                    <div class="info" style="margin-top: 0; font-size: 13px;">
 +                        <strong>Info Prescrizione:</strong><br>
 +                        • La data viene impostata automaticamente ad oggi<br>
 +                        • Selezionare il medico responsabile della prescrizione<br>
 +                        • Questi dati appariranno nel riepilogo finale
 +                    </div>
 +                </div>
 +            </div>
 +        </div>
 +        
         <div class="section">         <div class="section">
             <h2>Dati Paziente</h2>             <h2>Dati Paziente</h2>
             <div class="form-row">             <div class="form-row">
                 <div class="form-col">                 <div class="form-col">
 +                    <div class="input-group">
 +                        <label for="medicalRecord">N° Cartella Clinica:</label>
 +                        <input type="text" id="medicalRecord" maxlength="10" placeholder="2025000001" style="width: 120px; font-family: monospace;">
 +                    </div>
                     <div class="input-group">                     <div class="input-group">
                         <label for="birthWeight">Peso alla nascita (g):</label>                         <label for="birthWeight">Peso alla nascita (g):</label>
Linea 402: Linea 544:
                         <label for="ph">pH ematico:</label>                         <label for="ph">pH ematico:</label>
                         <input type="number" id="ph" min="7.0" max="7.6" step="0.01" placeholder="7.35-7.45 normale">                         <input type="number" id="ph" min="7.0" max="7.6" step="0.01" placeholder="7.35-7.45 normale">
 +                    </div>
 +                    <div class="input-group">
 +                        <label for="baseExcess">BE - Base Excess (mEq/L):</label>
 +                        <input type="number" id="baseExcess" min="-15" max="10" step="0.1" placeholder="-4 +2 normale">
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
Linea 413: Linea 559:
                         <strong>Natremia:</strong> 135-145 mEq/L<br>                         <strong>Natremia:</strong> 135-145 mEq/L<br>
                         <strong>pH:</strong> 7.35-7.45<br>                         <strong>pH:</strong> 7.35-7.45<br>
 +                        <strong>BE:</strong> -4 a +2 mEq/L<br>
                         <strong>Diuresi:</strong> 1-3 mL/kg/die                         <strong>Diuresi:</strong> 1-3 mL/kg/die
                     </div>                     </div>
Linea 427: Linea 574:
     </div>     </div>
  
-    <!-- TAB 2: NUTRIZIONE ENTERALE -->+    <!-- TAB 2: NUTRIZIONE ENTERALE (VERSIONE 17 ORIGINALE) -->
     <div id="enteral" class="tab-content">     <div id="enteral" class="tab-content">
         <div class="info">         <div class="info">
Linea 517: Linea 664:
             </div>             </div>
  
-            <button id="calculateEnteralBtn" class="button" onclick="calculateEnteral()">Calcola Apporti Enterali</button>+            <button id="calculateEnteralBtn" class="button calculate-nutrition-pending" onclick="calculateEnteral()">Calcola Apporti Enterali</button>
         </div>         </div>
  
Linea 526: Linea 673:
     </div>     </div>
  
-    <!-- TAB 3: CALCOLO FABBISOGNI -->+    <!-- TAB 3: CALCOLO FABBISOGNI (VERSIONE 17 ORIGINALE COMPLETA) -->
     <div id="nutrition-calc" class="tab-content">     <div id="nutrition-calc" class="tab-content">
         <div class="info">         <div class="info">
Linea 566: Linea 713:
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqCarbs">Carboidrati (g/kg/die):</label>+                        <label for="carbUnit">Unità glucidi:</label> 
 +                        <select id="carbUnit" onchange="updateCarbUnit()"> 
 +                            <option value="g">g/kg/die</option> 
 +                            <option value="mg">mg/kg/min</option> 
 +                        </select> 
 +                    </div> 
 +                    <div class="input-group"> 
 +                        <label for="reqCarbs" id="carbLabel">Glucidi (g/kg/die):</label>
                         <input type="number" id="reqCarbs" min="0" max="20" step="0.1" value="6.0">                         <input type="number" id="reqCarbs" min="0" max="20" step="0.1" value="6.0">
                     </div>                     </div>
Linea 576: Linea 730:
                 <div class="form-col">                 <div class="form-col">
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqCalcium">Calcio (mg/kg/die):</label>+                        <label for="reqCalcium">Calcio elementare (mg/kg/die):</label>
                         <input type="number" id="reqCalcium" min="0" max="200" step="5" value="0">                         <input type="number" id="reqCalcium" min="0" max="200" step="5" value="0">
                     </div>                     </div>
Linea 584: Linea 738:
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqMagnesium">Magnesio (mg/kg/die):</label> +                        <label for="reqMagnesium">Magnesio (mEq/kg/die):</label> 
-                        <input type="number" id="reqMagnesium" min="0" max="50" step="1" value="0">+                        <input type="number" id="reqMagnesium" min="0" max="10" step="0.1" value="0">
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
                         <label for="reqSodium">Sodio (mEq/kg/die):</label>                         <label for="reqSodium">Sodio (mEq/kg/die):</label>
                         <input type="number" id="reqSodium" min="0" max="10" step="0.1" value="0">                         <input type="number" id="reqSodium" min="0" max="10" step="0.1" value="0">
 +                    </div>
 +                    <div class="input-group">
 +                        <label for="sodiumType">Tipo di sodio:</label>
 +                        <select id="sodiumType" onchange="updateSodiumChoice()">
 +                            <option value="nacl">Sodio Cloruro (NaCl)</option>
 +                            <option value="sodium_acetate">Sodio Acetato (alcalinizzante)</option>
 +                        </select>
 +                    </div>
 +                    <div id="sodiumRecommendation" class="hidden" style="margin-top: 5px;">
 +                        <!-- Popolato dinamicamente -->
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
Linea 600: Linea 764:
             <div class="form-row">             <div class="form-row">
                 <div class="form-col">                 <div class="form-col">
-                    <h4>Vitamine e Oligoelementi (dal 4° giorno)</h4>+                    <h4>Vitamine e Oligoelementi (dal 3° giorno)</h4>
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqVitalipid">Vitalipid (ml/die):</label>+                        <label for="reqVitalipid">Vitalipid (ml/kg/die):</label>
                         <input type="number" id="reqVitalipid" min="0" max="10" step="0.5" value="0">                         <input type="number" id="reqVitalipid" min="0" max="10" step="0.5" value="0">
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqSoluvit">Soluvit (ml/die):</label>+                        <label for="reqSoluvit">Soluvit (ml/kg/die):</label>
                         <input type="number" id="reqSoluvit" min="0" max="5" step="0.5" value="0">                         <input type="number" id="reqSoluvit" min="0" max="5" step="0.5" value="0">
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
-                        <label for="reqPeditrace">Peditrace (ml/die):</label>+                        <label for="reqPeditrace">Peditrace (ml/kg/die):</label>
                         <input type="number" id="reqPeditrace" min="0" max="10" step="0.5" value="0">                         <input type="number" id="reqPeditrace" min="0" max="10" step="0.5" value="0">
 +                    </div>
 +                    <div class="input-group">
 +                        <label for="reqCarnitine">Carnitina (mg/kg/die):</label>
 +                        <input type="number" id="reqCarnitine" min="0" max="20" step="1" value="0">
                     </div>                     </div>
                 </div>                 </div>
Linea 617: Linea 785:
                     <div class="info" style="margin-top: 0; font-size: 13px;">                     <div class="info" style="margin-top: 0; font-size: 13px;">
                         <strong>Regole Vitamine/Oligoelementi:</strong><br>                         <strong>Regole Vitamine/Oligoelementi:</strong><br>
-                        <strong>• Dal 4° giorno:</strong> Vitalipid 5ml, Soluvit 2ml, Peditrace 1ml<br>+                        <strong>• Dal 3° giorno:</strong> Vitalipid 4 ml/kg/die, Soluvit 1 ml/kg/die, Peditrace 1 ml/kg/die<br>
                         <strong>• Sospensione automatica:</strong> Se enterale ≥100 ml/kg/die<br>                         <strong>• Sospensione automatica:</strong> Se enterale ≥100 ml/kg/die<br>
-                        <strong>• Modificabili manualmente:</strong> Campi editabili per personalizzazione+                        <strong>• Modificabili manualmente:</strong> Campi editabili per personalizzazione<br><br> 
 +                        <strong>Regole Carnitina:</strong><br> 
 +                        <strong>• NPT > 1 mese:</strong> Carnitina 5 mg/kg/die<br> 
 +                        <strong>• NPT < 1 mese:</strong> Non necessaria<br> 
 +                        <strong>• Fonte:</strong> Carnitene (100 mg/ml)
                     </div>                     </div>
                 </div>                 </div>
Linea 631: Linea 803:
     </div>     </div>
  
-    <!-- TAB 4: NUTRIZIONE PARENTERALE -->+    <!-- TAB 4: NUTRIZIONE PARENTERALE (VERSIONE 17 ORIGINALE) -->
     <div id="parenteral" class="tab-content">     <div id="parenteral" class="tab-content">
         <div class="info">         <div class="info">
Linea 667: Linea 839:
  
         <div id="parenteralResults" class="results hidden">         <div id="parenteralResults" class="results hidden">
-            <h3>Composizione NPT Finale</h3>+            <h3>Prescrizione parenterale</h3>
             <div id="parenteralTable"></div>             <div id="parenteralTable"></div>
 +            
 +            <h3 style="margin-top: 30px;">Ricetta per Preparazione (include volume deflussore)</h3>
 +            <div id="preparationTable"></div>
 +            
 +            <div style="margin-top: 20px;">
 +                <button class="button" onclick="generatePDF('foglio_lavoro')">📄 Genera PDF - FOGLIO DI LAVORO</button>
 +                <button class="button" onclick="generatePDF('report_parenterale')" style="margin-left: 10px;">📄 Genera PDF - REPORT PARENTERALE</button>
 +            </div>
         </div>         </div>
     </div>     </div>
  
-    <!-- TAB 5: CONFIGURAZIONE -->+    <!-- TAB 5: REPORT FINALE (SPOSTATO DA TAB 6) --> 
 +    <div id="report" class="tab-content"> 
 +        <div class="info"> 
 +            <strong>PASSO 5 - REPORT FINALE</strong><br> 
 +            <strong>Obiettivo:</strong> Generare la documentazione completa per prescrizione e preparazione 
 +        </div> 
 +         
 +        <div class="section no-print"> 
 +            <h2>Genera Documentazione</h2> 
 +            <button class="button" onclick="generatePrescription()">Genera Prescrizione Medica</button> 
 +            <button class="button" onclick="generateWorksheet()">Genera Ricetta Preparazione</button> 
 +            <button class="button secondary" onclick="window.print()">Stampa Pagina</button> 
 +        </div> 
 +         
 +        <div id="reportOutput"></div> 
 +    </div> 
 + 
 +    <!-- TAB 6: CONFIGURAZIONE (SPOSTATO DA TAB 5) -->
     <div id="config" class="tab-content">     <div id="config" class="tab-content">
         <div class="info">         <div class="info">
-            <strong>CONFIGURAZIONE COMPONENTI</strong><br> +            <strong>CONFIGURAZIONE COMPLETA</strong><br> 
-            <strong>Sistema:</strong> NPT Calculator v2.0 - Database completo componenti nutrizionali+            <strong>Sistema:</strong> NPT Calculator v3.0 - Database completo componenti + configurazione clinica avanzata 
 +        </div> 
 +        <div class="section"> 
 +            <h2>Parametri Sistema</h2> 
 +            <div class="form-row"> 
 +                <div class="form-col"> 
 +                    <div class="input-group"> 
 +                        <label for="deflectorVolume">Volume deflussore (ml):</label> 
 +                        <input type="number" id="deflectorVolume" min="0" max="100" step="5" value="30" oninput="markConfigChanged('system')"> 
 +                    </div> 
 +                    <div class="info" style="margin-top: 10px; font-size: 12px;"> 
 +                        <strong>Info Volume Deflussore:</strong><br> 
 +                        • Volume perso nel deflussore durante la preparazione<br> 
 +                        • Viene aggiunto automaticamente alla ricetta di preparazione<br> 
 +                        • Valore standard: 30 ml (modificabile) 
 +                    </div> 
 +                </div> 
 +                <div class="form-col"> 
 +                    <button id="updateSystemBtn" class="button" onclick="updateSystemConfig()">Aggiorna Parametri Sistema</button> 
 +                </div> 
 +            </div>
         </div>         </div>
                  
Linea 709: Linea 926:
                 <div class="form-col">                 <div class="form-col">
                     <button class="button secondary" onclick="showAddEnteralForm()">Aggiungi Nuova Formula</button>                     <button class="button secondary" onclick="showAddEnteralForm()">Aggiungi Nuova Formula</button>
-                </div> 
-            </div> 
-             
-            <!-- Form per aggiungere nuova formula enterale --> 
-            <div id="addEnteralForm" class="hidden" style="background: #f8f9fa; padding: 15px; border-radius: 5px; margin-top: 15px; border: 2px solid #3498db;"> 
-                <h4>Aggiungi Nuova Formula Enterale</h4> 
-                <div class="form-row"> 
-                    <div class="form-col"> 
-                        <div class="input-group"> 
-                            <label for="newEnteralName">Nome Formula:</label> 
-                            <input type="text" id="newEnteralName" placeholder="es. Aptamil PreNan" style="width: 200px;"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralKey">Codice (univoco):</label> 
-                            <input type="text" id="newEnteralKey" placeholder="es. aptamil_prenan" style="width: 200px;"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralProtein">Proteine (g/100ml):</label> 
-                            <input type="number" id="newEnteralProtein" step="0.1" value="1.5"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralCarbs">Carboidrati (g/100ml):</label> 
-                            <input type="number" id="newEnteralCarbs" step="0.1" value="7.5"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralLipids">Lipidi (g/100ml):</label> 
-                            <input type="number" id="newEnteralLipids" step="0.1" value="3.5"> 
-                        </div> 
-                    </div> 
-                    <div class="form-col"> 
-                        <div class="input-group"> 
-                            <label for="newEnteralSodium">Sodio (mEq/100ml):</label> 
-                            <input type="number" id="newEnteralSodium" step="0.001" value="0.020"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralPotassium">Potassio (mEq/100ml):</label> 
-                            <input type="number" id="newEnteralPotassium" step="0.001" value="0.070"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralCalcium">Calcio (mg/100ml):</label> 
-                            <input type="number" id="newEnteralCalcium" step="0.1" value="50"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralPhosphorus">Fosforo (mg/100ml):</label> 
-                            <input type="number" id="newEnteralPhosphorus" step="0.1" value="30"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralMagnesium">Magnesio (mg/100ml):</label> 
-                            <input type="number" id="newEnteralMagnesium" step="0.1" value="5"> 
-                        </div> 
-                        <div class="input-group"> 
-                            <label for="newEnteralEnergy">Energia (kcal/100ml):</label> 
-                            <input type="number" id="newEnteralEnergy" step="1" value="67"> 
-                        </div> 
-                    </div> 
-                </div> 
-                <div class="form-row"> 
-                    <div class="form-col"> 
-                        <button class="button" onclick="addNewEnteralFormula()">Crea Formula</button> 
-                        <button class="button secondary" onclick="cancelAddEnteral()">Annulla</button> 
-                    </div> 
                 </div>                 </div>
             </div>             </div>
Linea 859: Linea 1015:
  
         <div class="section">         <div class="section">
-            <h2>Vitamine e Oligoelementi</h2>+            <h2>Lista Medici Prescrittori</h2
 +            <div class="info" style="margin-bottom: 15px;"> 
 +                <strong>🩺 CONFIGURAZIONE MEDICI</strong><br> 
 +                Gestisci la lista dei medici prescrittori. Le modifiche si applicano automaticamente alla dropdown del TAB 1. 
 +            </div>
             <div style="overflow-x: auto;">             <div style="overflow-x: auto;">
                 <table class="config-table">                 <table class="config-table">
                     <thead>                     <thead>
                         <tr>                         <tr>
-                            <th style="min-width: 180px;">Prodotto</th> +                            <th style="min-width: 120px;">Nome</th> 
-                            <th>Dose Pediatrica</th> +                            <th style="min-width: 120px;">Cognome</th> 
-                            <th>Dose Max</th> +                            <th style="min-width: 80px;">Titolo</th> 
-                            <th>Contenuto Acqua</th> +                            <th style="min-width: 250px;">Nome Completo (Visualizzato)</th> 
-                            <th style="min-width300px;">Composizione</th>+                            <th>Azioni</th> 
 +                        </tr> 
 +                    </thead> 
 +                    <tbody id="doctorsConfigTable"> 
 +                        <!-- Popolato dinamicamente --> 
 +                    </tbody> 
 +                </table> 
 +            </div> 
 +            <div class="form-row"> 
 +                <div class="form-col"> 
 +                    <button id="updateDoctorsBtn" class="button" onclick="updateDoctorsConfig()">Aggiorna Lista Medici</button> 
 +                </div> 
 +                <div class="form-col"> 
 +                    <button class="button secondary" onclick="showAddDoctorForm()">Aggiungi Nuovo Medico</button> 
 +                </div> 
 +            </div> 
 +        </div> 
 + 
 +        <!-- SEZIONE CONFIGURAZIONE CLINICA AVANZATA (NOVITÀ) --> 
 +        <div class="config-advanced"> 
 +            <h3>🔬 CONFIGURAZIONE CLINICA AVANZATA</h3> 
 +             
 +            <div class="section"> 
 +                <h2>Parametri Elettroliti e Controlli</h2> 
 +                <div class="form-row"> 
 +                    <div class="form-col"> 
 +                        <div class="input-group"> 
 +                            <label for="calciumReq">Calcio standard (mg/kg/die):</label> 
 +                            <input type="number" id="calciumReq" min="0" max="200" value="160"> 
 +                            <span style="margin-left: 10px; font-size: 12px; color: #666;">Range: 120-200</span> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="phosphorusReq">Fosforo standard (mg/kg/die):</label> 
 +                            <input type="number" id="phosphorusReq" min="0" max="100" value="84"> 
 +                            <span style="margin-left10px; font-size: 12px; color: #666;">Range: 60-120</span> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="magnesiumReq">Magnesio standard (mEq/kg/die):</label> 
 +                            <input type="number" id="magnesiumReq" min="0" max="2" step="0.1" value="0.6"> 
 +                            <span style="margin-left: 10px; font-size: 12px; color: #666;">Range: 0.3-1.0</span> 
 +                        </div> 
 +                    </div> 
 +                    <div class="form-col"> 
 +                        <div class="input-group"> 
 +                            <label for="maxGIR">GIR massimo (mg/kg/min):</label> 
 +                            <input type="number" id="maxGIR" min="5" max="20" step="0.1" value="12.0"> 
 +                            <span style="margin-left: 10px; font-size: 12px; color: #666;">Limite sicurezza</span> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="maxLipids">Lipidi massimi (g/kg/die):</label> 
 +                            <input type="number" id="maxLipids" min="1" max="4" step="0.1" value="3.0"> 
 +                            <span style="margin-left: 10px; font-size: 12px; color: #666;">Limite sicurezza</span> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="maxProtein">Proteine massime (g/kg/die):</label> 
 +                            <input type="number" id="maxProtein" min="3" max="6" step="0.1" value="4.5"> 
 +                            <span style="margin-left: 10px; font-size: 12px; color: #666;">Limite sicurezza</span> 
 +                        </div> 
 +                    </div> 
 +                </div> 
 +                <button class="button" onclick="updateClinicalConfig()">AGGIORNA PARAMETRI CLINICI</button> 
 +            </div> 
 + 
 +            <div class="section"> 
 +                <h2>Piano di Monitoraggio Automatico</h2> 
 +                <table class="monitoring-table"> 
 +                    <thead> 
 +                        <tr> 
 +                            <th>Controllo</th> 
 +                            <th>Frequenza</th> 
 +                            <th>Range Normale</th> 
 +                            <th>Azione se Fuori Range</th>
                         </tr>                         </tr>
                     </thead>                     </thead>
                     <tbody>                     <tbody>
                         <tr>                         <tr>
-                            <td class="component-name">Vitalipid N Infant</td> +                            <td><strong>Glicemia</strong></td> 
-                            <td>4 ml/kg/die</td> +                            <td>Ogni 6-8h</td> 
-                            <td>10 ml/die</td> +                            <td>70-110 mg/dL</td> 
-                            <td>9 ml H₂O/10ml</td> +                            <td>Aggiustare velocità glucosio</td>
-                            <td style="font-size: 11px; color: #7f8c8d;">Vit A, D, E, K - Vitamine liposolubili per neonati</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td class="component-name">Soluvit N</td> +                            <td><strong>Elettroliti</strong></td> 
-                            <td>5 ml/die</td> +                            <td>Ogni 24-48h</td> 
-                            <td>5 ml/die</td> +                            <td>Na: 135-145, K: 3.5-5.0</td> 
-                            <td>4.75 ml H₂O/5ml</td> +                            <td>Modificare apporti NPT</td>
-                            <td style="font-size: 11px; color: #7f8c8d;">B1, B2, B6, B12, C, Folati, Niacina - Idrosolubili</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td class="component-name">Peditrace</td> +                            <td><strong>BUN/Creatinina</strong></td> 
-                            <td>1 ml/kg/die</td> +                            <td>Ogni 48h</td> 
-                            <td>10 ml/die</td> +                            <td>BUN: 9-14 mg/dL</td> 
-                            <td>0.99 ml H₂O/ml</td> +                            <td>Aggiustare proteine</td> 
-                            <td style="font-size: 11pxcolor: #7f8c8d;">Zn, Cu, Mn, Se - Oligoelementi pediatrici</td>+                        </tr> 
 +                        <tr> 
 +                            <td><strong>Trigliceridi</strong></td> 
 +                            <td>2 volte/settimana</td> 
 +                            <td>&lt150 mg/dL</td> 
 +                            <td>Ridurre lipidi se &gt200</td> 
 +                        </tr> 
 +                        <tr> 
 +                            <td><strong>Funzione epatica</strong></td> 
 +                            <td>Settimanale</td> 
 +                            <td>AST/ALT normali</td> 
 +                            <td>Valutare sospensione NPT</td>
                         </tr>                         </tr>
                     </tbody>                     </tbody>
                 </table>                 </table>
             </div>             </div>
-        </div> 
  
-        <div class="section"> +            <div class="section"> 
-            <h2>Gestione Configurazioni</h2+                <h2>⚠️ ALERT AUTOMATICI</h2> 
-            <div class="form-row"+                <div class="alert-critical"> 
-                <div class="form-col"> +                    <strong>INTERRUZIONE IMMEDIATA NPT SE:</strong><br
-                    <button class="button secondary" onclick="exportConfig()">Esporta Configurazione</button+                    • Glicemia > 250 mg/dL o 40 mg/dL<br> 
-                    <p style="font-size: 12px; color: #666;">Salva tutte le configurazioni attuali in un file JSON</p>+                    • Trigliceridi > 400 mg/dL<br> 
 +                    • AST/ALT 3x valore normale<br> 
 +                    • Segni di sepsi cateter-correlata<br> 
 +                    • Edema importante con bilancio positivo > 20 ml/kg/die
                 </div>                 </div>
-                <div class="form-col"> +                 
-                    <input type="file" id="configFile" accept=".json" style="displaynone;" onchange="importConfig()"+                <div class="warning"> 
-                    <button class="button secondary" onclick="document.getElementById('configFile').click()">Importa Configurazione</button+                    <strong>AGGIUSTAMENTI NECESSARI SE:</strong><br
-                    <p style="font-size: 12px; color: #666;">Carica configurazioni da file JSON</p>+                    • GIR 12 mg/kg/min → Ridurre glucosio<br
 +                    • BUN > 20 mg/dL → Ridurre proteine<br> 
 +                    • BUN 5 mg/dL → Aumentare proteine<br> 
 +                    • Trigliceridi 200-400 mg/dL → Ridurre/sospendere lipidi<br> 
 +                    • Ipernatremia → Ridurre sodio, aumentare liquidi liberi
                 </div>                 </div>
             </div>             </div>
-            <div class="form-row"> + 
-                <div class="form-col"> +            <div class="section"> 
-                    <button class="button" style="background-color#e67e22;" onclick="resetToDefaults()">Ripristina Valori Default</button+                <h2>Impostazioni Ospedale</h2> 
-                    <style="font-size12pxcolor#666;">Cancella tutte le modifiche e torna ai valori originali</p+                <div class="form-row"> 
-                </div> +                    <div class="form-col"> 
-                <div class="form-col"> +                        <div class="input-group"> 
-                    <div id="storageStatusstyle="padding10px; background: #d1ecf1; border-radius5px; font-size: 12px;"> +                            <label for="hospitalName">Nome Ospedale:</label> 
-                        <strong>💾 Salvataggio Automatico Attivo</strong><br+                            <input type="text" id="hospitalName" value="ASST LECCO" style="width250px;"
-                        Le modifiche vengono salvate automaticamente nel browser+                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="departmentName">Dipartimento:</label
 +                            <input type="text" id="departmentName" value="S.C. Neonatologia e TIN" style="width250px;"> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="directorName">Direttore:</label> 
 +                            <input type="text" id="directorName" value="Dott. Roberto Bellù" style="width: 250px;"> 
 +                        </div
 +                    </div> 
 +                    <div class="form-col"> 
 +                        <div class="input-group"
 +                            <label for="autoSave">Salvataggio automatico:</label> 
 +                            <select id="autoSave"> 
 +                                <option value="true">Attivo</option> 
 +                                <option value="false">Disattivo</option> 
 +                            </select> 
 +                        </div> 
 +                        <div class="input-group"> 
 +                            <label for="decimalPlaces">Cifre decimali:</label> 
 +                            <select id="decimalPlaces"> 
 +                                <option value="1">1 cifra</option> 
 +                                <option value="2" selected>2 cifre</option> 
 +                                <option value="3">3 cifre</option> 
 +                            </select
 +                        </div>
                     </div>                     </div>
                 </div>                 </div>
 +                <button class="button secondary" onclick="resetConfiguration()">RESET CONFIGURAZIONE</button>
 +                <button class="button" onclick="saveConfiguration()">SALVA CONFIGURAZIONE</button>
             </div>             </div>
         </div>         </div>
  
         <div id="configResults" class="results hidden">         <div id="configResults" class="results hidden">
-            <h3>Stato Configurazione v2.0</h3>+            <h3>Stato Configurazione v3.0</h3>
             <div id="configInfo"></div>             <div id="configInfo"></div>
         </div>         </div>
Linea 933: Linea 1206:
  
 <script> <script>
-// DATI NUTRIZIONALI COMPLETI+// DATI NUTRIZIONALI COMPLETI (DA VERSIONE 17)
 const formulaData = { const formulaData = {
     maternal: { name: "Latte Materno", protein: 1.2, carbs: 7.0, lipids: 4.0, sodium: 0.007, potassium: 0.035, calcium: 28.0, phosphorus: 15.0, magnesium: 3.0, energy: 67 },     maternal: { name: "Latte Materno", protein: 1.2, carbs: 7.0, lipids: 4.0, sodium: 0.007, potassium: 0.035, calcium: 28.0, phosphorus: 15.0, magnesium: 3.0, energy: 67 },
Linea 946: Linea 1219:
 }; };
  
-// CONFIGURAZIONI PARENTERALI COMPLETE+// CONFIGURAZIONI PARENTERALI COMPLETE (DA VERSIONE 17)
 const parenteralConfig = { const parenteralConfig = {
     trophamine: {     trophamine: {
Linea 961: Linea 1234:
         description: "Emulsione lipidica endovenosa",         description: "Emulsione lipidica endovenosa",
         notes: "Fornisce acidi grassi essenziali. Max 4g/kg/die"         notes: "Fornisce acidi grassi essenziali. Max 4g/kg/die"
-    }, 
-    glucose10: { 
-        name: "Glucosio 10%", 
-        protein: 0, carbs: 10.0, lipids: 0, sodium: 0, potassium: 0, 
-        calcium: 0, phosphorus: 0, magnesium: 0, energy: 40, water: 90, 
-        description: "Soluzione glucosata ipotonica", 
-        notes: "Osmolarità: ~550 mOsm/L. Per volumi elevati" 
-    }, 
-    glucose20: { 
-        name: "Glucosio 20%", 
-        protein: 0, carbs: 20.0, lipids: 0, sodium: 0, potassium: 0, 
-        calcium: 0, phosphorus: 0, magnesium: 0, energy: 80, water: 80, 
-        description: "Soluzione glucosata ipertonica", 
-        notes: "Osmolarità: ~1100 mOsm/L. Concentrazione media" 
-    }, 
-    glucose33: { 
-        name: "Glucosio 33%", 
-        protein: 0, carbs: 33.0, lipids: 0, sodium: 0, potassium: 0, 
-        calcium: 0, phosphorus: 0, magnesium: 0, energy: 132, water: 67, 
-        description: "Soluzione glucosata ipertonica", 
-        notes: "Osmolarità: ~1800 mOsm/L. Per concentrazioni medie" 
     },     },
     glucose50: {     glucose50: {
Linea 1017: Linea 1269:
         description: "Elettrolita essenziale",         description: "Elettrolita essenziale",
         notes: "10 mEq Na/ml. Prima scelta per supplementazione sodio"         notes: "10 mEq Na/ml. Prima scelta per supplementazione sodio"
 +    },
 +    sodium_acetate: {
 +        name: "Sodio Acetato (2 mEq/mL)",
 +        protein: 0, carbs: 0, lipids: 0, sodium: 667, potassium: 0,
 +        calcium: 0, phosphorus: 0, magnesium: 0, energy: 0, water: 99,
 +        description: "Elettrolita alcalinizzante",
 +        notes: "6.67 mEq Na/ml. Per acidosi: pH < 7.25 o BE < -4"
     },     },
     kcl: {     kcl: {
Linea 1024: Linea 1283:
         description: "Elettrolita essenziale",         description: "Elettrolita essenziale",
         notes: "10 mEq K/ml. Max velocità infusione: 0.5 mEq/kg/h"         notes: "10 mEq K/ml. Max velocità infusione: 0.5 mEq/kg/h"
 +    },
 +    carnitene: {
 +        name: "Carnitene (100 mg/ml)",
 +        protein: 0, carbs: 0, lipids: 0, sodium: 0, potassium: 0,
 +        calcium: 0, phosphorus: 0, magnesium: 0, energy: 0, water: 99,
 +        carnitine: 10000, // 100 mg/ml = 10000 mg/100ml
 +        description: "L-Carnitina per NPT prolungata",
 +        notes: "100 mg/ml. Indicata per NPT > 1 mese. Dose: 5 mg/kg/die"
     }     }
 }; };
Linea 1035: Linea 1302:
         dose: "1-4g/100ml"         dose: "1-4g/100ml"
     }     }
 +};
 +
 +// Database medici dinamico
 +let doctorsData = {
 +    dr_bellu: { name: "Roberto", surname: "Bellù", title: "Dr.", fullName: "Dr. Roberto Bellù" },
 +    dr_condo: { name: "Manuela", surname: "Condò", title: "Dr.ssa", fullName: "Dr.ssa Manuela Condò" },
 +    dr_maccioni: { name: "Carla", surname: "Maccioni", title: "Dr.ssa", fullName: "Dr.ssa Carla Maccioni" },
 +    dr_meroni: { name: "Federica", surname: "Meroni", title: "Dr.ssa", fullName: "Dr.ssa Federica Meroni" },
 +    dr_calzatini: { name: "Francesco", surname: "Calzatini", title: "Dr.", fullName: "Dr. Francesco Calzatini" },
 +    dr_ferrari: { name: "Elisabetta", surname: "Ferrari", title: "Dr.ssa", fullName: "Dr.ssa Elisabetta Ferrari" },
 +    dr_ferendeles: { name: "Francesca", surname: "Ferendeles", title: "Dr.ssa", fullName: "Dr.ssa Francesca Ferendeles" },
 +    dr_fumagalli_l: { name: "Letizia", surname: "Fumagalli", title: "Dr.ssa", fullName: "Dr.ssa Letizia Fumagalli" },
 +    dr_fumagalli_m: { name: "Mara", surname: "Fumagalli", title: "Dr.ssa", fullName: "Dr.ssa Mara Fumagalli" },
 +    dr_corno: { name: "Federica", surname: "Corno", title: "Dr.ssa", fullName: "Dr.ssa Federica Corno" },
 +    dr_evasi: { name: "Veronica", surname: "Evasi", title: "Dr.ssa", fullName: "Dr.ssa Veronica Evasi" },
 +    dr_cereda: { name: "Lidia", surname: "Cereda", title: "Dr.ssa", fullName: "Dr.ssa Lidia Cereda" },
 +    dr_ceccon: { name: "Chiara", surname: "Ceccon", title: "Dr.ssa", fullName: "Dr.ssa Chiara Ceccon" },
 +    dr_nava: { name: "Chiara", surname: "Nava", title: "Dr.ssa", fullName: "Dr.ssa Chiara Nava" },
 +    dr_terenzi: { name: "Francesca", surname: "Terenzi", title: "Dr.ssa", fullName: "Dr.ssa Francesca Terenzi" },
 +    dr_raffa: { name: "Milena", surname: "Raffa", title: "Dr.ssa", fullName: "Dr.ssa Milena Raffa" },
 +    dr_aquisti: { name: "Giulia", surname: "Aquisti", title: "Dr.ssa", fullName: "Dr.ssa Giulia Aquisti" }
 }; };
  
Linea 1042: Linea 1330:
 let currentRequirements = null; let currentRequirements = null;
  
-// FUNZIONI DI SALVATAGGIO PERSISTENTE +// CONFIGURAZIONE CLINICA AVANZATA (NUOVO
-function saveToStorage() { +let clinicalConfig = { 
-    const configData = { +    calciumReq160
-        formulaDataformulaData+    phosphorusReq84
-        parenteralConfigparenteralConfig+    magnesiumReq0.6
-        fortifierDatafortifierData+    maxGIR12.0, 
-        timestampnew Date().toISOString() +    maxLipids: 3.0, 
-    }; +    maxProtein: 4.5
-    try { +    hospitalName: "ASST LECCO", 
-        localStorage.setItem('npt_calculator_config'JSON.stringify(configData)); +    departmentName: "S.C. Neonatologia e TIN"
-        console.log('Configurazione salvata nel localStorage'); +    directorName: "Dott. Roberto Bellù" 
-    } catch (error) { +};
-        console.error('Errore nel salvataggio:'error); +
-    } +
-}+
  
-function loadFromStorage() { +// FUNZIONE RESET PULSANTE FABBISOGNI 
-    try { +function resetNutritionButton() { 
-        const savedData localStorage.getItem('npt_calculator_config'); +    const nutritionBtn document.getElementById('calculateNutritionBtn'); 
-        if (savedData) { +    if (nutritionBtn) { 
-            const configData JSON.parse(savedData)+        nutritionBtn.className 'button calculate-nutrition-pending'; 
-             +        nutritionBtn.innerHTML = 'RICALCOLA FABBISOGNI'
-            // Aggiorna dati globali con quelli salvati +         
-            if (configData.formulaData) { +        // Nascondi risultati precedenti 
-                Object.assign(formulaData, configData.formulaData); +        const nutritionResults = document.getElementById('nutritionResults'); 
-            } +        if (nutritionResults) { 
-            if (configData.parenteralConfig) { +            nutritionResults.classList.add('hidden');
-                Object.assign(parenteralConfig, configData.parenteralConfig); +
-            +
-            if (configData.fortifierData) { +
-                Object.assign(fortifierData, configData.fortifierData); +
-            } +
-             +
-            console.log('Configurazione caricata dal localStorage:', configData.timestamp)+
-            return true;+
         }         }
-    } catch (error) { +         
-        console.error('Errore nel caricamento:', error);+        // Reset anche il pulsante NPT perché i fabbisogni sono cambiati 
 +        resetParenteralButton();
     }     }
-    return false; 
 } }
  
-function resetToDefaults() { +// FUNZIONE RESET PULSANTE PARENTERALE 
-    if (confirm('Sei sicuro di voler ripristinare tutti valori di default? Tutte le modifiche verranno perse.')) { +function resetParenteralButton() { 
-        localStorage.removeItem('npt_calculator_config'); +    const parenteralBtn = document.getElementById('calculateParenteralBtn'); 
-        location.reload();+    if (parenteralBtn) { 
 +        parenteralBtn.className = 'button'; 
 +        parenteralBtn.innerHTML = 'CALCOLA NPT AUTOMATICA'; 
 +         
 +        // Reset anche campi visualizzati 
 +        document.getElementById('calculatedTotalVolume').value = "Premere 'Calcola NPT'"; 
 +        document.getElementById('suggestedGlucose').value = "Premere 'Calcola NPT'"; 
 +        document.getElementById('calculatedProteinVol').value = "--"
 +        document.getElementById('calculatedLipidVol').value = "--"; 
 +         
 +        // Nascondi i risultati precedenti 
 +        const parenteralResults = document.getElementById('parenteralResults'); 
 +        if (parenteralResults) { 
 +            parenteralResults.classList.add('hidden'); 
 +        }
     }     }
-} 
- 
-// FUNZIONE CALCOLO ELETTROLITI AGGIUNTIVI 
-function calculateElectrolyteAdditions(calciumNeeded, phosphorusNeeded, magnesiumNeeded, sodiumNeeded, potassiumNeeded, currentWeightKg) { 
-    const additions = { 
-        ca_gluconato: 0, 
-        esafosfina: 0, 
-        mg_sulfate: 0, 
-        nacl: 0, 
-        kcl: 0, 
-        totalVolume: 0, 
-        providedCalcium: 0, 
-        providedPhosphorus: 0, 
-        providedMagnesium: 0, 
-        providedSodium: 0, 
-        providedPotassium: 0 
-    }; 
-     
-    // Calcola fabbisogni totali per paziente 
-    const totalCalciumNeeded = calciumNeeded * currentWeightKg; // mg 
-    const totalPhosphorusNeeded = phosphorusNeeded * currentWeightKg; // mg 
-    const totalMagnesiumNeeded = magnesiumNeeded * currentWeightKg; // mg 
-    const totalSodiumNeeded = sodiumNeeded * currentWeightKg; // mEq 
-    const totalPotassiumNeeded = potassiumNeeded * currentWeightKg; // mEq 
-     
-    // Calcio Gluconato 10% (840 mg Ca/100ml) 
-    if (totalCalciumNeeded > 0) { 
-        additions.ca_gluconato = totalCalciumNeeded / (parenteralConfig.ca_gluconato.calcium / 100); 
-        additions.providedCalcium = totalCalciumNeeded; 
-    } 
-     
-    // Esafosfina (1600 mg P/100ml + 130 mEq Na/100ml) 
-    if (totalPhosphorusNeeded > 0) { 
-        additions.esafosfina = totalPhosphorusNeeded / (parenteralConfig.esafosfina.phosphorus / 100); 
-        additions.providedPhosphorus = totalPhosphorusNeeded; 
-        // Esafosfina fornisce anche sodio 
-        additions.providedSodium += (additions.esafosfina * parenteralConfig.esafosfina.sodium / 100); 
-    } 
-     
-    // Magnesio Solfato (800 mEq Mg/100ml) 
-    if (totalMagnesiumNeeded > 0) { 
-        additions.mg_sulfate = totalMagnesiumNeeded / (parenteralConfig.mg_sulfate.magnesium / 100); 
-        additions.providedMagnesium = totalMagnesiumNeeded; 
-    } 
-     
-    // Sodio rimanente (dopo quello da Esafosfina) 
-    const remainingSodium = Math.max(0, totalSodiumNeeded - additions.providedSodium); 
-    if (remainingSodium > 0) { 
-        additions.nacl = remainingSodium / (parenteralConfig.nacl.sodium / 100); 
-        additions.providedSodium += remainingSodium; 
-    } 
-     
-    // Potassio Cloruro (1000 mEq K/100ml) 
-    if (totalPotassiumNeeded > 0) { 
-        additions.kcl = totalPotassiumNeeded / (parenteralConfig.kcl.potassium / 100); 
-        additions.providedPotassium = totalPotassiumNeeded; 
-    } 
-     
-    // Volume totale degli elettroliti 
-    additions.totalVolume = additions.ca_gluconato + additions.esafosfina + additions.mg_sulfate + additions.nacl + additions.kcl; 
-     
-    return additions; 
 } }
  
Linea 1177: Linea 1406:
     }     }
          
-    // Popola le tabelle di configurazione quando si apre il TAB 5+    // Popola le tabelle di configurazione quando si apre il TAB 6 (ora config)
     if (tabId === 'config') {     if (tabId === 'config') {
         setTimeout(() => {         setTimeout(() => {
             populateEnteralConfigTable();             populateEnteralConfigTable();
             populateParenteralConfigTable();             populateParenteralConfigTable();
-            populateFortifierConfigTable();+            populateDoctorsConfigTable();
         }, 100);         }, 100);
     }     }
 } }
  
-// FUNZIONE CALCOLO FASE NUTRIZIONALE+// FUNZIONE GESTIONE CARTELLA CLINICA 
 +function setupMedicalRecordField() { 
 +    const medicalRecordInput = document.getElementById('medicalRecord'); 
 +    const currentYear = new Date().getFullYear().toString(); 
 +     
 +    // Imposta il valore iniziale con l'anno corrente 
 +    if (!medicalRecordInput.value) { 
 +        medicalRecordInput.value = currentYear; 
 +    } 
 +     
 +    // Gestisce l'input per mantenere sempre l'anno all'inizio 
 +    medicalRecordInput.addEventListener('input', function(e) { 
 +        let value = e.target.value.replace(/\D/g, ''); // Solo numeri 
 +         
 +        // Se l'utente cerca di cancellare l'anno, lo ripristina 
 +        if (value.length < 4 || !value.startsWith(currentYear)) { 
 +            value = currentYear + value.slice(4); 
 +        } 
 +         
 +        // Limita a 10 cifre totali 
 +        if (value.length > 10) { 
 +            value = value.slice(0, 10); 
 +        } 
 +         
 +        e.target.value = value; 
 +    }); 
 +     
 +    // Quando il campo ottiene il focus, posiziona il cursore dopo l'anno 
 +    medicalRecordInput.addEventListener('focus', function(e) { 
 +        if (e.target.value === currentYear) { 
 +            // Posiziona il cursore alla fine 
 +            setTimeout(() => { 
 +                e.target.setSelectionRange(4, 4); 
 +            }, 0); 
 +        } 
 +    }); 
 +     
 +    // Suggerimento visivo 
 +    medicalRecordInput.addEventListener('blur', function(e) { 
 +        if (e.target.value === currentYear) { 
 +            e.target.placeholder = currentYear + '000001'; 
 +        } 
 +    }); 
 +
 + 
 +function updateDoctorsDropdown() { 
 +    const prescribingDoctorSelect = document.getElementById('prescribingDoctor'); 
 +    if (!prescribingDoctorSelect) return; 
 +     
 +    const currentValue = prescribingDoctorSelect.value; 
 +    prescribingDoctorSelect.innerHTML = '<option value="">Seleziona medico</option>'; 
 +     
 +    Object.keys(doctorsData).forEach(function(key) { 
 +        const doctor = doctorsData[key]; 
 +        const option = document.createElement('option'); 
 +        option.value = key; 
 +        option.textContent = doctor.fullName; 
 +        prescribingDoctorSelect.appendChild(option); 
 +    }); 
 +     
 +    // Ripristina il valore precedente se esiste ancora 
 +    if (currentValue && doctorsData[currentValue]) { 
 +        prescribingDoctorSelect.value = currentValue; 
 +    } 
 +
 + 
 +// FUNZIONE CALCOLO FASE NUTRIZIONALE (DA VERSIONE 17)
 function calculatePhase() { function calculatePhase() {
-    const birthWeight = parseInt(document.getElementById('birthWeight').value); +    const medicalRecord = document.getElementById('medicalRecord').value; 
-    const currentWeight = parseInt(document.getElementById('currentWeight').value);+    const phaseBirthWeight = parseInt(document.getElementById('birthWeight').value); 
 +    const phaseCurrentWeight = parseInt(document.getElementById('currentWeight').value);
     const daysOfLife = parseInt(document.getElementById('daysOfLife').value);     const daysOfLife = parseInt(document.getElementById('daysOfLife').value);
     const bun = document.getElementById('bun').value;     const bun = document.getElementById('bun').value;
Linea 1196: Linea 1492:
     const sodium = document.getElementById('sodium').value;     const sodium = document.getElementById('sodium').value;
     const ph = document.getElementById('ph').value;     const ph = document.getElementById('ph').value;
 +    const baseExcess = document.getElementById('baseExcess').value;
     const diuresis = document.getElementById('diuresis').value;     const diuresis = document.getElementById('diuresis').value;
 +    const prescriptionDate = document.getElementById('prescriptionDate').value;
 +    const prescribingDoctorValue = document.getElementById('prescribingDoctor').value;
 +    
 +    // Trova il nome completo del medico
 +    const doctorFullName = prescribingDoctorValue && doctorsData[prescribingDoctorValue] ? 
 +                          doctorsData[prescribingDoctorValue].fullName : '';
          
     patientData = {     patientData = {
-        birthWeight: birthWeight,  +        medicalRecordmedicalRecord, 
-        currentWeight: currentWeight+        birthWeight: phaseBirthWeight,  
 +        currentWeight: phaseCurrentWeight
         daysOfLife: daysOfLife,         daysOfLife: daysOfLife,
         bun: bun,         bun: bun,
Linea 1206: Linea 1510:
         sodium: sodium,         sodium: sodium,
         ph: ph,         ph: ph,
-        diuresis: diuresis+        baseExcess: baseExcess, 
 +        diuresis: diuresis
 +        prescriptionDate: prescriptionDate, 
 +        prescribingDoctor: prescribingDoctorValue, 
 +        prescribingDoctorName: doctorFullName
     };     };
          
Linea 1258: Linea 1566:
         } else if (phValue > 7.45) {         } else if (phValue > 7.45) {
             otherWarnings.push('⚠️ Alcalosi: ridurre bicarbonato, aumentare cloruri');             otherWarnings.push('⚠️ Alcalosi: ridurre bicarbonato, aumentare cloruri');
 +        }
 +    }
 +    
 +    if (baseExcess && baseExcess !== '') {
 +        const beValue = parseFloat(baseExcess);
 +        if (beValue < -4) {
 +            otherWarnings.push('⚠️ BE < -4: Acidosi metabolica - Considera Sodio Acetato in NPT');
 +        } else if (beValue > 2) {
 +            otherWarnings.push('⚠️ BE > +2: Alcalosi metabolica - Ridurre bicarbonato');
 +        }
 +    }
 +    
 +    // Raccomandazione combinata pH + BE per Sodio Acetato
 +    if (ph && baseExcess) {
 +        const phValue = parseFloat(ph);
 +        const beValue = parseFloat(baseExcess);
 +        if (phValue < 7.25 || beValue < -4) {
 +            otherWarnings.push('🧪 RACCOMANDAZIONE: Usa Sodio Acetato invece di NaCl in NPT');
         }         }
     }     }
Linea 1274: Linea 1600:
     phaseInfoHtml += '<div class="form-col">';     phaseInfoHtml += '<div class="form-col">';
     phaseInfoHtml += '<h4>Dati Paziente</h4>';     phaseInfoHtml += '<h4>Dati Paziente</h4>';
-    phaseInfoHtml += '<p><strong>Peso:</strong> ' + currentWeight + 'g (nascita: ' + birthWeight + 'g)</p>';+    if (medicalRecord) { 
 +        phaseInfoHtml += '<p><strong>Cartella:</strong> ' + medicalRecord + '</p>'; 
 +    } 
 +    phaseInfoHtml += '<p><strong>Peso:</strong> ' + phaseCurrentWeight + 'g (nascita: ' + phaseBirthWeight + 'g)</p>';
     phaseInfoHtml += '<p><strong>Giorni di vita:</strong> ' + daysOfLife + '</p>';     phaseInfoHtml += '<p><strong>Giorni di vita:</strong> ' + daysOfLife + '</p>';
     phaseInfoHtml += '<p><strong>Fase nutrizionale:</strong> ' + phase + '</p>';     phaseInfoHtml += '<p><strong>Fase nutrizionale:</strong> ' + phase + '</p>';
Linea 1294: Linea 1623:
         const phStatus = parseFloat(patientData.ph) >= 7.35 && parseFloat(patientData.ph) <= 7.45 ? 'Normale' : 'Fuori range';         const phStatus = parseFloat(patientData.ph) >= 7.35 && parseFloat(patientData.ph) <= 7.45 ? 'Normale' : 'Fuori range';
         phaseInfoHtml += '<p><strong>pH:</strong> ' + patientData.ph + ' (' + phStatus + ')</p>';         phaseInfoHtml += '<p><strong>pH:</strong> ' + patientData.ph + ' (' + phStatus + ')</p>';
 +    }
 +    if (patientData.baseExcess) {
 +        const beStatus = parseFloat(patientData.baseExcess) >= -4 && parseFloat(patientData.baseExcess) <= 2 ? 'Normale' : 'Fuori range';
 +        phaseInfoHtml += '<p><strong>BE:</strong> ' + patientData.baseExcess + ' mEq/L (' + beStatus + ')</p>';
     }     }
     if (patientData.diuresis) {     if (patientData.diuresis) {
Linea 1317: Linea 1650:
     document.getElementById('calculatePhaseBtn').className = 'button config-update-completed';     document.getElementById('calculatePhaseBtn').className = 'button config-update-completed';
     document.getElementById('calculatePhaseBtn').innerHTML = 'FASE CALCOLATA ✓';     document.getElementById('calculatePhaseBtn').innerHTML = 'FASE CALCOLATA ✓';
-+     
- +    // Aggiorna il suggerimento sodio se il TAB 3 è già stato visitato 
-// FUNZIONE AGGIORNAMENTO DISPLAY CONCENTRAZIONE +    updateSodiumRecommendation(); 
-function updateConcentrationDisplay() { +     
-    const concentration = document.getElementById('fortifierConcentration').value+    // RESET anche il pulsante NPT 
-    document.getElementById('concentrationValue').textContent = concentration + '%';+    resetParenteralButton();
 } }
  
Linea 1347: Linea 1680:
 } }
  
-// FUNZIONE CALCOLO NUTRIZIONE ENTERALE AGGIORNATA CON LIQUIDI+// FUNZIONE AGGIORNAMENTO DISPLAY CONCENTRAZIONE 
 +function updateConcentrationDisplay() { 
 +    const concentration = document.getElementById('fortifierConcentration').value; 
 +    document.getElementById('concentrationValue').textContent = concentration + '%'; 
 +
 + 
 +// FUNZIONE CALCOLO NUTRIZIONE ENTERALE (DA VERSIONE 17)
 function calculateEnteral() { function calculateEnteral() {
-    if (!patientData.birthWeight) { +    // Controlla se i dati di base sono presenti 
-        alert('Prima inserire i dati del paziente nel TAB 1');+    const enteralCurrentWeight = parseInt(document.getElementById('currentWeight').value); 
 +    const enteralBirthWeight = parseInt(document.getElementById('birthWeight').value); 
 +     
 +    if (!enteralCurrentWeight || !enteralBirthWeight) { 
 +        alert('Prima inserire peso attuale e peso alla nascita nel TAB 1');
         return;         return;
 +    }
 +    
 +    // Aggiorna patientData se non è stato ancora fatto
 +    if (!patientData.currentWeight) {
 +        patientData.currentWeight = enteralCurrentWeight;
 +        patientData.birthWeight = enteralBirthWeight;
     }     }
          
Linea 1357: Linea 1706:
     const dailyVolume = parseFloat(document.getElementById('dailyVolume').value);     const dailyVolume = parseFloat(document.getElementById('dailyVolume').value);
     const additionalFluids = parseFloat(document.getElementById('additionalFluids').value) || 0;     const additionalFluids = parseFloat(document.getElementById('additionalFluids').value) || 0;
-    const fortifierType = document.getElementById('fortifierType').value; 
-    const fortifierConcentration = parseFloat(document.getElementById('fortifierConcentration').value) || 0; 
          
     const currentWeight = patientData.currentWeight;     const currentWeight = patientData.currentWeight;
Linea 1386: Linea 1733:
         const formula = formulaData[formulaType];         const formula = formulaData[formulaType];
         const volumePerKg = (dailyVolume / currentWeight) * 1000;         const volumePerKg = (dailyVolume / currentWeight) * 1000;
-         
-        // Calcoli base della formula 
-        let totalProtein = formula.protein; 
-        let totalCarbs = formula.carbs; 
-        let totalLipids = formula.lipids; 
-        let totalSodium = formula.sodium; 
-        let totalPotassium = formula.potassium; 
-        let totalCalcium = formula.calcium; 
-        let totalPhosphorus = formula.phosphorus; 
-        let totalMagnesium = formula.magnesium; 
-        let totalEnergy = formula.energy; 
-         
-        let fortifierInfo = ''; 
-         
-        // Aggiunta fortificante se selezionato 
-        if (formulaType === 'maternal' && fortifierType !== 'none' && fortifierConcentration > 0) { 
-            const fortifier = fortifierData[fortifierType]; 
-            const fortifierGramsPer100ml = fortifierConcentration; 
-             
-            const fortifierProteinPer100ml = (fortifier.protein * fortifierGramsPer100ml) / 100; 
-            const fortifierCarbsPer100ml = (fortifier.carbs * fortifierGramsPer100ml) / 100; 
-            const fortifierLipidsPer100ml = (fortifier.lipids * fortifierGramsPer100ml) / 100; 
-            const fortifierSodiumPer100ml = (fortifier.sodium * fortifierGramsPer100ml) / 100; 
-            const fortifierPotassiumPer100ml = (fortifier.potassium * fortifierGramsPer100ml) / 100; 
-            const fortifierCalciumPer100ml = (fortifier.calcium * fortifierGramsPer100ml) / 100; 
-            const fortifierPhosphorusPer100ml = (fortifier.phosphorus * fortifierGramsPer100ml) / 100; 
-            const fortifierMagnesiumPer100ml = (fortifier.magnesium * fortifierGramsPer100ml) / 100; 
-            const fortifierEnergyPer100ml = (fortifier.energy * fortifierGramsPer100ml) / 100; 
-             
-            totalProtein += fortifierProteinPer100ml; 
-            totalCarbs += fortifierCarbsPer100ml; 
-            totalLipids += fortifierLipidsPer100ml; 
-            totalSodium += fortifierSodiumPer100ml; 
-            totalPotassium += fortifierPotassiumPer100ml; 
-            totalCalcium += fortifierCalciumPer100ml; 
-            totalPhosphorus += fortifierPhosphorusPer100ml; 
-            totalMagnesium += fortifierMagnesiumPer100ml; 
-            totalEnergy += fortifierEnergyPer100ml; 
-             
-            fortifierInfo = '<br><strong>Fortificante:</strong> ' + fortifier.name + ' al ' + fortifierConcentration + '% (' + fortifierGramsPer100ml + 'g/100ml)'; 
-        } 
                  
         // Calcoli finali per kg di peso         // Calcoli finali per kg di peso
Linea 1433: Linea 1739:
             additionalFluids: additionalFluids,             additionalFluids: additionalFluids,
             totalFluids: totalFluids,             totalFluids: totalFluids,
-            protein: (dailyVolume * totalProtein / 100) / (currentWeight / 1000), +            protein: (dailyVolume * formula.protein / 100) / (currentWeight / 1000), 
-            carbs: (dailyVolume * totalCarbs / 100) / (currentWeight / 1000), +            carbs: (dailyVolume * formula.carbs / 100) / (currentWeight / 1000), 
-            lipids: (dailyVolume * totalLipids / 100) / (currentWeight / 1000), +            lipids: (dailyVolume * formula.lipids / 100) / (currentWeight / 1000), 
-            energy: (dailyVolume * totalEnergy / 100) / (currentWeight / 1000), +            energy: (dailyVolume * formula.energy / 100) / (currentWeight / 1000), 
-            sodium: (dailyVolume * totalSodium / 100) / (currentWeight / 1000), +            sodium: (dailyVolume * formula.sodium / 100) / (currentWeight / 1000), 
-            potassium: (dailyVolume * totalPotassium / 100) / (currentWeight / 1000), +            potassium: (dailyVolume * formula.potassium / 100) / (currentWeight / 1000), 
-            calcium: (dailyVolume * totalCalcium / 100) / (currentWeight / 1000), +            calcium: (dailyVolume * formula.calcium / 100) / (currentWeight / 1000), 
-            phosphorus: (dailyVolume * totalPhosphorus / 100) / (currentWeight / 1000), +            phosphorus: (dailyVolume * formula.phosphorus / 100) / (currentWeight / 1000), 
-            magnesium: (dailyVolume * totalMagnesium / 100) / (currentWeight / 1000)+            magnesium: (dailyVolume * formula.magnesium / 100) / (currentWeight / 1000)
         };         };
                  
         let tableHtml = '<div class="info">';         let tableHtml = '<div class="info">';
-        tableHtml += '<strong>Formula:</strong> ' + formula.name + fortifierInfo + '<br>';+        tableHtml += '<strong>Formula:</strong> ' + formula.name + '<br>';
         tableHtml += '<strong>Volume latte:</strong> ' + dailyVolume + ' ml (' + volumePerKg.toFixed(1) + ' ml/kg/die)<br>';         tableHtml += '<strong>Volume latte:</strong> ' + dailyVolume + ' ml (' + volumePerKg.toFixed(1) + ' ml/kg/die)<br>';
         if (additionalFluids > 0) {         if (additionalFluids > 0) {
Linea 1457: Linea 1763:
         tableHtml += '<table class="results-table">';         tableHtml += '<table class="results-table">';
         tableHtml += '<tr><th>Nutriente</th><th>Per 100ml</th><th>Per kg/die</th><th>Unita</th></tr>';         tableHtml += '<tr><th>Nutriente</th><th>Per 100ml</th><th>Per kg/die</th><th>Unita</th></tr>';
-        tableHtml += '<tr><td>Proteine</td><td>'totalProtein.toFixed(1) + '</td><td>' + enteralData.protein.toFixed(1) + '</td><td>g</td></tr>'; +        tableHtml += '<tr><td>Proteine</td><td>'formula.protein.toFixed(1) + '</td><td>' + enteralData.protein.toFixed(1) + '</td><td>g</td></tr>'; 
-        tableHtml += '<tr><td>Carboidrati</td><td>'totalCarbs.toFixed(1) + '</td><td>' + enteralData.carbs.toFixed(1) + '</td><td>g</td></tr>'; +        tableHtml += '<tr><td>Carboidrati</td><td>'formula.carbs.toFixed(1) + '</td><td>' + enteralData.carbs.toFixed(1) + '</td><td>g</td></tr>'; 
-        tableHtml += '<tr><td>Lipidi</td><td>'totalLipids.toFixed(1) + '</td><td>' + enteralData.lipids.toFixed(1) + '</td><td>g</td></tr>'; +        tableHtml += '<tr><td>Lipidi</td><td>'formula.lipids.toFixed(1) + '</td><td>' + enteralData.lipids.toFixed(1) + '</td><td>g</td></tr>'; 
-        tableHtml += '<tr class="energy-highlight"><td><strong>Energia</strong></td><td><strong>'totalEnergy.toFixed(0) + '</strong></td><td><strong>' + enteralData.energy.toFixed(0) + '</strong></td><td><strong>kcal</strong></td></tr>';+        tableHtml += '<tr class="energy-highlight"><td><strong>Energia</strong></td><td><strong>'formula.energy.toFixed(0) + '</strong></td><td><strong>' + enteralData.energy.toFixed(0) + '</strong></td><td><strong>kcal</strong></td></tr>';
         tableHtml += '</table>';         tableHtml += '</table>';
-         
-        if (fortifierType !== 'none' && fortifierConcentration > 0) { 
-            tableHtml += '<div class="info">'; 
-            tableHtml += '<strong>Dettaglio Fortificazione:</strong><br>'; 
-            tableHtml += '• <strong>Fortificante:</strong> ' + fortifierData[fortifierType].name + '<br>'; 
-            tableHtml += '• <strong>Concentrazione:</strong> ' + fortifierConcentration + '% (' + fortifierConcentration + 'g/100ml)<br>'; 
-            tableHtml += '• <strong>Dose totale:</strong> ' + (dailyVolume * fortifierConcentration / 100).toFixed(1) + 'g/die<br>'; 
-            tableHtml += '• <strong>Range raccomandato:</strong> ' + (fortifierData[fortifierType].dose || '2-6g/100ml'); 
-            tableHtml += '</div>'; 
-        } 
                  
         document.getElementById('enteralTable').innerHTML = tableHtml;         document.getElementById('enteralTable').innerHTML = tableHtml;
Linea 1484: Linea 1780:
         enteralBtn.innerHTML = 'Apporti Enterali Calcolati ✓';         enteralBtn.innerHTML = 'Apporti Enterali Calcolati ✓';
     }     }
 +    
 +    // RESET del pulsante Fabbisogni quando si modificano gli apporti enterali
 +    resetNutritionButton();
 } }
  
-// FUNZIONE CARICAMENTO VALORI STANDARD+// FUNZIONE CARICAMENTO VALORI STANDARD (DA VERSIONE 17)
 function loadNutritionDefaults() { function loadNutritionDefaults() {
-    if (!patientData.birthWeight) { +    // Controlla se i dati di base sono presenti 
-        alert('Prima inserire i dati del paziente nel TAB 1');+    const defaultsCurrentWeight = parseInt(document.getElementById('currentWeight').value); 
 +    const defaultsBirthWeight = parseInt(document.getElementById('birthWeight').value); 
 +    const defaultsDaysOfLife = parseInt(document.getElementById('daysOfLife').value); 
 +     
 +    if (!defaultsCurrentWeight || !defaultsBirthWeight || !defaultsDaysOfLife) { 
 +        alert('Prima inserire peso attuale, peso alla nascita e giorni di vita nel TAB 1');
         return;         return;
 +    }
 +    
 +    // Aggiorna patientData se non è stato ancora fatto
 +    if (!patientData.currentWeight) {
 +        patientData.currentWeight = defaultsCurrentWeight;
 +        patientData.birthWeight = defaultsBirthWeight;
 +        patientData.daysOfLife = defaultsDaysOfLife;
     }     }
          
     const targetDay = parseInt(document.getElementById('targetDay').value);     const targetDay = parseInt(document.getElementById('targetDay').value);
-    const birthWeight = patientData.birthWeight;+    const patientBirthWeightForCalculation = patientData.birthWeight;
          
     const weightCategorySelect = document.getElementById('weightCategory');     const weightCategorySelect = document.getElementById('weightCategory');
-    let selectedCategory = weightCategorySelect.value || (birthWeight <= 1500 ? '≤1500g' : '>1500g');+    let selectedCategory = weightCategorySelect.value || (patientBirthWeightForCalculation <= 1500 ? '≤1500g' : '>1500g');
     weightCategorySelect.value = selectedCategory;     weightCategorySelect.value = selectedCategory;
          
Linea 1523: Linea 1834:
     document.getElementById('reqCarbs').value = plan.carbs;     document.getElementById('reqCarbs').value = plan.carbs;
     document.getElementById('reqLipids').value = plan.lipids;     document.getElementById('reqLipids').value = plan.lipids;
-    document.getElementById('reqCalcium').value = targetDay > 3 ? 160 : 0; +     
-    document.getElementById('reqPhosphorus').value = targetDay > 3 ? 84 : 0; +    // Usa configurazione clinica per elettroliti 
-    document.getElementById('reqMagnesium').value = targetDay > 3 ? : 0;+    document.getElementById('reqCalcium').value = targetDay > 3 ? clinicalConfig.calciumReq : 0; 
 +    document.getElementById('reqPhosphorus').value = targetDay > 3 ? clinicalConfig.phosphorusReq : 0; 
 +    document.getElementById('reqMagnesium').value = targetDay > 3 ? clinicalConfig.magnesiumReq : 0;
     document.getElementById('reqSodium').value = targetDay > 2 ? 2.0 : 0;     document.getElementById('reqSodium').value = targetDay > 2 ? 2.0 : 0;
     document.getElementById('reqPotassium').value = targetDay > 2 ? 1.5 : 0;     document.getElementById('reqPotassium').value = targetDay > 2 ? 1.5 : 0;
          
-    updateVitaminsAndTrace(); +    // Gestione automatica tipo di sodio basata sui parametri clinici 
-     +    const sodiumSelect = document.getElementById('sodiumType'); 
-    document.getElementById('loadDefaultsBtn').className = 'button load-defaults-completed'+    if (patientData.ph || patientData.baseExcess
-    document.getElementById('loadDefaultsBtn').innerHTML 'Valori Caricati'+        const ph = patientData.ph ? parseFloat(patientData.ph) : null; 
-+        const be patientData.baseExcess ? parseFloat(patientData.baseExcess) : null
- +         
-// FUNZIONE AGGIORNAMENTO VITAMINE +        // Auto-seleziona Sodio Acetato se acidosi 
-function updateVitaminsAndTrace() { +        if ((ph && ph < 7.30) || (be && be < -4)) { 
-    if (!patientData.currentWeight || !patientData.daysOfLife) { +            sodiumSelect.value = 'sodium_acetate'; 
-        return { vitalipid: 0, soluvit: 0, peditrace: 0, enteralVolumePerKg:};+        } else { 
 +            sodiumSelect.value = 'nacl'; 
 +        }
     }     }
          
-    const targetDay = parseInt(document.getElementById('targetDay').value); +    // Aggiorna il suggerimento sodio 
-    const currentWeight = patientData.currentWeight; +    updateSodiumRecommendation();
-    const enteralVolumePerKg = enteralData ? (enteralData.totalFluids / currentWeight * 1000: 0;+
          
-    let vitalipid = 0; +    // Gestione vitamine/oligoelementi con controllo enterale 
-    let soluvit 0+    const patientCurrentWeight patientData.currentWeight
-    let peditrace = 0;+    const enteralVolumePerKg enteralData ? (enteralData.totalFluids / patientCurrentWeight * 1000) : 0;
          
-    if (targetDay >= 4) { +    if (targetDay >= 3 && enteralVolumePerKg < 100) { 
-        if (enteralVolumePerKg < 100) { +        document.getElementById('reqVitalipid').value 4.0; 
-            vitalipid 5.0; +        document.getElementById('reqSoluvit').value 1.0; 
-            soluvit 2.0; +        document.getElementById('reqPeditrace').value = 1.0; 
-            peditrace = 1.0; +    else { 
-        }+        // Mantieni i valori a zero se prima del 3° giorno o se enterale ≥100 ml/kg/die 
 +        document.getElementById('reqVitalipid').value = 0; 
 +        document.getElementById('reqSoluvit').value = 0; 
 +        document.getElementById('reqPeditrace').value = 0;
     }     }
          
-    // Aggiorna solo se i campi sono a zero (non modificati manualmente+    document.getElementById('reqCarnitine').value = 0; // La carnitina verrà gestita separatamente 
-    if (document.getElementById('reqVitalipid').value == 0) { +     
-        document.getElementById('reqVitalipid').value vitalipid+    document.getElementById('loadDefaultsBtn').className 'button load-defaults-completed'; 
-    } +    document.getElementById('loadDefaultsBtn').innerHTML 'Valori Caricati ✓'
-    if (document.getElementById('reqSoluvit').value == 0{ +     
-        document.getElementById('reqSoluvit').value = soluvit+    // RESET del pulsante Fabbisogni quando si modificano i valori standard 
-    } +    resetNutritionButton(); 
-    if (document.getElementById('reqPeditrace').value == 0) { +
-        document.getElementById('reqPeditrace').value = peditrace;+ 
 +// FUNZIONE AGGIORNAMENTO UNITÀ CARBOIDRATI 
 +function updateCarbUnit() { 
 +    const unit = document.getElementById('carbUnit').value
 +    const carbLabel document.getElementById('carbLabel'); 
 +    const carbInput = document.getElementById('reqCarbs'); 
 +     
 +    if (unit === 'mg') { 
 +        carbLabel.textContent = 'Glucidi (mg/kg/min):'
 +        carbInput.setAttribute('max', '15')
 +        carbInput.setAttribute('step', '0.1')
 +    } else 
 +        carbLabel.textContent = 'Glucidi (g/kg/die):'
 +        carbInput.setAttribute('max', '20')
 +        carbInput.setAttribute('step', '0.1');
     }     }
          
-    return {  +    // Reset fabbisogni quando si cambia unità 
-        vitalipid: parseFloat(document.getElementById('reqVitalipid').value),  +    resetNutritionButton();
-        soluvit: parseFloat(document.getElementById('reqSoluvit').value),  +
-        peditrace: parseFloat(document.getElementById('reqPeditrace').value),  +
-        enteralVolumePerKg: enteralVolumePerKg  +
-    };+
 } }
  
 // FUNZIONE AGGIORNAMENTO CATEGORIA PESO // FUNZIONE AGGIORNAMENTO CATEGORIA PESO
 function updateWeightCategory() { function updateWeightCategory() {
-    document.getElementById('loadDefaultsBtn').className = 'button load-defaults-pending'; +    // Reset fabbisogni quando si cambia categoria peso 
-    document.getElementById('loadDefaultsBtn').innerHTML = 'Carica Valori Standard';+    resetNutritionButton();
 } }
  
-// FUNZIONE CALCOLO FABBISOGNI NUTRIZIONALI+// FUNZIONE AGGIORNAMENTO TIPO SODIO 
 +function updateSodiumChoice() { 
 +    // Resetta i fabbisogni quando si cambia il tipo di sodio 
 +    resetNutritionButton(); 
 +
 + 
 +// FUNZIONE AGGIORNAMENTO SUGGERIMENTO SODIO 
 +function updateSodiumRecommendation() { 
 +    const sodiumSelect = document.getElementById('sodiumType'); 
 +    const recommendationDiv = document.getElementById('sodiumRecommendation'); 
 +     
 +    if (!patientData.ph && !patientData.baseExcess) { 
 +        // Nessun dato clinico disponibile 
 +        recommendationDiv.classList.add('hidden'); 
 +        return; 
 +    } 
 +     
 +    const ph = patientData.ph ? parseFloat(patientData.ph) : null; 
 +    const be = patientData.baseExcess ? parseFloat(patientData.baseExcess) : null; 
 +     
 +    // Logica di raccomandazione 
 +    let needsAcetate = false; 
 +    let reason = ''; 
 +     
 +    if (ph && ph < 7.30) { 
 +        needsAcetate = true; 
 +        reason = 'pH < 7.30 (acidosi)'; 
 +    } else if (be && be < -4) { 
 +        needsAcetate = true; 
 +        reason = 'BE < -4 mEq/L (acidosi metabolica)'; 
 +    } else if (ph && be && (ph < 7.30 || be < -4)) { 
 +        needsAcetate = true; 
 +        reason = 'pH < 7.30 o BE < -4 (acidosi)'; 
 +    } 
 +     
 +    if (needsAcetate) { 
 +        // Suggerisci Sodio Acetato 
 +        if (sodiumSelect.value === 'nacl') { 
 +            // L'utente ha selezionato NaCl ma dovrebbe usare Acetato 
 +            recommendationDiv.innerHTML = '<div class="warning" style="padding: 8px; font-size: 12px;">'
 +                '<strong>⚠️ RACCOMANDAZIONE CLINICA:</strong><br>'
 +                'In base ai parametri clinici (' + reason + '), si raccomanda <strong>Sodio Acetato</strong> invece di Sodio Cloruro per effetto alcalinizzante.'
 +                '</div>'; 
 +            recommendationDiv.classList.remove('hidden'); 
 +        } else { 
 +            // L'utente ha già selezionato Acetato - mostra conferma 
 +            recommendationDiv.innerHTML = '<div class="info" style="padding: 8px; font-size: 12px;">'
 +                '<strong>✅ SCELTA APPROPRIATA:</strong><br>'
 +                'Sodio Acetato è indicato per i parametri clinici attuali (' + reason + ').'
 +                '</div>'; 
 +            recommendationDiv.classList.remove('hidden'); 
 +        } 
 +    } else { 
 +        // Parametri normali 
 +        if (sodiumSelect.value === 'sodium_acetate') { 
 +            // L'utente ha selezionato Acetato ma i parametri sono normali 
 +            recommendationDiv.innerHTML = '<div class="info" style="padding: 8px; font-size: 12px;">'
 +                '<strong>ℹ️ NOTA:</strong><br>'
 +                'I parametri clinici sono nella norma. Sodio Cloruro potrebbe essere sufficiente, ma Sodio Acetato è comunque sicuro.'
 +                '</div>'; 
 +            recommendationDiv.classList.remove('hidden'); 
 +        } else { 
 +            // Tutto normale 
 +            recommendationDiv.classList.add('hidden'); 
 +        } 
 +    } 
 +
 + 
 +// FUNZIONE CALCOLO FABBISOGNI NUTRIZIONALI (DA VERSIONE 17)
 function calculateNutrition() { function calculateNutrition() {
-    if (!patientData.birthWeight) { +    // Controlla se i dati di base sono presenti 
-        alert('Prima inserire i dati del paziente nel TAB 1');+    const nutritionCurrentWeight = parseInt(document.getElementById('currentWeight').value); 
 +    const nutritionBirthWeight = parseInt(document.getElementById('birthWeight').value); 
 +     
 +    if (!nutritionCurrentWeight || !nutritionBirthWeight) { 
 +        alert('Prima inserire peso attuale e peso alla nascita nel TAB 1');
         return;         return;
 +    }
 +    
 +    // Aggiorna patientData se non è stato ancora fatto
 +    if (!patientData.currentWeight) {
 +        patientData.currentWeight = nutritionCurrentWeight;
 +        patientData.birthWeight = nutritionBirthWeight;
     }     }
          
Linea 1593: Linea 1998:
         protein: parseFloat(document.getElementById('reqProtein').value),         protein: parseFloat(document.getElementById('reqProtein').value),
         carbs: parseFloat(document.getElementById('reqCarbs').value),         carbs: parseFloat(document.getElementById('reqCarbs').value),
 +        carbUnit: document.getElementById('carbUnit').value,
         lipids: parseFloat(document.getElementById('reqLipids').value),         lipids: parseFloat(document.getElementById('reqLipids').value),
         calcium: parseFloat(document.getElementById('reqCalcium').value),         calcium: parseFloat(document.getElementById('reqCalcium').value),
Linea 1599: Linea 2005:
         sodium: parseFloat(document.getElementById('reqSodium').value),         sodium: parseFloat(document.getElementById('reqSodium').value),
         potassium: parseFloat(document.getElementById('reqPotassium').value),         potassium: parseFloat(document.getElementById('reqPotassium').value),
-        vitalipid: parseFloat(document.getElementById('reqVitalipid').value), +        vitalipid: parseFloat(document.getElementById('reqVitalipid').value) || 0
-        soluvit: parseFloat(document.getElementById('reqSoluvit').value), +        soluvit: parseFloat(document.getElementById('reqSoluvit').value) || 0
-        peditrace: parseFloat(document.getElementById('reqPeditrace').value)+        peditrace: parseFloat(document.getElementById('reqPeditrace').value) || 0, 
 +        carnitine: parseFloat(document.getElementById('reqCarnitine').value) || 0
     };     };
          
-    const vitaminsInfo = updateVitaminsAndTrace(); +    // Converti carboidrati sempre in g/kg/die per i calcoli 
-    requirements.vitalipid vitaminsInfo.vitalipid+    const carbsGPerKgDay = requirements.carbUnit === 'mg' ?  
-    requirements.soluvit vitaminsInfo.soluvit+        (requirements.carbs * 1440 / 1000) : requirements.carbs
-    requirements.peditrace vitaminsInfo.peditrace;+     
 +    const patientCurrentWeight patientData.currentWeight
 +    const enteralVolumePerKg enteralData ? (enteralData.totalFluids / patientCurrentWeight * 1000) : 0;
          
     const enteralProtein = enteralData ? enteralData.protein : 0;     const enteralProtein = enteralData ? enteralData.protein : 0;
Linea 1615: Linea 2024:
          
     const residualProtein = Math.max(0, requirements.protein - enteralProtein);     const residualProtein = Math.max(0, requirements.protein - enteralProtein);
-    const residualCarbs = Math.max(0, requirements.carbs - enteralCarbs);+    const residualCarbs = Math.max(0, carbsGPerKgDay - enteralCarbs);
     const residualLipids = Math.max(0, requirements.lipids - enteralLipids);     const residualLipids = Math.max(0, requirements.lipids - enteralLipids);
-    const totalEnergyRequirement = (requirements.protein * 4) + (requirements.carbs * 4) + (requirements.lipids * 9);+    const totalEnergyRequirement = (requirements.protein * 4) + (carbsGPerKgDay * 4) + (requirements.lipids * 9);
     const residualEnergy = Math.max(0, totalEnergyRequirement - enteralEnergy);     const residualEnergy = Math.max(0, totalEnergyRequirement - enteralEnergy);
          
Linea 1633: Linea 2042:
     const residualSodium = Math.max(0, requirements.sodium - enteralSodium);     const residualSodium = Math.max(0, requirements.sodium - enteralSodium);
     const residualPotassium = Math.max(0, requirements.potassium - enteralPotassium);     const residualPotassium = Math.max(0, requirements.potassium - enteralPotassium);
-     
-    let bunNote = ''; 
-    if (patientData.bun && patientData.bun !== '') { 
-        const bunValue = parseFloat(patientData.bun); 
-        if (bunValue < 9) { 
-            bunNote = '<div class="info"><strong>BUN < 9 mg/dL:</strong> Proteine aumentate automaticamente per ottimizzazione nutrizionale</div>'; 
-        } else if (bunValue > 14) { 
-            bunNote = '<div class="warning"><strong>BUN > 14 mg/dL:</strong> Proteine ridotte automaticamente per protezione renale</div>'; 
-        } 
-    } 
-     
-    let vitaminsNote = ''; 
-    if (vitaminsInfo.enteralVolumePerKg >= 100) { 
-        vitaminsNote = '<div class="info"><strong>Vitamine/Oligoelementi:</strong> Sospesi automaticamente (enterale ≥100 ml/kg/die)</div>'; 
-    } else if (patientData.daysOfLife >= 4 && requirements.vitalipid > 0) { 
-        vitaminsNote = '<div class="info"><strong>Vitamine/Oligoelementi:</strong> Vitalipid 5ml + Soluvit 2ml (dal 4° giorno)</div>'; 
-    } else if (patientData.daysOfLife < 4) { 
-        vitaminsNote = '<div class="info"><strong>Vitamine/Oligoelementi:</strong> Non necessari prima del 4° giorno di vita</div>'; 
-    } 
          
     window.residualNeeds = {     window.residualNeeds = {
Linea 1666: Linea 2056:
         soluvit: requirements.soluvit,         soluvit: requirements.soluvit,
         peditrace: requirements.peditrace,         peditrace: requirements.peditrace,
 +        carnitine: requirements.carnitine,
         energy: residualEnergy,         energy: residualEnergy,
         totalEnergyRequirement: totalEnergyRequirement         totalEnergyRequirement: totalEnergyRequirement
     };     };
 +    
 +    // Calcola mg/kg/min per la tabella
 +    const carbsMgPerKgMin = (carbsGPerKgDay * 1000) / 1440;
 +    const enteralCarbsMgPerKgMin = (enteralCarbs * 1000) / 1440;
 +    const residualCarbsMgPerKgMin = (residualCarbs * 1000) / 1440;
          
     let tableHtml = '<table class="nutrition-table">';     let tableHtml = '<table class="nutrition-table">';
-    tableHtml += '<tr><th>Componente</th><th>Fabbisogno</th><th>Da Enterale</th><th>Da NPT</th><th>Unita</th></tr>';+    tableHtml += '<tr><th>Componente</th><th>Fabbisogno</th><th>Da Enterale</th><th>Da NPT</th><th>Unità</th></tr>';
     tableHtml += '<tr><td><strong>Liquidi</strong></td><td><strong>' + requirements.liquids + '</strong></td><td><strong>' + (enteralData ? (enteralData.totalFluids/patientData.currentWeight*1000).toFixed(1) : '0') + '</strong></td><td class="highlight"><strong>' + Math.max(0, requirements.liquids - (enteralData ? enteralData.totalFluids/patientData.currentWeight*1000 : 0)).toFixed(1) + '</strong></td><td><strong>ml/kg/die</strong></td></tr>';     tableHtml += '<tr><td><strong>Liquidi</strong></td><td><strong>' + requirements.liquids + '</strong></td><td><strong>' + (enteralData ? (enteralData.totalFluids/patientData.currentWeight*1000).toFixed(1) : '0') + '</strong></td><td class="highlight"><strong>' + Math.max(0, requirements.liquids - (enteralData ? enteralData.totalFluids/patientData.currentWeight*1000 : 0)).toFixed(1) + '</strong></td><td><strong>ml/kg/die</strong></td></tr>';
     tableHtml += '<tr><td>Proteine</td><td>' + requirements.protein + '</td><td>' + enteralProtein.toFixed(1) + '</td><td class="highlight">' + residualProtein.toFixed(1) + '</td><td>g/kg/die</td></tr>';     tableHtml += '<tr><td>Proteine</td><td>' + requirements.protein + '</td><td>' + enteralProtein.toFixed(1) + '</td><td class="highlight">' + residualProtein.toFixed(1) + '</td><td>g/kg/die</td></tr>';
-    tableHtml += '<tr><td>Carboidrati</td><td>'requirements.carbs + '</td><td>' + enteralCarbs.toFixed(1) + '</td><td class="highlight">' + residualCarbs.toFixed(1) + '</td><td>g/kg/die</td></tr>';+    tableHtml += '<tr><td>Glucidi (g/kg/die)</td><td>'carbsGPerKgDay.toFixed(1) + '</td><td>' + enteralCarbs.toFixed(1) + '</td><td class="highlight">' + residualCarbs.toFixed(1) + '</td><td>g/kg/die</td></tr>'; 
 +    tableHtml += '<tr><td>Glucidi (mg/kg/min)</td><td>' + carbsMgPerKgMin.toFixed(1) + '</td><td>' + enteralCarbsMgPerKgMin.toFixed(1) + '</td><td class="highlight">' + residualCarbsMgPerKgMin.toFixed(1) + '</td><td>mg/kg/min</td></tr>';
     tableHtml += '<tr><td>Lipidi</td><td>' + requirements.lipids + '</td><td>' + enteralLipids.toFixed(1) + '</td><td class="highlight">' + residualLipids.toFixed(1) + '</td><td>g/kg/die</td></tr>';     tableHtml += '<tr><td>Lipidi</td><td>' + requirements.lipids + '</td><td>' + enteralLipids.toFixed(1) + '</td><td class="highlight">' + residualLipids.toFixed(1) + '</td><td>g/kg/die</td></tr>';
-     +    tableHtml += '<tr><td>Calcio elementare</td><td>' + requirements.calcium + '</td><td>' + enteralCalcium.toFixed(1) + '</td><td class="highlight">' + residualCalcium.toFixed(1) + '</td><td>mg/kg/die</td></tr>';
-    tableHtml += '<tr><td>Calcio</td><td>' + requirements.calcium + '</td><td>' + enteralCalcium.toFixed(1) + '</td><td class="highlight">' + residualCalcium.toFixed(1) + '</td><td>mg/kg/die</td></tr>';+
     tableHtml += '<tr><td>Fosforo</td><td>' + requirements.phosphorus + '</td><td>' + enteralPhosphorus.toFixed(1) + '</td><td class="highlight">' + residualPhosphorus.toFixed(1) + '</td><td>mg/kg/die</td></tr>';     tableHtml += '<tr><td>Fosforo</td><td>' + requirements.phosphorus + '</td><td>' + enteralPhosphorus.toFixed(1) + '</td><td class="highlight">' + residualPhosphorus.toFixed(1) + '</td><td>mg/kg/die</td></tr>';
-    tableHtml += '<tr><td>Magnesio</td><td>' + requirements.magnesium + '</td><td>' + enteralMagnesium.toFixed(1) + '</td><td class="highlight">' + residualMagnesium.toFixed(1) + '</td><td>mg/kg/die</td></tr>';+    tableHtml += '<tr><td>Magnesio</td><td>' + requirements.magnesium + '</td><td>' + enteralMagnesium.toFixed(2) + '</td><td class="highlight">' + residualMagnesium.toFixed(2) + '</td><td>mEq/kg/die</td></tr>';
     tableHtml += '<tr><td>Sodio</td><td>' + requirements.sodium + '</td><td>' + enteralSodium.toFixed(2) + '</td><td class="highlight">' + residualSodium.toFixed(2) + '</td><td>mEq/kg/die</td></tr>';     tableHtml += '<tr><td>Sodio</td><td>' + requirements.sodium + '</td><td>' + enteralSodium.toFixed(2) + '</td><td class="highlight">' + residualSodium.toFixed(2) + '</td><td>mEq/kg/die</td></tr>';
     tableHtml += '<tr><td>Potassio</td><td>' + requirements.potassium + '</td><td>' + enteralPotassium.toFixed(2) + '</td><td class="highlight">' + residualPotassium.toFixed(2) + '</td><td>mEq/kg/die</td></tr>';     tableHtml += '<tr><td>Potassio</td><td>' + requirements.potassium + '</td><td>' + enteralPotassium.toFixed(2) + '</td><td class="highlight">' + residualPotassium.toFixed(2) + '</td><td>mEq/kg/die</td></tr>';
-    tableHtml += '<tr><td>Vitalipid</td><td>' + requirements.vitalipid + '</td><td>0</td><td class="highlight">' + requirements.vitalipid + '</td><td>ml/die</td></tr>'; +    tableHtml += '<tr><td>Vitalipid</td><td>' + requirements.vitalipid + '</td><td>0</td><td class="highlight">' + requirements.vitalipid + '</td><td>ml/kg/die</td></tr>'; 
-    tableHtml += '<tr><td>Soluvit</td><td>' + requirements.soluvit + '</td><td>0</td><td class="highlight">' + requirements.soluvit + '</td><td>ml/die</td></tr>'; +    tableHtml += '<tr><td>Soluvit</td><td>' + requirements.soluvit + '</td><td>0</td><td class="highlight">' + requirements.soluvit + '</td><td>ml/kg/die</td></tr>'; 
-    tableHtml += '<tr><td>Peditrace</td><td>' + requirements.peditrace + '</td><td>0</td><td class="highlight">' + requirements.peditrace + '</td><td>ml/die</td></tr>'; +    tableHtml += '<tr><td>Peditrace</td><td>' + requirements.peditrace + '</td><td>0</td><td class="highlight">' + requirements.peditrace + '</td><td>ml/kg/die</td></tr>'; 
-    tableHtml += '<tr class="day-column"><td><strong>ENERGIA</strong></td><td><strong>' + totalEnergyRequirement.toFixed(0) + '</strong></td><td><strong>' + enteralEnergy.toFixed(0) + '</strong></td><td class="energy-highlight">' + residualEnergy.toFixed(0) + '</td><td><strong>kcal/kg/die</strong></td></tr>';+    tableHtml += '<tr><td>Carnitina</td><td>' + requirements.carnitine + '</td><td>0</td><td class="highlight">' + requirements.carnitine + '</td><td>mg/kg/die</td></tr>'; 
 +    tableHtml += '<tr class="day-column"><td><strong>ENERGIA TOTALE</strong></td><td><strong>' + totalEnergyRequirement.toFixed(0) + '</strong></td><td><strong>' + enteralEnergy.toFixed(0) + '</strong></td><td class="energy-highlight">' + residualEnergy.toFixed(0) + '</td><td><strong>kcal/kg/die</strong></td></tr>';
     tableHtml += '</table>';     tableHtml += '</table>';
-     
-    tableHtml += vitaminsNote; 
-    tableHtml += bunNote; 
          
     document.getElementById('nutritionTable').innerHTML = tableHtml;     document.getElementById('nutritionTable').innerHTML = tableHtml;
     document.getElementById('nutritionResults').classList.remove('hidden');     document.getElementById('nutritionResults').classList.remove('hidden');
     document.getElementById('calculateNutritionBtn').className = 'button calculate-nutrition-completed';     document.getElementById('calculateNutritionBtn').className = 'button calculate-nutrition-completed';
-    document.getElementById('calculateNutritionBtn').innerHTML = 'FABBISOGNI CALCOLATI';+    document.getElementById('calculateNutritionBtn').innerHTML = 'FABBISOGNI CALCOLATI '
 +     
 +    // RESET del pulsante NPT quando si modificano i fabbisogni 
 +    resetParenteralButton(); 
 +
 + 
 +// FUNZIONE CALCOLO ELETTROLITI AGGIUNTIVI (DA VERSIONE 17) 
 +function calculateElectrolyteAdditions(calciumNeeded, phosphorusNeeded, magnesiumNeeded, sodiumNeeded, potassiumNeeded, currentWeightKg) { 
 +    const additions = { 
 +        ca_gluconato: 0, 
 +        esafosfina: 0, 
 +        mg_sulfate: 0, 
 +        nacl: 0, 
 +        sodium_acetate: 0, 
 +        kcl: 0, 
 +        totalVolume: 0, 
 +        sodiumSource: 'nacl' 
 +    }; 
 +     
 +    // Determina il tipo di sodio da utilizzare 
 +    const sodiumTypeSelect = document.getElementById('sodiumType'); 
 +    const selectedSodiumType = sodiumTypeSelect ? sodiumTypeSelect.value : 'nacl'; 
 +    additions.sodiumSource = selectedSodiumType; 
 +     
 +    // Calcola fabbisogni totali per paziente 
 +    const totalCalciumNeeded = calciumNeeded * currentWeightKg; // mg 
 +    const totalPhosphorusNeeded = phosphorusNeeded * currentWeightKg; // mg 
 +    const totalMagnesiumNeeded = magnesiumNeeded * currentWeightKg; // mEq 
 +    const totalSodiumNeeded = sodiumNeeded * currentWeightKg; // mEq 
 +    const totalPotassiumNeeded = potassiumNeeded * currentWeightKg; // mEq 
 +     
 +    // Calcio Gluconato 10% (840 mg Ca/100ml) 
 +    if (totalCalciumNeeded > 0) { 
 +        additions.ca_gluconato = totalCalciumNeeded / (parenteralConfig.ca_gluconato.calcium / 100); 
 +    } 
 +     
 +    // Esafosfina (1600 mg P/100ml + 130 mEq Na/100ml) 
 +    let sodiumFromEsafosfina = 0; 
 +    if (totalPhosphorusNeeded > 0) { 
 +        additions.esafosfina = totalPhosphorusNeeded / (parenteralConfig.esafosfina.phosphorus / 100); 
 +        sodiumFromEsafosfina = (additions.esafosfina * parenteralConfig.esafosfina.sodium / 100); 
 +    } 
 +     
 +    // Magnesio Solfato (800 mEq Mg/100ml) 
 +    if (totalMagnesiumNeeded > 0) { 
 +        additions.mg_sulfate = totalMagnesiumNeeded / (parenteralConfig.mg_sulfate.magnesium / 100); 
 +    } 
 +     
 +    // Sodio rimanente (dopo quello da Esafosfina) 
 +    const remainingSodium = Math.max(0, totalSodiumNeeded - sodiumFromEsafosfina); 
 +     
 +    if (remainingSodium > 0) { 
 +        if (selectedSodiumType === 'sodium_acetate') { 
 +            const concentrationSodiumAcetate = parenteralConfig.sodium_acetate.sodium / 100; 
 +            additions.sodium_acetate = remainingSodium / concentrationSodiumAcetate; 
 +        } else { 
 +            const concentrationNaCl = parenteralConfig.nacl.sodium / 100; 
 +            additions.nacl = remainingSodium / concentrationNaCl; 
 +        } 
 +    } 
 +     
 +    // Potassio Cloruro (1000 mEq K/100ml) 
 +    if (totalPotassiumNeeded > 0) { 
 +        additions.kcl = totalPotassiumNeeded / (parenteralConfig.kcl.potassium / 100); 
 +    } 
 +     
 +    // Volume totale degli elettroliti 
 +    additions.totalVolume = additions.ca_gluconato + additions.esafosfina + additions.mg_sulfate + additions.nacl + additions.sodium_acetate + additions.kcl; 
 +     
 +    return additions;
 } }
  
-// FUNZIONE CALCOLO NPT PARENTERALE CORRETTA+// FUNZIONE CALCOLO NPT PARENTERALE (DA VERSIONE 17 CON CONTROLLI CLINICI)
 function calculateParenteral() { function calculateParenteral() {
     if (!window.residualNeeds) {     if (!window.residualNeeds) {
Linea 1704: Linea 2167:
     }     }
          
-    const currentWeight = patientData.currentWeight; +    const parentCurrentWeight = patientData.currentWeight; 
-    const currentWeightKg = currentWeight / 1000;+    const currentWeightKg = parentCurrentWeight / 1000;
     const residualNeeds = window.residualNeeds;     const residualNeeds = window.residualNeeds;
 +    
 +    // CONTROLLI DI SICUREZZA BASATI SU CONFIGURAZIONE CLINICA
 +    const gir = (residualNeeds.carbs * 1000) / 1440; // mg/kg/min
 +    let alerts = [];
 +    
 +    if (gir > clinicalConfig.maxGIR) {
 +        alerts.push('⚠️ GIR > ' + clinicalConfig.maxGIR + ' mg/kg/min - Rischio iperglicemia');
 +    }
 +    if (residualNeeds.lipids > clinicalConfig.maxLipids) {
 +        alerts.push('⚠️ Lipidi > ' + clinicalConfig.maxLipids + ' g/kg/die - Monitorare trigliceridi');
 +    }
 +    if (residualNeeds.protein > clinicalConfig.maxProtein) {
 +        alerts.push('⚠️ Proteine > ' + clinicalConfig.maxProtein + ' g/kg/die - Monitorare BUN');
 +    }
          
     // Volume totale residuo richiesto     // Volume totale residuo richiesto
     const totalVolume = Math.round(residualNeeds.liquids * currentWeightKg);     const totalVolume = Math.round(residualNeeds.liquids * currentWeightKg);
          
-    // Calcola elettroliti aggiuntivi necessari+    // CALCOLA ELETTROLITI AGGIUNTIVI
     const electrolyteAdditions = calculateElectrolyteAdditions(     const electrolyteAdditions = calculateElectrolyteAdditions(
         residualNeeds.calcium,         residualNeeds.calcium,
Linea 1727: Linea 2204:
     const lipidVolume = Math.round((residualNeeds.lipids * currentWeightKg * 100) / 20);     const lipidVolume = Math.round((residualNeeds.lipids * currentWeightKg * 100) / 20);
          
-    // Volume vitamine/oligoelementi +    // Volume vitamine/oligoelementi/carnitina 
-    const vitaminsVolume = residualNeeds.vitalipid + residualNeeds.soluvit + residualNeeds.peditrace;+    const vitaminsVolume = (residualNeeds.vitalipid * currentWeightKg) (residualNeeds.soluvit * currentWeightKg) (residualNeeds.peditrace * currentWeightKg); 
 +    const carnitineVolume = residualNeeds.carnitine > 0 ? (residualNeeds.carnitine * currentWeightKg) / 100 : 0;
          
-    // Volume utilizzato da proteine, lipidi, elettroliti e vitamine +    // CALCOLO CON GLUCOSIO 50% + ACQUA BIDISTILLATA 
-    const usedVolume proteinVolume + lipidVolume + electrolyteAdditions.totalVolume + vitaminsVolume;+    const neededGlucose residualNeeds.carbs * currentWeightKg; // grammi totali di glucosio 
 +    const glucose50Volume = (neededGlucose * 100) / 50// ml di glucosio 50% necessari
          
-    // Volume rimanente per il glucosio +    // Volume utilizzato 
-    const glucoseVolume = totalVolume - usedVolume;+    const usedVolume proteinVolume + lipidVolume + vitaminsVolume + carnitineVolume + glucose50Volume + electrolyteAdditions.totalVolume;
          
-    // Calcolo concentrazione glucosio necessaria +    // Volume rimanente = Acqua Bidistillata 
-    const neededGlucose residualNeeds.carbs * currentWeightKg; +    const waterVolume = totalVolume - usedVolume;
-     +
-    let glucoseConc = 10; +
-    let glucoseMessage = ''; +
-     +
-    if (glucoseVolume <= 0) { +
-        glucoseMessage = '<div class="warning"><strong>ERRORE CALCOLO:</strong><br>'+
-                        '• Volume totale richiesto: ' + totalVolume + ' ml<br>'+
-                        '• Volume proteine + lipidi: ' + (proteinVolume + lipidVolume) + ' ml<br>'+
-                        '• Volume elettroliti: ' + electrolyteAdditions.totalVolume.toFixed(1) + ' ml<br>'+
-                        '• Volume vitamine: ' + vitaminsVolume + ' ml<br>'+
-                        '• Volume glucosio risultante: ' + glucoseVolume + ' ml (NEGATIVO!)<br><br>'+
-                        '<strong>SOLUZIONE:</strong> Aumentare il volume totale NPT o ridurre gli elettroliti.</div>'; +
-         +
-        document.getElementById('calculatedTotalVolume').value = totalVolume + ' ml (ERRORE)'; +
-        document.getElementById('suggestedGlucose').value = 'Impossibile Volume negativo'; +
-        document.getElementById('calculatedProteinVol').value = proteinVolume + ' ml'; +
-        document.getElementById('calculatedLipidVol').value = lipidVolume + ' ml'; +
-         +
-        document.getElementById('parenteralTable').innerHTML = glucoseMessage; +
-        document.getElementById('parenteralResults').classList.remove('hidden'); +
-        return; +
-    } +
-     +
-    if (neededGlucose <= 0) { +
-        glucoseMessage = '<div class="info"><strong>GLUCOSIO DA ENTERALE:</strong><br>'+
-                        '• Tutto il glucosio necessario (' + (residualNeeds.carbs * currentWeightKg).toFixed(1) + 'g) proviene dall\'alimentazione enterale<br>'+
-                        '• Apporto enterale: ' + (enteralData ? enteralData.carbs.toFixed(1) : 0) + ' g/kg/die<br>'+
-                        '• Non necessario glucosio in NPT</div>'; +
-         +
-        glucoseConc = 0; +
-        document.getElementById('suggestedGlucose').value = 'Non necessario (enterale sufficiente)'; +
-    } else { +
-        const requiredConcentration = (neededGlucose * 100) / glucoseVolume; +
-         +
-        if (requiredConcentration <= 12) { +
-            glucoseConc = 10; +
-        } else if (requiredConcentration <= 25) { +
-            glucoseConc = 20; +
-        } else if (requiredConcentration <= 40) { +
-            glucoseConc = 33; +
-        } else { +
-            glucoseConc = 50; +
-        } +
-         +
-        glucoseMessage = '<div class="info"><strong>CALCOLO GLUCOSIO:</strong><br>'+
-                        '• Glucosio necessario: ' + neededGlucose.toFixed(1) + 'g<br>'+
-                        '• Volume disponibile: ' + glucoseVolume + 'ml<br>'+
-                        '• Concentrazione richiesta: ' + requiredConcentration.toFixed(1) + '%<br>'+
-                        '• Concentrazione selezionata: ' + glucoseConc + '%</div>'; +
-         +
-        document.getElementById('suggestedGlucose').value = glucoseConc + '%'; +
-    } +
-     +
-    // Calcoli finali +
-    const actualGlucose = (glucoseVolume * glucoseConc) / 100; +
-    const actualProtein = (proteinVolume * 6) / 100; +
-    const actualLipids = (lipidVolume * 20) / 100; +
-     +
-    const glucosePerKg = actualGlucose / currentWeightKg; +
-    const proteinPerKg = actualProtein / currentWeightKg; +
-    const lipidsPerKg = actualLipids / currentWeightKg; +
-    const totalKcal = (glucosePerKg * 4) + (proteinPerKg * 4) + (lipidsPerKg * 9); +
-    const glucoseRate = (glucosePerKg * 1000) / (24 * 60);+
          
     document.getElementById('calculatedTotalVolume').value = totalVolume + ' ml';     document.getElementById('calculatedTotalVolume').value = totalVolume + ' ml';
 +    document.getElementById('suggestedGlucose').value = 'Glucosio 50% + Acqua + Elettroliti';
     document.getElementById('calculatedProteinVol').value = proteinVolume + ' ml';     document.getElementById('calculatedProteinVol').value = proteinVolume + ' ml';
     document.getElementById('calculatedLipidVol').value = lipidVolume + ' ml';     document.getElementById('calculatedLipidVol').value = lipidVolume + ' ml';
          
-    let resultHtml = glucoseMessage; +    let resultHtml = '<div class="info">'; 
-     +    resultHtml += '<strong>NPT v3.0 UNIFIED SISTEMA COMPLETO CON CONTROLLI CLINICI</strong><br>'; 
-    resultHtml += '<div class="info">'; +    resultHtml += '<strong>Peso:</strong> ' + parentCurrentWeight + 'g<br>'; 
-    resultHtml += '<strong>NPT v2.0 - Peso: ' + currentWeight + 'g</strong><br>';+    resultHtml += '<strong>GIR:</strong> ' + gir.toFixed(1) + ' mg/kg/min<br>';
     resultHtml += '<strong>Enterale:</strong> ' + (enteralData ? enteralData.totalFluids : 0) + ' ml (' + (enteralData ? (enteralData.totalFluids/currentWeightKg).toFixed(1) : 0) + ' ml/kg/die)<br>';     resultHtml += '<strong>Enterale:</strong> ' + (enteralData ? enteralData.totalFluids : 0) + ' ml (' + (enteralData ? (enteralData.totalFluids/currentWeightKg).toFixed(1) : 0) + ' ml/kg/die)<br>';
     if (enteralData && enteralData.additionalFluids > 0) {     if (enteralData && enteralData.additionalFluids > 0) {
         resultHtml += '<strong>→ Latte:</strong> ' + (enteralData.volume || 0) + ' ml, <strong>Altri liquidi:</strong> ' + enteralData.additionalFluids + ' ml<br>';         resultHtml += '<strong>→ Latte:</strong> ' + (enteralData.volume || 0) + ' ml, <strong>Altri liquidi:</strong> ' + enteralData.additionalFluids + ' ml<br>';
-    } 
-    resultHtml += '<strong>BUN:</strong> ' + (patientData.bun || 'Non inserito') + ' mg/dL '; 
-    if (patientData.bun) { 
-        const bunVal = parseFloat(patientData.bun); 
-        if (bunVal < 9) { 
-            resultHtml += 'Basso'; 
-        } else if (bunVal > 14) { 
-            resultHtml += 'Elevato'; 
-        } else { 
-            resultHtml += 'OK'; 
-        } 
     }     }
     resultHtml += '</div>';     resultHtml += '</div>';
 +    
 +    // MOSTRA ALERT CLINICI SE PRESENTI
 +    if (alerts.length > 0) {
 +        resultHtml += '<div class="alert-critical"><strong>ALERT CLINICI:</strong><br>' + alerts.join('<br>') + '</div>';
 +    }
          
     resultHtml += '<table class="results-table">';     resultHtml += '<table class="results-table">';
     resultHtml += '<tr><th>Componente</th><th>Volume (ml)</th></tr>';     resultHtml += '<tr><th>Componente</th><th>Volume (ml)</th></tr>';
          
-    if (glucoseConc > 0) { +    if (neededGlucose > 0) { 
-        resultHtml += '<tr><td><strong>Glucosio ' + glucoseConc + '%</strong></td><td><strong>'glucoseVolume + '</strong></td></tr>'; +        resultHtml += '<tr><td><strong>Glucosio 50%</strong></td><td><strong>'glucose50Volume.toFixed(1) + '</strong></td></tr>';
-    } else { +
-        resultHtml += '<tr><td><strong>Glucosio (Non necessario)</strong></td><td><strong>0</strong></td></tr>';+
     }     }
          
-    resultHtml += '<tr><td><strong>Trophamine 6%</strong></td><td><strong>' + proteinVolume + '</strong></td></tr>'; +    resultHtml += '<tr><td><strong>Trophamine 6%</strong></td><td><strong>' + proteinVolume.toFixed(1) + '</strong></td></tr>'; 
-    resultHtml += '<tr><td><strong>Intralipid 20%</strong></td><td><strong>' + lipidVolume + '</strong></td></tr>';+    resultHtml += '<tr><td><strong>Intralipid 20%</strong></td><td><strong>' + lipidVolume.toFixed(1) + '</strong></td></tr>';
          
-    // Elettroliti aggiuntivi+    // ELETTROLITI AGGIUNTIVI
     if (electrolyteAdditions.ca_gluconato > 0) {     if (electrolyteAdditions.ca_gluconato > 0) {
         resultHtml += '<tr><td><strong>Calcio Gluconato 10% (1g/10mL, 0.44 mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.ca_gluconato.toFixed(1) + '</strong></td></tr>';         resultHtml += '<tr><td><strong>Calcio Gluconato 10% (1g/10mL, 0.44 mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.ca_gluconato.toFixed(1) + '</strong></td></tr>';
Linea 1851: Linea 2260:
     if (electrolyteAdditions.nacl > 0) {     if (electrolyteAdditions.nacl > 0) {
         resultHtml += '<tr><td><strong>Sodio Cloruro (3mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.nacl.toFixed(1) + '</strong></td></tr>';         resultHtml += '<tr><td><strong>Sodio Cloruro (3mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.nacl.toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.sodium_acetate > 0) {
 +        resultHtml += '<tr><td><strong>Sodio Acetato (2 mEq/mL) - Alcalinizzante</strong></td><td><strong>' + electrolyteAdditions.sodium_acetate.toFixed(1) + '</strong></td></tr>';
     }     }
     if (electrolyteAdditions.kcl > 0) {     if (electrolyteAdditions.kcl > 0) {
Linea 1856: Linea 2268:
     }     }
          
 +    // VITAMINE
     if (residualNeeds.vitalipid > 0) {     if (residualNeeds.vitalipid > 0) {
-        resultHtml += '<tr><td><strong>Vitalipid N Infant</strong></td><td><strong>'residualNeeds.vitalipid + '</strong></td></tr>';+        const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg; 
 +        resultHtml += '<tr><td><strong>Vitalipid N Infant</strong></td><td><strong>'vitalipidVolume.toFixed(1) + '</strong></td></tr>';
     }     }
     if (residualNeeds.soluvit > 0) {     if (residualNeeds.soluvit > 0) {
-        resultHtml += '<tr><td><strong>Soluvit N</strong></td><td><strong>'residualNeeds.soluvit + '</strong></td></tr>';+        const soluvitVolume = residualNeeds.soluvit * currentWeightKg; 
 +        resultHtml += '<tr><td><strong>Soluvit N</strong></td><td><strong>'soluvitVolume.toFixed(1) + '</strong></td></tr>';
     }     }
     if (residualNeeds.peditrace > 0) {     if (residualNeeds.peditrace > 0) {
-        resultHtml += '<tr><td><strong>Peditrace</strong></td><td><strong>'residualNeeds.peditrace + '</strong></td></tr>';+        const peditraceVolume = residualNeeds.peditrace * currentWeightKg; 
 +        resultHtml += '<tr><td><strong>Peditrace</strong></td><td><strong>'peditraceVolume.toFixed(1) + '</strong></td></tr>';
     }     }
          
-    resultHtml += '<tr class="energy-highlight"><td><strong>TOTALE NPT</strong></td><td><strong>' + totalVolume + ' ml</strong></td></tr>';+    // CARNITINA 
 +    if (residualNeeds.carnitine > 0) { 
 +        resultHtml += '<tr><td><strong>Carnitene (100 mg/ml)</strong></td><td><strong>' + carnitineVolume.toFixed(1) + '</strong></td></tr>'; 
 +    } 
 +     
 +    // ACQUA BIDISTILLATA 
 +    if (waterVolume > 0) { 
 +        resultHtml += '<tr><td><strong>Acqua Bidistillata</strong></td><td><strong>' + waterVolume.toFixed(1) + '</strong></td></tr>'; 
 +    } 
 +     
 +    resultHtml += '<tr class="energy-highlight"><td><strong>TOTALE NPT</strong></td><td><strong>' + totalVolume.toFixed(1) + ' ml</strong></td></tr>';
     resultHtml += '</table>';     resultHtml += '</table>';
          
     document.getElementById('parenteralTable').innerHTML = resultHtml;     document.getElementById('parenteralTable').innerHTML = resultHtml;
-    document.getElementById('parenteralResults').classList.remove('hidden'); 
          
-    // Aggiorna il pulsante a verde +    // CREAZIONE RICETTA PER PREPARAZIONE 
-    const parenteralBtn = document.getElementById('calculateParenteralBtn'); +    const deflectorVolume parseInt(document.getElementById('deflectorVolume').value) || 30
-    if (parenteralBtn{ +    const totalVolumeWithDeflector = totalVolume + deflectorVolume; 
-        parenteralBtn.className = 'button config-update-completed'; +    const ratio = totalVolumeWithDeflector / totalVolume; 
-        parenteralBtn.innerHTML = 'NPT CALCOLATA ✓';+     
 +    let preparationHtml = '<div class="info">'; 
 +    preparationHtml += '<strong>📋 RICETTA PER PREPARAZIONE (Volume deflussore: ' + deflectorVolume + ' ml)</strong><br>'; 
 +    preparationHtml += '• <strong>Volume prescrizione:</strong> ' + totalVolume + ' ml<br>'; 
 +    preparationHtml += '• <strong>Volume deflussore:</strong> +' + deflectorVolume + ' ml<br>'; 
 +    preparationHtml += '• <strong>Volume totale preparazione:</strong> ' + totalVolumeWithDeflector + ' ml'; 
 +    preparationHtml += '</div>'; 
 +     
 +    preparationHtml += '<table class="results-table">'; 
 +    preparationHtml += '<tr><th>Componente</th><th>Volume Prescrizione (ml)</th><th>Volume Preparazione (ml)</th></tr>'; 
 +     
 +    if (neededGlucose > 0) { 
 +        preparationHtml += '<tr><td><strong>Glucosio 50%</strong></td><td>' + glucose50Volume.toFixed(1) + '</td><td><strong>' + (glucose50Volume * ratio).toFixed(1) + '</strong></td></tr>';
     }     }
 +    
 +    preparationHtml += '<tr><td><strong>Trophamine 6%</strong></td><td>' + proteinVolume.toFixed(1) + '</td><td><strong>' + (proteinVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    preparationHtml += '<tr><td><strong>Intralipid 20%</strong></td><td>' + lipidVolume.toFixed(1) + '</td><td><strong>' + (lipidVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    
 +    if (electrolyteAdditions.ca_gluconato > 0) {
 +        preparationHtml += '<tr><td><strong>Calcio Gluconato 10% (1g/10mL, 0.44 mEq/mL)</strong></td><td>' + electrolyteAdditions.ca_gluconato.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.ca_gluconato * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.esafosfina > 0) {
 +        preparationHtml += '<tr><td><strong>Esafosfina (5g/50mL)</strong></td><td>' + electrolyteAdditions.esafosfina.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.esafosfina * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.mg_sulfate > 0) {
 +        preparationHtml += '<tr><td><strong>Magnesio Solfato (2g/10ml, 1.6 mEq/mL)</strong></td><td>' + electrolyteAdditions.mg_sulfate.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.mg_sulfate * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.nacl > 0) {
 +        preparationHtml += '<tr><td><strong>Sodio Cloruro (3mEq/mL)</strong></td><td>' + electrolyteAdditions.nacl.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.nacl * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.sodium_acetate > 0) {
 +        preparationHtml += '<tr><td><strong>Sodio Acetato (2 mEq/mL) - Alcalinizzante</strong></td><td>' + electrolyteAdditions.sodium_acetate.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.sodium_acetate * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (electrolyteAdditions.kcl > 0) {
 +        preparationHtml += '<tr><td><strong>Potassio Cloruro (2 mEq/mL)</strong></td><td>' + electrolyteAdditions.kcl.toFixed(1) + '</td><td><strong>' + (electrolyteAdditions.kcl * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    
 +    // VITAMINE con denominazioni complete
 +    if (residualNeeds.vitalipid > 0) {
 +        const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg;
 +        preparationHtml += '<tr><td><strong>Vitalipid N Infant</strong></td><td>' + vitalipidVolume.toFixed(1) + '</td><td><strong>' + (vitalipidVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (residualNeeds.soluvit > 0) {
 +        const soluvitVolume = residualNeeds.soluvit * currentWeightKg;
 +        preparationHtml += '<tr><td><strong>Soluvit N</strong></td><td>' + soluvitVolume.toFixed(1) + '</td><td><strong>' + (soluvitVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    if (residualNeeds.peditrace > 0) {
 +        const peditraceVolume = residualNeeds.peditrace * currentWeightKg;
 +        preparationHtml += '<tr><td><strong>Peditrace</strong></td><td>' + peditraceVolume.toFixed(1) + '</td><td><strong>' + (peditraceVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    
 +    // CARNITINA con denominazione completa
 +    if (residualNeeds.carnitine > 0) {
 +        preparationHtml += '<tr><td><strong>Carnitene (100 mg/ml)</strong></td><td>' + carnitineVolume.toFixed(1) + '</td><td><strong>' + (carnitineVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    
 +    if (waterVolume > 0) {
 +        preparationHtml += '<tr><td><strong>Acqua Bidistillata</strong></td><td>' + waterVolume.toFixed(1) + '</td><td><strong>' + (waterVolume * ratio).toFixed(1) + '</strong></td></tr>';
 +    }
 +    
 +    preparationHtml += '<tr class="energy-highlight"><td><strong>TOTALE</strong></td><td><strong>' + totalVolume + ' ml</strong></td><td><strong>' + totalVolumeWithDeflector + ' ml</strong></td></tr>';
 +    preparationHtml += '</table>';
 +    
 +    document.getElementById('preparationTable').innerHTML = preparationHtml;
 +    document.getElementById('parenteralResults').classList.remove('hidden');
 +    
 +    document.getElementById('calculateParenteralBtn').className = 'button config-update-completed';
 +    document.getElementById('calculateParenteralBtn').innerHTML = 'NPT CALCOLATA ✓';
 +    
 +    // Salva i dati per il report
 +    window.nptCalculation = {
 +        totalVolume: totalVolume,
 +        waterVolume: waterVolume,
 +        glucose50Volume: glucose50Volume,
 +        proteinVolume: proteinVolume,
 +        lipidVolume: lipidVolume,
 +        gir: gir,
 +        neededGlucose: neededGlucose,
 +        electrolyteAdditions: electrolyteAdditions,
 +        vitaminsVolume: vitaminsVolume,
 +        carnitineVolume: carnitineVolume,
 +        deflectorVolume: deflectorVolume
 +    };
 } }
  
-// FUNZIONI CONFIGURAZIONE+// FUNZIONI CONFIGURAZIONE (DA VERSIONE 17)
 function populateEnteralConfigTable() { function populateEnteralConfigTable() {
     const tbody = document.getElementById('enteralConfigTable');     const tbody = document.getElementById('enteralConfigTable');
Linea 1927: Linea 2433:
 } }
  
-function populateFortifierConfigTable() { +function populateDoctorsConfigTable() { 
-    const tbody = document.getElementById('fortifierConfigTable');+    const tbody = document.getElementById('doctorsConfigTable');
     if (!tbody) return;     if (!tbody) return;
          
-    // Mantiene solo la riga predefinita e aggiunge quelle dinamiche +    tbody.innerHTML = ''; 
-    const existingRows = tbody.querySelectorAll('tr'); +    Object.keys(doctorsData).forEach(key => 
-    // Rimuovi tutte le righe tranne la prima (Prenidina FM85) +        const doctor doctorsData[key]; 
-    for (let i = existingRows.length - 1; i > 0; i--) { +        const row = tbody.insertRow(); 
-        existingRows[i].remove(); +        row.innerHTML = '<td><input type="text" id="doctor_' + key + '_name" value="'doctor.name + '" style="width: 100px;" oninput="markConfigChanged(\'doctors\')"></td>'
-    } +            '<td><input type="text" id="doctor_' + key + '_surname" value="'doctor.surname + '" style="width: 100px;" oninput="markConfigChanged(\'doctors\')"></td>'
-     +            '<td><select id="doctor_' + key + '_titlestyle="width: 70px;" oninput="markConfigChanged(\'doctors\')">'
-    // Aggiungi nuovi fortificanti dinamici +                '<option value="Dr."'(doctor.title === 'Dr.' ? ' selected'''+ '>Dr.</option>' + 
-    Object.keys(fortifierData).forEach(function(key+                '<option value="Dr.ssa"'(doctor.title === 'Dr.ssa? ' selected'''+ '>Dr.ssa</option>' + 
-        if (key !== 'prenidina_fm85') { // Skip il predefinito già presente +                '<option value="Prof."'(doctor.title === 'Prof.' ? ' selected'''+ '>Prof.</option>' + 
-            const fortifier fortifierData[key]; +                '<option value="Prof.ssa"'(doctor.title === 'Prof.ssaselected''+ '>Prof.ssa</option>' + 
-            const row = tbody.insertRow(); +            '</select></td>'
-            row.innerHTML = '<td class="component-name">' + fortifier.name + '</td>'+            '<td style="font-weightbold; color: #2c3e50;">'doctor.fullName + '</td>'
-                '<td><input type="number" id="fortifier_' + key + '_protein" value="'fortifier.protein + '" step="0.1" oninput="markConfigChanged(\'fortifier\')"></td>'+            '<td><button class="button secondary" onclick="removeDoctor(\'' + key + '\')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>';
-                '<td><input type="number" id="fortifier_' + key + '_carbs" value="'fortifier.carbs + '" step="0.1" oninput="markConfigChanged(\'fortifier\')"></td>'+
-                '<td><input type="number" id="fortifier_' + key + '_lipidsvalue="' + fortifier.lipids + '" step="0.1" oninput="markConfigChanged(\'fortifier\')"></td>' + +
-                '<td><input type="number" id="fortifier_' + key + '_sodium" value="+ fortifier.sodium + '" step="0.1" oninput="markConfigChanged(\'fortifier\')"></td>' + +
-                '<td><input type="numberid="fortifier_' + key + '_potassium" value="+ fortifier.potassium + '" step="0.1" oninput="markConfigChanged(\'fortifier\')"></td>' + +
-                '<td><input type="numberid="fortifier_' + key + '_calcium" value="+ fortifier.calcium + '" step="1" oninput="markConfigChanged(\'fortifier\')"></td>' + +
-                '<td><input type="numberid="fortifier_' + key + '_phosphorus" value="' + fortifier.phosphorus + '" step="1" oninput="markConfigChanged(\'fortifier\')"></td>+
-                '<td><input type="number" id="fortifier_+ key + '_magnesium" value="+ fortifier.magnesium + '" step="1" oninput="markConfigChanged(\'fortifier\')"></td>' + +
-                '<td><input type="number" id="fortifier_' + key + '_energy" value="' + fortifier.energy + '" step="1" oninput="markConfigChanged(\'fortifier\')"></td>'+
-                '<td style="font-size11px; color: #7f8c8d;">Fortificante personalizzato<br><em>Dose: ' + fortifier.dose + '</em></td>'+
-                '<td><button class="button secondary" onclick="removeFortifier(\'' + key + '\')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>'; +
-        }+
     });     });
 } }
  
-// FUNZIONE PER MARCARE LE MODIFICHE NELLA CONFIGURAZIONE 
 function markConfigChanged(configType) { function markConfigChanged(configType) {
     let buttonId = '';     let buttonId = '';
Linea 1976: Linea 2470:
             buttonId = 'updateFortifierBtn';             buttonId = 'updateFortifierBtn';
             buttonText = 'SALVA MODIFICHE FORTIFICANTI';             buttonText = 'SALVA MODIFICHE FORTIFICANTI';
 +            break;
 +        case 'doctors':
 +            buttonId = 'updateDoctorsBtn';
 +            buttonText = 'SALVA MODIFICHE MEDICI';
 +            break;
 +        case 'system':
 +            buttonId = 'updateSystemBtn';
 +            buttonText = 'SALVA PARAMETRI SISTEMA';
             break;             break;
     }     }
Linea 1986: Linea 2488:
 } }
  
-// FUNZIONI CONFIGURAZIONE COMPLETE 
 function updateEnteralConfig() {  function updateEnteralConfig() { 
     let changesCount = 0;     let changesCount = 0;
Linea 1993: Linea 2494:
         const oldValues = Object.assign({}, formulaData[key]);         const oldValues = Object.assign({}, formulaData[key]);
                  
-        formulaData[key].protein parseFloat(document.getElementById('config_' + key + '_protein').value); +        const proteinEl = document.getElementById('config_' + key + '_protein')
-        formulaData[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); +        if (proteinEl) { 
-        formulaData[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); +            formulaData[key].protein = parseFloat(proteinEl.value); 
-        formulaData[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); +            formulaData[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); 
-        formulaData[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); +            formulaData[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); 
-        formulaData[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); +            formulaData[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); 
-        formulaData[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); +            formulaData[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); 
-        formulaData[key].magnesium = parseFloat(document.getElementById('config_' + key + '_magnesium').value); +            formulaData[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); 
-        formulaData[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); +            formulaData[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); 
-         +            formulaData[key].magnesium = parseFloat(document.getElementById('config_' + key + '_magnesium').value); 
-        if (JSON.stringify(oldValues) !== JSON.stringify(formulaData[key])) { +            formulaData[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); 
-            changesCount++;+             
 +            if (JSON.stringify(oldValues) !== JSON.stringify(formulaData[key])) { 
 +                changesCount++; 
 +            }
         }         }
     });     });
-     
-    // SALVA NEL LOCALSTORAGE 
-    saveToStorage(); 
          
     const button = document.getElementById('updateEnteralBtn');     const button = document.getElementById('updateEnteralBtn');
Linea 2020: Linea 2521:
         }, 3000);         }, 3000);
     }     }
-     
-    console.log('Updated formula data:', formulaData); 
 } }
  
Linea 2030: Linea 2529:
         const oldValues = Object.assign({}, parenteralConfig[key]);         const oldValues = Object.assign({}, parenteralConfig[key]);
                  
-        parenteralConfig[key].protein parseFloat(document.getElementById('config_' + key + '_protein').value); +        const proteinEl = document.getElementById('config_' + key + '_protein')
-        parenteralConfig[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); +        if (proteinEl) { 
-        parenteralConfig[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); +            parenteralConfig[key].protein = parseFloat(proteinEl.value); 
-        parenteralConfig[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); +            parenteralConfig[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); 
-        parenteralConfig[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); +            parenteralConfig[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); 
-        parenteralConfig[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); +            parenteralConfig[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); 
-        parenteralConfig[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); +            parenteralConfig[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); 
-        parenteralConfig[key].magnesium = parseFloat(document.getElementById('config_' + key + '_magnesium').value); +            parenteralConfig[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); 
-        parenteralConfig[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); +            parenteralConfig[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); 
-        parenteralConfig[key].water = parseFloat(document.getElementById('config_' + key + '_water').value); +            parenteralConfig[key].magnesium = parseFloat(document.getElementById('config_' + key + '_magnesium').value); 
-         +            parenteralConfig[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); 
-        if (JSON.stringify(oldValues) !== JSON.stringify(parenteralConfig[key])) { +            parenteralConfig[key].water = parseFloat(document.getElementById('config_' + key + '_water').value); 
-            changesCount++;+             
 +            if (JSON.stringify(oldValues) !== JSON.stringify(parenteralConfig[key])) { 
 +                changesCount++; 
 +            }
         }         }
     });     });
-     
-    // SALVA NEL LOCALSTORAGE 
-    saveToStorage(); 
          
     const button = document.getElementById('updateParenteralBtn');     const button = document.getElementById('updateParenteralBtn');
Linea 2058: Linea 2557:
         }, 3000);         }, 3000);
     }     }
-     
-    console.log('Updated parenteral config:', parenteralConfig); 
 } }
  
 function updateFortifierConfig() {  function updateFortifierConfig() { 
     // Aggiorna Prenidina FM85 predefinita     // Aggiorna Prenidina FM85 predefinita
-    fortifierData.prenidina_fm85.protein parseFloat(document.getElementById('fortifier_prenidina_fm85_protein').value); +    const proteinEl = document.getElementById('fortifier_prenidina_fm85_protein')
-    fortifierData.prenidina_fm85.carbs = parseFloat(document.getElementById('fortifier_prenidina_fm85_carbs').value); +    if (proteinEl) { 
-    fortifierData.prenidina_fm85.lipids = parseFloat(document.getElementById('fortifier_prenidina_fm85_lipids').value); +        fortifierData.prenidina_fm85.protein = parseFloat(proteinEl.value); 
-    fortifierData.prenidina_fm85.sodium = parseFloat(document.getElementById('fortifier_prenidina_fm85_sodium').value); +        fortifierData.prenidina_fm85.carbs = parseFloat(document.getElementById('fortifier_prenidina_fm85_carbs').value); 
-    fortifierData.prenidina_fm85.potassium = parseFloat(document.getElementById('fortifier_prenidina_fm85_potassium').value); +        fortifierData.prenidina_fm85.lipids = parseFloat(document.getElementById('fortifier_prenidina_fm85_lipids').value); 
-    fortifierData.prenidina_fm85.calcium = parseFloat(document.getElementById('fortifier_prenidina_fm85_calcium').value); +        fortifierData.prenidina_fm85.sodium = parseFloat(document.getElementById('fortifier_prenidina_fm85_sodium').value); 
-    fortifierData.prenidina_fm85.phosphorus = parseFloat(document.getElementById('fortifier_prenidina_fm85_phosphorus').value); +        fortifierData.prenidina_fm85.potassium = parseFloat(document.getElementById('fortifier_prenidina_fm85_potassium').value); 
-    fortifierData.prenidina_fm85.magnesium = parseFloat(document.getElementById('fortifier_prenidina_fm85_magnesium').value); +        fortifierData.prenidina_fm85.calcium = parseFloat(document.getElementById('fortifier_prenidina_fm85_calcium').value); 
-    fortifierData.prenidina_fm85.energy = parseFloat(document.getElementById('fortifier_prenidina_fm85_energy').value);+        fortifierData.prenidina_fm85.phosphorus = parseFloat(document.getElementById('fortifier_prenidina_fm85_phosphorus').value); 
 +        fortifierData.prenidina_fm85.magnesium = parseFloat(document.getElementById('fortifier_prenidina_fm85_magnesium').value); 
 +        fortifierData.prenidina_fm85.energy = parseFloat(document.getElementById('fortifier_prenidina_fm85_energy').value); 
 +    }
          
-    // Aggiorna fortificanti dinamici +    const button = document.getElementById('updateFortifierBtn'); 
-    let changesCount = 1// Prenidina sempre aggiornata +    if (button) { 
-    Object.keys(fortifierData).forEach(function(key+        button.className = 'button config-update-completed'; 
-        if (key !== 'prenidina_fm85'{ +        button.innerHTML = 'FORTIFICANTI SALVATE ✓'; 
-            const proteinEl = document.getElementById('fortifier_' + key + '_protein'); +        setTimeout(() => { 
-            if (proteinEl) { +            button.className = 'button'; 
-                fortifierData[key].protein parseFloat(proteinEl.value); +            button.innerHTML = 'Aggiorna Fortificanti'; 
-                fortifierData[key].carbs parseFloat(document.getElementById('fortifier_' + key + '_carbs').value); +        }, 3000); 
-                fortifierData[key].lipids parseFloat(document.getElementById('fortifier_' + key + '_lipids').value)+    } 
-                fortifierData[key].sodium parseFloat(document.getElementById('fortifier_' + key + '_sodium').value)+
-                fortifierData[key].potassium parseFloat(document.getElementById('fortifier_' + key + '_potassium').value)+ 
-                fortifierData[key].calcium parseFloat(document.getElementById('fortifier_' + key + '_calcium').value)+function updateDoctorsConfig() { 
-                fortifierData[key].phosphorus parseFloat(document.getElementById('fortifier_' + key + '_phosphorus').value)+    let changesCount = 0; 
-                fortifierData[key].magnesium = parseFloat(document.getElementById('fortifier_' + key + '_magnesium').value); +     
-                fortifierData[key].energy = parseFloat(document.getElementById('fortifier_' + key + '_energy').value);+    Object.keys(doctorsData).forEach(key => 
 +        const oldValues = Object.assign({}, doctorsData[key]); 
 +         
 +        const nameEl = document.getElementById('doctor_' + key + '_name'); 
 +        if (nameEl) { 
 +            const newName nameEl.value.trim(); 
 +            const newSurname = document.getElementById('doctor_' + key + '_surname').value.trim(); 
 +            const newTitle = document.getElementById('doctor_' + key + '_title').value; 
 +             
 +            doctorsData[key].name newName
 +            doctorsData[key].surname newSurname
 +            doctorsData[key].title newTitle
 +            doctorsData[key].fullName newTitle + ' ' + newName + ' ' + newSurname
 +             
 +            if (JSON.stringify(oldValues!== JSON.stringify(doctorsData[key])) {
                 changesCount++;                 changesCount++;
             }             }
Linea 2094: Linea 2608:
     });     });
          
-    // SALVA NEL LOCALSTORAGE +    updateDoctorsDropdown(); 
-    saveToStorage();+    populateDoctorsConfigTable();
          
-    const button = document.getElementById('updateFortifierBtn');+    const button = document.getElementById('updateDoctorsBtn');
     if (button) {     if (button) {
         button.className = 'button config-update-completed';         button.className = 'button config-update-completed';
-        button.innerHTML = 'FORTIFICANTI SALVATE ✓ (' + changesCount + ' modifiche)';+        button.innerHTML = 'MEDICI SALVATI ✓ (' + changesCount + ' modifiche)';
         setTimeout(() => {         setTimeout(() => {
             button.className = 'button';             button.className = 'button';
-            button.innerHTML = 'Aggiorna Fortificanti';+            button.innerHTML = 'Aggiorna Lista Medici'; 
 +        }, 3000); 
 +    } 
 +
 + 
 +function updateSystemConfig() { 
 +    const button = document.getElementById('updateSystemBtn'); 
 +    if (button) { 
 +        button.className = 'button config-update-completed'; 
 +        button.innerHTML = 'PARAMETRI SALVATI ✓'; 
 +        setTimeout(() => { 
 +            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Parametri Sistema';
         }, 3000);         }, 3000);
     }     }
          
-    console.log('Updated fortifier data:', fortifierData);+    resetParenteralButton();
 } }
-function exportConfig() {+ 
 +// FUNZIONI CONFIGURAZIONE CLINICA AVANZATA (NUOVE) 
 +function updateClinicalConfig() { 
 +    clinicalConfig.calciumReq = parseFloat(document.getElementById('calciumReq').value); 
 +    clinicalConfig.phosphorusReq = parseFloat(document.getElementById('phosphorusReq').value); 
 +    clinicalConfig.magnesiumReq = parseFloat(document.getElementById('magnesiumReq').value); 
 +    clinicalConfig.maxGIR = parseFloat(document.getElementById('maxGIR').value); 
 +    clinicalConfig.maxLipids = parseFloat(document.getElementById('maxLipids').value); 
 +    clinicalConfig.maxProtein = parseFloat(document.getElementById('maxProtein').value); 
 +     
 +    alert('Parametri clinici aggiornati:\n'
 +          '• Calcio standard: ' + clinicalConfig.calciumReq + ' mg/kg/die\n'
 +          '• Fosforo standard: ' + clinicalConfig.phosphorusReq + ' mg/kg/die\n'
 +          '• GIR massimo: ' + clinicalConfig.maxGIR + ' mg/kg/min\n'
 +          '• Lipidi massimi: ' + clinicalConfig.maxLipids + ' g/kg/die'); 
 +
 + 
 +function resetConfiguration() { 
 +    // Reset configurazione clinica 
 +    document.getElementById('calciumReq').value = 160; 
 +    document.getElementById('phosphorusReq').value = 84; 
 +    document.getElementById('magnesiumReq').value = 0.6; 
 +    document.getElementById('maxGIR').value = 12.0; 
 +    document.getElementById('maxLipids').value = 3.0; 
 +    document.getElementById('maxProtein').value = 4.5; 
 +     
 +    // Reset configurazione sistema 
 +    document.getElementById('deflectorVolume').value = 30; 
 +    document.getElementById('hospitalName').value = "ASST LECCO"; 
 +    document.getElementById('departmentName').value = "S.C. Neonatologia e TIN"; 
 +    document.getElementById('directorName').value = "Dott. Roberto Bellù"; 
 +     
 +    // Reset configurazione clinica globale 
 +    clinicalConfig = { 
 +        calciumReq: 160, 
 +        phosphorusReq: 84, 
 +        magnesiumReq: 0.6, 
 +        maxGIR: 12.0, 
 +        maxLipids: 3.0, 
 +        maxProtein: 4.5, 
 +        hospitalName: "ASST LECCO", 
 +        departmentName: "S.C. Neonatologia e TIN", 
 +        directorName: "Dott. Roberto Bellù" 
 +    }; 
 +     
 +    alert('Configurazione ripristinata ai valori predefiniti'); 
 +
 + 
 +function saveConfiguration() {
     const config = {     const config = {
-        version"2.0"+        deflectorVolumedocument.getElementById('deflectorVolume').value
-        timestampnew Date().toISOString(), +        hospitalNamedocument.getElementById('hospitalName').value, 
-        enteralFormulasformulaData+        departmentName: document.getElementById('departmentName').value
-        parenteralComponentsparenteralConfig+        directorNamedocument.getElementById('directorName').value
-        fortifierDatafortifierData+        autoSavedocument.getElementById('autoSave').value
-        bunMonitoringtrue+        decimalPlacesdocument.getElementById('decimalPlaces').value
 +        clinicalConfigclinicalConfig
     };     };
          
-    const dataStr = JSON.stringify(config, null, 2); +    // Aggiorna configurazione clinica 
-    const dataBlob = new Blob([dataStr], {type: 'application/json'}); +    clinicalConfig.hospitalName config.hospitalName
-    const url = URL.createObjectURL(dataBlob); +    clinicalConfig.departmentName config.departmentName
-    const link document.createElement('a')+    clinicalConfig.directorName config.directorName;
-    link.href url+
-    link.download 'npt_config_v2_BUN_' + new Date().toISOString().split('T')[0] + '.json'; +
-    link.click(); +
-    URL.revokeObjectURL(url);+
          
-    showConfigResult('Configurazione v2.0 con BUN esportata con successo!');+    // Simula salvataggio configurazione 
 +    window.savedConfig = config; 
 +    alert('Configurazione salvata con successo!');
 } }
  
-function importConfig() { +// FUNZIONI REPORT (COMPLETE CON TUTTI GLI ELEMENTI) 
-    const file = document.getElementById('configFile').files[0]+function generatePrescription() { 
-    if (!file) return;+    if (!window.residualNeeds || !patientData.currentWeight) { 
 +        alert('Prima completare tutti i calcoli precedenti'); 
 +        return; 
 +    }
          
-    const reader = new FileReader(); +    const currentDate = new Date().toLocaleDateString('it-IT'); 
-    reader.onload function(e) { +    const currentTime = new Date().toLocaleTimeString('it-IT'); 
-        try { +    const prescriptionPatientWeightKg patientData.currentWeight / 1000; 
-            const config JSON.parse(e.target.result); +    const calc = window.nptCalculation; 
-             +     
-            if (config.enteralFormulas{ +    if (!calc) { 
-                Object.assign(formulaData, config.enteralFormulas); +        alert('Prima calcolare la NPT nel TAB 4'); 
-                populateEnteralConfigTable(); +        return; 
-            +    } 
-             +     
-            if (config.parenteralComponents) { +    const birthDate new Date(); 
-                Object.assign(parenteralConfig, config.parenteralComponents); +    birthDate.setDate(birthDate.getDate() - patientData.daysOfLife); 
-                populateParenteralConfigTable(); +     
-            } +    const doctorName = patientData.prescribingDoctorName ||  
-             +                      (patientData.prescribingDoctor && doctorsData[patientData.prescribingDoctor] ?  
-            if (config.fortifierData) { +                       doctorsData[patientData.prescribingDoctor].fullName : 'Non specificato'); 
-                Object.assign(fortifierData, config.fortifierData); +     
-                populateFortifierConfigTable(); +    let html = '<div class="report-output">'; 
-            +     
-             +    // INTESTAZIONE MEDICA ESATTA COME DA PDF 
-            // SALVA LE MODIFICHE IMPORTATE +    html += '<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #2c3e50; padding-bottom: 15px; margin-bottom: 25px;">'; 
-            saveToStorage(); +     
-             +    // PARTE SINISTRA - INFO OSPEDALE 
-            showConfigResult('Configurazione v' + (config.version || '1.0') + ' importata e salvata con successo!'); +    html += '<div style="text-align: left;">'; 
-             +    html += '<h2 style="margin: 0; font-size: 16px; color: #2c3e50;">Dipartimento Area della Donna e Materno Infantile</h2>'; 
-        } catch (error) { +    html += '<h3 style="margin: 5px 0; font-size: 14px; color: #34495e;">S.C. Neonatologia Terapia Intensiva Neonatale</h3>'; 
-            showConfigResult('Errore nell\'importazione: ' + error.message, 'error'); +    html += '<p style="margin: 5px 0; font-size: 12px; color: #7f8c8d;">Direttore: ' + clinicalConfig.directorName + '</p>'; 
-        } +    html += '</div>'; 
-    }; +     
-    reader.readAsText(file);+    // PARTE DESTRA - LOGO ASST 
 +    html += '<div style="text-align: right;">'; 
 +    html += '<h1 style="margin: 0; font-size: 24px; color: #2c3e50; font-weight: bold;">' + clinicalConfig.hospitalName + '</h1>'; 
 +    html += '</div>'; 
 +     
 +    html += '</div>'; 
 +     
 +    // TITOLO DOCUMENTO 
 +    html += '<div style="text-align: center; margin: 20px 0;">'; 
 +    html += '<h2 style="font-size: 18px; font-weight: bold; color: #2c3e50; margin: 10px 0;">CALCOLO NUTRIZIONALE PARENTERALE</h2>'; 
 +    html += '<p style="font-size: 14px; color: #7f8c8d; margin: 5px 0;">Data: ' + currentDate + '</p>'; 
 +    html += '</div>'; 
 +     
 +    // DATI PAZIENTE 
 +    html += '<div style="background-color: #f8f9fa; padding: 15px; border-left: 4px solid #3498db; margin: 20px 0;">'; 
 +    html += '<h3 style="margin-top: 0; color: #2c3e50;">DATI PAZIENTE</h3>'; 
 +    html += '<div style="display: flex; justify-content: space-between;">'; 
 +    html += '<div>'; 
 +    html += '<p><strong>Medico Prescrittore:</strong> ' + doctorName + '</p>'; 
 +    html += '<p><strong>Data Prescrizione:</strong> ' + (patientData.prescriptionDate || currentDate+ '</p>'
 +    html += '<p><strong>N° Cartella:</strong> ' + (patientData.medicalRecord || 'N/A'+ '</p>'
 +    html += '</div>'; 
 +    html += '<div>'; 
 +    html += '<p><strong>Data Nascita:</strong> ' + birthDate.toLocaleDateString('it-IT') + '</p>'; 
 +    html += '<p><strong>Età:</strong> ' + patientData.daysOfLife + ' giorni di vita</p>'; 
 +    html += '<p><strong>Peso:</strong> ' + patientData.currentWeight + 'g (' + prescriptionPatientWeightKg.toFixed(3) + ' kg)</p>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +     
 +    // COMPOSIZIONE NPT COMPLETA (TUTTI GLI ELEMENTI DAL TAB 4) 
 +    html += '<h3 style="color: #27ae60; margin-top: 30px;">COMPOSIZIONE NPT</h3>'; 
 +    html += '<table style="width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px;">'; 
 +    html += '<thead><tr style="background-color: #34495e; color: white;">'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">COMPONENTE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">VOLUME (ml)</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">CONCENTRAZIONE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">QUANTITÀ TOTALE</th>'; 
 +    html += '</tr></thead><tbody>'; 
 +     
 +    // ACQUA BIDISTILLATA 
 +    if (calc.waterVolume > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Acqua Bidistillata</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.waterVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td></tr>'; 
 +    
 +     
 +    // GLUCOSIO 
 +    if (calc.neededGlucose > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Glucosio</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.glucose50Volume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">50%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + calc.neededGlucose.toFixed(1+ ' g</td></tr>'
 +    } 
 +     
 +    // PROTEINE 
 +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Trophamine</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.proteinVolume.toFixed(1+ '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">6%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.protein * prescriptionPatientWeightKg).toFixed(1) + ' g</td></tr>'
 +     
 +    // LIPIDI 
 +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Intralipid</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.lipidVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">20%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.lipids * prescriptionPatientWeightKg).toFixed(1) + ' g</td></tr>'; 
 +     
 +    // ELETTROLITI (SE PRESENTI) 
 +    if (calc.electrolyteAdditions.ca_gluconato > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Calcio Gluconato 10%</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.ca_gluconato.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">100 mg/ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">'(window.residualNeeds.calcium * prescriptionPatientWeightKg).toFixed(1) + ' mg Ca</td></tr>'
 +    } 
 +    if (calc.electrolyteAdditions.esafosfina > 0
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Esafosfina</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.esafosfina.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">100 mg P/ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.phosphorus * prescriptionPatientWeightKg).toFixed(1) + ' mg P</td></tr>'
 +    
 +    if (calc.electrolyteAdditions.mg_sulfate > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Magnesio Solfato</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.mg_sulfate.toFixed(1+ '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">200 mg/ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.magnesium * prescriptionPatientWeightKg).toFixed(1) + ' mEq Mg</td></tr>'
 +    } 
 +    if (calc.electrolyteAdditions.nacl > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Sodio Cloruro</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.nacl.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">5.85 g/100ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">+ (window.residualNeeds.sodium * prescriptionPatientWeightKg).toFixed(1) + ' mEq Na</td></tr>'; 
 +    } 
 +    if (calc.electrolyteAdditions.sodium_acetate > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Sodio Acetato</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.sodium_acetate.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">Alcalinizzante</td><td style="border: 1px solid #2c3e50; padding: 10px;">+ (window.residualNeeds.sodium * prescriptionPatientWeightKg).toFixed(1) + ' mEq Na</td></tr>'
 +    } 
 +    if (calc.electrolyteAdditions.kcl > 0) { 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Potassio Cloruro</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.electrolyteAdditions.kcl.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">149 mg/ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.potassium * prescriptionPatientWeightKg).toFixed(1) + ' mEq K</td></tr>'; 
 +    } 
 +     
 +    // VITAMINE (SE PRESENTI) 
 +    if (window.residualNeeds.vitalipid > 0) { 
 +        const vitalipidVolume = window.residualNeeds.vitalipid * prescriptionPatientWeightKg; 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Vitalipid N Infant</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + vitalipidVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">Vitamine liposolubili</td><td style="border: 1px solid #2c3e50; padding: 10px;">+ (window.residualNeeds.vitalipid * prescriptionPatientWeightKg).toFixed(1) + ' ml</td></tr>'; 
 +    } 
 +    if (window.residualNeeds.soluvit > 0) { 
 +        const soluvitVolume = window.residualNeeds.soluvit * prescriptionPatientWeightKg; 
 +        html += '<tr><td style="border1px solid #2c3e50; padding: 10px;"><strong>Soluvit N</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + soluvitVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">Vitamine idrosolubili</td><td style="border: 1px solid #2c3e50; padding: 10px;">+ (window.residualNeeds.soluvit * prescriptionPatientWeightKg).toFixed(1) + ' ml</td></tr>'; 
 +    } 
 +    if (window.residualNeeds.peditrace > 0) { 
 +        const peditraceVolume = window.residualNeeds.peditrace * prescriptionPatientWeightKg; 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Peditrace</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + peditraceVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">Oligoelementi</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.peditrace * prescriptionPatientWeightKg).toFixed(1) + ' ml</td></tr>'; 
 +    } 
 +     
 +    // CARNITINA (SE PRESENTE) 
 +    if (window.residualNeeds.carnitine > 0) { 
 +        const carnitineVolume = (window.residualNeeds.carnitine * prescriptionPatientWeightKg) / 100; 
 +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>Carnitene</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + carnitineVolume.toFixed(1) + '</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">100 mg/ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (window.residualNeeds.carnitine * prescriptionPatientWeightKg).toFixed(1) + ' mg</td></tr>'; 
 +    } 
 +     
 +    // TOTALE 
 +    html += '<tr style="background-color: #e8f5e8; font-weight: bold; border-top: 2px solid #27ae60;"><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>TOTALE NPT</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.totalVolume + ' ml</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + (calc.totalVolume / 24).toFixed(2) + ' ml/h</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + window.residualNeeds.energy.toFixed(0) + ' kcal</strong></td></tr>'
 +    html += '</tbody></table>'; 
 +     
 +    // PARAMETRI CLINICI 
 +    html += '<div style="background-color: #fff3cd; border: 1px solid #ffc107; border-radius: 5px; padding: 15px; margin: 20px 0;">'; 
 +    html += '<h4 style="margin-top: 0; color: #856404;">PARAMETRI CLINICI</h4>'; 
 +    html += '<p><strong>GIR:</strong> ' + calc.gir.toFixed(1+ ' mg/kg/min</p>'; 
 +    html += '<p><strong>Velocità infusione:</strong> ' + (calc.totalVolume / 24).toFixed(2) + ' ml/h</p>'; 
 +    html += '<p><strong>Via di somministrazione:</strong> Accesso venoso centrale</p>'; 
 +    html += '<p><strong>Durata:</strong> 24 ore continue</p>'; 
 +    html += '</div>'; 
 +     
 +    // FIRMA 
 +    html += '<div style="margin-top: 40px; display: flex; justify-content: space-between;">'; 
 +    html += '<div style="text-align: center; width: 200px;">'; 
 +    html += '<p><strong>Data:</strong> ' + currentDate + '</p>'; 
 +    html += '<p><strong>Ora:</strong> ' + currentTime + '</p>'; 
 +    html += '</div>'; 
 +    html += '<div style="text-align: center; width: 200px;">'; 
 +    html += '<div style="border-bottom: 1px solid #2c3e50; margin-bottom: 5px; height: 40px;"></div>'; 
 +    html += '<p><strong>Medico Prescrittore</strong><br>' + doctorName + '</p>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +     
 +    document.getElementById('reportOutput').innerHTML = html;
 } }
  
-function showConfigResult(message, type) { +function generateWorksheet() { 
-    const resultsDiv document.getElementById('configResults'); +    if (!window.residualNeeds || !patientData.currentWeight) { 
-    const configInfo document.getElementById('configInfo');+        alert('Prima completare tutti i calcoli precedenti'); 
 +        return; 
 +    } 
 +     
 +    const calc window.nptCalculation; 
 +    if (!calc) { 
 +        alert('Prima calcolare la NPT nel TAB 4'); 
 +        return; 
 +    } 
 +     
 +    const currentDate new Date().toLocaleDateString('it-IT')
 +    const currentTime = new Date().toLocaleTimeString('it-IT'); 
 +    const worksheetPatientWeightKg = patientData.currentWeight / 1000; 
 +     
 +    const birthDate = new Date(); 
 +    birthDate.setDate(birthDate.getDate() - patientData.daysOfLife); 
 +     
 +    const deflectorVolume = calc.deflectorVolume || 30; 
 +    const totalVolumeWithDeflector = calc.totalVolume + deflectorVolume; 
 +    const ratio = totalVolumeWithDeflector / calc.totalVolume; 
 +     
 +    let html = '<div class="report-output">'; 
 +    html += '<div class="medical-header">'; 
 +    html += '<h1>' + clinicalConfig.hospitalName + '</h1>'; 
 +    html += '<h2>' + clinicalConfig.departmentName + '</h2>'; 
 +    html += '<p>Direttore: ' + clinicalConfig.directorName + '</p>'; 
 +    html += '</div>'; 
 +     
 +    html += '<div style="text-align: center; font-size: 20px; font-weight: bold; color: #2c3e50; margin: 20px 0; text-transform: uppercase;">RICETTA PER PREPARAZIONE NPT</div>'; 
 +     
 +    html += '<div style="background-color: #f8f9fa; padding: 15px; border-left: 4px solid #3498db; margin: 20px 0;">'; 
 +    html += '<h3 style="margin-top: 0; color: #2c3e50;">INFORMAZIONI PAZIENTE</h3>'; 
 +    html += '<p><strong>Data e Ora:</strong> ' + currentDate + ' - ' + currentTime + '</p>'; 
 +    html += '<p><strong>Cartella:</strong> ' + (patientData.medicalRecord || 'N/A') + '</p>'; 
 +    html += '<p><strong>Peso:</strong> ' + patientData.currentWeight + 'g (' + worksheetPatientWeightKg.toFixed(3) + ' kg)</p>'; 
 +    html += '<p><strong>Giorni di vita:</strong> ' + patientData.daysOfLife + '</p>'; 
 +    html += '</div>'; 
 +     
 +    html += '<div style="background-color: #fff3cd; border: 1px solid #ffc107; border-radius: 5px; padding: 15px; margin: 20px 0;">'; 
 +    html += '<h4 style="margin-top: 0; color: #856404;">PARAMETRI NUTRIZIONALI</h4>'; 
 +    html += '<p><strong>GIR:</strong> ' + calc.gir.toFixed(1) + ' mg/kg/min</p>'; 
 +    html += '<p><strong>Velocità infusione:</strong> ' + (calc.totalVolume / 24).toFixed(2) + ' ml/h</p>'; 
 +    html += '<p><strong>Durata:</strong> 24 ore continue</p>'; 
 +    html += '</div>'; 
 +     
 +    html += '<table style="width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px;">'; 
 +    html += '<thead><tr style="background-color: #34495e; color: white;">'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">COMPONENTE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">CONCENTRAZIONE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">VOLUME PRESCRIZIONE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">VOLUME PREPARAZIONE</th>'; 
 +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">ORDINE</th>'; 
 +    html += '</tr></thead><tbody>';
          
-    configInfo.innerHTML message; +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;">Acqua Bidistillata</td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td><td style="border1px solid #2c3e50; padding: 10px;">+ Math.max(0, calc.waterVolume).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50padding: 10px;">' + Math.max(0, calc.waterVolume * ratio).toFixed(1) + ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">1°</td></tr>';
-    resultsDiv.className = 'results+ (type === 'error' ? ' error' : ''); +
-    resultsDiv.classList.remove('hidden');+
          
-    if (type !== 'error') { +    if (calc.neededGlucose > 0) { 
-        setTimeout(function() { +        html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;">Glucosio</td><td style="border: 1px solid #2c3e50; padding: 10px;">50%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + calc.glucose50Volume.toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (calc.glucose50Volume * ratio).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">2°</td></tr>'; 
-            resultsDiv.classList.add('hidden'); +    } 
-        }, 8000);+     
 +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;">Trophamine</td><td style="border: 1px solid #2c3e50; padding: 10px;">6%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + calc.proteinVolume.toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (calc.proteinVolume * ratio).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">3°</td></tr>'; 
 +     
 +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;">Intralipid</td><td style="border: 1px solid #2c3e50; padding: 10px;">20%</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + calc.lipidVolume.toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + (calc.lipidVolume * ratio).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>4° ULTIMO</strong></td></tr>'; 
 +     
 +    html += '<tr style="background-color: #e8f5e8; font-weight: bold; border-top: 2px solid #27ae60;"><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>TOTALE</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + calc.totalVolume + ' ml</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;"><strong>' + totalVolumeWithDeflector + ' ml</strong></td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td></tr>'; 
 +    html += '</tbody></table>'; 
 +     
 +    html += '<div style="background-color: #fff3cd; border: 1px solid #ffc107; border-radius: 5px; padding: 15px; margin: 20px 0;">'; 
 +    html += '<h4 style="margin-top: 0; color: #856404;">AVVERTENZE</h4>'; 
 +    html += '<ul>'; 
 +    html += '<li>Preparazione sterile in cappa a flusso laminare</li>'; 
 +    html += '<li>Seguire rigorosamente l\'ordine di aggiunta</li>'; 
 +    html += '<li>Intralipid sempre per ultimo</li>'; 
 +    html += '<li>Conservare a 2-8°C, usare entro 24 ore</li>'; 
 +    html += '</ul>'; 
 +    html += '</div>'; 
 +     
 +    html += '<div style="margin-top: 40px; display: flex; justify-content: space-between;">'; 
 +    html += '<div style="text-align: center; width: 200px;">'; 
 +    html += '<div style="border-bottom: 1px solid #2c3e50; margin-bottom: 5px; height: 40px;"></div>'; 
 +    html += '<p><strong>Preparato da</strong><br>Farmacista</p>'; 
 +    html += '</div>'; 
 +    html += '<div style="text-align: center; width: 200px;">'; 
 +    html += '<div style="border-bottom: 1px solid #2c3e50; margin-bottom: 5px; height: 40px;"></div>'; 
 +    html += '<p><strong>Controllato da</strong><br>Infermiere</p>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +    html += '</div>'; 
 +     
 +    document.getElementById('reportOutput').innerHTML = html; 
 +
 + 
 +// FUNZIONE GENERAZIONE PDF (DA VERSIONE 17) 
 +function generatePDF(type) { 
 +    if (!window.residualNeeds || !patientData.currentWeight) { 
 +        alert('Prima calcolare la NPT completa'); 
 +        return; 
 +    } 
 + 
 +    const { jsPDF } window.jspdf; 
 +    const doc new jsPDF(); 
 +     
 +    // INTESTAZIONE COMUNE 
 +    doc.setFontSize(10); 
 +    doc.text(clinicalConfig.departmentName, 20, 15); 
 +    doc.text('Direttore: ' + clinicalConfig.directorName, 20, 20); 
 +     
 +    // Logo ASST (posizionamento approssimativo) 
 +    doc.text(clinicalConfig.hospitalName, 170, 20); 
 +     
 +    const currentDate = new Date().toLocaleDateString('it-IT'); 
 +    doc.text('CALCOLO NUTRIZIONALE PARENTERALE Data: ' + currentDate, 20, 35); 
 +     
 +    if (type === 'foglio_lavoro') { 
 +        generateFoglioLavoroPDF(doc); 
 +    } else if (type === 'report_parenterale') { 
 +        generateReportParenteralePDF(doc); 
 +    } 
 +     
 +    // Salva il PDF 
 +    const fileName = type === 'foglio_lavoro' ? 'Foglio_Lavoro_NPT.pdf' : 'Report_Parenterale_NPT.pdf'; 
 +    doc.save(fileName); 
 +
 + 
 +function generateFoglioLavoroPDF(doc) { 
 +    // Implementazione semplificata del PDF 
 +    let yPos = 50; 
 +     
 +    doc.setFontSize(12); 
 +    doc.text('FOGLIO DI LAVORO NPT', 20, yPos); 
 +    yPos += 20; 
 +     
 +    doc.setFontSize(10); 
 +    doc.text('Paziente: ' + (patientData.medicalRecord || 'N/A'), 20, yPos); 
 +    yPos += 10; 
 +    doc.text('Peso: ' + patientData.currentWeight + 'g', 20, yPos); 
 +    yPos += 10; 
 +    doc.text('Giorni di vita: ' + patientData.daysOfLife, 20, yPos); 
 +    yPos += 20; 
 +     
 +    const calc = window.nptCalculation; 
 +    doc.text('Volume totale NPT: ' + calc.totalVolume + ' ml', 20, yPos); 
 +    yPos += 10; 
 +    doc.text('GIR: ' + calc.gir.toFixed(1) + ' mg/kg/min', 20, yPos); 
 +    yPos += 10; 
 +    doc.text('Velocita infusione: ' + (calc.totalVolume / 24).toFixed(2) + ' ml/h', 20, yPos); 
 +} 
 + 
 +function generateReportParenteralePDF(doc) { 
 +    // Implementazione semplificata del PDF 
 +    let yPos = 50; 
 +     
 +    doc.setFontSize(12); 
 +    doc.text('REPORT PARENTERALE'20, yPos); 
 +    yPos += 20; 
 +     
 +    doc.setFontSize(10); 
 +    doc.text('Sistema: NPT Calculator v3.0 UNIFIED', 20, yPos); 
 +    yPos += 10; 
 +    doc.text('Data: ' + new Date().toLocaleDateString('it-IT'), 20, yPos); 
 +
 + 
 +// FUNZIONI PLACEHOLDER 
 +function showAddEnteralForm() { 
 +    alert('Aggiungi nuova formula enterale - Implementazione completa nel codice sorgente'); 
 +
 + 
 +function showAddFortifierForm() { 
 +    alert('Aggiungi nuovo fortificante - Implementazione completa nel codice sorgente'); 
 +
 + 
 +function showAddParenteralForm() { 
 +    alert('Aggiungi nuovo componente parenterale - Implementazione completa nel codice sorgente'); 
 +
 + 
 +function showAddDoctorForm() { 
 +    alert('Aggiungi nuovo medico - Implementazione completa nel codice sorgente'); 
 +
 + 
 +function removeEnteralFormula(key) { 
 +    if (confirm('Sei sicuro di voler rimuovere questa formula?')) { 
 +        alert('Rimozione formula - Implementazione completa nel codice sorgente'); 
 +    } 
 +
 + 
 +function removeParenteralComponent(key) { 
 +    if (confirm('Sei sicuro di voler rimuovere questo componente?')) { 
 +        alert('Rimozione componente - Implementazione completa nel codice sorgente'); 
 +    } 
 +
 + 
 +function removeFortifier(key) { 
 +    if (confirm('Sei sicuro di voler rimuovere questo fortificante?')) { 
 +        alert('Rimozione fortificante - Implementazione completa nel codice sorgente'); 
 +    } 
 +
 + 
 +function removeDoctor(key) { 
 +    if (confirm('Sei sicuro di voler rimuovere questo medico?')) { 
 +        alert('Rimozione medico - Implementazione completa nel codice sorgente');
     }     }
 } }
Linea 2184: Linea 3072:
 // INIZIALIZZAZIONE // INIZIALIZZAZIONE
 document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
-    console.log('NPT Calculator v2.0 con BUN e Liquidi Monitoring inizializzato');+    console.log('NPT Calculator v3.0 UNIFIED inizializzato');
          
-    // CARICA CONFIGURAZIONE SALVATA +    // Imposta la data odierna come default 
-    const configLoaded loadFromStorage()+    const today new Date().toISOString().split('T')[0]
-    if (configLoaded+    document.getElementById('prescriptionDate').value today
-        console.log('✅ Configurazione personalizzata caricata dal localStorage'); +     
-        // Aggiorna status +    // Configura il campo cartella clinica 
-        const statusDiv = document.getElementById('storageStatus')+    setupMedicalRecordField();
-        if (statusDiv) { +
-            statusDiv.innerHTML '<strong>💾 Configurazione Personalizzata Caricata</strong><br>Le tue modifiche sono state ripristinate automaticamente'+
-            statusDiv.style.background = '#d4edda'; +
-        } +
-    } else { +
-        console.log('📋 Usando configurazione di default'); +
-    }+
          
     document.getElementById('birthWeight').addEventListener('change', function() {     document.getElementById('birthWeight').addEventListener('change', function() {
         document.getElementById('currentWeight').value = this.value;         document.getElementById('currentWeight').value = this.value;
     });     });
 +    
 +    // Event listeners per resettare Fabbisogni e NPT quando si modificano i valori manualmente
 +    const requirementFields = [
 +        'reqLiquids', 'reqProtein', 'reqCarbs', 'reqLipids', 
 +        'reqCalcium', 'reqPhosphorus', 'reqMagnesium', 
 +        'reqSodium', 'reqPotassium', 'reqVitalipid', 'reqSoluvit', 'reqPeditrace', 'reqCarnitine'
 +    ];
 +    
 +    requirementFields.forEach(fieldId => {
 +        const field = document.getElementById(fieldId);
 +        if (field) {
 +            field.addEventListener('input', function() {
 +                resetNutritionButton();
 +            });
 +            field.addEventListener('change', function() {
 +                resetNutritionButton();
 +            });
 +        }
 +    });
 +    
 +    // Event listener per il tipo di sodio
 +    const sodiumTypeSelect = document.getElementById('sodiumType');
 +    if (sodiumTypeSelect) {
 +        sodiumTypeSelect.addEventListener('change', function() {
 +            updateSodiumChoice();
 +            updateSodiumRecommendation();
 +        });
 +    }
 +    
 +    // Event listener per il volume del deflussore
 +    const deflectorVolumeInput = document.getElementById('deflectorVolume');
 +    if (deflectorVolumeInput) {
 +        deflectorVolumeInput.addEventListener('input', function() {
 +            resetParenteralButton();
 +        });
 +    }
 +    
 +    // Inizializza configurazione clinica avanzata
 +    document.getElementById('calciumReq').value = clinicalConfig.calciumReq;
 +    document.getElementById('phosphorusReq').value = clinicalConfig.phosphorusReq;
 +    document.getElementById('magnesiumReq').value = clinicalConfig.magnesiumReq;
 +    document.getElementById('maxGIR').value = clinicalConfig.maxGIR;
 +    document.getElementById('maxLipids').value = clinicalConfig.maxLipids;
 +    document.getElementById('maxProtein').value = clinicalConfig.maxProtein;
 +    document.getElementById('hospitalName').value = clinicalConfig.hospitalName;
 +    document.getElementById('departmentName').value = clinicalConfig.departmentName;
 +    document.getElementById('directorName').value = clinicalConfig.directorName;
          
     updateFortifierOptions();     updateFortifierOptions();
-    console.log('NPT Calculator v2.0 pronto - Tab orizzontali funzionanti - Salvataggio persistente attivo');+    updateDoctorsDropdown(); 
 +    console.log('NPT Calculator v3.0 UNIFIED pronto');
 }); });
 </script> </script>
docuneo/programma_npt.1753804076.txt.gz · Ultima modifica: da 127.0.0.1