<?php 

header('Content-Type: text/html; charset=UTF-8');
function cleanString($text) {
    $utf8 = array(
        '/[áàâãªä]/u'   =>   '&aacute;',
        '/[ÁÀÂÃÄ]/u'    =>   '&Aacute;',
        '/[ÍÌÎÏ]/u'     =>   '&Iacute;',
        '/[íìîï]/u'     =>   '&iacute;',
        '/[éèêë]/u'     =>   '&eacute;',
        '/[ÉÈÊË]/u'     =>   '&Eacute;',
        '/[óòôõºö]/u'   =>   '&oacute;',
        '/[ÓÒÔÕÖ]/u'    =>   '&Oacute;',
        '/[úùûü]/u'     =>   '&uacute;',
        '/[ÚÙÛÜ]/u'     =>   '&Uacute;',
        '/ç/'           =>   'c',
        '/Ç/'           =>   'C',
        '/ñ/'           =>   '&ntilde;',
        '/Ñ/'           =>   '&Ntilde;',
        '/–/'           =>   '-', // UTF-8 hyphen to "normal" hyphen
        '/[’‘‹›‚]/u'    =>   ' ', // Literally a single quote
        '/[“”«»„]/u'    =>   ' ', // Double quote
        '/ /'           =>   ' ', // nonbreaking space (equiv. to 0x160)
    );
    return preg_replace(array_keys($utf8), array_values($utf8), $text);
}

	setlocale(LC_ALL,"es_ES");
	$meses = array("ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO","SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE");
	$fecha = strftime("%d DE ".$meses[date('n')-1]." DE %Y");

	
	use App\Libraries\ejLib;
    $var = ejLib::getInstance();
    $soapclient = $var->getWs();
    $wsClave = $var->get_wsClave();

    $folio = $_GET['folio']; 
    $centro_sal = $_GET['centro_sal']; 
   

	//Datos de la solicitud
	$data = $soapclient->ConsultaExterna_get_SolicitudEstudiosDeLaboratorio($folio, $centro_sal, $wsClave);
	$data = new SimpleXMLElement(utf8_encode($data));
	

	//Listado Laboratoriales
	$dataLab = $soapclient->ConsultaExterna_get_EstudiosDeLaboratorioAsignados($folio, $centro_sal, $wsClave);
	$Laboratoriales = new SimpleXMLElement(utf8_encode($dataLab));


 // foreach($data->respuesta as $row){
 // 	print_r($row);
	// echo "<br><br><br>";
 // }

?>
<style type="text/css">
	table.tblDatos {
  border-collapse: separate;
  border-spacing:  5px 9px;
}
	.tr_head{
		background-color: #c4bd97;
		font-weight: 800;
		font-size: 6px;
	}
	.tr_bg0{
		background-color: #fff;
		font-size: 6px;
	}
	.tr_bg1{
		background-color: #daeef3;	
		font-size: 6px;
	}

	.tr_bg0 td, .tr_bg1 td{
		border-bottom: 1px solid #000;
		text-align: center;
		border-left: 1px solid #000;
		height: 30px;
	}

	.bb{
		border-bottom: 1px solid #000;		
	}
	.br{
		border-right: 1px solid #000;		
	}
	.br0{
		border-right: 0px solid #000;		
	}
	.bl{
		border-left: 1px solid #000;		
	}
	.bl0{
		border-left: 0px solid #000;		
	}
	.bt{
		border-top: 1px solid #000;		
	}
	.td_border_top{
		border-top: 1px solid #000;
	}
	.td_border_bottom{
		border-bottom: 1px solid #000;
	}
	.td_border_left{
		border-left: 1px solid #000;
	}
	.center{
		text-align: center;
	}


	table.blueTable {
  border: 1px solid #1C6EA4;
  background-color: #EEEEEE;
  width: 100%;
  text-align: left;
  border-collapse: collapse;
}
table.blueTable td, table.blueTable th {
  border: 1px solid #AAAAAA;
  padding: 3px 2px;
}
table.blueTable tbody td {
  font-size: 13px;
}
table.blueTable tr:nth-child(even) {
  background: #D0E4F5;
}
table.blueTable thead {
  background: #1C6EA4;
  background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
  background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
  background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
  border-bottom: 2px solid #444444;
}
table.blueTable thead th {
  font-size: 15px;
  font-weight: bold;
  color: #FFFFFF;
  border-left: 2px solid #D0E4F5;
}
table.blueTable thead th:first-child {
  border-left: none;
}

