/* INFORME OPERACIONAL */

/* 248  CAMBIAR TABLA HIS POR HTEMP */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HIS WHERE(COD_ITEM IN('96150','U140','96150.01')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='F' AND EDAD BETWEEN 12 AND 17) AND ANIO = 2021

SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='F' AND EDAD BETWEEN 12 AND 17 AND ANIO=2021 AND MES=1)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 
	
SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
 FROM(SELECT ID_CITA, 
 SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='F' AND EDAD BETWEEN 12 AND 17)THEN 1 ELSE 0 END)AS COD1, 
 SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 

/* 252 */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HTEMP WHERE(COD_ITEM IN('96150','U140')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='M'AND EDAD BETWEEN 12 AND 17)
	
SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='M' AND EDAD BETWEEN 12 AND 17)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 


/* 257 */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HTEMP WHERE(COD_ITEM IN('96150','U140')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='F'AND EDAD BETWEEN 18 AND 29)

SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='F' AND EDAD BETWEEN 18 AND 29)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 

/* 262 */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HTEMP WHERE(COD_ITEM IN('96150','U140')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='M'AND EDAD BETWEEN 18 AND 29)
	
SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='M' AND EDAD BETWEEN 18 AND 29)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 

/* 267 */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HTEMP WHERE(COD_ITEM IN('96150','U140')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='F'AND EDAD BETWEEN 30 AND 59)

SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='F' AND EDAD BETWEEN 30 AND 59)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 
	
/* 272 */
SELECT COUNT(COD_ITEM)AS JS 
	FROM HTEMP WHERE(COD_ITEM IN('96150','U140')AND TIP_DIAG='D'AND LAB='VIF'AND SEXO='M'AND EDAD BETWEEN 30 AND 59)

SELECT ISNULL(SUM(CASE WHEN(COD1>0 AND COD2>0)THEN 1 ELSE 0 END),0)AS JS 
	FROM(SELECT ID_CITA,	
	SUM(CASE WHEN(COD_ITEM='99208'AND TIP_DIAG='D' AND SEXO='M' AND EDAD BETWEEN 30 AND 59 AND ANIO=2021)THEN 1 ELSE 0 END)AS COD1,	
	SUM(CASE WHEN((COD_ITEM IN('96150','U140') AND LAB='VIF') OR (COD_ITEM = '96150.01' AND (LAB IS NULL OR LAB='')) AND TIP_DIAG='D') THEN 1 ELSE 0 END)AS COD2 FROM HIS GROUP BY ID_CITA)AS T 
	


/* CCH CONTROL CALIDAD */


/* 359 TAMIZAJE DE VBG CON LAB DIFERENTE VACIO O TIPO DIAGNOSTICO DISTITO A DEFINITIVO */
SELECT * FROM HIS 
	WHERE COD_ITEM='96150.01' AND (LAB<>'' OR TIP_DIAG<>'D');

/* 360 TAMIZAJE DE VBG CON LAB = VACIO O TIPO DIAGNOSTICO DISTITO A DEFINITIVO;  FECHA_ATEN < 28-02-2021 */
SELECT * FROM HIS 
	WHERE COD_ITEM IN('U140','96150') AND (LAB='' OR TIP_DIAG<>'D') AND FECHA<='2021-02-28';


/* 361	TAMIZAJE DE SALUD MENTAL EN VIOLENCIA CON CODIGO QUE NO SE UTILIZA AL 2021; CODIGO CORRECTO=96150.01 */
SELECT * FROM HIS 
	WHERE COD_ITEM IN('U140','96150') AND (LAB='VIF' OR LAB='' OR LAB IS NULL) AND FECHA>='2021-03-01';	

/* 362 TAMIZAJE DE SALUD MENTAL EN TRASTORNOS DEPRESIVOS CON CODIGO QUE NO SE UTILIZA AL 2021; CODIGO CORRECTO=96150.03 */
SELECT * FROM HIS 
	WHERE COD_ITEM IN('U140','96150') AND (LAB='TD' OR LAB='' OR LAB IS NULL) AND FECHA>='2021-03-01';
	
/* 363 TAMIZAJE DE SALUD MENTAL EN ALCOHOL Y DROGAS CON CODIGO QUE NO SE UTILIZA AL 2021; CODIGO CORRECTO=96150.02 */	
SELECT * FROM HIS 
	WHERE COD_ITEM IN('U140','96150') AND (LAB='AD' OR LAB='' OR LAB IS NULL) AND FECHA>='2021-03-01';
	
/* 364 TAMIZAJE DE SALUD MENTAL EN PSICOSIS CON CODIGO QUE NO SE UTILIZA AL 2021; CODIGO CORRECTO=96150.04 */	
SELECT * FROM HIS 
	WHERE COD_ITEM IN('U140','96150') AND (LAB='EP' OR LAB='' OR LAB IS NULL) AND FECHA>='2021-03-01';

	


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	