<?php
// FORMATO MSP-002: CONSULTA EXTERNA / ANAMNESIS Y EXAMEN FÍSICO
// Versión Refactorizada para coincidir EXACTAMENTE con el PDF del MSP
?>
<form name="formulariop" id="formulariop" method="POST">
    <input type="hidden" name="idatencion" id="idatencion" value="<?php echo $_POST['idatencion'] ?? ''; ?>">
    <input type="hidden" name="tipo_formato" value="MSP_002">

    <!-- ENCABEZADO OFICIAL -->
    <div class="msp-002-header" style="background-color: #f4f4f4; padding: 10px; text-align: center; font-weight: bold; border: 1px solid #ddd; margin-bottom: 10px;">
        CONSULTA EXTERNA - ANAMNESIS Y EXAMEN FÍSICO (002)
    </div>

    <!-- DATOS DEL PACIENTE -->
    <?php include 'partials/patient_header.php'; ?>

    <div class="msp-container">

        <!-- 1. MOTIVO DE CONSULTA -->
        <div class="msp-section">
            <div class="msp-section-title">1. MOTIVO DE CONSULTA</div>
            <textarea class="msp-textarea" name="motivo_consulta" required rows="2"
                placeholder="Anote la causa del problema en la versión del informante..."></textarea>
        </div>

        <!-- 2. ANTECEDENTES PERSONALES -->
        <div class="msp-section">
            <div class="msp-section-title">2. ANTECEDENTES PERSONALES</div>
            <div class="msp-alert msp-alert-info" style="margin-bottom: 5px; padding: 5px;">
                <small>DATOS CLÍNICO - QUIRÚRGICOS RELEVANTES Y GINECO OBSTÉTRICOS</small>
            </div>
            <textarea class="msp-textarea" name="antecedentes_personales" rows="3" placeholder="Describa antecedentes relevantes..."></textarea>
            
            <div class="msp-row msp-mt-10">
                <div class="msp-col-4">
                    <label class="msp-field-label">Alergias</label>
                    <input type="text" class="msp-input" name="alergia" style="border-color: #F44336;">
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">Intervenciones Quirúrgicas</label>
                    <input type="text" class="msp-input" name="intervenciones_quirurgicas">
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">Vacunas Completas</label>
                    <select class="msp-select" name="vacunas_completas">
                        <option value="">Seleccione...</option>
                        <option value="SI">SI</option>
                        <option value="NO">NO</option>
                    </select>
                </div>
            </div>
        </div>

        <!-- 3. ANTECEDENTES FAMILIARES -->
        <div class="msp-section">
            <div class="msp-section-title">3. ANTECEDENTES FAMILIARES</div>
            <div class="msp-row">
                <div class="msp-col-3">
                    <label><input type="checkbox" name="ant_fam_cardiopatia" value="1"> 1. Cardiopatía</label><br>
                    <label><input type="checkbox" name="ant_fam_diabetes" value="1"> 2. Diabetes</label>
                </div>
                <div class="msp-col-3">
                    <label><input type="checkbox" name="ant_fam_enf_vascular" value="1"> 3. Enf. C. Vascular</label><br>
                    <label><input type="checkbox" name="ant_fam_hipertension" value="1"> 4. Hipertensión</label>
                </div>
                <div class="msp-col-3">
                    <label><input type="checkbox" name="ant_fam_cancer" value="1"> 5. Cáncer</label><br>
                    <label><input type="checkbox" name="ant_fam_tuberculosis" value="1"> 6. Tuberculosis</label>
                </div>
                <div class="msp-col-3">
                    <label><input type="checkbox" name="ant_fam_enf_mental" value="1"> 7. Enf. Mental</label><br>
                    <label><input type="checkbox" name="ant_fam_enf_infecciosa" value="1"> 8. Enf. Infecciosa</label>
                </div>
                <div class="msp-col-6 msp-mt-10">
                    <label><input type="checkbox" name="ant_fam_malformacion" value="1"> 9. Malformación</label>
                </div>
                <div class="msp-col-6 msp-mt-10">
                    <label><input type="checkbox" name="ant_fam_otro" value="1"> 10. Otro</label>
                </div>
            </div>
            <textarea class="msp-textarea msp-mt-10" name="antecedentes_familiares_obs" rows="2" placeholder="Observaciones de antecedentes familiares..."></textarea>
        </div>

        <!-- 4. ENFERMEDAD O PROBLEMA ACTUAL -->
        <div class="msp-section">
            <div class="msp-section-title">4. ENFERMEDAD O PROBLEMA ACTUAL</div>
            <div class="msp-alert msp-alert-info" style="margin-bottom: 5px; padding: 5px;">
                <small>CRONOLOGÍA, LOCALIZACIÓN, CARACTERÍSTICAS, INTENSIDAD, CAUSA APARENTE, FACTORES QUE AGRAVAN O MEJORAN, SÍNTOMAS ASOCIADOS, MEDICAMENTOS RECIBIDOS, EVOLUCIÓN.</small>
            </div>
            <textarea class="msp-textarea" name="enfermedad_actual" rows="4" required></textarea>
        </div>

        <!-- 5. REVISIÓN ACTUAL DE ÓRGANOS Y SISTEMAS -->
        <div class="msp-section">
            <div class="msp-section-title">5. REVISIÓN ACTUAL DE ÓRGANOS Y SISTEMAS</div>
            <div class="msp-row">
                <div class="msp-col-4">
                    <label class="msp-field-label">1. Sentidos</label>
                    <select class="msp-select" name="rev_sentidos">
                        <option value="SP">SP (Sin Patología)</option>
                        <option value="CP">CP (Con Patología)</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">2. Respiratorio</label>
                    <select class="msp-select" name="rev_respiratorio">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">3. Cardio Vascular</label>
                    <select class="msp-select" name="rev_cardio_vascular">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">4. Digestivo</label>
                    <select class="msp-select" name="rev_digestivo">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">5. Genital</label>
                    <select class="msp-select" name="rev_genital">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">6. Urinario</label>
                    <select class="msp-select" name="rev_urinario">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">7. Músculo Esquelético</label>
                    <select class="msp-select" name="rev_musculo_esqueletico">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">8. Endocrino</label>
                    <select class="msp-select" name="rev_endocrino">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">9. Hemo Linfático</label>
                    <select class="msp-select" name="rev_hemo_linfatico">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">10. Nervioso</label>
                    <select class="msp-select" name="rev_nervioso">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
            </div>
            <textarea class="msp-textarea msp-mt-10" name="rev_sistemas_obs" rows="2" placeholder="Describir si marcó CP..."></textarea>
        </div>

        <!-- 6. SIGNOS VITALES Y ANTROPOMETRÍA -->
        <?php include 'partials/vital_signs.php'; ?>

        <!-- 7. EXAMEN FÍSICO REGIONAL -->
        <div class="msp-section">
            <div class="msp-section-title">7. EXAMEN FÍSICO REGIONAL</div>
            <div class="msp-row">
                <div class="msp-col-4">
                    <label class="msp-field-label">1. Cabeza</label>
                    <select class="msp-select" name="ef_cabeza">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">2. Cuello</label>
                    <select class="msp-select" name="ef_cuello">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">3. Tórax</label>
                    <select class="msp-select" name="ef_torax">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">4. Abdomen</label>
                    <select class="msp-select" name="ef_abdomen">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">5. Pelvis</label>
                    <select class="msp-select" name="ef_pelvis">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
                <div class="msp-col-4">
                    <label class="msp-field-label">6. Extremidades</label>
                    <select class="msp-select" name="ef_extremidades">
                        <option value="SP">SP</option>
                        <option value="CP">CP</option>
                    </select>
                </div>
            </div>
            <textarea class="msp-textarea msp-mt-10" name="examen_fisico" rows="3" placeholder="Describir si marcó CP..."></textarea>
        </div>

        <!-- 8. DIAGNÓSTICO -->
        <?php include 'partials/diagnostics.php'; ?>

        <!-- 9. PLANES DE TRATAMIENTO -->
        <div class="msp-section">
            <div class="msp-section-title">9. PLANES DE TRATAMIENTO</div>
            <div class="msp-alert msp-alert-info" style="margin-bottom: 5px; padding: 5px;">
                <small>REGISTRAR LOS PLANES: DIAGNÓSTICO, TERAPÉUTICO Y EDUCACIONAL</small>
            </div>
            <textarea class="msp-textarea" name="tratamiento" rows="5" placeholder="Prescripciones médicas y recomendaciones..."></textarea>

            <div class="msp-row msp-mt-10">
                <div class="msp-col-4">
                    <label class="msp-field-label">Próxima Cita</label>
                    <input type="date" class="msp-input" name="proxima_cita">
                </div>
                <div class="msp-col-8">
                    <label class="msp-field-label">Signos de Alarma</label>
                    <input type="text" class="msp-input" name="signnose_de_alarma" placeholder="Describa signos de alarma...">
                </div>
            </div>
        </div>


        <!-- BOTONES OCULTOS (Gestionados por sistema de pestañas) -->
        <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12" id="guardar" style="display: none;">
            <button class="btn btn-primary btn-lg msp-btn-primary" type="submit" id="btnGuardarP">
                <i class="fa fa-save"></i> GUARDAR CONSULTA EXTERNA 002
            </button>
            <button class="btn btn-danger btn-lg msp-btn-danger" onclick="cancelarform()" type="button">
                <i class="fa fa-arrow-circle-left"></i> Cancelar
            </button>
        </div>

    </div>
</form>