Differenze

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

Link a questa pagina di confronto

Entrambe le parti precedenti la revisioneRevisione precedente
Prossima revisione
Revisione precedente
docuneo:programma_npt [2025/07/31 22:21] neoadmindocuneo: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 210: Linea 218:
  
         .hidden {         .hidden {
-            display: none !important; +            display: none;
-        } +
- +
-        .visible { +
-            display: block !important;+
         }         }
  
-        /* CSS TAB ORIZZONTALI */+        /* CSS TAB ORIZZONTALI CORRETTI */
         .tabs {         .tabs {
             display: flex;             display: flex;
Linea 226: 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 234: 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 311: Linea 316:
         }         }
  
-        /* STILI PER IL REPORT NPT */ +        .config-table 
-        .npt-report +            width100%
-            backgroundwhite+            border-collapsecollapse
-            padding20px+            margin15px 0;
-            font-familyArial, sans-serif;+
             font-size: 12px;             font-size: 12px;
-            line-height: 1.4; 
-            max-width: 800px; 
-            margin: 0 auto; 
-            border: 1px solid #ddd; 
         }         }
  
-        .report-header { +        .config-table th, .config-table td 
-            display: flex; +            border: 1px solid #ddd
-            justify-content: space-between; +            padding: 6px
-            align-items: center; +            text-aligncenter;
-            border-bottom2px solid #333+
-            padding-bottom10px+
-            margin-bottom20px;+
         }         }
  
-        .report-header-left +        .config-table th 
-            flex1;+            background-color: #34495e; 
 +            colorwhite;
         }         }
  
-        .report-header-right +        .config-table input 
-            width: 100px; +            width: 60px; 
-            height: 60px; +            padding3px
-            background-color#e8f4f8+            border: 1px solid #ddd
-            border: 1px solid #ccc+            border-radius3px;
-            display: flex; +
-            align-itemscenter; +
-            justify-content: center; +
-            font-size: 10px; +
-            color: #666;+
         }         }
  
-        .report-title { +        .component-name {
-            font-size: 14px;+
             font-weight: bold;             font-weight: bold;
-            margin-bottom5px;+            background-color#f8f9fa; 
 +            text-align: left !important;
         }         }
  
-        .report-subtitle +        /* SEZIONE NUOVA PER TAB 5 CONFIGURAZIONE AVANZATA */ 
-            font-size11px+        .config-advanced 
-            color: #666+            background-color#f8f9fa
-            margin-bottom15px;+            border2px solid #17a2b8
 +            border-radius: 10px; 
 +            padding: 20px; 
 +            margin20px 0;
         }         }
  
-        .report-section +        .config-advanced h3 { 
-            margin-bottom: 20px;+            color: #0c5460; 
 +            margin-top: 0; 
 +            border-bottom: 2px solid #17a2b8; 
 +            padding-bottom: 10px;
         }         }
  
-        .report-section-title { +        .monitoring-table {
-            background-color: #333; +
-            color: white; +
-            padding: 5px 10px; +
-            font-weight: bold; +
-            font-size: 12px; +
-            margin-bottom: 0; +
-        } +
- +
-        .report-table {+
             width: 100%;             width: 100%;
             border-collapse: collapse;             border-collapse: collapse;
-            font-size: 11px;+            margin: 15px 0; 
 +            font-size: 12px;
         }         }
  
-        .report-table td { +        .monitoring-table th, .monitoring-table td { 
-            padding: 3px 8px; +            border: 1px solid #17a2b8; 
-            border-bottom: 1px solid #ddd+            padding: 8px
-            vertical-align: top;+            text-align: left;
         }         }
  
-        .report-table .label-col +        .monitoring-table th 
-            width200px+            background-color#17a2b8
-            font-weightnormal;+            colorwhite;
         }         }
  
-        .report-table .value-col +        .alert-critical 
-            text-alignright;+            background-color: #721c24; 
 +            color: white; 
 +            padding: 15px; 
 +            border-radius: 5px; 
 +            margin15px 0;
             font-weight: bold;             font-weight: bold;
         }         }
  
-        .composition-table +        /* REPORT SECTION */ 
-            width100%+        .report-output 
-            border-collapsecollapse+            border2px solid #3498db
-            font-size11px+            border-radius10px
-            margin-top: 0;+            padding30px
 +            margin-top: 30px; 
 +            background-color: white; 
 +            font-family: 'Times New Roman', serif; 
 +            line-height: 1.6;
         }         }
  
-        .composition-table th { +        .medical-header {
-            background-color: #f0f0f0; +
-            padding: 5px 8px;+
             text-align: center;             text-align: center;
-            font-weightbold+            border-bottom3px solid #2c3e50
-            border1px solid #ddd;+            padding-bottom15px; 
 +            margin-bottom: 25px;
         }         }
  
-        .composition-table td +        .medical-header h1 
-            padding3px 8px+            font-size24px
-            border1px solid #ddd+            color: #2c3e50
-            text-alignright;+            margin5px 0;
         }         }
  
-        .composition-table .component-name-col +        .medical-header h2 
-            text-alignleft !important+            font-size: 18px; 
-            width60%;+            color#34495e
 +            margin3px 0;
         }         }
  
-        .composition-total +        .medical-header p 
-            background-color: #f8f8f8+            font-size: 14px; 
-            font-weightbold;+            color: #7f8c8d
 +            margin2px 0;
         }         }
  
-        .elements-table +        .no-print {  
-            width100%; +            displayblock
-            border-collapse: collapse; +
-            font-size: 11px; +
-            margin-top: 0; +
-        } +
- +
-        .elements-table td { +
-            padding: 3px 8px; +
-            border-bottom: 1px solid #ddd; +
-        } +
- +
-        .elements-table .element-name { +
-            width: 200px; +
-        } +
- +
-        .elements-table .element-value { +
-            text-align: right; +
-            font-weight: bold; +
-            width: 80px; +
-        } +
- +
-        .elements-table .element-unit { +
-            text-align: left; +
-            width: 40px; +
-            font-size: 10px; +
-        } +
- +
-        .report-footer { +
-            margin-top: 30px; +
-            padding-top: 10px; +
-            border-top: 1px solid #ddd; +
-            font-size: 10px; +
-            color: #666; +
-            text-align: center;+
         }         }
  
         @media print {         @media print {
-            .npt-report +            .no-print {  
-                box-shadow: none+                display: none !important
-                border: none; +
-                margin: 0; +
-                padding: 15px;+
             }             }
-             +            body {  
-            .button +                backgroundwhite
-                displaynone;+
             }             }
-             +            .container {  
-            .tabs, .tab-content:not(.active) +                box-shadow: none; 
-                display: none !important;+
             }             }
         }         }
Linea 484: 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 -->+    <!-- 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 522: Linea 492:
                         <label for="prescribingDoctor">Medico prescrittore:</label>                         <label for="prescribingDoctor">Medico prescrittore:</label>
                         <select id="prescribingDoctor" style="width: 200px;">                         <select id="prescribingDoctor" style="width: 200px;">
-                            <option value="">Seleziona medico</option> +                            <!-- Popolato dinamicamente -->
-                            <option value="dr_bellu">Dr. Roberto Bellù</option> +
-                            <option value="dr_condo">Dr.ssa Manuela Condò</option> +
-                            <option value="dr_maccioni">Dr.ssa Carla Maccioni</option> +
-                            <option value="dr_meroni">Dr.ssa Federica Meroni</option> +
-                            <option value="dr_calzatini">Dr. Francesco Calzatini</option> +
-                            <option value="dr_ferrari">Dr.ssa Elisabetta Ferrari</option>+
                         </select>                         </select>
                     </div>                     </div>
Linea 557: Linea 521:
                     <div class="input-group">                     <div class="input-group">
                         <label for="currentWeight">Peso attuale (g):</label>                         <label for="currentWeight">Peso attuale (g):</label>
-                        <input type="number" id="currentWeight" min="400" max="5000" value="3550">+                        <input type="number" id="currentWeight" min="400" max="5000" value="1000">
                     </div>                     </div>
                     <div class="input-group">                     <div class="input-group">
Linea 610: 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 709: 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 839: 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 881: Linea 845:
             <div id="preparationTable"></div>             <div id="preparationTable"></div>
                          
-            <div style="margin-top: 30px; padding: 15px; background-color: #f0f8ff; border-left: 4px solid #3498db; border-radius: 5px;"> +            <div style="margin-top: 20px;"> 
-                <h3 style="color: #2c3e50; margin-top: 0;">📋 Report Professionali</h3> +                <button class="button" onclick="generatePDF('foglio_lavoro')">📄 Genera PDF FOGLIO DI LAVORO</button> 
-                <p style="margin-bottom: 15px;">Genera i report in formato ospedaliero per stampa e archiviazione:</p> +                <button class="button" onclick="generatePDF('report_parenterale')" style="margin-left: 10px;">📄 Genera PDF - REPORT PARENTERALE</button>
-                <div style="display: flex; gap: 10px; flex-wrap: wrap;"> +
-                    <button id="generateWorkReportBtn" class="button" onclick="generateAndShowWorkReport()" style="background-color: #27ae60;">Genera Foglio di Lavoro</button> +
-                    <button id="generateFinalReportBtn" class="button" onclick="generateAndShowFinalReport()" style="background-color: #3498db;">Genera Report Parenterale</button> +
-                    <button id="printReportBtn" class="button secondary hidden" onclick="printCurrentReport()" style="margin-left: 10px;">Stampa Report Attivo</button+
-                </div>+
             </div>             </div>
-             
-            <div id="nptWorkReport" class="hidden" style="margin-top: 20px;"></div> 
-            <div id="nptFinalReport" class="hidden" style="margin-top: 20px;"></div> 
         </div>         </div>
     </div>     </div>
  
-    <!-- TAB 5: CONFIGURAZIONE --> +    <!-- TAB 5: REPORT FINALE (SPOSTATO DA TAB 6) --> 
-    <div id="config" class="tab-content">+    <div id="report" class="tab-content">
         <div class="info">         <div class="info">
-            <strong>CONFIGURAZIONE COMPONENTI</strong><br> +            <strong>PASSO 5 - REPORT FINALE</strong><br> 
-            <strong>Sistema:</strong> NPT Calculator v2.0 - Database completo componenti nutrizionali+            <strong>Obiettivo:</strong> Generare la documentazione completa per prescrizione e preparazione
         </div>         </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 class="info">
 +            <strong>CONFIGURAZIONE COMPLETA</strong><br>
 +            <strong>Sistema:</strong> NPT Calculator v3.0 - Database completo componenti + configurazione clinica avanzata
 +        </div>
         <div class="section">         <div class="section">
             <h2>Parametri Sistema</h2>             <h2>Parametri Sistema</h2>
Linea 909: Linea 881:
                     <div class="input-group">                     <div class="input-group">
                         <label for="deflectorVolume">Volume deflussore (ml):</label>                         <label for="deflectorVolume">Volume deflussore (ml):</label>
-                        <input type="number" id="deflectorVolume" min="0" max="100" step="5" value="30">+                        <input type="number" id="deflectorVolume" min="0" max="100" step="5" value="30" oninput="markConfigChanged('system')">
                     </div>                     </div>
                     <div class="info" style="margin-top: 10px; font-size: 12px;">                     <div class="info" style="margin-top: 10px; font-size: 12px;">
Linea 923: Linea 895:
             </div>             </div>
         </div>         </div>
 +        
         <div class="section">         <div class="section">
             <h2>Formule Enterali (Valori per 100ml)</h2>             <h2>Formule Enterali (Valori per 100ml)</h2>
             <div style="overflow-x: auto;">             <div style="overflow-x: auto;">
-                <table class="results-table" style="font-size: 12px;">+                <table class="config-table">
                     <thead>                     <thead>
                         <tr>                         <tr>
Linea 940: Linea 912:
                             <th>Magnesio<br>(mg)</th>                             <th>Magnesio<br>(mg)</th>
                             <th>Energia<br>(kcal)</th>                             <th>Energia<br>(kcal)</th>
 +                            <th>Azioni</th>
                         </tr>                         </tr>
                     </thead>                     </thead>
-                    <tbody>+                    <tbody id="enteralConfigTable"> 
 +                        <!-- Popolato dinamicamente --> 
 +                    </tbody> 
 +                </table> 
 +            </div> 
 +            <div class="form-row"> 
 +                <div class="form-col"> 
 +                    <button id="updateEnteralBtn" class="button" onclick="updateEnteralConfig()">Aggiorna Formule Enterali</button> 
 +                </div> 
 +                <div class="form-col"> 
 +                    <button class="button secondary" onclick="showAddEnteralForm()">Aggiungi Nuova Formula</button> 
 +                </div> 
 +            </div> 
 +        </div> 
 + 
 +        <div class="section"> 
 +            <h2>Fortificanti in Polvere (Valori per 100g)</h2> 
 +            <div style="overflow-x: auto;"> 
 +                <table class="config-table"> 
 +                    <thead>
                         <tr>                         <tr>
-                            <td><strong>Latte Materno</strong></td+                            <th style="min-width: 180px;">Fortificante</th> 
-                            <td>1.2</td+                            <th>Proteine<br>(g)</th> 
-                            <td>7.0</td+                            <th>Carboidrati<br>(g)</th
-                            <td>4.0</td+                            <th>Lipidi<br>(g)</th
-                            <td>0.007</td+                            <th>Sodio<br>(mEq)</th
-                            <td>0.035</td+                            <th>Potassio<br>(mEq)</th
-                            <td>28.0</td+                            <th>Calcio<br>(mg)</th
-                            <td>15.0</td+                            <th>Fosforo<br>(mg)</th
-                            <td>3.0</td+                            <th>Magnesio<br>(mg)</th
-                            <td>67</td>+                            <th>Energia<br>(kcal)</th
 +                            <th style="min-width: 200px;">Note</th
 +                            <th>Azioni</th>
                         </tr>                         </tr>
 +                    </thead>
 +                    <tbody id="fortifierConfigTable">
                         <tr>                         <tr>
