<?php

// Global variable for table object
$primeras_20_29_2018 = NULL;

//
// Table class for primeras_20_29_2018
//
class crprimeras_20_29_2018 extends crTableBase {

//	var $SelectLimit = TRUE;
	var $Orden;
	var $Diez_Primeras_Causas_de_Morbilidad;
	var $total_primeras_causas_morbilidad;
	var $_25;
	var $tasa;
	var $Causa_Completa;
	var $Codigo_diagnostico;
	var $cuadro;
	var $Codigo_tres;
	var $Unidad_edad;
	var $Edad;

	//
	// Table class constructor
	//
	function __construct() {
		global $ReportLanguage;
		$this->TableVar = 'primeras_20_29_2018';
		$this->TableName = 'primeras_20_29_2018';
		$this->TableType = 'CUSTOMVIEW';
		$this->ExportAll = TRUE;
		$this->ExportPageBreakCount = 0;

		// Orden
		$this->Orden = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Orden', 'Orden', '(Case When (consulta_final_2018.Codigo_tres = \'K02\') Then 1 When (consulta_final_2018.Codigo_tres = \'K05\') Then 2 When (consulta_final_2018.Codigo_tres = \'F31\') Then 3 When (consulta_final_2018.Codigo_tres = \'K04\') Then 4 When (consulta_final_2018.Codigo_tres = \'K29\') Then 5 When (consulta_final_2018.Codigo_tres = \'N39\') Then 6 When (consulta_final_2018.Codigo_tres = \'F32\') Then 7 When (consulta_final_2018.Codigo_tres = \'K01\') Then 8 When (consulta_final_2018.Codigo_tres = \'F19\') Then 9 When (consulta_final_2018.Codigo_tres = \'M54\') Then 10 Else \'\' End)', 200, EWR_DATATYPE_STRING, -1);
		$this->fields['Orden'] = &$this->Orden;
		$this->Orden->DateFilter = "";
		$this->Orden->SqlSelect = "";
		$this->Orden->SqlOrderBy = "";

		// Diez Primeras Causas de Morbilidad
		$this->Diez_Primeras_Causas_de_Morbilidad = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Diez_Primeras_Causas_de_Morbilidad', 'Diez Primeras Causas de Morbilidad', '(Case When (consulta_final_2018.Codigo_tres = \'K02\') Then \'CARIES DENTAL\' When (consulta_final_2018.Codigo_tres = \'K05\') Then \'GINGIVITIS Y ENFERMEDADES PERIODONTALES\' When (consulta_final_2018.Codigo_tres = \'F31\') Then \'TRASTORNO AFECTIVO BIPOLAR\' When (consulta_final_2018.Codigo_tres = \'K04\') Then \'ENFERMEDADES DE LA PULPA Y DE LOS TEJIDOS PERIAPICALES\' When (consulta_final_2018.Codigo_tres = \'K29\') Then \'GASTRITIS Y DUODENITIS\' When (consulta_final_2018.Codigo_tres = \'N39\') Then \'OTROS TRASTORNOS DEL SISTEMA URINARIO\' When (consulta_final_2018.Codigo_tres = \'F32\') Then \'EPISODIO DEPRESIVO\' When (consulta_final_2018.Codigo_tres = \'K01\') Then \'DIENTES INCLUIDOS E IMPACTADOS\' When (consulta_final_2018.Codigo_tres = \'F19\') Then \'TRASTORNOS MENTALES Y DE COMPORTAMIENTO DEBIDOS AL USO DE MULTIPLES DROGAS Y AL USO DE OTRAS SUSTANCIAS PSICOACTIVAS\' When (consulta_final_2018.Codigo_tres = \'M54\') Then \'DORSALGIA\' When (consulta_final_2018.Letra = \'R\') Then \'SIGNOS,SINTOMAS Y AFECCIONES MAL DEFINIDAS \' Else \'RESTO DE CAUSAS\' End)', 200, EWR_DATATYPE_STRING, -1);
		$this->fields['Diez_Primeras_Causas_de_Morbilidad'] = &$this->Diez_Primeras_Causas_de_Morbilidad;
		$this->Diez_Primeras_Causas_de_Morbilidad->DateFilter = "";
		$this->Diez_Primeras_Causas_de_Morbilidad->SqlSelect = "";
		$this->Diez_Primeras_Causas_de_Morbilidad->SqlOrderBy = "";

		// total_primeras_causas_morbilidad
		$this->total_primeras_causas_morbilidad = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_total_primeras_causas_morbilidad', 'total_primeras_causas_morbilidad', 'Count(consulta_final_2018.Codigo_diagnostico)', 20, EWR_DATATYPE_NUMBER, -1);
		$this->total_primeras_causas_morbilidad->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['total_primeras_causas_morbilidad'] = &$this->total_primeras_causas_morbilidad;
		$this->total_primeras_causas_morbilidad->DateFilter = "";
		$this->total_primeras_causas_morbilidad->SqlSelect = "";
		$this->total_primeras_causas_morbilidad->SqlOrderBy = "";

		// %
		$this->_25 = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x__25', '%', '(Count(consulta_final_2018.Codigo_diagnostico) / (Select Count(0) From consulta_final_2018 Where consulta_final_2018.Unidad_edad = 1 And consulta_final_2018.Edad In (20, 21, 22, 23, 24, 25, 26, 27, 28, 29)) * 100)', 131, EWR_DATATYPE_NUMBER, -1);
		$this->_25->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['_25'] = &$this->_25;
		$this->_25->DateFilter = "";
		$this->_25->SqlSelect = "";
		$this->_25->SqlOrderBy = "";

		// tasa
		$this->tasa = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_tasa', 'tasa', '(((Count(consulta_final_2018.Codigo_diagnostico) / 72324)) * 1000)', 131, EWR_DATATYPE_NUMBER, -1);
		$this->tasa->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectFloat");
		$this->fields['tasa'] = &$this->tasa;
		$this->tasa->DateFilter = "";
		$this->tasa->SqlSelect = "";
		$this->tasa->SqlOrderBy = "";

		// Causa_Completa
		$this->Causa_Completa = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Causa_Completa', 'Causa_Completa', 'consulta_final_2018.Causa_Completa', 200, EWR_DATATYPE_STRING, -1);
		$this->fields['Causa_Completa'] = &$this->Causa_Completa;
		$this->Causa_Completa->DateFilter = "";
		$this->Causa_Completa->SqlSelect = "";
		$this->Causa_Completa->SqlOrderBy = "";

		// Codigo_diagnostico
		$this->Codigo_diagnostico = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Codigo_diagnostico', 'Codigo_diagnostico', 'consulta_final_2018.Codigo_diagnostico', 200, EWR_DATATYPE_STRING, -1);
		$this->fields['Codigo_diagnostico'] = &$this->Codigo_diagnostico;
		$this->Codigo_diagnostico->DateFilter = "";
		$this->Codigo_diagnostico->SqlSelect = "";
		$this->Codigo_diagnostico->SqlOrderBy = "";

		// cuadro
		$this->cuadro = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_cuadro', 'cuadro', '(Case When (consulta_final_2018.Codigo_tres = \'K02\') Then 1 When (consulta_final_2018.Codigo_tres = \'K05\') Then 2 When (consulta_final_2018.Codigo_tres = \'F31\') Then 3 When (consulta_final_2018.Codigo_tres = \'K04\') Then 4 When (consulta_final_2018.Codigo_tres = \'K29\') Then 5 When (consulta_final_2018.Codigo_tres = \'N39\') Then 6 When (consulta_final_2018.Codigo_tres = \'F32\') Then 7 When (consulta_final_2018.Codigo_tres = \'K01\') Then 8 When (consulta_final_2018.Codigo_tres = \'F19\') Then 9 When (consulta_final_2018.Codigo_tres = \'M54\') Then 10 When (consulta_final_2018.Letra = \'R\') Then 11 Else 12 End)', 3, EWR_DATATYPE_NUMBER, -1);
		$this->cuadro->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['cuadro'] = &$this->cuadro;
		$this->cuadro->DateFilter = "";
		$this->cuadro->SqlSelect = "";
		$this->cuadro->SqlOrderBy = "";

		// Codigo_tres
		$this->Codigo_tres = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Codigo_tres', 'Codigo_tres', 'consulta_final_2018.Codigo_tres', 200, EWR_DATATYPE_STRING, -1);
		$this->fields['Codigo_tres'] = &$this->Codigo_tres;
		$this->Codigo_tres->DateFilter = "";
		$this->Codigo_tres->SqlSelect = "";
		$this->Codigo_tres->SqlOrderBy = "";

		// Unidad_edad
		$this->Unidad_edad = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Unidad_edad', 'Unidad_edad', 'consulta_final_2018.Unidad_edad', 16, EWR_DATATYPE_NUMBER, -1);
		$this->Unidad_edad->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['Unidad_edad'] = &$this->Unidad_edad;
		$this->Unidad_edad->DateFilter = "";
		$this->Unidad_edad->SqlSelect = "";
		$this->Unidad_edad->SqlOrderBy = "";

		// Edad
		$this->Edad = new crField('primeras_20_29_2018', 'primeras_20_29_2018', 'x_Edad', 'Edad', 'consulta_final_2018.Edad', 3, EWR_DATATYPE_NUMBER, -1);
		$this->Edad->FldDefaultErrMsg = $ReportLanguage->Phrase("IncorrectInteger");
		$this->fields['Edad'] = &$this->Edad;
		$this->Edad->DateFilter = "";
		$this->Edad->SqlSelect = "";
		$this->Edad->SqlOrderBy = "";
	}

	// Single column sort
	function UpdateSort(&$ofld) {
		if ($this->CurrentOrder == $ofld->FldName) {
			$sLastSort = $ofld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$sThisSort = $this->CurrentOrderType;
			} else {
				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			}
			$ofld->setSort($sThisSort);
		} else {
			if ($ofld->GroupingFieldId == 0) $ofld->setSort("");
		}
	}

	// Get Sort SQL
	function SortSql() {
		$sDtlSortSql = "";
		$argrps = array();
		foreach ($this->fields as $fld) {
			if ($fld->getSort() <> "") {
				if ($fld->GroupingFieldId > 0) {
					if ($fld->FldGroupSql <> "")
						$argrps[$fld->GroupingFieldId] = str_replace("%s", $fld->FldExpression, $fld->FldGroupSql) . " " . $fld->getSort();
					else
						$argrps[$fld->GroupingFieldId] = $fld->FldExpression . " " . $fld->getSort();
				} else {
					if ($sDtlSortSql <> "") $sDtlSortSql .= ", ";
					$sDtlSortSql .= $fld->FldExpression . " " . $fld->getSort();
				}
			}
		}
		$sSortSql = "";
		foreach ($argrps as $grp) {
			if ($sSortSql <> "") $sSortSql .= ", ";
			$sSortSql .= $grp;
		}
		if ($sDtlSortSql <> "") {
			if ($sSortSql <> "") $sSortSql .= ",";
			$sSortSql .= $sDtlSortSql;
		}
		return $sSortSql;
	}

	// Table level SQL
	// From

	var $_SqlFrom = "";

	function getSqlFrom() {
		return ($this->_SqlFrom <> "") ? $this->_SqlFrom : "consulta_final_2018";
	}

	function SqlFrom() { // For backward compatibility
		return $this->getSqlFrom();
	}

	function setSqlFrom($v) {
		$this->_SqlFrom = $v;
	}

	// Select
	var $_SqlSelect = "";

	function getSqlSelect() {
		return ($this->_SqlSelect <> "") ? $this->_SqlSelect : "SELECT (Count(consulta_final_2018.Codigo_diagnostico) / (Select Count(0) From consulta_final_2018 Where consulta_final_2018.Unidad_edad = 1 And consulta_final_2018.Edad In (20,21,22,23,24,25,26,27,28,29)) * 100) As `%`, (((Count(consulta_final_2018.Codigo_diagnostico) / 72324)) * 1000) As tasa, consulta_final_2018.Causa_Completa, Count(consulta_final_2018.Codigo_diagnostico) As total_primeras_causas_morbilidad, consulta_final_2018.Codigo_diagnostico, (Case When (consulta_final_2018.Codigo_tres = 'K02') Then 'CARIES DENTAL' When (consulta_final_2018.Codigo_tres = 'K05') Then 'GINGIVITIS Y ENFERMEDADES PERIODONTALES' When (consulta_final_2018.Codigo_tres = 'F31') Then 'TRASTORNO AFECTIVO BIPOLAR' When (consulta_final_2018.Codigo_tres = 'K04') Then 'ENFERMEDADES DE LA PULPA Y DE LOS TEJIDOS PERIAPICALES' When (consulta_final_2018.Codigo_tres = 'K29') Then 'GASTRITIS Y DUODENITIS' When (consulta_final_2018.Codigo_tres = 'N39') Then 'OTROS TRASTORNOS DEL SISTEMA URINARIO' When (consulta_final_2018.Codigo_tres = 'F32') Then 'EPISODIO DEPRESIVO' When (consulta_final_2018.Codigo_tres = 'K01') Then 'DIENTES INCLUIDOS E IMPACTADOS' When (consulta_final_2018.Codigo_tres = 'F19') Then 'TRASTORNOS MENTALES Y DE COMPORTAMIENTO DEBIDOS AL USO DE MULTIPLES DROGAS Y AL USO DE OTRAS SUSTANCIAS PSICOACTIVAS' When (consulta_final_2018.Codigo_tres = 'M54') Then 'DORSALGIA' When (consulta_final_2018.Letra = 'R') Then 'SIGNOS,SINTOMAS Y AFECCIONES MAL DEFINIDAS ' Else 'RESTO DE CAUSAS' End) As `Diez Primeras Causas de Morbilidad`, (Case When (consulta_final_2018.Codigo_tres = 'K02') Then 1 When (consulta_final_2018.Codigo_tres = 'K05') Then 2 When (consulta_final_2018.Codigo_tres = 'F31') Then 3 When (consulta_final_2018.Codigo_tres = 'K04') Then 4 When (consulta_final_2018.Codigo_tres = 'K29') Then 5 When (consulta_final_2018.Codigo_tres = 'N39') Then 6 When (consulta_final_2018.Codigo_tres = 'F32') Then 7 When (consulta_final_2018.Codigo_tres = 'K01') Then 8 When (consulta_final_2018.Codigo_tres = 'F19') Then 9 When (consulta_final_2018.Codigo_tres = 'M54') Then 10 Else '' End) As Orden, (Case When (consulta_final_2018.Codigo_tres = 'K02') Then 1 When (consulta_final_2018.Codigo_tres = 'K05') Then 2 When (consulta_final_2018.Codigo_tres = 'F31') Then 3 When (consulta_final_2018.Codigo_tres = 'K04') Then 4 When (consulta_final_2018.Codigo_tres = 'K29') Then 5 When (consulta_final_2018.Codigo_tres = 'N39') Then 6 When (consulta_final_2018.Codigo_tres = 'F32') Then 7 When (consulta_final_2018.Codigo_tres = 'K01') Then 8 When (consulta_final_2018.Codigo_tres = 'F19') Then 9 When (consulta_final_2018.Codigo_tres = 'M54') Then 10 When (consulta_final_2018.Letra = 'R') Then 11 Else 12 End) As cuadro, consulta_final_2018.Codigo_tres, consulta_final_2018.Unidad_edad, consulta_final_2018.Edad FROM " . $this->getSqlFrom();
	}

	function SqlSelect() { // For backward compatibility
		return $this->getSqlSelect();
	}

	function setSqlSelect($v) {
		$this->_SqlSelect = $v;
	}

	// Where
	var $_SqlWhere = "";

	function getSqlWhere() {
		$sWhere = ($this->_SqlWhere <> "") ? $this->_SqlWhere : "consulta_final_2018.Unidad_edad = 1 And consulta_final_2018.Edad In (20,21,22,23,24,25,26,27,28,29)";
		return $sWhere;
	}

	function SqlWhere() { // For backward compatibility
		return $this->getSqlWhere();
	}

	function setSqlWhere($v) {
		$this->_SqlWhere = $v;
	}

	// Group By
	var $_SqlGroupBy = "";

	function getSqlGroupBy() {
		return ($this->_SqlGroupBy <> "") ? $this->_SqlGroupBy : "`Diez Primeras Causas de Morbilidad`";
	}

	function SqlGroupBy() { // For backward compatibility
		return $this->getSqlGroupBy();
	}

	function setSqlGroupBy($v) {
		$this->_SqlGroupBy = $v;
	}

	// Having
	var $_SqlHaving = "";

	function getSqlHaving() {
		return ($this->_SqlHaving <> "") ? $this->_SqlHaving : "";
	}

	function SqlHaving() { // For backward compatibility
		return $this->getSqlHaving();
	}

	function setSqlHaving($v) {
		$this->_SqlHaving = $v;
	}

	// Order By
	var $_SqlOrderBy = "";

	function getSqlOrderBy() {
		return ($this->_SqlOrderBy <> "") ? $this->_SqlOrderBy : "cuadro";
	}

	function SqlOrderBy() { // For backward compatibility
		return $this->getSqlOrderBy();
	}

	function setSqlOrderBy($v) {
		$this->_SqlOrderBy = $v;
	}

	// Select Aggregate
	var $_SqlSelectAgg = "";

	function getSqlSelectAgg() {
		return ($this->_SqlSelectAgg <> "") ? $this->_SqlSelectAgg : "SELECT Count(consulta_final_2018.Codigo_diagnostico) AS `tmp_total_primeras_causas_morbilidad`, (Count(consulta_final_2018.Codigo_diagnostico) / (Select Count(0) From consulta_final_2018 Where consulta_final_2018.Unidad_edad = 1 And consulta_final_2018.Edad In (20, 21, 22, 23, 24, 25, 26, 27, 28, 29)) * 100) AS `tmp__25`, (((Count(consulta_final_2018.Codigo_diagnostico) / 72324)) * 1000) AS `tmp_tasa` FROM " . $this->getSqlFrom();
	}

	function SqlSelectAgg() { // For backward compatibility
		return $this->getSqlSelectAgg();
	}

	function setSqlSelectAgg($v) {
		$this->_SqlSelectAgg = $v;
	}

	// Aggregate Prefix
	var $_SqlAggPfx = "";

	function getSqlAggPfx() {
		return ($this->_SqlAggPfx <> "") ? $this->_SqlAggPfx : "";
	}

	function SqlAggPfx() { // For backward compatibility
		return $this->getSqlAggPfx();
	}

	function setSqlAggPfx($v) {
		$this->_SqlAggPfx = $v;
	}

	// Aggregate Suffix
	var $_SqlAggSfx = "";

	function getSqlAggSfx() {
		return ($this->_SqlAggSfx <> "") ? $this->_SqlAggSfx : "";
	}

	function SqlAggSfx() { // For backward compatibility
		return $this->getSqlAggSfx();
	}

	function setSqlAggSfx($v) {
		$this->_SqlAggSfx = $v;
	}

	// Select Count
	var $_SqlSelectCount = "";

	function getSqlSelectCount() {
		return ($this->_SqlSelectCount <> "") ? $this->_SqlSelectCount : "SELECT COUNT(*) FROM " . $this->getSqlFrom();
	}

	function SqlSelectCount() { // For backward compatibility
		return $this->getSqlSelectCount();
	}

	function setSqlSelectCount($v) {
		$this->_SqlSelectCount = $v;
	}

	// Sort URL
	function SortUrl(&$fld) {
		return "";
	}

	// Table level events
	// Page Selecting event
	function Page_Selecting(&$filter) {

		// Enter your code here	
	}

	// Page Breaking event
	function Page_Breaking(&$break, &$content) {

		// Example:
		//$break = FALSE; // Skip page break, or
		//$content = "<div style=\"page-break-after:always;\">&nbsp;</div>"; // Modify page break content

	}

	// Row Rendering event
	function Row_Rendering() {

		// Enter your code here	
	}

	// Cell Rendered event
	function Cell_Rendered(&$Field, $CurrentValue, &$ViewValue, &$ViewAttrs, &$CellAttrs, &$HrefValue, &$LinkAttrs) {

		//$ViewValue = "xxx";
		//$ViewAttrs["style"] = "xxx";

	}

	// Row Rendered event
	function Row_Rendered() {

		// To view properties of field class, use:
		//var_dump($this-><FieldName>); 

	}

	// User ID Filtering event
	function UserID_Filtering(&$filter) {

		// Enter your code here
	}

	// Load Filters event
	function Page_FilterLoad() {

		// Enter your code here
		// Example: Register/Unregister Custom Extended Filter
		//ewr_RegisterFilter($this-><Field>, 'StartsWithA', 'Starts With A', 'GetStartsWithAFilter'); // With function, or
		//ewr_RegisterFilter($this-><Field>, 'StartsWithA', 'Starts With A'); // No function, use Page_Filtering event
		//ewr_UnregisterFilter($this-><Field>, 'StartsWithA');

	}

	// Page Filter Validated event
	function Page_FilterValidated() {

		// Example:
		//$this->MyField1->SearchValue = "your search criteria"; // Search value

	}

	// Page Filtering event
	function Page_Filtering(&$fld, &$filter, $typ, $opr = "", $val = "", $cond = "", $opr2 = "", $val2 = "") {

		// Note: ALWAYS CHECK THE FILTER TYPE ($typ)! Example:
		// if ($typ == "dropdown" && $fld->FldName == "MyField") // Dropdown filter
		//     $filter = "..."; // Modify the filter
		// if ($typ == "extended" && $fld->FldName == "MyField") // Extended filter
		//     $filter = "..."; // Modify the filter
		// if ($typ == "popup" && $fld->FldName == "MyField") // Popup filter
		//     $filter = "..."; // Modify the filter
		// if ($typ == "custom" && $opr == "..." && $fld->FldName == "MyField") // Custom filter, $opr is the custom filter ID
		//     $filter = "..."; // Modify the filter

	}

	// Email Sending event
	function Email_Sending(&$Email, &$Args) {

		//var_dump($Email); var_dump($Args); exit();
		return TRUE;
	}

	// Lookup Selecting event
	function Lookup_Selecting($fld, &$filter) {

		// Enter your code here
	}
}
?>