table.blueTable tfoot {
  font-size: 14px;
  font-weight: bold;
  color: #FFFFFF;
  background: #D0E4F5;
  background: -moz-linear-gradient(top, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
  background: -webkit-linear-gradient(top, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
  background: linear-gradient(to bottom, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
  border-top: 2px solid #444444;
}
table.blueTable tfoot td {
  font-size: 14px;
}
table.blueTable tfoot .links {
  text-align: right;
}
table.blueTable tfoot .links a{
  display: inline-block;
  background: #1C6EA4;
  color: #FFFFFF;
  padding: 2px 8px;
  border-radius: 5px;
}

</style>
<table style="width: 100%;">
	<tr><td  style="">
		<table width="100%" style="column-span: 0px; border-spacing: 0px;">
			<tr><td style="width: 20%;"><img src="img/png/LogoSSa.png" height="50px" /></td>
				<td style="width: 30%;">
					<table width="100%" style="font-size: 12px;">
						<tr>
							<td style="text-align: center;"><b>SECRETAR&#205;A DE SALUD</b></td>
						</tr>
						<tr>
							<td style="text-align: center;"><small>SOLICITUD DE ESTUDIOS AUXILIARES DE DIAGN&#211;STICO </small></td>
						</tr>
						
					</table>
					
				</td>
				<td> </td>
			</tr>
		</table>
	</td></tr>
	<tr><td style="text-align: center; font-size: 12px;">
		<?php echo ""; ?>
	</td></tr>
	<tr><td>
		
	</td></tr>		
</table>

<table  style="width: 100%; font-family: sans-serif; font-size:12px;" class="tblDatos">
	<tbody>
		<tr>
			<td colspan="5" rowspan="2"><strong>Nombre del paciente:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->nombre_paciente) }}</span></td>
			<td><strong>Fecha:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->fecha_consulta) }}</span></td>
		</tr>
		<tr>
			<td><strong>Folio:</strong> <span style=" text-decoration: underline;">{{ $folio }}</span></td>
		</tr>
		<tr>
			<td colspan="2"><strong>Fecha de nacimiento:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->fecha_nacimiento_paciente) }}</span></td>
			<td colspan="2"><strong>Edad:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->edad_paciente) }}</span> </td>
			<td colspan="2"><strong>Sexo:</strong><span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->sexo_paciente) }}</span></td>
		</tr>
		<tr>
			<td colspan="2"><strong>CURP:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->curp_paciente) }}</span> </td>
			<td colspan="2"><strong>Peso:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->peso) }}</span></td>
			<td ><strong>Talla:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->talla) }}</span></td>
			<td ><strong>TA:</strong><span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->ta_sistolica) }}/ {{ utf8_decode($data->respuesta->ta_diastolica) }}</span></td>
		</tr>
		<tr>
			<td colspan="3"><strong>Unidad Medica:</strong><span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->nombre_umed) }}</span></td>
			<td colspan="3"><strong>Servicio:</strong> <span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->servicio_nombre) }}</span></td>
			
		</tr>
		<tr>
			<td colspan="6"><strong>Medico Solicitante:</strong><span style=" text-decoration: underline;">{{ utf8_decode($data->respuesta->medico_solicitante) }}</span> </td>
			<td colspan="6"></td>
			
		</tr>
		<tr>
			<td colspan="2"><strong>Diagnosticos:</strong></td>
			<td colspan="2"></td>
			<td colspan="2"></td>
		</tr>
		<tr>
			<td colspan="6">{{ utf8_decode($data->respuesta->diagnosticos) }}</td>
		</tr>
		<tr>
			<td colspan="2"><strong>ESTUDIOS A REALIZAR:</strong></td>
			<td colspan="2"></td>
			<td colspan="2"></td>
		</tr>
		
	</tbody>
</table>


    <div id="tblEstudios" name="tblEstudios">
                      <table style="font-size: 12px; width: 95%; margin:auto;" class=" blueTable table table-hover table-bordered">
                        <tr style="background-color:#e5e5e5">                          
                          <th style="text-align: left; width: 100px;">Clave</th>
                          <th style="text-align: left;">Estudio</th>                          
                                              
                        </tr>
                   <!-- registros -->
                    <?php
                  foreach($Laboratoriales->respuesta as $reg){
                    if( !isset($reg->error) ){
                      ?>
                        <tr>
                          <td><?php echo $reg->clave ; ?></td>
                          <td><?php echo utf8_decode($reg->descripcion); ?></td>
                         
                        </tr>

                      
                    <?php
                    }else{
                      ?>
                        <tr>
                          <td>------</td>
                          <td></td>
                          <td style="text-align: center;"></td>
                        </tr>
                    <?php
                    }
                  }?>
                      </table>

  <br>
  <table style="font-size: 12px; width: 50%; margin:auto;" class="table table-hover table-bordered">
	<tbody>
		<tr>
			<td colspan="6" style="text-align: center;"></td>
			<td colspan="6" style="text-align: center;"></td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">{{ utf8_decode($data->respuesta->medico_solicitante) }}</td>
		</tr>
		<tr style="text-align: center;" >
			<td colspan="6" style="border-top: solid; text-align: center;">Nombre del medico</td>
		</tr>
	</tbody>
</table>
                  </div>