-                            <td><strong>Latte Materno + Prenidina FM85</strong></td> +                            <td class="component-name">Prenidina FM85</td> 
-                            <td>2.6</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_protein" value="14" step="0.1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>7.4</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_carbs" value="4" step="0.1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>4.25</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_lipids" value="2.5" step="0.1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>0.009</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_sodium" value="2" step="0.1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>0.050</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_potassium" value="15" step="0.1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>63.0</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_calcium" value="3500" step="1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>35.0</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_phosphorus" value="2000" step="1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>4.5</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_magnesium" value="150" step="1" oninput="markConfigChanged('fortifier')"></td> 
-                            <td>87</td> +                            <td><input type="number" id="fortifier_prenidina_fm85_energy" value="400" step="1" oninput="markConfigChanged('fortifier')"></td> 
-                        </tr> +                            <td style="font-size: 11px; color: #7f8c8d;">Fortificante latte materno<br><em>Dose: 1-4g/100ml</em></td> 
-                        <tr> +                            <td><button class="button secondary" onclick="removeFortifier('prenidina_fm85')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>
-                            <td><strong>Nestle NAN Supreme Pro 1</strong></td> +
-                            <td>1.3</td> +
-                            <td>7.6</td> +
-                            <td>3.5</td> +
-                            <td>0.024</td> +
-                            <td>0.075</td> +
-                            <td>44.1</td> +
-                            <td>24.4</td> +
-                            <td>6.56</td> +
-                            <td>67</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>Humana 1</strong></td> +
-                            <td>1.4</td> +
-                            <td>7.6</td> +
-                            <td>3.2</td> +
-                            <td>0.020</td> +
-                            <td>0.070</td> +
-                            <td>59.0</td> +
-                            <td>33.0</td> +
-                            <td>5.0</td> +
-                            <td>67</td+
-                        </tr> +
-                        <tr+
-                            <td><strong>BBmilk Zero</strong></td> +
-                            <td>1.8</td> +
-                            <td>7.8</td> +
-                            <td>3.6</td> +
-                            <td>0.022</td> +
-                            <td>0.075</td> +
-                            <td>65.0</td> +
-                            <td>36.0</td> +
-                            <td>6.0</td> +
-                            <td>70</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>BBmilk PDF</strong></td> +
-                            <td>1.7</td> +
-                            <td>7.9</td> +
-                            <td>3.7</td> +
-                            <td>0.025</td> +
-                            <td>0.078</td> +
-                            <td>68.0</td> +
-                            <td>38.0</td> +
-                            <td>6.5</td> +
-                            <td>71</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>Nestle PreNan POST</strong></td> +
-                            <td>2.0</td> +
-                            <td>8.2</td> +
-                            <td>4.0</td> +
-                            <td>0.030</td> +
-                            <td>0.085</td> +
-                            <td>75.0</td> +
-                            <td>42.0</td> +
-                            <td>7.5</td> +
-                            <td>73</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>Alfare</strong></td> +
-                            <td>1.9</td> +
-                            <td>7.1</td> +
-                            <td>3.4</td> +
-                            <td>0.015</td> +
-                            <td>0.050</td> +
-                            <td>52.0</td> +
-                            <td>35.0</td> +
-                            <td>5.5</td> +
-                            <td>67</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>Infatrini</strong></td> +
-                            <td>2.6</td> +
-                            <td>10.8</td> +
-                            <td>5.4</td> +
-                            <td>0.028</td> +
-                            <td>0.082</td> +
-                            <td>85.0</td> +
-                            <td>58.0</td> +
-                            <td>9.2</td> +
-                            <td>101</td>+
                         </tr>                         </tr>
                     </tbody>                     </tbody>
                 </table>                 </table>
             </div>             </div>
-            <div class="infostyle="margin-top: 15px;"> +            <div class="form-row"
-                <strong>ℹ️ Informazioni:</strongQuesti valori sono configurati nel database e vengono utilizzati per i calcoli nutrizionali. Sono basati su letteratura e schede tecniche ufficiali.+                <div class="form-col"
 +                    <button id="updateFortifierBtn" class="button" onclick="updateFortifierConfig()">Aggiorna Fortificanti</button
 +                </div> 
 +                <div class="form-col"> 
 +                    <button class="button secondary" onclick="showAddFortifierForm()">Aggiungi Nuovo Fortificante</button> 
 +                </div>
             </div>             </div>
         </div>         </div>
Linea 1062: Linea 981:
             <h2>Componenti Parenterali (Valori per 100ml)</h2>             <h2>Componenti Parenterali (Valori per 100ml)</h2>
             <div style="overflow-x: auto;">             <div style="overflow-x: auto;">
-                <table class="results-table" style="font-size: 12px;">+                <table class="config-table">
                     <thead>                     <thead>
                         <tr>                         <tr>
-                            <th style="min-width: 200px;">Componente</th>+                            <th style="min-width: 180px;">Componente</th> 
 +                            <th>Proteine<br>(g)</th> 
 +                            <th>Carboidrati<br>(g)</th> 
 +                            <th>Lipidi<br>(g)</th> 
 +                            <th>Sodio<br>(mEq)</th> 
 +                            <th>Potassio<br>(mEq)</th>
                             <th>Calcio<br>(mg)</th>                             <th>Calcio<br>(mg)</th>
                             <th>Fosforo<br>(mg)</th>                             <th>Fosforo<br>(mg)</th>
                             <th>Magnesio<br>(mEq)</th>                             <th>Magnesio<br>(mEq)</th>
-                            <th>Sodio<br>(mEq)</th> +                            <th>Energia<br>(kcal)</th> 
-                            <th>Potassio<br>(mEq)</th> +                            <th>Acqua<br>(ml)</th> 
-                            <th style="min-width: 250px;">Descrizione</th>+                            <th style="min-width: 200px;">Descrizione e Note</th> 
 +                            <th>Azioni</th>
                         </tr>                         </tr>
                     </thead>                     </thead>
-                    <tbody>+                    <tbody id="parenteralConfigTable"> 
 +                        <!-- Popolato dinamicamente --> 
 +                    </tbody> 
 +                </table> 
 +            </div> 
 +            <div class="form-row"> 
 +                <div class="form-col"> 
 +                    <button id="updateParenteralBtn" class="button" onclick="updateParenteralConfig()">Aggiorna Componenti Parenterali</button> 
 +                </div> 
 +                <div class="form-col"> 
 +                    <button class="button secondary" onclick="showAddParenteralForm()">Aggiungi Nuovo Componente</button> 
 +                </div> 
 +            </div> 
 +        </div> 
 + 
 +        <div class="section"> 
 +            <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;"> 
 +                <table class="config-table"> 
 +                    <thead>
                         <tr>                         <tr>
-                            <td><strong>Calcio Gluconato 10%</strong></td+                            <th style="min-width: 120px;">Nome</th
-                            <td>840</td+                            <th style="min-width: 120px;">Cognome</th
-                            <td>0</td+                            <th style="min-width: 80px;">Titolo</th
-                            <td>0</td+                            <th style="min-width: 250px;">Nome Completo (Visualizzato)</th
-                            <td>0</td> +                            <th>Azioni</th>
-                            <td>0</td> +
-                            <td>1g/10mL, 0.44 mEq/mL - Sale di calcio organico</td>+
                         </tr>                         </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-left: 10px; 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>                         <tr>
-                            <td><strong>Esafosfina</strong></td+                            <th>Controllo</th
-                            <td>0</td+                            <th>Frequenza</th
-                            <td>1600</td+                            <th>Range Normale</th
-                            <td>0</td> +                            <th>Azione se Fuori Range</th>
-                            <td>130</td> +
-                            <td>0</td> +
-                            <td>5g/50mL - Glicerofosfato di sodio</td>+
                         </tr>                         </tr>
 +                    </thead>
 +                    <tbody>
                         <tr>                         <tr>
-                            <td><strong>Magnesio Solfato</strong></td> +                            <td><strong>Glicemia</strong></td> 
-                            <td>0</td> +                            <td>Ogni 6-8h</td> 
-                            <td>0</td> +                            <td>70-110 mg/dL</td> 
-                            <td>800</td> +                            <td>Aggiustare velocità glucosio</td>
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>2g/10mL, 1.6 mEq/mL - Elettrolita essenziale</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td><strong>Sodio Cloruro</strong></td> +                            <td><strong>Elettroliti</strong></td> 
-                            <td>0</td> +                            <td>Ogni 24-48h</td> 
-                            <td>0</td> +                            <td>Na: 135-145, K: 3.5-5.0</td> 
-                            <td>0</td> +                            <td>Modificare apporti NPT</td>
-                            <td>1000</td> +
-                            <td>0</td> +
-                            <td>3mEq/mL - Prima scelta per sodio</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td><strong>Sodio Acetato</strong></td> +                            <td><strong>BUN/Creatinina</strong></td> 
-                            <td>0</td> +                            <td>Ogni 48h</td> 
-                            <td>0</td> +                            <td>BUN: 9-14 mg/dL</td> 
-                            <td>0</td> +                            <td>Aggiustare proteine</td>
-                            <td>667</td> +
-                            <td>0</td> +
-                            <td>2 mEq/mL - Alcalinizzante per acidosi</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td><strong>Potassio Cloruro</strong></td> +                            <td><strong>Trigliceridi</strong></td> 
-                            <td>0</td> +                            <td>2 volte/settimana</td> 
-                            <td>0</td> +                            <td>&lt; 150 mg/dL</td> 
-                            <td>0</td> +                            <td>Ridurre lipidi se &gt; 200</td>
-                            <td>0</td> +
-                            <td>1000</td> +
-                            <td>2 mEq/mL - Max vel. 0.5 mEq/kg/h</td>+
                         </tr>                         </tr>
                         <tr>                         <tr>
-                            <td><strong>Trophamine 6%</strong></td> +                            <td><strong>Funzione epatica</strong></td> 
-                            <td>0</td> +                            <td>Settimanale</td> 
-                            <td>0</td> +                            <td>AST/ALT normali</td> 
-                            <td>0</td> +                            <td>Valutare sospensione NPT</td>
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>Aminoacidi pediatrici - 6g/100mL</td> +
-                        </tr> +
-                        <tr> +
-                            <td><strong>Intralipid 20%</strong></td> +
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>0</td> +
-                            <td>Emulsione lipidica - 20g/100mL</td>+
                         </tr>                         </tr>
                     </tbody>                     </tbody>
                 </table>                 </table>
             </div>             </div>
-            <div class="infostyle="margin-top: 15px;"> + 
-                <strong>ℹ️ Informazioni:</strong> Concentrazioni standard utilizzate per i calcoli elettrolitici. I valori sono basati su preparazioni farmaceutiche standard.+            <div class="section"
 +                <h2>⚠️ ALERT AUTOMATICI</h2> 
 +                <div class="alert-critical"> 
 +                    <strong>INTERRUZIONE IMMEDIATA NPT SE:</strong><br> 
 +                    • Glicemia > 250 mg/dL o < 40 mg/dL<br> 
 +                    • 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 class="warning"> 
 +                    <strong>AGGIUSTAMENTI NECESSARI SE:</strong><br> 
 +                    • 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="section"> +            <div class="section"> 
-            <h2>Lista Medici Prescrittori</h2> +                <h2>Impostazioni Ospedale</h2> 
-            <div class="infostyle="margin-bottom: 15px;"> +                <div class="form-row"
-                <strong>🩺 Database Medici:</strongLista dei medici autorizzati alla prescrizione NPT. Questi nomi appaiono nella dropdown del TAB 1. +                    <div class="form-col"> 
-            </div+                        <div class="input-group"> 
-            <div style="overflow-x: auto;"+                            <label for="hospitalName">Nome Ospedale:</label
-                <table class="results-table" style="font-size12px;"> +                            <input type="textid="hospitalName" value="ASST LECCO" style="width250px;"> 
-                    <thead+                        </div
-                        <tr+                        <div class="input-group"
-                            <th>Nome</th+                            <label for="departmentName">Dipartimento:</label
-                            <th>Cognome</th+                            <input type="text" id="departmentName" value="S.C. Neonatologia e TIN" style="width: 250px;"> 
-                            <th>Titolo</th+                        </div> 
-                            <th>Nome Completo (Visualizzato)</th+                        <div class="input-group"
-                        </tr+                            <label for="directorName">Direttore:</label
-                    </thead+                            <input type="text" id="directorName" value="Dott. Roberto Bellù" style="width: 250px;"
-                    <tbody+                        </div
-                        <tr><td>Roberto</td><td>Bellù</td><td>Dr.</td><td><strong>Dr. Roberto Bellù</strong></td></tr+                    </div
-                        <tr><td>Manuela</td><td>Condò</td><td>Dr.ssa</td><td><strong>Dr.ssa Manuela Condò</strong></td></tr+                    <div class="form-col"
-                        <tr><td>Carla</td><td>Maccioni</td><td>Dr.ssa</td><td><strong>Dr.ssa Carla Maccioni</strong></td></tr+                        <div class="input-group"> 
-                        <tr><td>Federica</td><td>Meroni</td><td>Dr.ssa</td><td><strong>Dr.ssa Federica Meroni</strong></td></tr+                            <label for="autoSave">Salvataggio automatico:</label> 
-                        <tr><td>Francesco</td><td>Calzatini</td><td>Dr.</td><td><strong>Dr. Francesco Calzatini</strong></td></tr+                            <select id="autoSave"> 
-                        <tr><td>Elisabetta</td><td>Ferrari</td><td>Dr.ssa</td><td><strong>Dr.ssa Elisabetta Ferrari</strong></td></tr+                                <option value="true">Attivo</option> 
-                    </tbody> +                                <option value="false">Disattivo</option> 
-                </table>+                            </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
 +                <button class="button secondary" onclick="resetConfiguration()">RESET CONFIGURAZIONE</button
 +                <button class="button" onclick="saveConfiguration()">SALVA CONFIGURAZIONE</button>
             </div>             </div>
         </div>         </div>
  
-        <div class="section"> +        <div id="configResults" class="results hidden"> 
-            <h2>Informazioni Sistema</h2+            <h3>Stato Configurazione v3.0</h3
-            <div class="info"> +            <div id="configInfo"></div>
-                <strong>📊 NPT Calculator v2.0 - Stato Sistema</strong><br> +
-                <strong>• Database Formule:</strong> 9 formule enterali configurate<br> +
-                <strong>• Database Componenti:</strong> 8 componenti parenterali configurati<br> +
-                <strong>• Medici Prescrittori:</strong> 6 medici autorizzati<br> +
-                <strong>• Algoritmi:</strong> Calcoli BUN, fasi nutrizionali, elettroliti automatici<br> +
-                <strong>• Report:</strong> Foglio di lavoro + Report parenterale completo<br> +
-                <strong>• Ultimo Aggiornamento:</strong> Luglio 2025 +
-            </div>+
         </div>         </div>
     </div>     </div>
Linea 1198: 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 1211: Linea 1219:
 }; };
  
-// CONFIGURAZIONI PARENTERALI COMPLETE+// CONFIGURAZIONI PARENTERALI COMPLETE (DA VERSIONE 17)
 const parenteralConfig = { const parenteralConfig = {
 +    trophamine: {
 +        name: "Trophamine 6%",
 +        protein: 6.0, carbs: 0, lipids: 0, sodium: 0, potassium: 0,
 +        calcium: 0, phosphorus: 0, magnesium: 0, energy: 24, water: 94,
 +        description: "Soluzione di aminoacidi pediatrica",
 +        notes: "Soluzione sterile per uso endovenoso. Osmolarità: ~360 mOsm/L"
 +    },
 +    intralipid: {
 +        name: "Intralipid 20%",
 +        protein: 0, carbs: 0, lipids: 20.0, sodium: 0, potassium: 0,
 +        calcium: 0, phosphorus: 0, magnesium: 0, energy: 200, water: 80,
 +        description: "Emulsione lipidica endovenosa",
 +        notes: "Fornisce acidi grassi essenziali. Max 4g/kg/die"
 +    },
 +    glucose50: {
 +        name: "Glucosio 50%",
 +        protein: 0, carbs: 50.0, lipids: 0, sodium: 0, potassium: 0,
 +        calcium: 0, phosphorus: 0, magnesium: 0, energy: 200, water: 50,
 +        description: "Soluzione glucosata molto ipertonica",
 +        notes: "Osmolarità: ~2800 mOsm/L. Solo per alte concentrazioni"
 +    },
     ca_gluconato: {     ca_gluconato: {
-        name: "Calcio Gluconato 10%", +        name: "Calcio Gluconato 10% (1g/10mL, 0.44 mEq/mL)", 
-        calcium840phosphorus: 0, magnesium: 0, sodium: 0, potassium: 0, +        protein0carbs: 0, lipids: 0, sodium: 0, potassium: 0, 
-        protein0carbs: 0, lipids: 0, energy: 0, water: 90+        calcium840phosphorus: 0, magnesium: 0, energy: 0, water: 90
 +        description: "Sale di calcio organico", 
 +        notes: "8.4 mg Ca/ml. Non precipita con fosfati"
     },     },
     esafosfina: {     esafosfina: {
-        name: "Esafosfina", +        name: "Esafosfina (5g/50mL)", 
-        calcium: 0, phosphorus1600magnesium: 0, sodium: 130, potassium: 0, +        protein: 0, carbs0lipids: 0, sodium: 130, potassium: 0, 
-        protein: 0, carbs0lipids: 0, energy: 0, water: 98+        calcium: 0, phosphorus1600magnesium: 0, energy: 0, water: 98
 +        description: "Glicerofosfato di sodio", 
 +        notes: "16 mg P/ml + 1.3 mEq Na/ml. Fosforo organico"
     },     },
     mg_sulfate: {     mg_sulfate: {
-        name: "Magnesio Solfato", +        name: "Magnesio Solfato (2g/10ml, 1.6 mEq/mL)", 
-        calcium: 0, phosphorus: 0, magnesium800, sodium: 0, potassium: 0, +        protein: 0, carbs: 0, lipids0, sodium: 0, potassium: 0, 
-        protein: 0, carbs: 0, lipids0, energy: 0, water: 99+        calcium: 0, phosphorus: 0, magnesium800, energy: 0, water: 99
 +        description: "Elettrolita essenziale", 
 +        notes: "8 mEq Mg/ml. Cofattore enzimatico"
     },     },
     nacl: {     nacl: {
-        name: "Sodio Cloruro", +        name: "Sodio Cloruro (3mEq/mL)", 
-        calcium: 0, phosphorus: 0, magnesium: 0, sodium: 1000, potassium: 0, +        protein: 0, carbs: 0, lipids: 0, sodium: 1000, potassium: 0, 
-        protein: 0, carbs: 0, lipids: 0, energy: 0, water: 99+        calcium: 0, phosphorus: 0, magnesium: 0, energy: 0, water: 99
 +        description: "Elettrolita essenziale", 
 +        notes: "10 mEq Na/ml. Prima scelta per supplementazione sodio"
     },     },
     sodium_acetate: {     sodium_acetate: {
-        name: "Sodio Acetato", +        name: "Sodio Acetato (2 mEq/mL)", 
-        calcium: 0, phosphorus: 0, magnesium: 0, sodium: 667, potassium: 0, +        protein: 0, carbs: 0, lipids: 0, sodium: 667, potassium: 0, 
-        protein: 0, carbs: 0, lipids: 0, energy: 0, water: 99+        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: {
-        name: "Potassio Cloruro", +        name: "Potassio Cloruro (2 mEq/mL)", 
-        calcium: 0, phosphorus: 0, magnesium: 0, sodium: 0, potassium: 1000, +        protein: 0, carbs: 0, lipids: 0, sodium: 0, potassium: 1000
-        protein: 0, carbs: 0, lipids: 0, energy: 0, water: 99+        calcium: 0, phosphorus: 0, magnesium: 0, energy: 0, water: 99, 
 +        description: "Elettrolita essenziale", 
 +        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"
     }     }
 }; };
  
-// Database medici +// Database fortificanti dinamico 
-const doctorsData = {+let fortifierData = { 
 +    prenidina_fm85:
 +        name: "Prenidina FM85", 
 +        protein: 14, carbs: 4, lipids: 2.5, sodium: 2, potassium: 15, 
 +        calcium: 3500, phosphorus: 2000, magnesium: 150, energy: 400, 
 +        dose: "1-4g/100ml" 
 +    } 
 +}; 
 + 
 +// Database medici dinamico 
 +let doctorsData = {
     dr_bellu: { name: "Roberto", surname: "Bellù", title: "Dr.", fullName: "Dr. Roberto Bellù" },     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_condo: { name: "Manuela", surname: "Condò", title: "Dr.ssa", fullName: "Dr.ssa Manuela Condò" },
Linea 1252: Linea 1311:
     dr_meroni: { name: "Federica", surname: "Meroni", title: "Dr.ssa", fullName: "Dr.ssa Federica Meroni" },     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_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_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 1258: Linea 1328:
 let patientData = {}; let patientData = {};
 let enteralData = null; let enteralData = null;
-window.currentActiveReport = null;+let currentRequirements = null;
  
-// INIZIALIZZAZIONE +// CONFIGURAZIONE CLINICA AVANZATA (NUOVO) 
-document.addEventListener('DOMContentLoaded', function() { +let clinicalConfig = { 
-    // Imposta data odierna +    calciumReq: 160, 
-    const today new Date().toISOString().split('T')[0]+    phosphorusReq: 84, 
-    document.getElementById('prescriptionDate').value = today+    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ù" 
 +}; 
 + 
 +// FUNZIONE RESET PULSANTE FABBISOGNI 
 +function resetNutritionButton() { 
 +    const nutritionBtn = document.getElementById('calculateNutritionBtn'); 
 +    if (nutritionBtn) { 
 +        nutritionBtn.className = 'button calculate-nutrition-pending'; 
 +        nutritionBtn.innerHTML = 'RICALCOLA FABBISOGNI'; 
 +         
 +        // Nascondi i risultati precedenti 
 +        const nutritionResults = document.getElementById('nutritionResults'); 
 +        if (nutritionResults) { 
 +            nutritionResults.classList.add('hidden'); 
 +        } 
 +         
 +        // Reset anche il pulsante NPT perché i fabbisogni sono cambiati 
 +        resetParenteralButton(); 
 +    
 +
 + 
 +// FUNZIONE RESET PULSANTE PARENTERALE 
 +function resetParenteralButton() { 
 +    const parenteralBtn document.getElementById('calculateParenteralBtn')
 +    if (parenteralBtn) { 
 +        parenteralBtn.className = 'button'; 
 +        parenteralBtn.innerHTML = 'CALCOLA NPT AUTOMATICA'; 
 +         
 +        // Reset anche i 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 TAB+// FUNZIONE CORRETTA PER CAMBIO TAB
 function showTab(tabId) { function showTab(tabId) {
-    // Rimuovi classe active da tutti i contenuti+    // Nascondi tutti i contenuti dei tab
     document.querySelectorAll('.tab-content').forEach(content => {     document.querySelectorAll('.tab-content').forEach(content => {
         content.classList.remove('active');         content.classList.remove('active');
     });     });
          
-    // Rimuovi classe active da tutte le tab+    // Rimuovi classe active da tutti i tab
     document.querySelectorAll('.tab').forEach(tab => {     document.querySelectorAll('.tab').forEach(tab => {
         tab.classList.remove('active');         tab.classList.remove('active');
     });     });
          
-    // Mostra il contenuto selezionato+    // Mostra il contenuto del tab selezionato
     const targetContent = document.getElementById(tabId);     const targetContent = document.getElementById(tabId);
     if (targetContent) {     if (targetContent) {
Linea 1285: Linea 1400:
     }     }
          
-    // Attiva la tab cliccata +    // Trova e attiva il tab cliccato 
-    event.target.closest('.tab').classList.add('active');+    const clickedTab = event.target.closest('.tab')
 +    if (clickedTab) { 
 +        clickedTab.classList.add('active'); 
 +    } 
 +     
 +    // Popola le tabelle di configurazione quando si apre il TAB 6 (ora config) 
 +    if (tabId === 'config') { 
 +        setTimeout(() => { 
 +            populateEnteralConfigTable(); 
 +            populateParenteralConfigTable(); 
 +            populateDoctorsConfigTable(); 
 +        }, 100); 
 +    }
 } }
  
-// FUNZIONE CALCOLO FASE+// 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 medicalRecord = document.getElementById('medicalRecord').value;     const medicalRecord = document.getElementById('medicalRecord').value;
-    const birthWeight = parseInt(document.getElementById('birthWeight').value); +    const phaseBirthWeight = parseInt(document.getElementById('birthWeight').value); 
-    const currentWeight = parseInt(document.getElementById('currentWeight').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 1302: Linea 1495:
     const diuresis = document.getElementById('diuresis').value;     const diuresis = document.getElementById('diuresis').value;
     const prescriptionDate = document.getElementById('prescriptionDate').value;     const prescriptionDate = document.getElementById('prescriptionDate').value;
-    const prescribingDoctor = document.getElementById('prescribingDoctor').value;+    const prescribingDoctorValue = document.getElementById('prescribingDoctor').value
 +     
 +    // Trova il nome completo del medico 
 +    const doctorFullName = prescribingDoctorValue && doctorsData[prescribingDoctorValue] ?  
 +                          doctorsData[prescribingDoctorValue].fullName : '';
          
     patientData = {     patientData = {
         medicalRecord: medicalRecord,         medicalRecord: medicalRecord,
-        birthWeight: birthWeight,  +        birthWeight: phaseBirthWeight,  
-        currentWeight: currentWeight+        currentWeight: phaseCurrentWeight
         daysOfLife: daysOfLife,         daysOfLife: daysOfLife,
         bun: bun,         bun: bun,
Linea 1316: Linea 1513:
         diuresis: diuresis,         diuresis: diuresis,
         prescriptionDate: prescriptionDate,         prescriptionDate: prescriptionDate,
-        prescribingDoctor: prescribingDoctor+        prescribingDoctor: prescribingDoctorValue, 
 +        prescribingDoctorName: doctorFullName
     };     };
          
Linea 1330: Linea 1528:
         if (bunValue < 9) {         if (bunValue < 9) {
             bunStatus = 'Basso - Aumentare proteine';             bunStatus = 'Basso - Aumentare proteine';
-            bunWarning = 'BUN basso: considerare aumento proteine';+            bunWarning = 'BUN basso: considerare aumento fortificazione proteica (+1%)';
         } else if (bunValue > 14) {         } else if (bunValue > 14) {
             bunStatus = 'Elevato - Ridurre proteine';             bunStatus = 'Elevato - Ridurre proteine';
-            bunWarning = 'BUN elevato: ridurre proteine';+            bunWarning = 'BUN elevato: ridurre fortificazione proteica (-1%)';
         } else {         } else {
             bunStatus = 'Normale (9-14 mg/dL)';             bunStatus = 'Normale (9-14 mg/dL)';
Linea 1339: Linea 1537:
     } else {     } else {
         bunStatus = 'Non inserito';         bunStatus = 'Non inserito';
 +    }
 +    
 +    // Analisi altri parametri
 +    let otherWarnings = [];
 +    
 +    if (glucose && glucose !== '') {
 +        const glucoseValue = parseFloat(glucose);
 +        if (glucoseValue < 70) {
 +            otherWarnings.push('⚠️ Ipoglicemia: considerare riduzione velocità glucosio');
 +        } else if (glucoseValue > 150) {
 +            otherWarnings.push('⚠️ Iperglicemia: ridurre concentrazione glucosio NPT');
 +        }
 +    }
 +    
 +    if (sodium && sodium !== '') {
 +        const sodiumValue = parseFloat(sodium);
 +        if (sodiumValue < 135) {
 +            otherWarnings.push('⚠️ Iponatremia: aumentare sodio in NPT');
 +        } else if (sodiumValue > 145) {
 +            otherWarnings.push('⚠️ Ipernatremia: ridurre sodio, aumentare liquidi');
 +        }
 +    }
 +    
 +    if (ph && ph !== '') {
 +        const phValue = parseFloat(ph);
 +        if (phValue < 7.35) {
 +            otherWarnings.push('⚠️ Acidosi: valutare bicarbonato o ridurre cloruri');
 +        } else if (phValue > 7.45) {
 +            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');
 +        }
 +    }
 +    
 +    if (diuresis && diuresis !== '') {
 +        const diuresisValue = parseFloat(diuresis);
 +        if (diuresisValue < 1) {
 +            otherWarnings.push('⚠️ Oliguria: ridurre liquidi, controllare funzione renale');
 +        } else if (diuresisValue > 3) {
 +            otherWarnings.push('⚠️ Poliuria: aumentare liquidi, controllare osmolarità');
 +        }
     }     }
          
Linea 1348: Linea 1603:
         phaseInfoHtml += '<p><strong>Cartella:</strong> ' + medicalRecord + '</p>';         phaseInfoHtml += '<p><strong>Cartella:</strong> ' + medicalRecord + '</p>';
     }     }
-    phaseInfoHtml += '<p><strong>Peso:</strong> ' + currentWeight + 'g (nascita: ' + birthWeight + 'g)</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 1356: Linea 1611:
     if (patientData.bun) {     if (patientData.bun) {
         phaseInfoHtml += '<p><strong>BUN:</strong> ' + patientData.bun + ' mg/dL (' + bunStatus + ')</p>';         phaseInfoHtml += '<p><strong>BUN:</strong> ' + patientData.bun + ' mg/dL (' + bunStatus + ')</p>';
 +    }
 +    if (patientData.glucose) {
 +        const gluStatus = parseFloat(patientData.glucose) >= 70 && parseFloat(patientData.glucose) <= 110 ? 'Normale' : 'Fuori range';
 +        phaseInfoHtml += '<p><strong>Glicemia:</strong> ' + patientData.glucose + ' mg/dL (' + gluStatus + ')</p>';
 +    }
 +    if (patientData.sodium) {
 +        const naStatus = parseFloat(patientData.sodium) >= 135 && parseFloat(patientData.sodium) <= 145 ? 'Normale' : 'Fuori range';
 +        phaseInfoHtml += '<p><strong>Natremia:</strong> ' + patientData.sodium + ' mEq/L (' + naStatus + ')</p>';
 +    }
 +    if (patientData.ph) {
 +        const phStatus = parseFloat(patientData.ph) >= 7.35 && parseFloat(patientData.ph) <= 7.45 ? 'Normale' : 'Fuori range';
 +        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) {
 +        const diuStatus = parseFloat(patientData.diuresis) >= 1 && parseFloat(patientData.diuresis) <= 3 ? 'Normale' : 'Fuori range';
 +        phaseInfoHtml += '<p><strong>Diuresi:</strong> ' + patientData.diuresis + ' mL/kg/die (' + diuStatus + ')</p>';
     }     }
     phaseInfoHtml += '</div>';     phaseInfoHtml += '</div>';
Linea 1362: Linea 1637:
     if (bunWarning) {     if (bunWarning) {
         phaseInfoHtml += '<div class="info"><strong>Nota BUN:</strong> ' + bunWarning + '</div>';         phaseInfoHtml += '<div class="info"><strong>Nota BUN:</strong> ' + bunWarning + '</div>';
 +    }
 +    
 +    if (otherWarnings.length > 0) {
 +        phaseInfoHtml += '<div class="warning"><strong>Avvertenze Cliniche:</strong><br>' + otherWarnings.join('<br>') + '</div>';
     }     }
          
Linea 1372: Linea 1651:
     document.getElementById('calculatePhaseBtn').innerHTML = 'FASE CALCOLATA ✓';     document.getElementById('calculatePhaseBtn').innerHTML = 'FASE CALCOLATA ✓';
          
 +    // Aggiorna il suggerimento sodio se il TAB 3 è già stato visitato
     updateSodiumRecommendation();     updateSodiumRecommendation();
 +    
 +    // RESET anche il pulsante NPT
 +    resetParenteralButton();
 } }
  
-function updateSodiumRecommendation() { +// FUNZIONE AGGIORNAMENTO OPZIONI FORTIFICANTE
-    // Implementazione vuota per ora +
-+
- +
-// FUNZIONE FORTIFICANTE+
 function updateFortifierOptions() { function updateFortifierOptions() {
     const formulaType = document.getElementById('formulaType').value;     const formulaType = document.getElementById('formulaType').value;
     const fortifierSection = document.getElementById('fortifierSection');     const fortifierSection = document.getElementById('fortifierSection');
 +    const fortifierSelect = document.getElementById('fortifierType');
          
     if (formulaType === 'maternal') {     if (formulaType === 'maternal') {
         fortifierSection.classList.remove('hidden');         fortifierSection.classList.remove('hidden');
 +        
 +        fortifierSelect.innerHTML = '<option value="none">Nessun fortificante</option>';
 +        Object.keys(fortifierData).forEach(function(key) {
 +            const option = document.createElement('option');
 +            option.value = key;
 +            option.textContent = fortifierData[key].name;
 +            fortifierSelect.appendChild(option);
 +        });
     } else {     } else {
         fortifierSection.classList.add('hidden');         fortifierSection.classList.add('hidden');
 +        fortifierSelect.value = 'none';
     }     }
 } }
  
 +// FUNZIONE AGGIORNAMENTO DISPLAY CONCENTRAZIONE
 function updateConcentrationDisplay() { function updateConcentrationDisplay() {
     const concentration = document.getElementById('fortifierConcentration').value;     const concentration = document.getElementById('fortifierConcentration').value;
Linea 1396: Linea 1686:
 } }
  
-// FUNZIONE CALCOLO ENTERALE+// 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 1434: Linea 1734:
         const volumePerKg = (dailyVolume / currentWeight) * 1000;         const volumePerKg = (dailyVolume / currentWeight) * 1000;
                  
 +        // Calcoli finali per kg di peso
         enteralData = {         enteralData = {
             volume: dailyVolume,             volume: dailyVolume,
Linea 1453: Linea 1754:
         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) {
-            tableHtml += '<strong>Altri liquidi:</strong> ' + additionalFluids + ' ml<br>';+            tableHtml += '<strong>Altri liquidi:</strong> ' + additionalFluids + ' ml (' + ((additionalFluids/currentWeight)*1000).toFixed(1) + ' ml/kg/die)<br>';
             tableHtml += '<strong>💧 TOTALE LIQUIDI:</strong> ' + totalFluids + ' ml (' + totalFluidsPerKg.toFixed(1) + ' ml/kg/die)';             tableHtml += '<strong>💧 TOTALE LIQUIDI:</strong> ' + totalFluids + ' ml (' + totalFluidsPerKg.toFixed(1) + ' ml/kg/die)';
         } else {         } else {
Linea 1473: Linea 1774:
     document.getElementById('enteralResults').classList.remove('hidden');     document.getElementById('enteralResults').classList.remove('hidden');
          
 +    // Aggiorna il pulsante a verde
     const enteralBtn = document.getElementById('calculateEnteralBtn');     const enteralBtn = document.getElementById('calculateEnteralBtn');
     if (enteralBtn) {     if (enteralBtn) {
Linea 1478: 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 DEFAULT+// 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 1517: 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.: 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;
          
-    // Vitamine/oligoelementi +    // Gestione automatica tipo di sodio basata sui parametri clinici 
-    const currentWeight = patientData.currentWeight; +    const sodiumSelect = document.getElementById('sodiumType'); 
-    const enteralVolumePerKg = enteralData ? (enteralData.totalFluids / currentWeight * 1000) : 0;+    if (patientData.ph || patientData.baseExcess) { 
 +        const ph = patientData.ph ? parseFloat(patientData.ph) : null; 
 +        const be = patientData.baseExcess ? parseFloat(patientData.baseExcess) : null; 
 +         
 +        // Auto-seleziona Sodio Acetato se acidosi 
 +        if ((ph && ph < 7.30) || (be && be < -4)) { 
 +            sodiumSelect.value = 'sodium_acetate'; 
 +        } else { 
 +            sodiumSelect.value = 'nacl'; 
 +        } 
 +    } 
 +     
 +    // Aggiorna il suggerimento sodio 
 +    updateSodiumRecommendation(); 
 +     
 +    // Gestione vitamine/oligoelementi con controllo enterale 
 +    const patientCurrentWeight = patientData.currentWeight; 
 +    const enteralVolumePerKg = enteralData ? (enteralData.totalFluids / patientCurrentWeight * 1000) : 0;
          
     if (targetDay >= 3 && enteralVolumePerKg < 100) {     if (targetDay >= 3 && enteralVolumePerKg < 100) {
Linea 1532: Linea 1868:
         document.getElementById('reqPeditrace').value = 1.0;         document.getElementById('reqPeditrace').value = 1.0;
     } else {     } 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('reqVitalipid').value = 0;
         document.getElementById('reqSoluvit').value = 0;         document.getElementById('reqSoluvit').value = 0;
Linea 1537: Linea 1874:
     }     }
          
-    document.getElementById('reqCarnitine').value = 0;+    document.getElementById('reqCarnitine').value = 0; // La carnitina verrà gestita separatamente
          
-    const loadBtn = document.getElementById('loadDefaultsBtn')+    document.getElementById('loadDefaultsBtn').className = 'button load-defaults-completed'; 
-    if (loadBtn) { +    document.getElementById('loadDefaultsBtn').innerHTML = 'Valori Caricati ✓'; 
-        loadBtn.className = 'button load-defaults-completed'; +     
-        loadBtn.innerHTML = 'Valori Standard Caricati ✓'; +    // RESET del pulsante Fabbisogni quando si modificano i valori standard 
-    }+    resetNutritionButton();
 } }
  
 +// FUNZIONE AGGIORNAMENTO UNITÀ CARBOIDRATI
 function updateCarbUnit() { function updateCarbUnit() {
     const unit = document.getElementById('carbUnit').value;     const unit = document.getElementById('carbUnit').value;
Linea 1560: Linea 1898:
         carbInput.setAttribute('step', '0.1');         carbInput.setAttribute('step', '0.1');
     }     }
 +    
 +    // Reset fabbisogni quando si cambia unità
 +    resetNutritionButton();
 } }
  
 +// FUNZIONE AGGIORNAMENTO CATEGORIA PESO
 function updateWeightCategory() { function updateWeightCategory() {
-    // Placeholder+    // Reset fabbisogni quando si cambia categoria peso 
 +    resetNutritionButton();
 } }
  
 +// FUNZIONE AGGIORNAMENTO TIPO SODIO
 function updateSodiumChoice() { function updateSodiumChoice() {
-    // Placeholder+    // Resetta i fabbisogni quando si cambia il tipo di sodio 
 +    resetNutritionButton();
 } }
  
-// FUNZIONE CALCOLO FABBISOGNI+// 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 1598: Linea 2015:
         (requirements.carbs * 1440 / 1000) : requirements.carbs;         (requirements.carbs * 1440 / 1000) : requirements.carbs;
          
-    const currentWeight = patientData.currentWeight;+    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 1671: Linea 2089:
     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+// FUNZIONE CALCOLO ELETTROLITI AGGIUNTIVI (DA VERSIONE 17)
 function calculateElectrolyteAdditions(calciumNeeded, phosphorusNeeded, magnesiumNeeded, sodiumNeeded, potassiumNeeded, currentWeightKg) { function calculateElectrolyteAdditions(calciumNeeded, phosphorusNeeded, magnesiumNeeded, sodiumNeeded, potassiumNeeded, currentWeightKg) {
     const additions = {     const additions = {
Linea 1683: Linea 2104:
         kcl: 0,         kcl: 0,
         totalVolume: 0,         totalVolume: 0,
-        providedCalcium: 0, 
-        providedPhosphorus: 0, 
-        providedMagnesium: 0, 
-        providedSodium: 0, 
-        providedPotassium: 0, 
         sodiumSource: 'nacl'         sodiumSource: 'nacl'
     };     };
          
 +    // Determina il tipo di sodio da utilizzare
     const sodiumTypeSelect = document.getElementById('sodiumType');     const sodiumTypeSelect = document.getElementById('sodiumType');
     const selectedSodiumType = sodiumTypeSelect ? sodiumTypeSelect.value : 'nacl';     const selectedSodiumType = sodiumTypeSelect ? sodiumTypeSelect.value : 'nacl';
     additions.sodiumSource = selectedSodiumType;     additions.sodiumSource = selectedSodiumType;
          
-    const totalCalciumNeeded = calciumNeeded * currentWeightKg; +    // Calcola fabbisogni totali per paziente 
-    const totalPhosphorusNeeded = phosphorusNeeded * currentWeightKg; +    const totalCalciumNeeded = calciumNeeded * currentWeightKg; // mg 
-    const totalMagnesiumNeeded = magnesiumNeeded * currentWeightKg; +    const totalPhosphorusNeeded = phosphorusNeeded * currentWeightKg; // mg 
-    const totalSodiumNeeded = sodiumNeeded * currentWeightKg; +    const totalMagnesiumNeeded = magnesiumNeeded * currentWeightKg; // mEq 
-    const totalPotassiumNeeded = potassiumNeeded * currentWeightKg;+    const totalSodiumNeeded = sodiumNeeded * currentWeightKg; // mEq 
 +    const totalPotassiumNeeded = potassiumNeeded * currentWeightKg; // mEq
          
     // Calcio Gluconato 10% (840 mg Ca/100ml)     // Calcio Gluconato 10% (840 mg Ca/100ml)
     if (totalCalciumNeeded > 0) {     if (totalCalciumNeeded > 0) {
         additions.ca_gluconato = totalCalciumNeeded / (parenteralConfig.ca_gluconato.calcium / 100);         additions.ca_gluconato = totalCalciumNeeded / (parenteralConfig.ca_gluconato.calcium / 100);
-        additions.providedCalcium = totalCalciumNeeded; 
     }     }
          
     // Esafosfina (1600 mg P/100ml + 130 mEq Na/100ml)     // Esafosfina (1600 mg P/100ml + 130 mEq Na/100ml)
 +    let sodiumFromEsafosfina = 0;
     if (totalPhosphorusNeeded > 0) {     if (totalPhosphorusNeeded > 0) {
         additions.esafosfina = totalPhosphorusNeeded / (parenteralConfig.esafosfina.phosphorus / 100);         additions.esafosfina = totalPhosphorusNeeded / (parenteralConfig.esafosfina.phosphorus / 100);
-        additions.providedPhosphorus = totalPhosphorusNeeded; +        sodiumFromEsafosfina = (additions.esafosfina * parenteralConfig.esafosfina.sodium / 100);
-        additions.providedSodium += (additions.esafosfina * parenteralConfig.esafosfina.sodium / 100);+
     }     }
          
Linea 1717: Linea 2134:
     if (totalMagnesiumNeeded > 0) {     if (totalMagnesiumNeeded > 0) {
         additions.mg_sulfate = totalMagnesiumNeeded / (parenteralConfig.mg_sulfate.magnesium / 100);         additions.mg_sulfate = totalMagnesiumNeeded / (parenteralConfig.mg_sulfate.magnesium / 100);
-        additions.providedMagnesium = totalMagnesiumNeeded; 
     }     }
          
-    // Sodio rimanente +    // Sodio rimanente (dopo quello da Esafosfina) 
-    const remainingSodium = Math.max(0, totalSodiumNeeded - additions.providedSodium);+    const remainingSodium = Math.max(0, totalSodiumNeeded - sodiumFromEsafosfina);
          
     if (remainingSodium > 0) {     if (remainingSodium > 0) {
Linea 1731: Linea 2147:
             additions.nacl = remainingSodium / concentrationNaCl;             additions.nacl = remainingSodium / concentrationNaCl;
         }         }
-        additions.providedSodium += remainingSodium; 
     }     }
          
Linea 1737: Linea 2152:
     if (totalPotassiumNeeded > 0) {     if (totalPotassiumNeeded > 0) {
         additions.kcl = totalPotassiumNeeded / (parenteralConfig.kcl.potassium / 100);         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.sodium_acetate + additions.kcl;     additions.totalVolume = additions.ca_gluconato + additions.esafosfina + additions.mg_sulfate + additions.nacl + additions.sodium_acetate + additions.kcl;
          
Linea 1745: Linea 2160:
 } }
  
-// FUNZIONE CALCOLO NPT PARENTERALE+// FUNZIONE CALCOLO NPT PARENTERALE (DA VERSIONE 17 CON CONTROLLI CLINICI)
 function calculateParenteral() { function calculateParenteral() {
     if (!window.residualNeeds) {     if (!window.residualNeeds) {
Linea 1752: 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
     const totalVolume = Math.round(residualNeeds.liquids * currentWeightKg);     const totalVolume = Math.round(residualNeeds.liquids * currentWeightKg);
          
 +    // CALCOLA ELETTROLITI AGGIUNTIVI
     const electrolyteAdditions = calculateElectrolyteAdditions(     const electrolyteAdditions = calculateElectrolyteAdditions(
         residualNeeds.calcium,         residualNeeds.calcium,
Linea 1767: Linea 2198:
     );     );
          
 +    // Volume proteine (Trophamine 6%)
     const proteinVolume = Math.round((residualNeeds.protein * currentWeightKg * 100) / 6);     const proteinVolume = Math.round((residualNeeds.protein * currentWeightKg * 100) / 6);
 +    
 +    // Volume lipidi (Intralipid 20%)
     const lipidVolume = Math.round((residualNeeds.lipids * currentWeightKg * 100) / 20);     const lipidVolume = Math.round((residualNeeds.lipids * currentWeightKg * 100) / 20);
          
 +    // Volume vitamine/oligoelementi/carnitina
     const vitaminsVolume = (residualNeeds.vitalipid * currentWeightKg) + (residualNeeds.soluvit * currentWeightKg) + (residualNeeds.peditrace * currentWeightKg);     const vitaminsVolume = (residualNeeds.vitalipid * currentWeightKg) + (residualNeeds.soluvit * currentWeightKg) + (residualNeeds.peditrace * currentWeightKg);
     const carnitineVolume = residualNeeds.carnitine > 0 ? (residualNeeds.carnitine * currentWeightKg) / 100 : 0;     const carnitineVolume = residualNeeds.carnitine > 0 ? (residualNeeds.carnitine * currentWeightKg) / 100 : 0;
          
-    const neededGlucose = residualNeeds.carbs * currentWeightKg; +    // CALCOLO CON GLUCOSIO 50% + ACQUA BIDISTILLATA 
-    const glucose50Volume = (neededGlucose * 100) / 50;+    const neededGlucose = residualNeeds.carbs * currentWeightKg; // grammi totali di glucosio 
 +    const glucose50Volume = (neededGlucose * 100) / 50; // ml di glucosio 50% necessari
          
 +    // Volume utilizzato
     const usedVolume = proteinVolume + lipidVolume + vitaminsVolume + carnitineVolume + glucose50Volume + electrolyteAdditions.totalVolume;     const usedVolume = proteinVolume + lipidVolume + vitaminsVolume + carnitineVolume + glucose50Volume + electrolyteAdditions.totalVolume;
 +    
 +    // Volume rimanente = Acqua Bidistillata
     const waterVolume = totalVolume - usedVolume;     const waterVolume = totalVolume - usedVolume;
-     
-    let glucoseMessage = ''; 
-     
-    if (waterVolume < 0) { 
-        glucoseMessage = '<div class="warning"><strong>ERRORE CALCOLO:</strong><br>' + 
-                        '• Volume totale richiesto: ' + totalVolume + ' ml<br>' + 
-                        '• Volume utilizzato: ' + usedVolume.toFixed(1) + ' ml<br>' + 
-                        '• Acqua rimanente: ' + waterVolume.toFixed(1) + ' ml (NEGATIVO!)<br><br>' + 
-                        '<strong>SOLUZIONE:</strong> Aumentare il volume totale NPT.</div>'; 
-         
-        document.getElementById('calculatedTotalVolume').value = totalVolume + ' ml (ERRORE)'; 
-        document.getElementById('suggestedGlucose').value = 'Errore - Volume insufficiente'; 
-        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 proviene dall\'alimentazione enterale<br>' + 
-                        '• Non necessario glucosio in NPT</div>'; 
-         
-        document.getElementById('suggestedGlucose').value = 'Non necessario (enterale sufficiente)'; 
-    } else { 
-        glucoseMessage = '<div class="info"><strong>CALCOLO GLUCOSIO:</strong><br>' + 
-                        '• Glucosio necessario: ' + neededGlucose.toFixed(1) + 'g<br>' + 
-                        '• Glucosio 50%: ' + glucose50Volume.toFixed(1) + 'ml<br>' + 
-                        '• Acqua bidistillata: ' + waterVolume.toFixed(1) + 'ml<br>' + 
-                        '• <strong>Concentrazione finale: ' + ((neededGlucose * 100) / totalVolume).toFixed(1) + '%</strong></div>'; 
-         
-        document.getElementById('suggestedGlucose').value = 'Glucosio 50% + Acqua'; 
-    } 
          
     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 += '<strong>Peso:</strong> ' + parentCurrentWeight + 'g<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>'; 
 +    if (enteralData && enteralData.additionalFluids > 0) { 
 +        resultHtml += '<strong>→ Latte:</strong> ' + (enteralData.volume || 0) + ' ml, <strong>Altri liquidi:</strong> ' + enteralData.additionalFluids + ' ml<br>'; 
 +    } 
 +    resultHtml += '</div>';
          
-    resultHtml += '<div class="info">'; +    // MOSTRA ALERT CLINICI SE PRESENTI 
-    resultHtml += '<strong>NPT v2.0 - COMPOSIZIONE COMPLETA</strong><br>'; +    if (alerts.length > 0) { 
-    resultHtml += '<strong>Peso:</strong> ' + currentWeight + 'g<br>'; +        resultHtml += '<div class="alert-critical"><strong>ALERT CLINICI:</strong><br>'alerts.join('<br>'+ '</div>'; 
-    resultHtml += '<strong>Enterale:</strong> ' + (enteralData ? enteralData.totalFluids : 0) + ml<br>'+    }
-    resultHtml +'</div>';+
          
     resultHtml += '<table class="results-table">';     resultHtml += '<table class="results-table">';
Linea 1834: Linea 2246:
          
     resultHtml += '<tr><td><strong>Trophamine 6%</strong></td><td><strong>' + proteinVolume.toFixed(1) + '</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>'Math.max(0, lipidVolume).toFixed(1) + '</strong></td></tr>';+    resultHtml += '<tr><td><strong>Intralipid 20%</strong></td><td><strong>' + lipidVolume.toFixed(1) + '</strong></td></tr>';
          
 +    // 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 1843: Linea 2256:
     }     }
     if (electrolyteAdditions.mg_sulfate > 0) {     if (electrolyteAdditions.mg_sulfate > 0) {
-        resultHtml += '<tr><td><strong>Magnesio Solfato (2g/10mL, 1.6 mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.mg_sulfate.toFixed(1) + '</strong></td></tr>';+        resultHtml += '<tr><td><strong>Magnesio Solfato (2g/10ml, 1.6 mEq/mL)</strong></td><td><strong>' + electrolyteAdditions.mg_sulfate.toFixed(1) + '</strong></td></tr>';
     }     }
     if (electrolyteAdditions.nacl > 0) {     if (electrolyteAdditions.nacl > 0) {
Linea 1855: Linea 2268:
     }     }
          
 +    // VITAMINE
     if (residualNeeds.vitalipid > 0) {     if (residualNeeds.vitalipid > 0) {
         const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg;         const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg;
Linea 1868: Linea 2282:
     }     }
          
 +    // CARNITINA
     if (residualNeeds.carnitine > 0) {     if (residualNeeds.carnitine > 0) {
-        resultHtml += '<tr><td><strong>Carnitene</strong></td><td><strong>' + carnitineVolume.toFixed(1) + '</strong></td></tr>';+        resultHtml += '<tr><td><strong>Carnitene (100 mg/ml)</strong></td><td><strong>' + carnitineVolume.toFixed(1) + '</strong></td></tr>';
     }     }
          
 +    // ACQUA BIDISTILLATA
     if (waterVolume > 0) {     if (waterVolume > 0) {
         resultHtml += '<tr><td><strong>Acqua Bidistillata</strong></td><td><strong>' + waterVolume.toFixed(1) + '</strong></td></tr>';         resultHtml += '<tr><td><strong>Acqua Bidistillata</strong></td><td><strong>' + waterVolume.toFixed(1) + '</strong></td></tr>';
Linea 1881: Linea 2297:
     document.getElementById('parenteralTable').innerHTML = resultHtml;     document.getElementById('parenteralTable').innerHTML = resultHtml;
          
-    // PREPARAZIONE CON DEFLUSSORE+    // CREAZIONE RICETTA PER PREPARAZIONE
     const deflectorVolume = parseInt(document.getElementById('deflectorVolume').value) || 30;     const deflectorVolume = parseInt(document.getElementById('deflectorVolume').value) || 30;
     const totalVolumeWithDeflector = totalVolume + deflectorVolume;     const totalVolumeWithDeflector = totalVolume + deflectorVolume;
 +    const ratio = totalVolumeWithDeflector / totalVolume;
          
     let preparationHtml = '<div class="info">';     let preparationHtml = '<div class="info">';
-    preparationHtml += '<strong>📋 RICETTA PREPARAZIONE (Deflussore: ' + deflectorVolume + ' ml)</strong><br>';+    preparationHtml += '<strong>📋 RICETTA PER PREPARAZIONE (Volume deflussore: ' + deflectorVolume + ' ml)</strong><br>';
     preparationHtml += '• <strong>Volume prescrizione:</strong> ' + totalVolume + ' ml<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 += '• <strong>Volume totale preparazione:</strong> ' + totalVolumeWithDeflector + ' ml';
     preparationHtml += '</div>';     preparationHtml += '</div>';
          
     preparationHtml += '<table class="results-table">';     preparationHtml += '<table class="results-table">';
-    preparationHtml += '<tr><th>Componente</th><th>Prescrizione (ml)</th><th>Preparazione (ml)</th></tr>'+    preparationHtml += '<tr><th>Componente</th><th>Volume Prescrizione (ml)</th><th>Volume Preparazione (ml)</th></tr>';
-     +
-    const ratio = totalVolumeWithDeflector / totalVolume;+
          
     if (neededGlucose > 0) {     if (neededGlucose > 0) {
Linea 1901: Linea 2317:
          
     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>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>'Math.max(0, lipidVolume).toFixed(1) + '</td><td><strong>' + (Math.max(0, lipidVolume* 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) {     if (electrolyteAdditions.ca_gluconato > 0) {
Linea 1910: Linea 2326:
     }     }
     if (electrolyteAdditions.mg_sulfate > 0) {     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>';+        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) {     if (electrolyteAdditions.nacl > 0) {
Linea 1922: Linea 2338:
     }     }
          
 +    // VITAMINE con denominazioni complete
     if (residualNeeds.vitalipid > 0) {     if (residualNeeds.vitalipid > 0) {
         const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg;         const vitalipidVolume = residualNeeds.vitalipid * currentWeightKg;
Linea 1935: Linea 2352:
     }     }
          
 +    // CARNITINA con denominazione completa
     if (residualNeeds.carnitine > 0) {     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>';         preparationHtml += '<tr><td><strong>Carnitene (100 mg/ml)</strong></td><td>' + carnitineVolume.toFixed(1) + '</td><td><strong>' + (carnitineVolume * ratio).toFixed(1) + '</strong></td></tr>';
Linea 1949: Linea 2367:
     document.getElementById('parenteralResults').classList.remove('hidden');     document.getElementById('parenteralResults').classList.remove('hidden');
          
-    // Salva i dati per report +    document.getElementById('calculateParenteralBtn').className = 'button config-update-completed'; 
-    window.nptCalculationData = { +    document.getElementById('calculateParenteralBtn').innerHTML = 'NPT CALCOLATA ✓'; 
-        currentWeight, currentWeightKg, totalVolume, electrolyteAdditions+     
-        proteinVolume, lipidVolume, vitaminsVolumecarnitineVolume+    // Salva i dati per il report 
-        glucose50VolumewaterVolumeneededGlucoseresidualNeeds+    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 (DA VERSIONE 17)
 +function populateEnteralConfigTable() {
 +    const tbody = document.getElementById('enteralConfigTable');
 +    if (!tbody) return;
          
-    const parenteralBtn = document.getElementById('calculateParenteralBtn'); +    tbody.innerHTML = ''; 
-    if (parenteralBtn) { +    Object.keys(formulaData).forEach(key => { 
-        parenteralBtn.className = 'button config-update-completed'; +        const formula = formulaData[key]; 
-        parenteralBtn.innerHTML = 'NPT CALCOLATA ✓';+        const row = tbody.insertRow(); 
 +        row.innerHTML = '<td class="component-name">' + formula.name + '</td>'
 +            '<td><input type="number" id="config_' + key + '_protein" value="' + formula.protein + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_carbs" value="' + formula.carbs + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_lipids" value="' + formula.lipids + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_sodium" value="' + formula.sodium + '" step="0.001" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_potassium" value="' + formula.potassium + '" step="0.001" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_calcium" value="' + formula.calcium + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_phosphorus" value="' + formula.phosphorus + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_magnesium" value="' + formula.magnesium + '" step="0.1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_energy" value="' + formula.energy + '" step="1" oninput="markConfigChanged(\'enteral\')"></td>'
 +            '<td><button class="button secondary" onclick="removeEnteralFormula(\'' + key + '\')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>'; 
 +    }); 
 +
 + 
 +function populateParenteralConfigTable() { 
 +    const tbody = document.getElementById('parenteralConfigTable'); 
 +    if (!tbody) return; 
 +     
 +    tbody.innerHTML = ''; 
 +    Object.keys(parenteralConfig).forEach(function(key) { 
 +        const component = parenteralConfig[key]; 
 +        const row = tbody.insertRow(); 
 +        row.innerHTML = '<td class="component-name">' + component.name + '</td>'
 +            '<td><input type="number" id="config_' + key + '_protein" value="' + component.protein + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_carbs" value="' + component.carbs + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_lipids" value="' + component.lipids + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_sodium" value="' + component.sodium + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_potassium" value="' + component.potassium + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_calcium" value="' + component.calcium + '" step="1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_phosphorus" value="' + component.phosphorus + '" step="1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_magnesium" value="' + component.magnesium + '" step="0.1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_energy" value="' + component.energy + '" step="1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td><input type="number" id="config_' + key + '_water" value="' + component.water + '" step="1" oninput="markConfigChanged(\'parenteral\')"></td>'
 +            '<td style="font-size: 11px; color: #7f8c8d; max-width: 200px;">' + (component.description || 'Componente') + '<br><em>' + (component.notes || 'Note') + '</em></td>'
 +            '<td><button class="button secondary" onclick="removeParenteralComponent(\'' + key + '\')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>'; 
 +    }); 
 +
 + 
 +function populateDoctorsConfigTable() { 
 +    const tbody = document.getElementById('doctorsConfigTable'); 
 +    if (!tbody) return; 
 +     
 +    tbody.innerHTML = ''; 
 +    Object.keys(doctorsData).forEach(key => { 
 +        const doctor = doctorsData[key]; 
 +        const row = tbody.insertRow(); 
 +        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 + '_title" style="width: 70px;" oninput="markConfigChanged(\'doctors\')">'
 +                '<option value="Dr."' + (doctor.title === 'Dr.' ? ' selected' : '') + '>Dr.</option>'
 +                '<option value="Dr.ssa"' + (doctor.title === 'Dr.ssa' ? ' selected' : '') + '>Dr.ssa</option>'
 +                '<option value="Prof."' + (doctor.title === 'Prof.' ? ' selected' : '') + '>Prof.</option>'
 +                '<option value="Prof.ssa"' + (doctor.title === 'Prof.ssa' ? ' selected' : '') + '>Prof.ssa</option>'
 +            '</select></td>'
 +            '<td style="font-weight: bold; color: #2c3e50;">' + doctor.fullName + '</td>'
 +            '<td><button class="button secondary" onclick="removeDoctor(\'' + key + '\')" style="padding: 5px 10px; font-size: 12px;">Rimuovi</button></td>'; 
 +    }); 
 +
 + 
 +function markConfigChanged(configType) { 
 +    let buttonId = ''; 
 +    let buttonText = ''; 
 +     
 +    switch(configType) { 
 +        case 'enteral': 
 +            buttonId = 'updateEnteralBtn'; 
 +            buttonText = 'SALVA MODIFICHE ENTERALI'; 
 +            break; 
 +        case 'parenteral': 
 +            buttonId = 'updateParenteralBtn'; 
 +            buttonText = 'SALVA MODIFICHE PARENTERALI'; 
 +            break; 
 +        case 'fortifier': 
 +            buttonId = 'updateFortifierBtn'; 
 +            buttonText = 'SALVA MODIFICHE FORTIFICANTI'; 
 +            break; 
 +        case 'doctors': 
 +            buttonId = 'updateDoctorsBtn'; 
 +            buttonText = 'SALVA MODIFICHE MEDICI'; 
 +            break; 
 +        case 'system': 
 +            buttonId = 'updateSystemBtn'; 
 +            buttonText = 'SALVA PARAMETRI SISTEMA'; 
 +            break; 
 +    } 
 +     
 +    const button = document.getElementById(buttonId); 
 +    if (button) { 
 +        button.className = 'button config-update-pending'; 
 +        button.innerHTML = buttonText;
     }     }
 } }
  
-// FUNZIONI REPORT +function updateEnteralConfig() {  
-function generateAndShowWorkReport() { +    let changesCount = 0; 
-    if (!window.nptCalculationData) { +     
-        alert('Prima calcolare la NPT!'); +    Object.keys(formulaData).forEach(key => { 
-        return;+        const oldValues = Object.assign({}, formulaData[key]); 
 +         
 +        const proteinEl = document.getElementById('config_' + key + '_protein'); 
 +        if (proteinEl) { 
 +            formulaData[key].protein = parseFloat(proteinEl.value); 
 +            formulaData[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); 
 +            formulaData[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); 
 +            formulaData[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); 
 +            formulaData[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); 
 +            formulaData[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); 
 +            formulaData[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); 
 +            formulaData[key].magnesium = parseFloat(document.getElementById('config_' + key + '_magnesium').value); 
 +            formulaData[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); 
 +             
 +            if (JSON.stringify(oldValues) !== JSON.stringify(formulaData[key])) { 
 +                changesCount++; 
 +            } 
 +        
 +    }); 
 +     
 +    const button = document.getElementById('updateEnteralBtn'); 
 +    if (button) { 
 +        button.className = 'button config-update-completed'; 
 +        button.innerHTML = 'ENTERALI SALVATE ✓ (' + changesCount + ' modifiche)'; 
 +        setTimeout(() => { 
 +            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Formule Enterali'; 
 +        }, 3000);
     }     }
 +}
 +
 +function updateParenteralConfig() { 
 +    let changesCount = 0;
          
-    const reportHtml generateWorkReportHTML(); +    Object.keys(parenteralConfig).forEach(function(key) { 
-    document.getElementById('nptWorkReport').innerHTML reportHtml+        const oldValues Object.assign({}, parenteralConfig[key]); 
-    document.getElementById('nptWorkReport').classList.remove('hidden'); +         
-    document.getElementById('nptFinalReport').classList.add('hidden'); +        const proteinEl = document.getElementById('config_' + key + '_protein')
-    document.getElementById('printReportBtn').classList.remove('hidden'); +        if (proteinEl) { 
-    window.currentActiveReport = 'work';+            parenteralConfig[key].protein parseFloat(proteinEl.value)
 +            parenteralConfig[key].carbs = parseFloat(document.getElementById('config_' + key + '_carbs').value); 
 +            parenteralConfig[key].lipids = parseFloat(document.getElementById('config_' + key + '_lipids').value); 
 +            parenteralConfig[key].sodium = parseFloat(document.getElementById('config_' + key + '_sodium').value); 
 +            parenteralConfig[key].potassium = parseFloat(document.getElementById('config_' + key + '_potassium').value); 
 +            parenteralConfig[key].calcium = parseFloat(document.getElementById('config_' + key + '_calcium').value); 
 +            parenteralConfig[key].phosphorus = parseFloat(document.getElementById('config_' + key + '_phosphorus').value); 
 +            parenteralConfig[key].magnesium parseFloat(document.getElementById('config_+ key + '_magnesium').value); 
 +            parenteralConfig[key].energy = parseFloat(document.getElementById('config_' + key + '_energy').value); 
 +            parenteralConfig[key].water = parseFloat(document.getElementById('config_' + key + '_water').value); 
 +             
 +            if (JSON.stringify(oldValues) !== JSON.stringify(parenteralConfig[key])) { 
 +                changesCount++; 
 +            } 
 +        } 
 +    });
          
-    const generateBtn = document.getElementById('generateWorkReportBtn'); +    const button = document.getElementById('updateParenteralBtn'); 
-    generateBtn.innerHTML = 'Foglio di Lavoro Generato ✓'; +    if (button) { 
-    generateBtn.className = 'button config-update-completed';+        button.className = 'button config-update-completed'; 
 +        button.innerHTML = 'PARENTERALI SALVATE ✓ (' + changesCount + ' modifiche)'; 
 +        setTimeout(() => { 
 +            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Componenti Parenterali'; 
 +        }, 3000); 
 +    }
 } }
  
-function generateAndShowFinalReport() { +function updateFortifierConfig() {  
-    if (!window.nptCalculationData) { +    // Aggiorna Prenidina FM85 predefinita 
-        alert('Prima calcolare la NPT!'); +    const proteinEl = document.getElementById('fortifier_prenidina_fm85_protein'); 
-        return;+    if (proteinEl) { 
 +        fortifierData.prenidina_fm85.protein = parseFloat(proteinEl.value); 
 +        fortifierData.prenidina_fm85.carbs = parseFloat(document.getElementById('fortifier_prenidina_fm85_carbs').value); 
 +        fortifierData.prenidina_fm85.lipids = parseFloat(document.getElementById('fortifier_prenidina_fm85_lipids').value); 
 +        fortifierData.prenidina_fm85.sodium = parseFloat(document.getElementById('fortifier_prenidina_fm85_sodium').value); 
 +        fortifierData.prenidina_fm85.potassium = parseFloat(document.getElementById('fortifier_prenidina_fm85_potassium').value); 
 +        fortifierData.prenidina_fm85.calcium = parseFloat(document.getElementById('fortifier_prenidina_fm85_calcium').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);
     }     }
          
-    const reportHtml generateFinalReportHTML(); +    const button = document.getElementById('updateFortifierBtn'); 
-    document.getElementById('nptFinalReport').innerHTML = reportHtml+    if (button
-    document.getElementById('nptFinalReport').classList.remove('hidden')+        button.className = 'button config-update-completed'; 
-    document.getElementById('nptWorkReport').classList.add('hidden')+        button.innerHTML = 'FORTIFICANTI SALVATE ✓'
-    document.getElementById('printReportBtn').classList.remove('hidden'); +        setTimeout((=> { 
-    window.currentActiveReport 'final';+            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Fortificanti'
 +        }, 3000)
 +    } 
 +
 + 
 +function updateDoctorsConfig() { 
 +    let changesCount 0;
          
-    const generateBtn = document.getElementById('generateFinalReportBtn'); +    Object.keys(doctorsData).forEach(key => { 
-    generateBtn.innerHTML = 'Report Parenterale Generato ✓'; +        const oldValues = Object.assign({}, doctorsData[key]); 
-    generateBtn.className = 'button config-update-completed';+         
 +        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++; 
 +            } 
 +        } 
 +    }); 
 +     
 +    updateDoctorsDropdown(); 
 +    populateDoctorsConfigTable(); 
 +     
 +    const button = document.getElementById('updateDoctorsBtn'); 
 +    if (button) { 
 +        button.className = 'button config-update-completed'; 
 +        button.innerHTML = 'MEDICI SALVATI ✓ (' + changesCount + ' modifiche)'; 
 +        setTimeout(() => { 
 +            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Lista Medici'; 
 +        }, 3000); 
 +    }
 } }
  
-function generateWorkReportHTML() { +function updateSystemConfig() { 
-    const data window.nptCalculationData; +    const button = document.getElementById('updateSystemBtn'); 
-    const deflectorVolume = parseInt(document.getElementById('deflectorVolume').value) || 30+    if (button) { 
-    const totalVolumeWithDeflector data.totalVolume + deflectorVolume+        button.className 'button config-update-completed'; 
-    const ratio totalVolumeWithDeflector / data.totalVolume;+        button.innerHTML = 'PARAMETRI SALVATI ✓'
 +        setTimeout(() => { 
 +            button.className = 'button'; 
 +            button.innerHTML = 'Aggiorna Parametri Sistema'; 
 +        }, 3000); 
 +    }
          
-    const today new Date(); +    resetParenteralButton(); 
-    const dateStr today.toLocaleDateString('it-IT');+
 + 
 +// 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);
          
-    const doctorName = patientData.prescribingDoctor ?  +    alert('Parametri clinici aggiornati:\n'
-        doctorsData[patientData.prescribingDoctor]?.fullName || 'N/A' : 'N/A';+          '• 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;
          
-    const infusionRate = (data.totalVolume 24).toFixed(2); +    // Reset configurazione sistema 
-    const finalConcentration = data.neededGlucose > 0 ? (data.neededGlucose * 100/ data.totalVolume : 0+    document.getElementById('deflectorVolume').value = 30
-    const estimatedOsmolarity = (finalConcentration * 55).toFixed(0);+    document.getElementById('hospitalName').value = "ASST LECCO"
 +    document.getElementById('departmentName').value = "S.C. Neonatologia e TIN"; 
 +    document.getElementById('directorName').value = "Dott. Roberto Bellù";
          
-    let html = '<div class="npt-report">';+    // 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ù" 
 +    };
          
-    // Header +    alert('Configurazione ripristinata ai valori predefiniti'); 
-    html += '<div class="report-header">'; +
-    html += '<div class="report-header-left">'; + 
-    html += '<div style="font-weightbold; font-size: 13px;">CALCOLO NUTRIZIONALE PARENTERALE Data: ' + dateStr + '</div>'; +function saveConfiguration() { 
-    html += '<div style="font-size: 11px; color: #666;">FOGLIO DI LAVORO</div>';+    const config = { 
 +        deflectorVolume: document.getElementById('deflectorVolume').value, 
 +        hospitalName: document.getElementById('hospitalName').value, 
 +        departmentName: document.getElementById('departmentName').value, 
 +        directorName: document.getElementById('directorName').value, 
 +        autoSave: document.getElementById('autoSave').value, 
 +        decimalPlaces: document.getElementById('decimalPlaces').value, 
 +        clinicalConfig: clinicalConfig 
 +    }; 
 +     
 +    // Aggiorna configurazione clinica 
 +    clinicalConfig.hospitalName = config.hospitalName; 
 +    clinicalConfig.departmentName = config.departmentName; 
 +    clinicalConfig.directorName = config.directorName; 
 +     
 +    // Simula salvataggio configurazione 
 +    window.savedConfig = config; 
 +    alert('Configurazione salvata con successo!'); 
 +
 + 
 +// FUNZIONI REPORT (COMPLETE CON TUTTI GLI ELEMENTI) 
 +function generatePrescription() { 
 +    if (!window.residualNeeds || !patientData.currentWeight) { 
 +        alert('Prima completare tutti i calcoli precedenti'); 
 +        return; 
 +    } 
 +     
 +    const currentDate = new Date().toLocaleDateString('it-IT'); 
 +    const currentTime = new Date().toLocaleTimeString('it-IT'); 
 +    const prescriptionPatientWeightKg = patientData.currentWeight / 1000; 
 +    const calc = window.nptCalculation; 
 +     
 +    if (!calc) { 
 +        alert('Prima calcolare la NPT nel TAB 4'); 
 +        return; 
 +    } 
 +     
 +    const birthDate = new Date(); 
 +    birthDate.setDate(birthDate.getDate() - patientData.daysOfLife); 
 +     
 +    const doctorName = patientData.prescribingDoctorName ||  
 +                      (patientData.prescribingDoctor && doctorsData[patientData.prescribingDoctor] ?  
 +                       doctorsData[patientData.prescribingDoctor].fullName : 'Non specificato'); 
 +     
 +    let html = '<div class="report-output">'; 
 +     
 +    // INTESTAZIONE MEDICA ESATTA COME DA PDF 
 +    html += '<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #2c3e50; padding-bottom: 15px; margin-bottom: 25px;">'; 
 +     
 +    // PARTE SINISTRA - INFO OSPEDALE 
 +    html += '<div style="text-alignleft;">'; 
 +    html += '<h2 style="margin: 0; font-size: 16px; color: #2c3e50;">Dipartimento Area della Donna e Materno Infantile</h2>'
 +    html +'<h3 style="margin: 5px 0; font-size: 14px; color: #34495e;">S.C. Neonatologia Terapia Intensiva Neonatale</h3>'; 
 +    html += '<style="margin: 5px 0; font-size: 12px; color: #7f8c8d;">Direttore: ' + clinicalConfig.directorName + '</p>';
     html += '</div>';     html += '</div>';
-    html += '<div class="report-header-right">LOGO OSPEDALE</div>';+     
 +    // 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>';
          
-    // Info Paziente 
-    html += '<div class="report-section">'; 
-    html += '<div class="report-section-title">INFO Paziente</div>'; 
-    html += '<table class="report-table">'; 
-    html += '<tr><td class="label-col">Medico Prescrittore</td><td class="value-col">' + doctorName + '</td></tr>'; 
-    html += '<tr><td class="label-col">Data Prescrizione</td><td class="value-col">' + dateStr + '</td></tr>'; 
-    html += '<tr><td class="label-col">Paziente</td><td class="value-col">' + (patientData.medicalRecord || 'N/A') + '</td></tr>'; 
-    html += '<tr><td class="label-col">Giorni di Vita</td><td class="value-col">' + patientData.daysOfLife + '</td></tr>'; 
-    html += '<tr><td class="label-col">Peso (g)</td><td class="value-col">' + data.currentWeight + '</td></tr>'; 
-    html += '</table>'; 
     html += '</div>';     html += '</div>';
          
-    // Composizione +    // TITOLO DOCUMENTO 
-    html += '<div class="report-section">'; +    html += '<div style="text-align: center; margin: 20px 0;">'; 
-    html += '<div class="report-section-title">Composizione Parenterale (numero sacche: 1)</div>'; +    html += '<h2 style="font-size: 18px; font-weight: bold; color: #2c3e50; margin: 10px 0;">CALCOLO NUTRIZIONALE PARENTERALE</h2>'; 
-    html += '<table class="composition-table">'; +    html += '<p style="font-size: 14px; color: #7f8c8d; margin: 5px 0;">Data: ' + currentDate + '</p>'; 
-    html += '<tr><th class="component-name-col"></th><th>Teorici</th><th>Con Deflussore</th><th></th></tr>';+    html += '</div>';
          
-    if (data.waterVolume > 0) { +    // DATI PAZIENTE 
-        html += '<tr><td class="component-name-col">Acqua bidistillata</td><td>'data.waterVolume.toFixed(2) + '</td><td>' + (data.waterVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>';+    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>';
     }     }
-    if (data.glucose50Volume > 0) { +     
-        html += '<tr><td class="component-name-col">glucosata 50% (parenterale)</td><td>'data.glucose50Volume.toFixed(2) + '</td><td>'(data.glucose50Volume * ratio).toFixed(2) + '</td><td>ml</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>';
     }     }
-    if (data.electrolyteAdditions.ca_gluconato > 0) { +     
-        html += '<tr><td class="component-name-col">Calcio gluconato (1g/10mL,0,44mEq/mL)</td><td>'data.electrolyteAdditions.ca_gluconato.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.ca_gluconato ratio).toFixed(2) + '</td><td>ml</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 (data.electrolyteAdditions.nacl > 0) { +    if (calc.electrolyteAdditions.esafosfina > 0) { 
-        html += '<tr><td class="component-name-col">Sodio cloruro (3mEq/mL)</td><td>'data.electrolyteAdditions.nacl.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.nacl ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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 (data.electrolyteAdditions.sodium_acetate > 0) { +    if (calc.electrolyteAdditions.mg_sulfate > 0) { 
-        html += '<tr><td class="component-name-col">Sodio acetato (2mEq/mL)</td><td>'data.electrolyteAdditions.sodium_acetate.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.sodium_acetate ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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 (data.electrolyteAdditions.kcl > 0) { +    if (calc.electrolyteAdditions.nacl > 0) { 
-        html += '<tr><td class="component-name-col">Potassio cloruro (2mEq/mL)</td><td>'data.electrolyteAdditions.kcl.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.kcl ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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 (data.electrolyteAdditions.mg_sulfate > 0) { +    if (calc.electrolyteAdditions.sodium_acetate > 0) { 
-        html += '<tr><td class="component-name-col">Magnesio solfato (2g/10mL,1.6mEq/mL)</td><td>'data.electrolyteAdditions.mg_sulfate.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.mg_sulfate ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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 (data.carnitineVolume > 0) { +    if (calc.electrolyteAdditions.kcl > 0) { 
-        html += '<tr><td class="component-name-col">Carnitene f</td><td>'data.carnitineVolume.toFixed(2) + '</td><td>' + (data.carnitineVolume ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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>';
     }     }
          
-    html += '<tr><td class="component-name-col">Trophamine 6%</td><td>' + data.proteinVolume.toFixed(2) + '</td><td>'(data.proteinVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; +    // VITAMINE (SE PRESENTI) 
-     +    if (window.residualNeeds.vitalipid > 0) { 
-    if (data.electrolyteAdditions.esafosfina > 0) { +        const vitalipidVolume = window.residualNeeds.vitalipid * prescriptionPatientWeightKg; 
-        html += '<tr><td class="component-name-col">Esafosfina f 5g</td><td>' + data.electrolyteAdditions.esafosfina.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.esafosfina ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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 (data.residualNeeds.peditrace > 0) { +    if (window.residualNeeds.soluvit > 0) { 
-        const peditraceVolume data.residualNeeds.peditrace data.currentWeightKg+        const soluvitVolume window.residualNeeds.soluvit prescriptionPatientWeightKg
-        html += '<tr><td class="component-name-col">Peditrace</td><td>'peditraceVolume.toFixed(2) + '</td><td>' + (peditraceVolume ratio).toFixed(2) + '</td><td>ml</td></tr>';+        html += '<tr><td style="border: 1px 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 (data.residualNeeds.soluvit > 0) { +    if (window.residualNeeds.peditrace > 0) { 
-        const soluvitVolume data.residualNeeds.soluvit data.currentWeightKg+        const peditraceVolume window.residualNeeds.peditrace prescriptionPatientWeightKg
-        html += '<tr><td class="component-name-col">Soluvit</td><td>'soluvitVolume.toFixed(2) + '</td><td>' + (soluvitVolume ratio).toFixed(2) + '</td><td>ml</td></tr>';+        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>';
     }     }
-    if (data.residualNeeds.vitalipid > 0) { +     
-        const vitalipidVolume data.residualNeeds.vitalipid data.currentWeightKg+    // CARNITINA (SE PRESENTE) 
-        html += '<tr><td class="component-name-col">Vitalipid N</td><td>'vitalipidVolume.toFixed(2) + '</td><td>' + (vitalipidVolume ratio).toFixed(2) + '</td><td>ml</td></tr>';+    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>';
     }     }
          
-    html += '<tr><td class="component-name-col">Intralipid 20%</td><td>'Math.max(0, data.lipidVolume).toFixed(2) + '</td><td>'(Math.max(0, data.lipidVolume) * ratio).toFixed(2) + '</td><td>ml</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>';
          
-    // Totali +    // PARAMETRI CLINICI 
-    html += '<tr class="composition-total"><td class="component-name-col"><strong>Totale</strong></td><td><strong>' + data.totalVolume.toFixed(2) + '</strong></td><td><strong>' + totalVolumeWithDeflector.toFixed(2) + '</strong></td><td><strong>ml</strong></td></tr>'; +    html += '<div style="background-color: #fff3cd; border: 1px solid #ffc107; border-radius: 5px; padding: 15px; margin: 20px 0;">'; 
-    html += '<tr><td class="component-name-col"><strong>Deflussore</strong></td><td><strong>'deflectorVolume + '</strong></td><td><strong>-</strong></td><td><strong>ml</strong></td></tr>'; +    html += '<h4 style="margin-top: 0; color: #856404;">PARAMETRI CLINICI</h4>'; 
-    html += '<tr><td class="component-name-col"><strong>Velocità infusione</strong></td><td><strong>'infusionRate + '</strong></td><td><strong>-</strong></td><td><strong>ml/h</strong></td></tr>'; +    html += '<p><strong>GIR:</strong> ' + calc.gir.toFixed(1) + ' mg/kg/min</p>'; 
-    html += '<tr><td class="component-name-col"><strong>Osmolarità Totale</strong></td><td><strong>' + estimatedOsmolarity + '</strong></td><td><strong>-</strong></td><td><strong>mOsm/ml</strong></td></tr>'; +    html += '<p><strong>Velocità infusione:</strong> ' + (calc.totalVolume / 24).toFixed(2) + ' ml/h</p>'; 
-    html += '</table>';+    html += '<p><strong>Via di somministrazione:</strong> Accesso venoso centrale</p>'
 +    html +'<p><strong>Durata:</strong> 24 ore continue</p>';
     html += '</div>';     html += '</div>';
          
-    html += '<div class="report-footer">'; +    // FIRMA 
-    html += 'NPT Calculator v2.0 Foglio di Lavoro generato il ' + new Date().toLocaleString('it-IT');+    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>';
-     
     html += '</div>';     html += '</div>';
          
-    return html;+    document.getElementById('reportOutput').innerHTML = html;
 } }
  
-function generateFinalReportHTML() { +function generateWorksheet() { 
-    const data = window.nptCalculationData; +    if (!window.residualNeeds || !patientData.currentWeight) { 
-    const deflectorVolume = parseInt(document.getElementById('deflectorVolume').value) || 30+        alert('Prima completare tutti i calcoli precedenti'); 
-    const totalVolumeWithDeflector = data.totalVolume + deflectorVolume+        return
-    const ratio = totalVolumeWithDeflector / data.totalVolume;+    }
          
-    const today new Date()+    const calc window.nptCalculation
-    const dateStr = today.toLocaleDateString('it-IT');+    if (!calc) { 
 +        alert('Prima calcolare la NPT nel TAB 4'); 
 +        return; 
 +    }
          
-    const medicalRecord patientData.medicalRecord || 'N/A'; +    const currentDate new Date().toLocaleDateString('it-IT')
-    const birthDate patientData.prescriptionDate ?  +    const currentTime = new Date().toLocaleTimeString('it-IT'); 
-        new Date(new Date(patientData.prescriptionDate).getTime() - (patientData.daysOfLife * 24 * 60 * 60 * 1000)).toLocaleDateString('it-IT':  +    const worksheetPatientWeightKg = patientData.currentWeight 1000;
-        'N/A'+
-    const doctorName = patientData.prescribingDoctor ?  +
-        doctorsData[patientData.prescribingDoctor]?.fullName || 'N/A' : 'N/A';+
          
-    const infusionRate = (data.totalVolume / 24).toFixed(2); +    const birthDate new Date(); 
-    const finalConcentration = data.neededGlucose > 0 ? (data.neededGlucose * 100) / data.totalVolume : 0; +    birthDate.setDate(birthDate.getDate() - patientData.daysOfLife);
-    const estimatedOsmolarity = (finalConcentration * 55 + data.electrolyteAdditions.totalVolume * 10).toFixed(0);+
          
-    let html '<div class="npt-report">';+    const deflectorVolume calc.deflectorVolume || 30; 
 +    const totalVolumeWithDeflector calc.totalVolume + deflectorVolume; 
 +    const ratio = totalVolumeWithDeflector / calc.totalVolume;
          
-    // INTESTAZIONE +    let html = '<div class="report-output">'; 
-    html += '<div class="report-header">'; +    html += '<div class="medical-header">'; 
-    html += '<div class="report-header-left">'; +    html += '<h1>' + clinicalConfig.hospitalName + '</h1>'; 
-    html += '<div style="font-weight: bold; font-size: 13px;">Dipartimento Area della Donna e Materno Infantile</div>'; +    html += '<h2>' + clinicalConfig.departmentName + '</h2>'; 
-    html += '<div style="font-size: 11px; color: #666;">S.C. Neonatologia e Terapia Intensiva Neonatale</div>'; +    html += '<p>Direttore: ' + clinicalConfig.directorName + '</p>';
-    html += '</div>'+
-    html +'<div class="report-header-right">LOGO OSPEDALE</div>';+
     html += '</div>';     html += '</div>';
          
-    html += '<div class="report-title">CALCOLO NUTRIZIONALE PARENTERALE Data' + dateStr + '</div>'; +    html += '<div style="text-aligncenterfont-size: 20px; font-weight: bold; color: #2c3e50; margin: 20px 0; text-transform: uppercase;">RICETTA PER PREPARAZIONE NPT</div>';
-    html += '<div class="report-subtitle">REPORT PARENTERALE</div>';+
          
-    // INFO PAZIENTE +    html += '<div style="background-color: #f8f9fapadding: 15px; border-left: 4px solid #3498db; margin: 20px 0;">'; 
-    html += '<div class="report-section">'; +    html += '<h3 style="margin-top: 0; color: #2c3e50;">INFORMAZIONI PAZIENTE</h3>'; 
-    html += '<div class="report-section-title">INFO Paziente</div>'; +    html += '<p><strong>Data e Ora:</strong> ' + currentDate + ' - ' + currentTime + '</p>'; 
-    html += '<table class="report-table">'; +    html += '<p><strong>Cartella:</strong> ' + (patientData.medicalRecord || 'N/A'+ '</p>'; 
-    html += '<tr><td class="label-col">Medico Prescrittore</td><td class="value-col">' + doctorName + '</td></tr>'; +    html += '<p><strong>Peso:</strong> ' + patientData.currentWeight + 'g (' + worksheetPatientWeightKg.toFixed(3) + ' kg)</p>'; 
-    html += '<tr><td class="label-col">Data Prescrizione</td><td class="value-col">' + dateStr + '</td></tr>'; +    html += '<p><strong>Giorni di vita:</strong> ' + patientData.daysOfLife + '</p>';
-    html += '<tr><td class="label-col">Data Somministrazione</td><td class="value-col">' + dateStr + '</td></tr>'; +
-    html += '<tr><td class="label-col">Paziente</td><td class="value-col">' + medicalRecord '</td></tr>'+
-    html +'<tr><td class="label-col">Data di Nascita</td><td class="value-col">' + birthDate + '</td></tr>'; +
-    html += '<tr><td class="label-col">Giorni di Vita</td><td class="value-col">' + patientData.daysOfLife + '</td></tr>'; +
-    html += '<tr><td class="label-col">Peso (g)</td><td class="value-col">' + data.currentWeight + '</td></tr>'; +
-    html += '</table>';+
     html += '</div>';     html += '</div>';
          
-    // LISTA APPORTI ENTERALI +    html += '<div style="background-color: #fff3cdborder: 1px solid #ffc107; border-radius: 5pxpadding: 15px; margin: 20px 0;">'; 
-    html += '<div class="report-section">'; +    html += '<h4 style="margin-top0color#856404;">PARAMETRI NUTRIZIONALI</h4>'; 
-    html += '<div class="report-section-title">Lista Degli Apporti per la Giornata Corrente</div>'; +    html += '<p><strong>GIR:</strong> ' + calc.gir.toFixed(1) + ' mg/kg/min</p>'; 
-    if (enteralData && enteralData.volume > 0) { +    html += '<p><strong>Velocità infusione:</strong> ' + (calc.totalVolume 24).toFixed(2) + ' ml/h</p>'; 
-        const formulaName = document.getElementById('formulaType').value; +    html += '<p><strong>Durata:</strong24 ore continue</p>';
-        const formulaDisplayName = formulaData[formulaName]?.name || 'Formula enterale'; +
-        html += '<table class="report-table">'; +
-        html += '<tr><td class="label-col">Apporto</td><td style="text-aligncenterwidth60px;"><strong>Quant.</strong></td><td style="text-align: left;"><strong>Somministrazione</strong></td></tr>'; +
-        html += '<tr><td class="label-col">' + formulaDisplayName + '</td><td style="text-align: center;">' + enteralData.volume + '</td><td style="text-align: left;">oro-naso-gastrica intermittente</td></tr>'; +
-        html += '</table>'; +
-    } else { +
-        html += '<table class="report-table">'; +
-        html += '<tr><td class="label-col">Apporto</td><td style="text-align: center; width: 60px;"><strong>Quant.</strong></td><td style="text-align: left;"><strong>Somministrazione</strong></td></tr>'; +
-        html += '<tr><td class="label-col">Nessun apporto enterale</td><td style="text-aligncenter;">-</td><td style="text-align: left;">-</td></tr>'; +
-        html += '</table>'; +
-    }+
     html += '</div>';     html += '</div>';
          
-    // COMPOSIZIONE PARENTERALE +    html += '<table style="width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px;">'; 
-    html += '<div class="report-section">'; +    html += '<thead><tr style="background-color: #34495e; color: white;">'; 
-    html += '<div class="report-section-title">Composizione Parenterale (numero sacche: 1)</div>'; +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">COMPONENTE</th>'; 
-    html += '<table class="composition-table">'; +    html += '<th style="border: 1px solid #2c3e50; padding: 10px;">CONCENTRAZIONE</th>'; 
-    html += '<tr><th class="component-name-col"></th><th>Teorici</th><th>Con Deflussore</th><th></th></tr>';+    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>';
          
-    // Componenti con ordine identico al foglio di lavoro +    html += '<tr><td style="border: 1px solid #2c3e50; padding: 10px;">Acqua Bidistillata</td><td style="border: 1px solid #2c3e50; padding: 10px;">-</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + Math.max(0, calc.waterVolume).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">' + Math.max(0, calc.waterVolume * ratio).toFixed(1) + ' ml</td><td style="border: 1px solid #2c3e50; padding: 10px;">1°</td></tr>'; 
-    if (data.waterVolume > 0) { +     
-        html += '<tr><td class="component-name-col">Acqua bidistillata</td><td>'data.waterVolume.toFixed(2) + '</td><td>' + (data.waterVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>';+    if (calc.neededGlucose > 0) { 
 +        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;"></td></tr>';
     }     }
-    if (data.glucose50Volume > 0) { 
-        html += '<tr><td class="component-name-col">glucosata 50% (parenterale)</td><td>' + data.glucose50Volume.toFixed(2) + '</td><td>' + (data.glucose50Volume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.electrolyteAdditions.ca_gluconato > 0) { 
-        html += '<tr><td class="component-name-col">Calcio gluconato (1g/10mL,0,44mEq/mL)</td><td>' + data.electrolyteAdditions.ca_gluconato.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.ca_gluconato * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.electrolyteAdditions.nacl > 0) { 
-        html += '<tr><td class="component-name-col">Sodio cloruro (3mEq/mL)</td><td>' + data.electrolyteAdditions.nacl.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.nacl * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.electrolyteAdditions.kcl > 0) { 
-        html += '<tr><td class="component-name-col">Potassio cloruro (2mEq/mL)</td><td>' + data.electrolyteAdditions.kcl.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.kcl * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.electrolyteAdditions.mg_sulfate > 0) { 
-        html += '<tr><td class="component-name-col">Magnesio solfato (2g/10mL,1.6mEq/mL)</td><td>' + data.electrolyteAdditions.mg_sulfate.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.mg_sulfate * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.carnitineVolume > 0) { 
-        html += '<tr><td class="component-name-col">Carnitene f</td><td>' + data.carnitineVolume.toFixed(2) + '</td><td>' + (data.carnitineVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.proteinVolume > 0) { 
-        html += '<tr><td class="component-name-col">Trophamine 6%</td><td>' + data.proteinVolume.toFixed(2) + '</td><td>' + (data.proteinVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.electrolyteAdditions.esafosfina > 0) { 
-        html += '<tr><td class="component-name-col">Esafosfina f 5g</td><td>' + data.electrolyteAdditions.esafosfina.toFixed(2) + '</td><td>' + (data.electrolyteAdditions.esafosfina * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.residualNeeds.peditrace > 0) { 
-        const peditraceVolume = data.residualNeeds.peditrace * data.currentWeightKg; 
-        html += '<tr><td class="component-name-col">Peditrace</td><td>' + peditraceVolume.toFixed(2) + '</td><td>' + (peditraceVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.residualNeeds.soluvit > 0) { 
-        const soluvitVolume = data.residualNeeds.soluvit * data.currentWeightKg; 
-        html += '<tr><td class="component-name-col">Soluvit</td><td>' + soluvitVolume.toFixed(2) + '</td><td>' + (soluvitVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    if (data.residualNeeds.vitalipid > 0) { 
-        const vitalipidVolume = data.residualNeeds.vitalipid * data.currentWeightKg; 
-        html += '<tr><td class="component-name-col">Vitalipid N</td><td>' + vitalipidVolume.toFixed(2) + '</td><td>' + (vitalipidVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
-    } 
-    // Gestione valore negativo per Intralipid 
-    const displayLipidVolume = data.lipidVolume < 0 ? 0 : data.lipidVolume; 
-    html += '<tr><td class="component-name-col">Intralipid 20%</td><td>' + displayLipidVolume.toFixed(2) + '</td><td>' + (displayLipidVolume * ratio).toFixed(2) + '</td><td>ml</td></tr>'; 
          
-    // Totali +    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;"></td></tr>';
-    html += '<tr class="composition-total"><td class="component-name-col"><strong>Totale</strong></td><td><strong>' + data.totalVolume.toFixed(2) + '</strong></td><td><strong>' + totalVolumeWithDeflector.toFixed(2) + '</strong></td><td><strong>ml</strong></td></tr>'; +
-    html += '<tr><td class="component-name-col"><strong>Deflussore</strong></td><td><strong>' + deflectorVolume + '</strong></td><td><strong>-</strong></td><td><strong>ml</strong></td></tr>'; +
-    html += '<tr><td class="component-name-col"><strong>Velocità infusione</strong></td><td><strong>' + infusionRate + '</strong></td><td><strong>-</strong></td><td><strong>ml/h</strong></td></tr>'; +
-    html += '<tr><td class="component-name-col"><strong>Osmolarità Totale</strong></td><td><strong>' + estimatedOsmolarity + '</strong></td><td><strong>-</strong></td><td><strong>mOsm/ml</strong></td></tr>'; +
-    html += '</table>'; +
-    html += '</div>';+
          
-    // TOTALE ELEMENTI PRO KILO +    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 #2c3e50padding: 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 += '<div class="report-section">'; +
-    html += '<div class="report-section-title">Totale Elementi Pro Kilo</div>'; +
-    html += '<table class="elements-table">';+
          
-    // Calcoli degli elementi totali (enterale + parenterale) +    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="border1px 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>'
-    const totalLiquids (enteralData ? enteralData.totalFluids 0) data.totalVolume; +    html +'</tbody></table>';
-    const totalLiquidsPerKg (totalLiquids data.currentWeightKg).toFixed(2);+
          
-    const totalProtein = (enteralData ? enteralData.protein * data.currentWeightKg / 1000 : 0) (data.residualNeeds.protein * data.currentWeightKg / 1000); +    html += '<div style="background-color#fff3cdborder1px solid #ffc107border-radius5pxpadding15pxmargin20px 0;">'; 
-    const totalLipids (enteralData ? enteralData.lipids * data.currentWeightKg / 1000 : 0) + (data.residualNeeds.lipids * data.currentWeightKg / 1000); +    html += '<h4 style="margin-top: 0color: #856404;">AVVERTENZE</h4>'; 
-    const totalCarbs (enteralData ? enteralData.carbs * data.currentWeightKg / 1000 0) + (data.residualNeeds.carbs * data.currentWeightKg / 1000); +    html += '<ul>'; 
-    const totalCalcium = (enteralData ? enteralData.calcium * data.currentWeightKg / 1000 0) + (data.residualNeeds.calcium * data.currentWeightKg / 1000); +    html += '<li>Preparazione sterile in cappa a flusso laminare</li>'; 
-    const totalPhosphorus = (enteralData ? enteralData.phosphorus * data.currentWeightKg / 1000 0) + (data.residualNeeds.phosphorus * data.currentWeightKg / 1000); +    html += '<li>Seguire rigorosamente l\'ordine di aggiunta</li>'; 
-    const totalSodium = (enteralData ? enteralData.sodium * data.currentWeightKg / 1000 0) + (data.residualNeeds.sodium * data.currentWeightKg / 1000); +    html += '<li>Intralipid sempre per ultimo</li>'; 
-    const totalPotassium = (enteralData ? enteralData.potassium * data.currentWeightKg / 1000 : 0) + (data.residualNeeds.potassium * data.currentWeightKg / 1000); +    html += '<li>Conservare a 2-8°C, usare entro 24 ore</li>'; 
-    const totalMagnesium = (enteralData ? enteralData.magnesium * data.currentWeightKg / 1000 : 0) + (data.residualNeeds.magnesium * data.currentWeightKg / 1000); +    html += '</ul>';
-    const totalCarnitine = data.residualNeeds.carnitine * data.currentWeightKg / 1000; +
-     +
-    const totalEnergy = (enteralData ? enteralData.energy * data.currentWeightKg / 1000 : 0) + (data.residualNeeds.energy * data.currentWeightKg / 1000); +
-    const totalNonProteinEnergy = totalEnergy - (totalProtein * 4); +
-    const glucoseMgKgMin = ((totalCarbs * 1000) / 1440).toFixed(3); +
-     +
-    html += '<tr><td class="element-name">liquidi</td><td class="element-value">' + totalLiquidsPerKg + '</td><td class="element-unit">ml</td></tr>'; +
-    html += '<tr><td class="element-name">Proteine</td><td class="element-value">' + (totalProtein * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">g</td></tr>'; +
-    html += '<tr><td class="element-name">Lipidi</td><td class="element-value">' + (totalLipids * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">g</td></tr>'; +
-    html += '<tr><td class="element-name">Glucidi</td><td class="element-value">' + (totalCarbs * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">g</td></tr>'; +
-    html += '<tr><td class="element-name">Calcio</td><td class="element-value">' + (totalCalcium * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mg</td></tr>'; +
-    html += '<tr><td class="element-name">Fosforo</td><td class="element-value">' + (totalPhosphorus * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mg</td></tr>'; +
-    html += '<tr><td class="element-name">Sodio</td><td class="element-value">' + (totalSodium * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mEq</td></tr>'; +
-    html += '<tr><td class="element-name">Potassio</td><td class="element-value">' + (totalPotassium * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mEq</td></tr>'; +
-    html += '<tr><td class="element-name">Magnesio</td><td class="element-value">' + (totalMagnesium * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mEq</td></tr>'; +
-    html += '<tr><td class="element-name">Carnitina</td><td class="element-value">' + (totalCarnitine * 1000 / data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">mg</td></tr>'; +
-    html += '<tr><td class="element-name">Oligoelementi</td><td class="element-value">' + (data.residualNeeds.peditrace * data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">ml</td></tr>'; +
-    html += '<tr><td class="element-name">Vit. idrosolubili</td><td class="element-value">' + (data.residualNeeds.soluvit * data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">ml</td></tr>'; +
-    html += '<tr><td class="element-name">Vit. liposolubili</td><td class="element-value">' + (data.residualNeeds.vitalipid * data.currentWeightKg).toFixed(2) + '</td><td class="element-unit">ml</td></tr>'; +
-    html += '<tr style="border-top: 2px solid #333;"><td class="element-name"><strong>KCal Totali</strong></td><td class="element-value"><strong>' + (totalEnergy * 1000 / data.currentWeightKg).toFixed(2) + '</strong></td><td class="element-unit"><strong>-</strong></td></tr>'; +
-    html += '<tr><td class="element-name"><strong>KCal non proteiche</strong></td><td class="element-value"><strong>' + (totalNonProteinEnergy * 1000 / data.currentWeightKg).toFixed(2) + '</strong></td><td class="element-unit"><strong>-</strong></td></tr>'; +
-    html += '<tr><td class="element-name"><strong>Glucosio (mg/Kg al minuto)</strong></td><td class="element-value"><strong>' + glucoseMgKgMin + '</strong></td><td class="element-unit"><strong>-</strong></td></tr>'; +
-    html += '</table>';+
     html += '</div>';     html += '</div>';
          
-    html += '<div class="report-footer">'; +    html += '<div style="margin-top: 40px; display: flex; justify-content: space-between;">'; 
-    html += 'NPT Calculator v2.0 Report Parenterale generato il ' + new Date().toLocaleString('it-IT');+    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>';
-     
     html += '</div>';     html += '</div>';
          
-    return html;+    document.getElementById('reportOutput').innerHTML = html;
 } }
  
-function printCurrentReport() { +// FUNZIONE GENERAZIONE PDF (DA VERSIONE 17) 
-    const reportContent = window.currentActiveReport === 'work' +function generatePDF(type) { 
-        document.getElementById('nptWorkReport').innerHTML : +    if (!window.residualNeeds || !patientData.currentWeight) { 
-        document.getElementById('nptFinalReport').innerHTML;+        alert('Prima calcolare la NPT completa'); 
 +        return; 
 +    } 
 + 
 +    const { jsPDF } = window.jspdf; 
 +    const doc = new jsPDF();
          
-    const reportTitle = window.currentActiveReport === 'work' +    // INTESTAZIONE COMUNE 
-        'Foglio di Lavoro NPT' : 'Report Parenterale NPT';+    doc.setFontSize(10); 
 +    doc.text(clinicalConfig.departmentName, 20, 15); 
 +    doc.text('Direttore: ' + clinicalConfig.directorName, 20, 20);
          
-    const printWindow = window.open('''_blank');+    // Logo ASST (posizionamento approssimativo) 
 +    doc.text(clinicalConfig.hospitalName, 17020);
          
-    printWindow.document.write(+    const currentDate = new Date().toLocaleDateString('it-IT')
-        <!DOCTYPE html> +    doc.text('CALCOLO NUTRIZIONALE PARENTERALE Data: + currentDate, 20, 35);
-        <html> +
-        <head> +
-            <title>${reportTitle}</title> +
-            <style> +
-                body { margin: 0; padding: 15px; font-family: Arial, sans-serif} +
-                ${document.querySelector('style').textContent} +
-            </style> +
-        </head> +
-        <body> +
-            ${reportContent} +
-        </body> +
-        </html> +
-    `);+
          
-    printWindow.document.close(); +    if (type === 'foglio_lavoro'
-    printWindow.print();+        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 updateSystemConfig() { +function generateFoglioLavoroPDF(doc) { 
-    const updateBtn document.getElementById('updateSystemBtn'); +    // Implementazione semplificata del PDF 
-    updateBtn.className = 'button config-update-completed'; +    let yPos 50; 
-    updateBtn.innerHTML = 'Parametri Sistema Aggiornati ✓';+     
 +    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;
          
-    setTimeout(() => { +    const calc window.nptCalculation; 
-        updateBtn.className = 'button'; +    doc.text('Volume totale NPT: + calc.totalVolume + ' ml', 20, yPos)
-        updateBtn.innerHTML = 'Aggiorna Parametri Sistema'; +    yPos +10; 
-    }3000);+    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', 20yPos);
 } }
  
 +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');
 +    }
 +}
 +
 +// INIZIALIZZAZIONE
 +document.addEventListener('DOMContentLoaded', function() {
 +    console.log('NPT Calculator v3.0 UNIFIED inizializzato');
 +    
 +    // Imposta la data odierna come default
 +    const today = new Date().toISOString().split('T')[0];
 +    document.getElementById('prescriptionDate').value = today;
 +    
 +    // Configura il campo cartella clinica
 +    setupMedicalRecordField();
 +    
 +    document.getElementById('birthWeight').addEventListener('change', function() {
 +        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();
 +    updateDoctorsDropdown();
 +    console.log('NPT Calculator v3.0 UNIFIED pronto');
 +});
 </script> </script>
 +
 </body> </body>
 </html> </html>
docuneo/programma_npt.1753993310.txt.gz · Ultima modifica: da neoadmin