<?php
require_once("../../base/php/startSession.php");
require_once("../../base/php/classDatabase.php");
require_once("../../base/php/Functions.php");
require_once("../../base/php/Environnement.php");
require_once("../../base/php/WebAppLog.php");

global $database;
global $getOption;
global $getParam;


$tableName = getPOST("tableName");
$getOption = getPOST("getOption");
$getParam = getPOST("getParam");
$refPrefix = getPOST("refPrefix");


//WebAppLog("","",print_r($_POST,true));

$database = new Database("iCTI");

//echo $softCode;

$httpString = "";
$httpString = $httpString . "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
$httpString = $httpString . "\n<HTTP_SERVICE>";

switch($tableName) {
	case "t_finess" :
		$httpString = $httpString . getRecords_finess();
		break;
	case "t_specialites_medecin" :
		$httpString = $httpString . getRecords_specialites_medecin();
		break;
	case "t_specialites_internes_medecin" :
		$httpString = $httpString . getRecords_specialites_internes_medecin();
		break;
	case "t_medecins" :
		$httpString = $httpString . getRecords_medecins();
		$httpString = $httpString . getCombo_specialites_internes_medecin();
		//$httpString = $httpString . getListe_medecins_a_regrouper();
		break;
	case "t_tranches_ages" :
		$httpString = $httpString . getRecords_tranches_ages();
		break;
	case "t_unites_medicales" :
		$httpString = $httpString . getRecords_unites_medicales();
		$httpString = $httpString . getCombo_types_autorisations();
		$httpString = $httpString . getCombo_medecins();
		$httpString = $httpString . getCombo_um();
		break;
	case "t_unites_fonctionnelles" :
		$httpString = $httpString . getRecords_unites_fonctionnelles();
		break;
	case "t_cmd" :
		$httpString = $httpString . getRecords_cmd();
		break;
	case "t_poles_oap" :
		$httpString = $httpString . getRecords_poles_oap();
		break;
	case "t_lignes_oap" :
		$httpString = $httpString . getRecords_lignes_oap();
		break;
	case "t_groupes_activite" :
		$httpString = $httpString . getRecords_groupes_activite();
		break;
	case "t_mco" :
		$httpString = $httpString . getRecords_mco();
		break;
	case "t_severites_ghm" :
		$httpString = $httpString . getRecords_severites_ghm();
		break;
	case "t_ghm" :
		$httpString = $httpString . getRecords_ghm();
		break;
	case "t_ghm_dms" :
		$httpString = $httpString . getRecords_ghm_dms();
		if ($getOption != "refresh") {
			$httpString = $httpString . getListe_ghm();
		}
		break;
	case "t_ghs" :
		$httpString = $httpString . getRecords_ghs();
		break;
	case "t_diagnostics" :
		$httpString = $httpString . getRecords_diagnostics();
		break;
	case "t_ccam_regroupements" :
		$httpString = $httpString . getRecords_ccam_regroupements();
		break;
	case "t_gestes_marqueurs" :
		$httpString = $httpString . getRecords_gestes_marqueurs();
		break;
	case "t_actes" :
		$httpString = $httpString . getRecords_actes();
		break;
	case "t_prestations" :
		$httpString = $httpString . getRecords_prestations();
		break;
	case "t_lpp" :
		$httpString = $httpString . getRecords_lpp();
		break;
	case "t_ucd" :
		$httpString = $httpString . getRecords_ucd();
		break;
	case "t_comites_medicaux" :
		$httpString = $httpString . getRecords_comites_medicaux();
		break;
	case "t_types_autorisations" :
		$httpString = $httpString . getRecords_types_autorisations();
		break;
	case "t_modes_entree" :
		$httpString = $httpString . getRecords_modes_entree();
		break;
	case "t_modes_sortie" :
		$httpString = $httpString . getRecords_modes_sortie();
		break;
	case "t_provenances_entree" :
		$httpString = $httpString . getRecords_provenances_entree();
		break;
	case "t_destinations_sortie" :
		$httpString = $httpString . getRecords_destinations_sortie();
		break;
	case "t_secteurs_geographiques" :
		$httpString = $httpString . getRecords_secteurs_geographiques();
		$httpString = $httpString . getListe_codes_postaux();
		break;
	case "t_departements" :
		$httpString = $httpString . getRecords_departements();
		break;
	case "t_codes_geographiques_pmsi" :
		$httpString = $httpString . getRecords_codes_geographiques_pmsi();
		break;
	case "t_codes_postaux" :
		$httpString = $httpString . getRecords_codes_postaux();
		$httpString = $httpString . getCombo_departements();
		break;
	case "t_etude_1" :
		$httpString = $httpString . getRecords_etude_1();
		break;
	// t_etude_2 déprécié et remplacé par t_etude_6
	case "t_etude_2" :
		$httpString = $httpString . getRecords_etude_2();
		break;
	/* deprecated
	case "t_etude_4" :
		$httpString .= getRecords_etude_4();
		break;
	*/
	case "t_etude_5" :
		$httpString .= getRecords_etude_5();
		break;
	case "t_etude_6" :
		$httpString .= getRecords_etude_6();
		break;
	case "t_expert_controle" :
		if ($getOption != "getRefSettings") {
			$httpString = $httpString . getRecords_expert_controle();
		}
		else {
			$httpString = $httpString . getRecords_expert_controle_refsettings($refPrefix);
		}
		break;
		
	case "t_datim_ccaminfo" :
		$httpString .= getRecords_datim_ccaminfo();
		break;
	case "t_datim_diaginfo" :
		$httpString .= getRecords_datim_diaginfo();
		break;
	case "t_datim_ghminfo" :
		$httpString .= getRecords_datim_ghminfo();
		break;
	case "t_divers" :
		$httpString .= getRecords_divers();
		break;
	case "t_etude_7" :
		$httpString .= getRecords_etude_7();
		break;
}

$httpString = $httpString . "\n</HTTP_SERVICE>";
 

//$httpString = compress64($httpString);

echo "<CTICONTENT>$httpString</CTICONTENT>";


// Finess
function getRecords_finess() {

global $database;

	$httpString = "";

	$sqlcmd = "SELECT t_finess.oid AS oid, t_finess.code AS code, t_finess.texte AS texte, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_1, 'DD/MM/YYYY'), coefficient_mco_1, coefficient_transition_1, coefficient_ht_1, coefficient_geo_1, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_2, 'DD/MM/YYYY'), coefficient_mco_2, coefficient_transition_2, coefficient_ht_2, coefficient_geo_2, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_3, 'DD/MM/YYYY'), coefficient_mco_3, coefficient_transition_3, coefficient_ht_3, coefficient_geo_3, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_4, 'DD/MM/YYYY'), coefficient_mco_4, coefficient_transition_4, coefficient_ht_4, coefficient_geo_4, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_5, 'DD/MM/YYYY'), coefficient_mco_5, coefficient_transition_5, coefficient_ht_5, coefficient_geo_5, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_6, 'DD/MM/YYYY'), coefficient_mco_6, coefficient_transition_6, coefficient_ht_6, coefficient_geo_6, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_7, 'DD/MM/YYYY'), coefficient_mco_7, coefficient_transition_7, coefficient_ht_7, coefficient_geo_7, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_8, 'DD/MM/YYYY'), coefficient_mco_8, coefficient_transition_8, coefficient_ht_8, coefficient_geo_8, ";
	$sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_mco_9, 'DD/MM/YYYY'), coefficient_mco_9, coefficient_transition_9, coefficient_ht_9, coefficient_geo_9, ";
	$sqlcmd = $sqlcmd . "coefficient_mco_simulation_fg11, ";
	$sqlcmd = $sqlcmd . "0, ";
	$sqlcmd = $sqlcmd . "t_territoires_sante.oid AS tersante_id, t_territoires_sante.code AS tersante_code, t_territoires_sante.texte AS tersante_texte, ";

    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_1, 'DD/MM/YYYY'), coefficient_pacte_resp_1, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_2, 'DD/MM/YYYY'), coefficient_pacte_resp_2, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_3, 'DD/MM/YYYY'), coefficient_pacte_resp_3, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_4, 'DD/MM/YYYY'), coefficient_pacte_resp_4, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_5, 'DD/MM/YYYY'), coefficient_pacte_resp_5, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_6, 'DD/MM/YYYY'), coefficient_pacte_resp_6, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_7, 'DD/MM/YYYY'), coefficient_pacte_resp_7, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_8, 'DD/MM/YYYY'), coefficient_pacte_resp_8, ";
    $sqlcmd = $sqlcmd . "to_char(date_debut_coefficient_pacte_resp_9, 'DD/MM/YYYY'), coefficient_pacte_resp_9 ";


	$sqlcmd = $sqlcmd . "FROM base.t_finess  ";
	$sqlcmd = $sqlcmd . "JOIN base.t_territoires_sante ON t_territoires_sante.oid = t_finess.territoire_sante_id  ";
	$sqlcmd = $sqlcmd . "WHERE t_finess.oid > 0 AND (t_finess.code IN (SELECT DISTINCT finess FROM pmsi.p_rss) OR (SELECT count(*) FROM pmsi.p_rss) = 0) ORDER BY t_finess.code";

	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				
				$date_debut_coefficient_mco_1 = trim($record[3]);
				if ($date_debut_coefficient_mco_1 == "31/12/2099") {
					$date_debut_coefficient_mco_1 = "";
				}
				$coefficient_mco_1 = $record[4] + 0;
				$coefficient_transition_1 = $record[5] + 0;
				$coefficient_ht_1 = $record[6] + 0;
				$coefficient_geo_1 = $record[7] + 0;
				$date_debut_coefficient_mco_2 = trim($record[8]);
				if ($date_debut_coefficient_mco_2 == "31/12/2099") {
					$date_debut_coefficient_mco_2 = "";
				}
				$coefficient_mco_2 = $record[9] + 0;
				$coefficient_transition_2 = $record[10] + 0;
				$coefficient_ht_2 = $record[11] + 0;
				$coefficient_geo_2 = $record[12] + 0;
				$date_debut_coefficient_mco_3 = trim($record[13]);
				if ($date_debut_coefficient_mco_3 == "31/12/2099") {
					$date_debut_coefficient_mco_3 = "";
				}
				$coefficient_mco_3 = $record[14] + 0;
				$coefficient_transition_3 = $record[15] + 0;
				$coefficient_ht_3 = $record[16] + 0;
				$coefficient_geo_3 = $record[17] + 0;
				$date_debut_coefficient_mco_4 = trim($record[18]);
				if ($date_debut_coefficient_mco_4 == "31/12/2099") {
					$date_debut_coefficient_mco_4 = "";
				}
				$coefficient_mco_4 = $record[19] + 0;
				$coefficient_transition_4 = $record[20] + 0;
				$coefficient_ht_4 = $record[21] + 0;
				$coefficient_geo_4 = $record[22] + 0;
				$date_debut_coefficient_mco_5 = trim($record[23]);
				if ($date_debut_coefficient_mco_5 == "31/12/2099") {
					$date_debut_coefficient_mco_5 = "";
				}
				$coefficient_mco_5 = $record[24] + 0;
				$coefficient_transition_5 = $record[25] + 0;
				$coefficient_ht_5 = $record[26] + 0;
				$coefficient_geo_5 = $record[27] + 0;
				$date_debut_coefficient_mco_6 = trim($record[28]);
				if ($date_debut_coefficient_mco_6 == "31/12/2099") {
					$date_debut_coefficient_mco_6 = "";
				}
				$coefficient_mco_6 = $record[29] + 0;
				$coefficient_transition_6 = $record[30] + 0;
				$coefficient_ht_6 = $record[31] + 0;
				$coefficient_geo_6 = $record[32] + 0;
				$date_debut_coefficient_mco_7 = trim($record[33]);
				if ($date_debut_coefficient_mco_7 == "31/12/2099") {
					$date_debut_coefficient_mco_7 = "";
				}
				$coefficient_mco_7 = $record[34] + 0;
				$coefficient_transition_7 = $record[35] + 0;
				$coefficient_ht_7 = $record[36] + 0;
				$coefficient_geo_7 = $record[37] + 0;
				$date_debut_coefficient_mco_8 = trim($record[38]);
				if ($date_debut_coefficient_mco_8 == "31/12/2099") {
					$date_debut_coefficient_mco_8 = "";
				}
				$coefficient_mco_8 = $record[39] + 0;
				$coefficient_transition_8 = $record[40] + 0;
				$coefficient_ht_8 = $record[41] + 0;
				$coefficient_geo_8 = $record[42] + 0;
				$date_debut_coefficient_mco_9 = trim($record[43]);
				if ($date_debut_coefficient_mco_9 == "31/12/2099") {
					$date_debut_coefficient_mco_9 = "";
				}
				$coefficient_mco_9 = $record[44] + 0;
				$coefficient_transition_9 = $record[45] + 0;
				$coefficient_ht_9 = $record[46] + 0;
				$coefficient_geo_9 = $record[47] + 0;
				
				$coefficient_mco_simulation_fg11 = $record[48] + 0;
				
				$nbref = $record[49] + 0;
				$tersante_id = $record[50] + 0;
				$tersante_code = toHTML(trim($record[51]));
				$tersante_texte = toHTML(trim($record[52]));
				
                $date_debut_coefficient_pacte_resp_1 = trim($record[53]);
                if ($date_debut_coefficient_pacte_resp_1 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_1 = "";
                }
                $coefficient_pacte_resp_1 = $record[54] + 0;
                $date_debut_coefficient_pacte_resp_2 = trim($record[55]);
                if ($date_debut_coefficient_pacte_resp_2 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_2 = "";
                }
                $coefficient_pacte_resp_2 = $record[56] + 0;
                $date_debut_coefficient_pacte_resp_3 = trim($record[57]);
                if ($date_debut_coefficient_pacte_resp_3 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_3 = "";
                }
                $coefficient_pacte_resp_3 = $record[58] + 0;
                $date_debut_coefficient_pacte_resp_4 = trim($record[59]);
                if ($date_debut_coefficient_pacte_resp_4 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_4 = "";
                }
                $coefficient_pacte_resp_4 = $record[60] + 0;
                $date_debut_coefficient_pacte_resp_5 = trim($record[61]);
                if ($date_debut_coefficient_pacte_resp_5 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_5 = "";
                }
                $coefficient_pacte_resp_5 = $record[62] + 0;
                $date_debut_coefficient_pacte_resp_6 = trim($record[63]);
                if ($date_debut_coefficient_pacte_resp_6 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_6 = "";
                }
                $coefficient_pacte_resp_6 = $record[64] + 0;
                $date_debut_coefficient_pacte_resp_7 = trim($record[65]);
                if ($date_debut_coefficient_pacte_resp_7 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_7 = "";
                }
                $coefficient_pacte_resp_7 = $record[66] + 0;
                $date_debut_coefficient_pacte_resp_8 = trim($record[67]);
                if ($date_debut_coefficient_pacte_resp_8 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_8 = "";
                }
                $coefficient_pacte_resp_8 = $record[68] + 0;
                $date_debut_coefficient_pacte_resp_9 = trim($record[69]);
                if ($date_debut_coefficient_pacte_resp_9 == "31/12/2099") {
                    $date_debut_coefficient_pacte_resp_9 = "";
                }
                $coefficient_pacte_resp_9 = $record[70] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "tersante_id=\"$tersante_id\" ";
				$httpString = $httpString . "tersante_code=\"$tersante_code\" ";
				$httpString = $httpString . "tersante_texte=\"$tersante_texte\" ";
				
				$httpString = $httpString . "date_debut_coefficient_mco_1=\"$date_debut_coefficient_mco_1\" ";
				$httpString = $httpString . "coefficient_mco_1=\"$coefficient_mco_1\" ";
				$httpString = $httpString . "coefficient_transition_1=\"$coefficient_transition_1\" ";
				$httpString = $httpString . "coefficient_ht_1=\"$coefficient_ht_1\" ";
				$httpString = $httpString . "coefficient_geo_1=\"$coefficient_geo_1\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_2=\"$date_debut_coefficient_mco_2\" ";
				$httpString = $httpString . "coefficient_mco_2=\"$coefficient_mco_2\" ";
				$httpString = $httpString . "coefficient_transition_2=\"$coefficient_transition_2\" ";
				$httpString = $httpString . "coefficient_ht_2=\"$coefficient_ht_2\" ";
				$httpString = $httpString . "coefficient_geo_2=\"$coefficient_geo_2\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_3=\"$date_debut_coefficient_mco_3\" ";
				$httpString = $httpString . "coefficient_mco_3=\"$coefficient_mco_3\" ";
				$httpString = $httpString . "coefficient_transition_3=\"$coefficient_transition_3\" ";
				$httpString = $httpString . "coefficient_ht_3=\"$coefficient_ht_3\" ";
				$httpString = $httpString . "coefficient_geo_3=\"$coefficient_geo_3\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_4=\"$date_debut_coefficient_mco_4\" ";
				$httpString = $httpString . "coefficient_mco_4=\"$coefficient_mco_4\" ";
				$httpString = $httpString . "coefficient_transition_4=\"$coefficient_transition_4\" ";
				$httpString = $httpString . "coefficient_ht_4=\"$coefficient_ht_4\" ";
				$httpString = $httpString . "coefficient_geo_4=\"$coefficient_geo_4\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_5=\"$date_debut_coefficient_mco_5\" ";
				$httpString = $httpString . "coefficient_mco_5=\"$coefficient_mco_5\" ";
				$httpString = $httpString . "coefficient_transition_5=\"$coefficient_transition_5\" ";
				$httpString = $httpString . "coefficient_ht_5=\"$coefficient_ht_5\" ";
				$httpString = $httpString . "coefficient_geo_5=\"$coefficient_geo_5\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_6=\"$date_debut_coefficient_mco_6\" ";
				$httpString = $httpString . "coefficient_mco_6=\"$coefficient_mco_6\" ";
				$httpString = $httpString . "coefficient_transition_6=\"$coefficient_transition_6\" ";
				$httpString = $httpString . "coefficient_ht_6=\"$coefficient_ht_6\" ";
				$httpString = $httpString . "coefficient_geo_6=\"$coefficient_geo_6\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_7=\"$date_debut_coefficient_mco_7\" ";
				$httpString = $httpString . "coefficient_mco_7=\"$coefficient_mco_7\" ";
				$httpString = $httpString . "coefficient_transition_7=\"$coefficient_transition_7\" ";
				$httpString = $httpString . "coefficient_ht_7=\"$coefficient_ht_7\" ";
				$httpString = $httpString . "coefficient_geo_7=\"$coefficient_geo_7\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_8=\"$date_debut_coefficient_mco_8\" ";
				$httpString = $httpString . "coefficient_mco_8=\"$coefficient_mco_8\" ";
				$httpString = $httpString . "coefficient_transition_8=\"$coefficient_transition_8\" ";
				$httpString = $httpString . "coefficient_ht_8=\"$coefficient_ht_8\" ";
				$httpString = $httpString . "coefficient_geo_8=\"$coefficient_geo_8\" ";
				$httpString = $httpString . "date_debut_coefficient_mco_9=\"$date_debut_coefficient_mco_9\" ";
				$httpString = $httpString . "coefficient_mco_9=\"$coefficient_mco_9\" ";
				$httpString = $httpString . "coefficient_transition_9=\"$coefficient_transition_9\" ";
				$httpString = $httpString . "coefficient_ht_9=\"$coefficient_ht_9\" ";
				$httpString = $httpString . "coefficient_geo_9=\"$coefficient_geo_9\" ";
				
				$httpString = $httpString . "coefficient_mco_simulation_fg11=\"$coefficient_mco_simulation_fg11\" ";


                $httpString = $httpString . "date_debut_coefficient_pacte_resp_1=\"$date_debut_coefficient_pacte_resp_1\" ";
                $httpString = $httpString . "coefficient_pacte_resp_1=\"$coefficient_pacte_resp_1\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_2=\"$date_debut_coefficient_pacte_resp_2\" ";
                $httpString = $httpString . "coefficient_pacte_resp_2=\"$coefficient_pacte_resp_2\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_3=\"$date_debut_coefficient_pacte_resp_3\" ";
                $httpString = $httpString . "coefficient_pacte_resp_3=\"$coefficient_pacte_resp_3\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_4=\"$date_debut_coefficient_pacte_resp_4\" ";
                $httpString = $httpString . "coefficient_pacte_resp_4=\"$coefficient_pacte_resp_4\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_5=\"$date_debut_coefficient_pacte_resp_5\" ";
                $httpString = $httpString . "coefficient_pacte_resp_5=\"$coefficient_pacte_resp_5\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_6=\"$date_debut_coefficient_pacte_resp_6\" ";
                $httpString = $httpString . "coefficient_pacte_resp_6=\"$coefficient_pacte_resp_6\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_7=\"$date_debut_coefficient_pacte_resp_7\" ";
                $httpString = $httpString . "coefficient_pacte_resp_7=\"$coefficient_pacte_resp_7\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_8=\"$date_debut_coefficient_pacte_resp_8\" ";
                $httpString = $httpString . "coefficient_pacte_resp_8=\"$coefficient_pacte_resp_8\" ";
                $httpString = $httpString . "date_debut_coefficient_pacte_resp_9=\"$date_debut_coefficient_pacte_resp_9\" ";
                $httpString = $httpString . "coefficient_pacte_resp_9=\"$coefficient_pacte_resp_9\" ";
				
				
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

// spécialités médecins
function getRecords_specialites_medecin() {

global $database;

	$httpString = "";

	

	$sqlcmd = "SELECT oid, code, texte, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_specialites_medecin  ";
	$sqlcmd = $sqlcmd . "c) ";
	$sqlcmd = $sqlcmd . "WHERE oid > 0 ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$nbref = $record[3] + 0;
				
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_specialites_internes_medecin() {

global $database;

	$httpString = "";

	
	$httpString = $httpString . "\r\n<RECORD ";
	$httpString = $httpString . "oid=\"-1\" ";
	$httpString = $httpString . "code=\"\" ";
	$httpString = $httpString . "texte=\"Nouvelle spécialité\" ";
	$httpString = $httpString . "specialite_defaut_code_1=\"\" ";
	$httpString = $httpString . "specialite_defaut_code_2=\"\" ";
	$httpString = $httpString . "specialite_defaut_code_3=\"\" ";
	$httpString = $httpString . "specialite_defaut_code_4=\"\" ";
	$httpString = $httpString . "specialite_defaut_code_5=\"\" ";
	$httpString = $httpString . "nbref=\"+0\" ";
	$httpString = $httpString . "/>";

	$sqlcmd = "SELECT oid, code, texte, ";
	$sqlcmd = $sqlcmd . "specialite_defaut_code_1, ";
	$sqlcmd = $sqlcmd . "specialite_defaut_code_2, ";
	$sqlcmd = $sqlcmd . "specialite_defaut_code_3, ";
	$sqlcmd = $sqlcmd . "specialite_defaut_code_4, ";
	$sqlcmd = $sqlcmd . "specialite_defaut_code_5, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_specialites_internes_medecin  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT specialite_interne_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_medecins  ";
	$sqlcmd = $sqlcmd . "GROUP BY specialite_interne_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_specialites_internes_medecin.oid = subview.specialite_interne_id) ";
	$sqlcmd = $sqlcmd . "WHERE oid > 0 ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$specialite_defaut_code_1 = toHTML(trim($record[3]));
				$specialite_defaut_code_2 = toHTML(trim($record[4]));
				$specialite_defaut_code_3 = toHTML(trim($record[5]));
				$specialite_defaut_code_4 = toHTML(trim($record[6]));
				$specialite_defaut_code_5 = toHTML(trim($record[7]));
				$nbref = $record[8] + 0;
				
				$specialite_defaut_codes = $specialite_defaut_code_1;
				if ($specialite_defaut_code_2 != "") {
					if ($specialite_defaut_codes != "") {
						$specialite_defaut_codes = $specialite_defaut_codes . ", ";
					}
					$specialite_defaut_codes = $specialite_defaut_codes . " " . $specialite_defaut_code_2;
				}
				if ($specialite_defaut_code_3 != "") {
					if ($specialite_defaut_codes != "") {
						$specialite_defaut_codes = $specialite_defaut_codes . ", ";
					}
					$specialite_defaut_codes = $specialite_defaut_codes . " " . $specialite_defaut_code_3;
				}
				if ($specialite_defaut_code_4 != "") {
					if ($specialite_defaut_codes != "") {
						$specialite_defaut_codes = $specialite_defaut_codes . ", ";
					}
					$specialite_defaut_codes = $specialite_defaut_codes . " " . $specialite_defaut_code_4;
				}
				if ($specialite_defaut_code_5 != "") {
					if ($specialite_defaut_codes != "") {
						$specialite_defaut_codes = $specialite_defaut_codes . ", ";
					}
					$specialite_defaut_codes = $specialite_defaut_codes . " " . $specialite_defaut_code_5;
				}
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "specialite_defaut_codes=\"$specialite_defaut_codes\" ";
				$httpString = $httpString . "specialite_defaut_code_1=\"$specialite_defaut_code_1\" ";
				$httpString = $httpString . "specialite_defaut_code_2=\"$specialite_defaut_code_2\" ";
				$httpString = $httpString . "specialite_defaut_code_3=\"$specialite_defaut_code_3\" ";
				$httpString = $httpString . "specialite_defaut_code_4=\"$specialite_defaut_code_4\" ";
				$httpString = $httpString . "specialite_defaut_code_5=\"$specialite_defaut_code_5\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

// médecins
function getRecords_medecins() {

global $database;

	$httpString = "";

	
	
	$sqlcmd = "SELECT 
				t_medecins.oid, 
				t_medecins.code, 
				t_medecins.nom, 
				t_medecins.prenom,
				t_medecins_reference.numero_ordre, 
				t_medecins_reference.specialite_id, 
				COALESCE(t_specialites_medecin.code || ' ' || t_specialites_medecin.texte,''), 
				t_medecins.medecin_id, 
				CASE WHEN t_medecins.medecin_id > 0 THEN t_medecins_reference.nom || ' ' || t_medecins_reference.prenom || ' (' || t_medecins_reference.code || ')' ELSE '' END, 
				t_medecins.identifiant_annuaire, 
				rss_ref.count, 
				act_ref.count 
			FROM pmsi.t_medecins 
			JOIN base.t_medecins t_medecins_reference ON t_medecins.medecin_id = t_medecins_reference.oid 
			LEFT JOIN base.t_specialites_medecin ON t_medecins_reference.specialite_id = t_specialites_medecin.oid AND t_medecins_reference.specialite_id <> 0
			LEFT JOIN 
				(SELECT medecin_rss_id, count(*) as count 
				FROM pmsi.p_rss 
				GROUP BY medecin_rss_id) rss_ref 
				ON (t_medecins.oid = rss_ref.medecin_rss_id) 
			LEFT JOIN 
				(SELECT medecin_id, count(*) as count 
				FROM pmsi.p_rss_actes 
				GROUP BY medecin_id) act_ref 
				ON (t_medecins.oid = act_ref.medecin_id)
			WHERE t_medecins.oid > 0 
			ORDER BY nom, prenom";
	$result = $database->exec($sqlcmd, "");
	
	$httpString_tmp = "";
				
	if ($result != false) {
	
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
					
			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$nom = toHTML(trim($record[2]));
				$prenom = toHTML(trim($record[3]));
				$no_adeli = toHTML(trim($record[4]));
				$specialite_id = $record[5];
				$specialite = toHTML(trim($record[6]));
				$medecin_reference_id = $record[7];
				$medecin_reference = toHTML(trim($record[8]));
				$identifiant_annuaire = toHTML(trim($record[9]));
				$nbref = $record[10] + 0;
				$nbref2 = $record[11] + 0;
				
				if ($specialite_id == "0") {
					$specialite = "";
				}
				if ($specialite_interne_id == "0") {
					$specialite_interne = "";
				}
			
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "nom=\"$nom\" ";
				$httpString_tmp = $httpString_tmp . "prenom=\"$prenom\" ";
				$httpString_tmp = $httpString_tmp . "no_adeli=\"$no_adeli\" ";
				$httpString_tmp = $httpString_tmp . "specialite_id=\"$specialite_id\" ";
				$httpString_tmp = $httpString_tmp . "specialite=\"$specialite\" ";
				$httpString_tmp = $httpString_tmp . "medecin_reference_id=\"$medecin_reference_id\" ";
				$httpString_tmp = $httpString_tmp . "medecin_reference=\"$medecin_reference\" ";
				$httpString_tmp = $httpString_tmp . "identifiant_annuaire=\"$identifiant_annuaire\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . "nbref2=\"+$nbref2\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}
			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

// spécialités médecins pour combo
function getCombo_specialites_internes_medecin() {

global $database;

	$httpString = "";

	
	$httpString = $httpString . "\r\n<COMBO_SPI>";

	$sqlcmd = "SELECT oid, code || ' ' || texte ";
	$sqlcmd = $sqlcmd . "FROM base.t_specialites_medecin  ";
	$sqlcmd = $sqlcmd . "WHERE oid >= 0 ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$texte = toHTML(trim($record[1]));
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}

	$httpString = $httpString . "\r\n</COMBO_SPI>";
	
	return $httpString;
	
	

}

// spécialités médecins pour combo
function getListe_medecins_a_regrouper() {

global $database;

	$httpString = "";

	
	$httpString = $httpString . "\r\n<LIST_MEDA>";

	$sqlcmd = "SELECT oid, nom || ' ' || prenom || ' (' || code || ')'";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_medecins  ";
	$sqlcmd = $sqlcmd . "WHERE oid >= 0 ";
	$sqlcmd = $sqlcmd . "AND oid not in (SELECT DISTINCT medecin_reference_id FROM pmsi.t_medecins) ";
	$sqlcmd = $sqlcmd . "ORDER BY nom, prenom";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$texte = toHTML(trim($record[1]));
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}

	$httpString = $httpString . "\r\n</LIST_MEDA>";
	
	return $httpString;
	
	

}

function getRecords_tranches_ages() {

global $database;

	initRecords_tranches_ages();

	$httpString = "";

	
	$httpString = $httpString . "\r\n<RECORD ";
	$httpString = $httpString . "oid=\"-1\" ";
	$httpString = $httpString . "code=\"\" ";
	$httpString = $httpString . "texte=\"Nouvelle tranche\" ";
	$httpString = $httpString . "texte_court=\"\" ";
	$httpString = $httpString . "age_min=\"\" ";
	$httpString = $httpString . "age_max=\"\" ";
	$httpString = $httpString . "/>";

	$sqlcmd = "SELECT oid, code, texte, texte_court, age_min, age_max ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_tranches_ages  ";
	$sqlcmd = $sqlcmd . "WHERE oid > 0 ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$age_min = $record[4] + 0;
				$age_max = $record[5] + 0;
				
				
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "age_min=\"$age_min\" ";
				$httpString = $httpString . "age_max=\"$age_max\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function initRecords_tranches_ages() {

global $database;

		$count = 0;
		$result = $database->exec("SELECT count(*) as count from pmsi.t_tranches_ages ");
		if ($result != false) {
			$record = $database->nextRecordInto();
			if ($record != FALSE) {
				$count = $record[0] + 0;
			}
		}
		if ($count == 0) {
		
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T01', 'Nouvaux nés', 'Nouvaux nés', 0, 0)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T02', '1 - 5 ans', '1 - 5 ans', 1, 5)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T03', '6 - 12 ans', '6 - 12 ans', 6, 12)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T04', '13 - 20 ans', '13 - 20 ans', 13, 20)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T05', '21 - 30 ans', '21 - 30 ans', 21, 30)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T06', '31 - 40 ans, '31 - 40 ans', 31, 40)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T07', '41 - 50 ans', '41 - 50 ans', 41, 50)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T08', '51 - 60 ans', '51 - 60 ans', 51, 60)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T09', '61 - 70 ans', '61 - 70 ans', 61, 70)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T10', '71 - 80 ans', '71 - 80 ans', 71, 80)";
			$result = $database->exec($sqlcmd);
			$sqlcmd = "INSERT INTO pmsi.t_tranches_ages (code, texte, texte_court, age_min, age_max) ";
			$sqlcmd = $sqlcmd . "VALUES('T11', '> 80', '> 80', 81, 150)";
			$result = $database->exec($sqlcmd);
		
		}

}

function getRecords_unites_medicales() {

global $database;

	$httpString = "";

	$sqlcmd = "
		SELECT
			t_unites_medicales.oid,
			t_unites_medicales.code,
			t_unites_medicales.texte,
			t_unites_medicales.type_ventilation_ca,
			t_unites_medicales.type_eclatement, 
			t_unites_medicales.type_sejour, 
			t_unites_medicales.type_autorisation,
			t_unites_medicales.type_autorisation || ' ' || t_types_autorisations.texte,
			t_unites_medicales.date_effet_autorisation,
			t_unites_medicales.nb_lits,
			t_unites_medicales.mode_hospitalisation,
			t_unites_medicales.medecin_par_defaut_id, 
			COALESCE(t_unites_medicales.um_expedition_id, 0), 
			CASE WHEN t_unites_medicales.um_expedition_id > 0 THEN um_expedition.code || ' - ' || um_expedition.texte ELSE ''::text END as um_expedition_codetexte,
			subview.count
		FROM pmsi.t_unites_medicales 
			LEFT JOIN pmsi.t_unites_medicales um_expedition ON um_expedition.oid = t_unites_medicales.um_expedition_id
			LEFT JOIN (
				SELECT unite_medicale_id, count(*) as count 
				FROM pmsi.p_rss_rum 
				GROUP BY unite_medicale_id
				) AS subview ON t_unites_medicales.oid = subview.unite_medicale_id
			LEFT JOIN pmsi.t_types_autorisations ON t_unites_medicales.type_autorisation = t_types_autorisations.code
		WHERE t_unites_medicales.oid > 0
		ORDER BY t_unites_medicales.code
	";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {

		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$type_ventilation_ca = toHTML(trim($record[3]));
				$type_eclatement = toHTML(trim($record[4]));
				$type_sejour = toHTML(trim($record[5]));
				$type_autorisation_code = toHTML(trim($record[6]));
				$type_autorisation = toHTML(trim($record[7]));
				$date_effet_autorisation = toHTML(trim($record[8]));
				$nb_lits = toHTML(trim($record[9]));
				$mode_hospitalisation = toHTML(trim($record[10]));
				$medecin_par_defaut_id = trim($record[11]) + 0;
				$um_expedition_id = trim($record[12]) + 0;
				$um_expedition_codetexte = toHTML(trim($record[13]));
				$nbref = $record[14] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "type_ventilation_ca=\"$type_ventilation_ca\" ";
				$httpString = $httpString . "type_eclatement=\"$type_eclatement\" ";
				$httpString = $httpString . "type_sejour=\"$type_sejour\" ";
				$httpString = $httpString . "type_autorisation_code=\"$type_autorisation_code\" ";
				$httpString = $httpString . "type_autorisation=\"$type_autorisation\" ";
				$httpString = $httpString . "date_effet_autorisation=\"$date_effet_autorisation\" ";
				$httpString = $httpString . "nb_lits=\"$nb_lits\" ";
				$httpString = $httpString . "mode_hospitalisation=\"$mode_hospitalisation\" ";
				$httpString = $httpString . "medecin_par_defaut_id=\"$medecin_par_defaut_id\" ";
				$httpString = $httpString . "um_expedition_id=\"$um_expedition_id\" ";
				$httpString = $httpString . "um_expedition_codetexte=\"$um_expedition_codetexte\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_unites_fonctionnelles() {
	
	global $database;
	
	$httpString = "";
	
	$sqlcmd = "
		SELECT
			t_unites_fonctionnelles.oid,
			t_unites_fonctionnelles.code,
			t_unites_fonctionnelles.texte,
			subview.count
		FROM 
			pmsi.t_unites_fonctionnelles 
			LEFT JOIN (
				SELECT unite_fonctionnelle_id, count(*) as count 
				FROM pmsi.p_rss_actes 
				GROUP BY unite_fonctionnelle_id
				) AS subview ON t_unites_fonctionnelles.oid = subview.unite_fonctionnelle_id
		WHERE t_unites_fonctionnelles.oid > 0
		ORDER BY t_unites_fonctionnelles.code
	";
	$result = $database->exec($sqlcmd);
	
	if ($result != false) {
		
		$ok = TRUE;
		
		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
			
			if ($record != FALSE) {
				$ok = TRUE;
				
				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$nbref = $record[3] + 0;
				
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";
			}
		}
	}
	return $httpString;
}

function getRecords_ghm_dms() {

global $database;
global $getOption;

	if ($getOption != "refresh") {
		$sqlcmd = "INSERT INTO pmsi.t_divers (code)
			SELECT code FROM
			(SELECT 'GHMDMS1' as code UNION SELECT 'GHMDMS2' UNION SELECT 'GHMDMS3') subview
			WHERE code NOT IN (SELECT code FROM pmsi.t_divers);";
		$result = $database->exec($sqlcmd);
	}

	$httpString = "";
	
	
	$sqlcmd = "SELECT 
			base.cti_group_concat_without_sep(oid::text || '=' || dms_1::text || ';')
			FROM pmsi.t_ghm WHERE dms_1 > 0";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		$record = $database->nextRecordInto();
		if ($record != FALSE) {
			$dms_1 = toHTML(trim($record[0]));
		}
	}
	$sqlcmd = "SELECT 
			base.cti_group_concat_without_sep(oid::text || '=' || dms_2::text || ';')
			FROM pmsi.t_ghm WHERE dms_2 > 0";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		$record = $database->nextRecordInto();
		if ($record != FALSE) {
			$dms_2 = toHTML(trim($record[0]));
		}
	}
	
	$sqlcmd = "SELECT 
			base.cti_group_concat_without_sep(oid::text || '=' || dms_3::text || ';')
			FROM pmsi.t_ghm WHERE dms_3 > 0";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		$record = $database->nextRecordInto();
		if ($record != FALSE) {
			$dms_3 = toHTML(trim($record[0]));
		}
	}

	$sqlcmd = "SELECT substr(code, 7, 1) as oid, 'Classe ' || substr(code, 7, 1) || CASE WHEN substr(code, 7, 1) = '1' THEN ' (Personnalisable)' ELSE ' (CTI)' END, texte 
			FROM pmsi.t_divers
			WHERE code IN ('GHMDMS1', 'GHMDMS2', 'GHMDMS3')
			ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {

		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$dms = "";
				if ($oid == 1 && $texte != "") {
					$dms = $dms_1;
				}
				if ($oid == 2 && $texte != "") {
					$dms = $dms_2;
				}
				if ($oid == 3 && $texte != "") {
					$dms = $dms_3;
				}
				
				$httpString = $httpString . "\r\n<RECORD oid=\"$oid\" code=\"$code\" texte=\"$texte\" dms=\"$dms\"  />";
			}
		}

	
	}
	
	return $httpString;
	
	

}

function getCombo_types_autorisations() {

global $database;

	$httpString = "";

	
	$httpString = $httpString . "\r\n<COMBO_TAU>";

	$sqlcmd = "SELECT code, code || ' ' || texte ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_types_autorisations  ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . " />";

			}
		}

	}

	$httpString = $httpString . "\r\n</COMBO_TAU>";
	
	return $httpString;
	
	

}

function getCombo_medecins() {

global $database;

	$httpString = "";
	
	
	$httpString = "$httpString\r\n<COMBO_MED>";
	
	$httpString_tmp = "";

	$sqlcmd = "SELECT t_medecins.oid, t_medecins.nom || ' ' || t_medecins.prenom
			FROM pmsi.t_medecins  
			WHERE t_medecins.oid > 0 
			ORDER BY 2";
	$result = $database->exec($sqlcmd);
	
	$httpString_tmp = "$httpString_tmp\r\n<RECORD oid=\"0\" texte=\"\"  />";
	
				
	if ($result != false) {
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
			
				$httpString_tmp = "$httpString_tmp\r\n<RECORD oid=\"$oid\" texte=\"$texte\"  />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	}
	
	$httpString = "$httpString$httpString_tmp\r\n</COMBO_MED>";

	
	return $httpString;
	
}

function getRecords_cmd() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_cmd.oid, t_cmd.code, t_cmd.texte, t_cmd.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_cmd  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_ghm.cmd_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm  ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid  ";
	$sqlcmd = $sqlcmd . "GROUP BY t_ghm.cmd_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_cmd.oid = subview.cmd_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_cmd.oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_mco() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_mco.code as oid, t_mco.code, t_mco.texte,  ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_mco  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_ghm.mco, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm  ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid  ";
	$sqlcmd = $sqlcmd . "GROUP BY t_ghm.mco) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_mco.code = subview.mco) ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$nbref = $record[3] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_severites_ghm() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_severites_ghm.code as oid, t_severites_ghm.code, t_severites_ghm.texte,  ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_severites_ghm  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_ghm.severite, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm  ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid  ";
	$sqlcmd = $sqlcmd . "GROUP BY t_ghm.severite) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_severites_ghm.code = subview.severite) ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$nbref = $record[3] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_poles_oap() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_poles_oap.oid, t_poles_oap.code, t_poles_oap.texte, t_poles_oap.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_poles_oap  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_lignes_oap.pole_oap_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm, pmsi.t_lignes_oap  ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid AND t_ghm.ligne_oap_id = t_lignes_oap.oid ";
	$sqlcmd = $sqlcmd . "GROUP BY t_lignes_oap.pole_oap_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_poles_oap.oid = subview.pole_oap_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_poles_oap.oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_groupes_activite() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_groupes_activite.oid, t_groupes_activite.code, t_groupes_activite.texte, t_groupes_activite.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_groupes_activite  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_ghm.groupe_activite_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid ";
	$sqlcmd = $sqlcmd . "GROUP BY t_ghm.groupe_activite_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_groupes_activite.oid = subview.groupe_activite_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_groupes_activite.oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY t_groupes_activite.code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_lignes_oap() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_lignes_oap.oid, t_lignes_oap.code, t_lignes_oap.texte, t_poles_oap.code || ' ' || t_poles_oap.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_lignes_oap  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_ghm.ligne_oap_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, pmsi.t_ghm  ";
	$sqlcmd = $sqlcmd . "WHERE p_rss.ghm_id = t_ghm.oid ";
	$sqlcmd = $sqlcmd . "GROUP BY t_ghm.ligne_oap_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_lignes_oap.oid = subview.ligne_oap_id), ";
	$sqlcmd = $sqlcmd . "pmsi.t_poles_oap ";
	$sqlcmd = $sqlcmd . "WHERE t_lignes_oap.oid > 0 AND t_lignes_oap.pole_oap_id = t_poles_oap.oid ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$pole_oap = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "pole_oap=\"$pole_oap\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_ghm() {

global $database;

	$httpString = "";

	
	$sqlcmd = "	SELECT 
					t_ghm.oid, 
					t_ghm.code, 
					t_ghm.texte, 
					t_ghm.aso, 
					t_cas.code AS cas_code,
					t_cas.code || ' - ' || t_cas.texte AS cas_code_texte,
					t_poles_oap.code || ' - ' || t_poles_oap.texte_court, 
					t_lignes_oap.code || ' - ' || t_lignes_oap.texte, 
					t_groupes_activite.code || ' - ' || t_groupes_activite.texte_court, 
					t_ghm.dms_1, 
					t_ghm.dms_2, 
					t_ghm.dms_3, 
					subview.count 
				FROM 
					pmsi.t_ghm  
					LEFT JOIN (	SELECT ghm_id, count(*) as count  
							FROM pmsi.p_rss  
							GROUP BY ghm_id
						   ) subview ON (t_ghm.oid = subview.ghm_id), 
					pmsi.t_poles_oap,
					pmsi.t_lignes_oap,
					pmsi.t_groupes_activite,
					base.t_cas
				WHERE
					t_ghm.oid > 0 
					AND t_ghm.ligne_oap_id = t_lignes_oap.oid 
					AND t_lignes_oap.pole_oap_id = t_poles_oap.oid 
					AND t_ghm.groupe_activite_id = t_groupes_activite.oid
					AND t_ghm.cas_id = t_cas.oid
				ORDER BY t_ghm.code";
	$result = $database->exec($sqlcmd);
	
	$httpString_tmp = "";
	
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$aso = toHTML(trim($record[3]));
				$cas = toHTML(trim($record[4]));
				$cas_code_texte = toHTML(trim($record[5]));
				$pole_oap = toHTML(trim($record[6]));
				$ligne_oap = toHTML(trim($record[7]));
				$groupe_activite = toHTML(trim($record[8]));
				$dms_1 = $record[9] + 0;
				$dms_2 = $record[10] + 0;
				$dms_3 = $record[11] + 0;
				$nbref = $record[12] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "aso=\"$aso\" ";
				$httpString_tmp = $httpString_tmp . "cas=\"$cas\" ";
				$httpString_tmp = $httpString_tmp . "cas_code_texte=\"$cas_code_texte\" ";
				$httpString_tmp = $httpString_tmp . "pole_oap=\"$pole_oap\" ";
				$httpString_tmp = $httpString_tmp . "ligne_oap=\"$ligne_oap\" ";
				$httpString_tmp = $httpString_tmp . "groupe_activite=\"$groupe_activite\" ";
				$httpString_tmp = $httpString_tmp . "dms_1=\"+$dms_1\" ";
				$httpString_tmp = $httpString_tmp . "dms_2=\"+$dms_2\" ";
				$httpString_tmp = $httpString_tmp . "dms_3=\"+$dms_3\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_ghs() {

global $database;

	
	$GHS_type_tarif = @$_POST["GHS_type_tarif"];
	if ($GHS_type_tarif == "") {
		$GHS_type_tarif = @$_GET["GHS_type_tarif"];
	}
	$GHS_date_tarif = @$_POST["GHS_date_tarif"];
	if ($GHS_date_tarif == "") {
		$GHS_date_tarif = @$_GET["GHS_date_tarif"];
	}

	if ($GHS_type_tarif == "") {
		$GHS_type_tarif = "PRIVE";
	}
	if ($GHS_date_tarif == "") {
		$GHS_date_tarif = date("Y-m-d");
	}

	$httpString = "";

	
	$sqlcmd = "SELECT t_ghs.oid, t_ghs.code, t_ghs.texte, ";
	$sqlcmd = $sqlcmd . "t_ghs.borne_basse, t_ghs.borne_haute, t_ghs.dms_nationale, t_ghs.tarif_ghs, t_ghs.forfait_exb, t_ghs.tarif_exb, t_ghs.tarif_exh, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_1, date_fin_prive_1, borne_basse_prive_1, borne_haute_prive_1, dms_nationale_prive_1, tarif_ghs_prive_1, forfait_exb_prive_1, tarif_exb_prive_1, tarif_exh_prive_1, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_2, date_fin_prive_2, borne_basse_prive_2, borne_haute_prive_2, dms_nationale_prive_2, tarif_ghs_prive_2, forfait_exb_prive_2, tarif_exb_prive_2, tarif_exh_prive_2, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_3, date_fin_prive_3, borne_basse_prive_3, borne_haute_prive_3, dms_nationale_prive_3, tarif_ghs_prive_3, forfait_exb_prive_3, tarif_exb_prive_3, tarif_exh_prive_3, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_4, date_fin_prive_4, borne_basse_prive_4, borne_haute_prive_4, dms_nationale_prive_4, tarif_ghs_prive_4, forfait_exb_prive_4, tarif_exb_prive_4, tarif_exh_prive_4, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_5, date_fin_prive_5, borne_basse_prive_5, borne_haute_prive_5, dms_nationale_prive_5, tarif_ghs_prive_5, forfait_exb_prive_5, tarif_exb_prive_5, tarif_exh_prive_5, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_6, date_fin_prive_6, borne_basse_prive_6, borne_haute_prive_6, dms_nationale_prive_6, tarif_ghs_prive_6, forfait_exb_prive_6, tarif_exb_prive_6, tarif_exh_prive_6, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_7, date_fin_prive_7, borne_basse_prive_7, borne_haute_prive_7, dms_nationale_prive_7, tarif_ghs_prive_7, forfait_exb_prive_7, tarif_exb_prive_7, tarif_exh_prive_7, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_8, date_fin_prive_8, borne_basse_prive_8, borne_haute_prive_8, dms_nationale_prive_8, tarif_ghs_prive_8, forfait_exb_prive_8, tarif_exb_prive_8, tarif_exh_prive_8, ";
	$sqlcmd = $sqlcmd . "date_debut_prive_9, date_fin_prive_9, borne_basse_prive_9, borne_haute_prive_9, dms_nationale_prive_9, tarif_ghs_prive_9, forfait_exb_prive_9, tarif_exb_prive_9, tarif_exh_prive_9, ";
	$sqlcmd = $sqlcmd . "date_debut_public_1, date_fin_public_1, borne_basse_public_1, borne_haute_public_1, dms_nationale_public_1, tarif_ghs_public_1, forfait_exb_public_1, tarif_exb_public_1, tarif_exh_public_1, ";
	$sqlcmd = $sqlcmd . "date_debut_public_2, date_fin_public_2, borne_basse_public_2, borne_haute_public_2, dms_nationale_public_2, tarif_ghs_public_2, forfait_exb_public_2, tarif_exb_public_2, tarif_exh_public_2, ";
	$sqlcmd = $sqlcmd . "date_debut_public_3, date_fin_public_3, borne_basse_public_3, borne_haute_public_3, dms_nationale_public_3, tarif_ghs_public_3, forfait_exb_public_3, tarif_exb_public_3, tarif_exh_public_3, ";
	$sqlcmd = $sqlcmd . "date_debut_public_4, date_fin_public_4, borne_basse_public_4, borne_haute_public_4, dms_nationale_public_4, tarif_ghs_public_4, forfait_exb_public_4, tarif_exb_public_4, tarif_exh_public_4, ";
	$sqlcmd = $sqlcmd . "date_debut_public_5, date_fin_public_5, borne_basse_public_5, borne_haute_public_5, dms_nationale_public_5, tarif_ghs_public_5, forfait_exb_public_5, tarif_exb_public_5, tarif_exh_public_5, ";
	$sqlcmd = $sqlcmd . "date_debut_public_6, date_fin_public_6, borne_basse_public_6, borne_haute_public_6, dms_nationale_public_6, tarif_ghs_public_6, forfait_exb_public_6, tarif_exb_public_6, tarif_exh_public_6, ";
	$sqlcmd = $sqlcmd . "date_debut_public_7, date_fin_public_7, borne_basse_public_7, borne_haute_public_7, dms_nationale_public_7, tarif_ghs_public_7, forfait_exb_public_7, tarif_exb_public_7, tarif_exh_public_7, ";
	$sqlcmd = $sqlcmd . "date_debut_public_8, date_fin_public_8, borne_basse_public_8, borne_haute_public_8, dms_nationale_public_8, tarif_ghs_public_8, forfait_exb_public_8, tarif_exb_public_8, tarif_exh_public_8, ";
	$sqlcmd = $sqlcmd . "date_debut_public_9, date_fin_public_9, borne_basse_public_9, borne_haute_public_9, dms_nationale_public_9, tarif_ghs_public_9, forfait_exb_public_9, tarif_exb_public_9, tarif_exh_public_9, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_ghs  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT ghs_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss  ";
	$sqlcmd = $sqlcmd . "GROUP BY ghs_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_ghs.oid = subview.ghs_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_ghs.oid > 0 AND t_ghs.code > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY t_ghs.code ";
	$result = $database->exec($sqlcmd);
	
	$httpString_tmp = "";
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$borne_basse = $record[3];
				$borne_haute = $record[4];
				$dms_nationale = $record[5];
				$tarif_ghs = $record[6];
				$forfait_exb = $record[7];
				$tarif_exb = $record[8];
				$tarif_exh = $record[9];
				
				$ddpr1 = $record[10];
				$dfpr1 = $record[11];
				$bbpr1 = $record[12];
				$bhpr1 = $record[13];
				$dmpr1 = $record[14];
				$tgpr1 = $record[15];
				$fbpr1 = $record[16];
				$tbpr1 = $record[17];
				$txpr1 = $record[18];
				
				$ddpr2 = $record[19];
				$dfpr2 = $record[20];
				$bbpr2 = $record[21];
				$bhpr2 = $record[22];
				$dmpr2 = $record[23];
				$tgpr2 = $record[24];
				$fbpr2 = $record[25];
				$tbpr2 = $record[26];
				$txpr2 = $record[27];
				
				$ddpr3 = $record[28];
				$dfpr3 = $record[29];
				$bbpr3 = $record[30];
				$bhpr3 = $record[31];
				$dmpr3 = $record[32];
				$tgpr3 = $record[33];
				$fbpr3 = $record[34];
				$tbpr3 = $record[35];
				$txpr3 = $record[36];
				
				$ddpr4 = $record[37];
				$dfpr4 = $record[38];
				$bbpr4 = $record[39];
				$bhpr4 = $record[40];
				$dmpr4 = $record[41];
				$tgpr4 = $record[42];
				$fbpr4 = $record[43];
				$tbpr4 = $record[44];
				$txpr4 = $record[45];
				
				$ddpr5 = $record[46];
				$dfpr5 = $record[47];
				$bbpr5 = $record[48];
				$bhpr5 = $record[49];
				$dmpr5 = $record[50];
				$tgpr5 = $record[51];
				$fbpr5 = $record[52];
				$tbpr5 = $record[53];
				$txpr5 = $record[54];
			
				$ddpr6 = $record[55];
				$dfpr6 = $record[56];
				$bbpr6 = $record[57];
				$bhpr6 = $record[58];
				$dmpr6 = $record[59];
				$tgpr6 = $record[60];
				$fbpr6 = $record[61];
				$tbpr6 = $record[62];
				$txpr6 = $record[63];
				
				$ddpr7 = $record[64];
				$dfpr7 = $record[65];
				$bbpr7 = $record[66];
				$bhpr7 = $record[67];
				$dmpr7 = $record[68];
				$tgpr7 = $record[69];
				$fbpr7 = $record[70];
				$tbpr7 = $record[71];
				$txpr7 = $record[72];
				
				$ddpr8 = $record[73];
				$dfpr8 = $record[74];
				$bbpr8 = $record[75];
				$bhpr8 = $record[76];
				$dmpr8 = $record[77];
				$tgpr8 = $record[78];
				$fbpr8 = $record[79];
				$tbpr8 = $record[80];
				$txpr8 = $record[81];
				
				$ddpr9 = $record[82];
				$dfpr9 = $record[83];
				$bbpr9 = $record[84];
				$bhpr9 = $record[85];
				$dmpr9 = $record[86];
				$tgpr9 = $record[87];
				$fbpr9 = $record[88];
				$tbpr9 = $record[89];
				$txpr9 = $record[90];
				
				$ddpp1 = $record[91];
				$dfpp1 = $record[92];
				$bbpp1 = $record[93];
				$bhpp1 = $record[94];
				$dmpp1 = $record[95];
				$tgpp1 = $record[96];
				$fbpp1 = $record[97];
				$tbpp1 = $record[98];
				$txpp1 = $record[99];
				
				$ddpp2 = $record[100];
				$dfpp2 = $record[101];
				$bbpp2 = $record[102];
				$bhpp2 = $record[103];
				$dmpp2 = $record[104];
				$tgpp2 = $record[105];
				$fbpp2 = $record[106];
				$tbpp2 = $record[107];
				$txpp2 = $record[108];
				
				$ddpp3 = $record[109];
				$dfpp3 = $record[110];
				$bbpp3 = $record[111];
				$bhpp3 = $record[112];
				$dmpp3 = $record[113];
				$tgpp3 = $record[114];
				$fbpp3 = $record[115];
				$tbpp3 = $record[116];
				$txpp3 = $record[117];
				
				$ddpp4 = $record[118];
				$dfpp4 = $record[119];
				$bbpp4 = $record[120];
				$bhpp4 = $record[121];
				$dmpp4 = $record[122];
				$tgpp4 = $record[123];
				$fbpp4 = $record[124];
				$tbpp4 = $record[125];
				$txpp4 = $record[126];
				
				$ddpp5 = $record[127];
				$dfpp5 = $record[128];
				$bbpp5 = $record[129];
				$bhpp5 = $record[130];
				$dmpp5 = $record[131];
				$tgpp5 = $record[132];
				$fbpp5 = $record[133];
				$tbpp5 = $record[134];
				$txpp5 = $record[135];
			
				$ddpp6 = $record[136];
				$dfpp6 = $record[137];
				$bbpp6 = $record[138];
				$bhpp6 = $record[139];
				$dmpp6 = $record[140];
				$tgpp6 = $record[141];
				$fbpp6 = $record[142];
				$tbpp6 = $record[143];
				$txpp6 = $record[144];
				
				$ddpp7 = $record[145];
				$dfpp7 = $record[146];
				$bbpp7 = $record[147];
				$bhpp7 = $record[148];
				$dmpp7 = $record[149];
				$tgpp7 = $record[150];
				$fbpp7 = $record[151];
				$tbpp7 = $record[152];
				$txpp7 = $record[153];
				
				$ddpp8 = $record[154];
				$dfpp8 = $record[155];
				$bbpp8 = $record[156];
				$bhpp8 = $record[157];
				$dmpp8 = $record[158];
				$tgpp8 = $record[159];
				$fbpp8 = $record[160];
				$tbpp8 = $record[161];
				$txpp8 = $record[162];
				
				$ddpp9 = $record[163];
				$dfpp9 = $record[164];
				$bbpp9 = $record[165];
				$bhpp9 = $record[166];
				$dmpp9 = $record[167];
				$tgpp9 = $record[168];
				$fbpp9 = $record[169];
				$tbpp9 = $record[170];
				$txpp9 = $record[171];
				
				$nbref = $record[172] + 0;
				
				$borne_basse = 0;
				$borne_haute = 0;
				$dms_nationale = 0;
				$tarif_ghs = 0;
				$forfait_exb = 0;
				$tarif_exb = "";
				$tarif_exh = "";
				
				if ($GHS_type_tarif != "PUBLIC") {
					if ($ddpr1 <= $GHS_date_tarif && $dfpr1 >= $GHS_date_tarif) {
						$borne_basse = $bbpr1;
						$borne_haute = $bhpr1;
						$dms_nationale = $dmpr1;
						$tarif_ghs = $tgpr1;
						$forfait_exb = $fbpr1;
						$tarif_exb = $tbpr1;
						$tarif_exh = $txpr1;
					}
					if ($ddpr2 <= $GHS_date_tarif && $dfpr2 >= $GHS_date_tarif) {
						$borne_basse = $bbpr2;
						$borne_haute = $bhpr2;
						$dms_nationale = $dmpr2;
						$tarif_ghs = $tgpr2;
						$forfait_exb = $fbpr2;
						$tarif_exb = $tbpr2;
						$tarif_exh = $txpr2;
					}
					if ($ddpr3 <= $GHS_date_tarif && $dfpr3 >= $GHS_date_tarif) {
						$borne_basse = $bbpr3;
						$borne_haute = $bhpr3;
						$dms_nationale = $dmpr3;
						$tarif_ghs = $tgpr3;
						$forfait_exb = $fbpr3;
						$tarif_exb = $tbpr3;
						$tarif_exh = $txpr3;
					}
					if ($ddpr4 <= $GHS_date_tarif && $dfpr4 >= $GHS_date_tarif) {
						$borne_basse = $bbpr4;
						$borne_haute = $bhpr4;
						$dms_nationale = $dmpr4;
						$tarif_ghs = $tgpr4;
						$forfait_exb = $fbpr4;
						$tarif_exb = $tbpr4;
						$tarif_exh = $txpr4;
					}
					if ($ddpr5 <= $GHS_date_tarif && $dfpr5 >= $GHS_date_tarif) {
						$borne_basse = $bbpr5;
						$borne_haute = $bhpr5;
						$dms_nationale = $dmpr5;
						$tarif_ghs = $tgpr5;
						$forfait_exb = $fbpr5;
						$tarif_exb = $tbpr5;
						$tarif_exh = $txpr5;
					}
					if ($ddpr6 <= $GHS_date_tarif && $dfpr6 >= $GHS_date_tarif) {
						$borne_basse = $bbpr6;
						$borne_haute = $bhpr6;
						$dms_nationale = $dmpr6;
						$tarif_ghs = $tgpr6;
						$forfait_exb = $fbpr6;
						$tarif_exb = $tbpr6;
						$tarif_exh = $txpr6;
					}
					if ($ddpr7 <= $GHS_date_tarif && $dfpr7 >= $GHS_date_tarif) {
						$borne_basse = $bbpr7;
						$borne_haute = $bhpr7;
						$dms_nationale = $dmpr7;
						$tarif_ghs = $tgpr7;
						$forfait_exb = $fbpr7;
						$tarif_exb = $tbpr7;
						$tarif_exh = $txpr7;
					}
					if ($ddpr8 <= $GHS_date_tarif && $dfpr8 >= $GHS_date_tarif) {
						$borne_basse = $bbpr8;
						$borne_haute = $bhpr8;
						$dms_nationale = $dmpr8;
						$tarif_ghs = $tgpr8;
						$forfait_exb = $fbpr8;
						$tarif_exb = $tbpr8;
						$tarif_exh = $txpr8;
					}
					if ($ddpr9 <= $GHS_date_tarif && $dfpr9 >= $GHS_date_tarif) {
						$borne_basse = $bbpr9;
						$borne_haute = $bhpr9;
						$dms_nationale = $dmpr9;
						$tarif_ghs = $tgpr9;
						$forfait_exb = $fbpr9;
						$tarif_exb = $tbpr9;
						$tarif_exh = $txpr9;
					}
				}
				else {
					if ($ddpp1 <= $GHS_date_tarif && $dfpp1 >= $GHS_date_tarif) {
						$borne_basse = $bbpp1;
						$borne_haute = $bhpp1;
						$dms_nationale = $dmpp1;
						$tarif_ghs = $tgpp1;
						$forfait_exb = $fbpp1;
						$tarif_exb = $tbpp1;
						$tarif_exh = $txpp1;
					}
					if ($ddpp2 <= $GHS_date_tarif && $dfpp2 >= $GHS_date_tarif) {
						$borne_basse = $bbpp2;
						$borne_haute = $bhpp2;
						$dms_nationale = $dmpp2;
						$tarif_ghs = $tgpp2;
						$forfait_exb = $fbpp2;
						$tarif_exb = $tbpp2;
						$tarif_exh = $txpp2;
					}
					if ($ddpp3 <= $GHS_date_tarif && $dfpp3 >= $GHS_date_tarif) {
						$borne_basse = $bbpp3;
						$borne_haute = $bhpp3;
						$dms_nationale = $dmpp3;
						$tarif_ghs = $tgpp3;
						$forfait_exb = $fbpp3;
						$tarif_exb = $tbpp3;
						$tarif_exh = $txpp3;
					}
					if ($ddpp4 <= $GHS_date_tarif && $dfpp4 >= $GHS_date_tarif) {
						$borne_basse = $bbpp4;
						$borne_haute = $bhpp4;
						$dms_nationale = $dmpp4;
						$tarif_ghs = $tgpp4;
						$forfait_exb = $fbpp4;
						$tarif_exb = $tbpp4;
						$tarif_exh = $txpp4;
					}
					if ($ddpp5 <= $GHS_date_tarif && $dfpp5 >= $GHS_date_tarif) {
						$borne_basse = $bbpp5;
						$borne_haute = $bhpp5;
						$dms_nationale = $dmpp5;
						$tarif_ghs = $tgpp5;
						$forfait_exb = $fbpp5;
						$tarif_exb = $tbpp5;
						$tarif_exh = $txpp5;
					}
					if ($ddpp6 <= $GHS_date_tarif && $dfpp6 >= $GHS_date_tarif) {
						$borne_basse = $bbpp6;
						$borne_haute = $bhpp6;
						$dms_nationale = $dmpp6;
						$tarif_ghs = $tgpp6;
						$forfait_exb = $fbpp6;
						$tarif_exb = $tbpp6;
						$tarif_exh = $txpp6;
					}
					if ($ddpp7 <= $GHS_date_tarif && $dfpp7 >= $GHS_date_tarif) {
						$borne_basse = $bbpp7;
						$borne_haute = $bhpp7;
						$dms_nationale = $dmpp7;
						$tarif_ghs = $tgpp7;
						$forfait_exb = $fbpp7;
						$tarif_exb = $tbpp7;
						$tarif_exh = $txpp7;
					}
					if ($ddpp8 <= $GHS_date_tarif && $dfpp8 >= $GHS_date_tarif) {
						$borne_basse = $bbpp8;
						$borne_haute = $bhpp8;
						$dms_nationale = $dmpp8;
						$tarif_ghs = $tgpp8;
						$forfait_exb = $fbpp8;
						$tarif_exb = $tbpp8;
						$tarif_exh = $txpp8;
					}
					if ($ddpp9 <= $GHS_date_tarif && $dfpp9 >= $GHS_date_tarif) {
						$borne_basse = $bbpp9;
						$borne_haute = $bhpp9;
						$dms_nationale = $dmpp9;
						$tarif_ghs = $tgpp9;
						$forfait_exb = $fbpp9;
						$tarif_exb = $tbpp9;
						$tarif_exh = $txpp9;
					}
				}

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "borne_basse=\"$borne_basse\" ";
				$httpString_tmp = $httpString_tmp . "borne_haute=\"$borne_haute\" ";
				$httpString_tmp = $httpString_tmp . "dms_nationale=\"$dms_nationale\" ";
				$httpString_tmp = $httpString_tmp . "tarif_ghs=\"$tarif_ghs\" ";
				$httpString_tmp = $httpString_tmp . "forfait_exb=\"$forfait_exb\" ";
				$httpString_tmp = $httpString_tmp . "tarif_exb=\"$tarif_exb\" ";
				$httpString_tmp = $httpString_tmp . "tarif_exh=\"$tarif_exh\" ";
				
				if ($ddpr1 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr1=\"$ddpr1\" ";
				$httpString_tmp = $httpString_tmp . "dfpr1=\"$dfpr1\" ";
				$httpString_tmp = $httpString_tmp . "bbpr1=\"$bbpr1\" ";
				$httpString_tmp = $httpString_tmp . "bhpr1=\"$bhpr1\" ";
				$httpString_tmp = $httpString_tmp . "dmpr1=\"$dmpr1\" ";
				$httpString_tmp = $httpString_tmp . "tgpr1=\"$tgpr1\" ";
				$httpString_tmp = $httpString_tmp . "fbpr1=\"$fbpr1\" ";
				$httpString_tmp = $httpString_tmp . "tbpr1=\"$tbpr1\" ";
				$httpString_tmp = $httpString_tmp . "txpr1=\"$txpr1\" ";
				}
				if ($ddpr2 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr2=\"$ddpr2\" ";
				$httpString_tmp = $httpString_tmp . "dfpr2=\"$dfpr2\" ";
				$httpString_tmp = $httpString_tmp . "bbpr2=\"$bbpr2\" ";
				$httpString_tmp = $httpString_tmp . "bhpr2=\"$bhpr2\" ";
				$httpString_tmp = $httpString_tmp . "dmpr2=\"$dmpr2\" ";
				$httpString_tmp = $httpString_tmp . "tgpr2=\"$tgpr2\" ";
				$httpString_tmp = $httpString_tmp . "fbpr2=\"$fbpr2\" ";
				$httpString_tmp = $httpString_tmp . "tbpr2=\"$tbpr2\" ";
				$httpString_tmp = $httpString_tmp . "txpr2=\"$txpr2\" ";
				}
				if ($ddpr3 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr3=\"$ddpr3\" ";
				$httpString_tmp = $httpString_tmp . "dfpr3=\"$dfpr3\" ";
				$httpString_tmp = $httpString_tmp . "bbpr3=\"$bbpr3\" ";
				$httpString_tmp = $httpString_tmp . "bhpr3=\"$bhpr3\" ";
				$httpString_tmp = $httpString_tmp . "dmpr3=\"$dmpr3\" ";
				$httpString_tmp = $httpString_tmp . "tgpr3=\"$tgpr3\" ";
				$httpString_tmp = $httpString_tmp . "fbpr3=\"$fbpr3\" ";
				$httpString_tmp = $httpString_tmp . "tbpr3=\"$tbpr3\" ";
				$httpString_tmp = $httpString_tmp . "txpr3=\"$txpr3\" ";
				}
				if ($ddpr4 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr4=\"$ddpr4\" ";
				$httpString_tmp = $httpString_tmp . "dfpr4=\"$dfpr4\" ";
				$httpString_tmp = $httpString_tmp . "bbpr4=\"$bbpr4\" ";
				$httpString_tmp = $httpString_tmp . "bhpr4=\"$bhpr4\" ";
				$httpString_tmp = $httpString_tmp . "dmpr4=\"$dmpr4\" ";
				$httpString_tmp = $httpString_tmp . "tgpr4=\"$tgpr4\" ";
				$httpString_tmp = $httpString_tmp . "fbpr4=\"$fbpr4\" ";
				$httpString_tmp = $httpString_tmp . "tbpr4=\"$tbpr4\" ";
				$httpString_tmp = $httpString_tmp . "txpr4=\"$txpr4\" ";
				}
				if ($ddpr5 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr5=\"$ddpr5\" ";
				$httpString_tmp = $httpString_tmp . "dfpr5=\"$dfpr5\" ";
				$httpString_tmp = $httpString_tmp . "bbpr5=\"$bbpr5\" ";
				$httpString_tmp = $httpString_tmp . "bhpr5=\"$bhpr5\" ";
				$httpString_tmp = $httpString_tmp . "dmpr5=\"$dmpr5\" ";
				$httpString_tmp = $httpString_tmp . "tgpr5=\"$tgpr5\" ";
				$httpString_tmp = $httpString_tmp . "fbpr5=\"$fbpr5\" ";
				$httpString_tmp = $httpString_tmp . "tbpr5=\"$tbpr5\" ";
				$httpString_tmp = $httpString_tmp . "txpr5=\"$txpr5\" ";
				}
				if ($ddpr6 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr6=\"$ddpr6\" ";
				$httpString_tmp = $httpString_tmp . "dfpr6=\"$dfpr6\" ";
				$httpString_tmp = $httpString_tmp . "bbpr6=\"$bbpr6\" ";
				$httpString_tmp = $httpString_tmp . "bhpr6=\"$bhpr6\" ";
				$httpString_tmp = $httpString_tmp . "dmpr6=\"$dmpr6\" ";
				$httpString_tmp = $httpString_tmp . "tgpr6=\"$tgpr6\" ";
				$httpString_tmp = $httpString_tmp . "fbpr6=\"$fbpr6\" ";
				$httpString_tmp = $httpString_tmp . "tbpr6=\"$tbpr6\" ";
				$httpString_tmp = $httpString_tmp . "txpr6=\"$txpr6\" ";
				}
				if ($ddpr7 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr7=\"$ddpr7\" ";
				$httpString_tmp = $httpString_tmp . "dfpr7=\"$dfpr7\" ";
				$httpString_tmp = $httpString_tmp . "bbpr7=\"$bbpr7\" ";
				$httpString_tmp = $httpString_tmp . "bhpr7=\"$bhpr7\" ";
				$httpString_tmp = $httpString_tmp . "dmpr7=\"$dmpr7\" ";
				$httpString_tmp = $httpString_tmp . "tgpr7=\"$tgpr7\" ";
				$httpString_tmp = $httpString_tmp . "fbpr7=\"$fbpr7\" ";
				$httpString_tmp = $httpString_tmp . "tbpr7=\"$tbpr7\" ";
				$httpString_tmp = $httpString_tmp . "txpr7=\"$txpr7\" ";
				}
				if ($ddpr8 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr8=\"$ddpr8\" ";
				$httpString_tmp = $httpString_tmp . "dfpr8=\"$dfpr8\" ";
				$httpString_tmp = $httpString_tmp . "bbpr8=\"$bbpr8\" ";
				$httpString_tmp = $httpString_tmp . "bhpr8=\"$bhpr8\" ";
				$httpString_tmp = $httpString_tmp . "dmpr8=\"$dmpr8\" ";
				$httpString_tmp = $httpString_tmp . "tgpr8=\"$tgpr8\" ";
				$httpString_tmp = $httpString_tmp . "fbpr8=\"$fbpr8\" ";
				$httpString_tmp = $httpString_tmp . "tbpr8=\"$tbpr8\" ";
				$httpString_tmp = $httpString_tmp . "txpr8=\"$txpr8\" ";
				}
				if ($ddpr9 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpr9=\"$ddpr9\" ";
				$httpString_tmp = $httpString_tmp . "dfpr9=\"$dfpr9\" ";
				$httpString_tmp = $httpString_tmp . "bbpr9=\"$bbpr9\" ";
				$httpString_tmp = $httpString_tmp . "bhpr9=\"$bhpr9\" ";
				$httpString_tmp = $httpString_tmp . "dmpr9=\"$dmpr9\" ";
				$httpString_tmp = $httpString_tmp . "tgpr9=\"$tgpr9\" ";
				$httpString_tmp = $httpString_tmp . "fbpr9=\"$fbpr9\" ";
				$httpString_tmp = $httpString_tmp . "tbpr9=\"$tbpr9\" ";
				$httpString_tmp = $httpString_tmp . "txpr9=\"$txpr9\" ";
				}
				if ($ddpp1 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp1=\"$ddpp1\" ";
				$httpString_tmp = $httpString_tmp . "dfpp1=\"$dfpp1\" ";
				$httpString_tmp = $httpString_tmp . "bbpp1=\"$bbpp1\" ";
				$httpString_tmp = $httpString_tmp . "bhpp1=\"$bhpp1\" ";
				$httpString_tmp = $httpString_tmp . "dmpp1=\"$dmpp1\" ";
				$httpString_tmp = $httpString_tmp . "tgpp1=\"$tgpp1\" ";
				$httpString_tmp = $httpString_tmp . "fbpp1=\"$fbpp1\" ";
				$httpString_tmp = $httpString_tmp . "tbpp1=\"$tbpp1\" ";
				$httpString_tmp = $httpString_tmp . "txpp1=\"$txpp1\" ";
				}
				if ($ddpp2 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp2=\"$ddpp2\" ";
				$httpString_tmp = $httpString_tmp . "dfpp2=\"$dfpp2\" ";
				$httpString_tmp = $httpString_tmp . "bbpp2=\"$bbpp2\" ";
				$httpString_tmp = $httpString_tmp . "bhpp2=\"$bhpp2\" ";
				$httpString_tmp = $httpString_tmp . "dmpp2=\"$dmpp2\" ";
				$httpString_tmp = $httpString_tmp . "tgpp2=\"$tgpp2\" ";
				$httpString_tmp = $httpString_tmp . "fbpp2=\"$fbpp2\" ";
				$httpString_tmp = $httpString_tmp . "tbpp2=\"$tbpp2\" ";
				$httpString_tmp = $httpString_tmp . "txpp2=\"$txpp2\" ";
				}
				if ($ddpp3 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp3=\"$ddpp3\" ";
				$httpString_tmp = $httpString_tmp . "dfpp3=\"$dfpp3\" ";
				$httpString_tmp = $httpString_tmp . "bbpp3=\"$bbpp3\" ";
				$httpString_tmp = $httpString_tmp . "bhpp3=\"$bhpp3\" ";
				$httpString_tmp = $httpString_tmp . "dmpp3=\"$dmpp3\" ";
				$httpString_tmp = $httpString_tmp . "tgpp3=\"$tgpp3\" ";
				$httpString_tmp = $httpString_tmp . "fbpp3=\"$fbpp3\" ";
				$httpString_tmp = $httpString_tmp . "tbpp3=\"$tbpp3\" ";
				$httpString_tmp = $httpString_tmp . "txpp3=\"$txpp3\" ";
				}
				if ($ddpp4 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp4=\"$ddpp4\" ";
				$httpString_tmp = $httpString_tmp . "dfpp4=\"$dfpp4\" ";
				$httpString_tmp = $httpString_tmp . "bbpp4=\"$bbpp4\" ";
				$httpString_tmp = $httpString_tmp . "bhpp4=\"$bhpp4\" ";
				$httpString_tmp = $httpString_tmp . "dmpp4=\"$dmpp4\" ";
				$httpString_tmp = $httpString_tmp . "tgpp4=\"$tgpp4\" ";
				$httpString_tmp = $httpString_tmp . "fbpp4=\"$fbpp4\" ";
				$httpString_tmp = $httpString_tmp . "tbpp4=\"$tbpp4\" ";
				$httpString_tmp = $httpString_tmp . "txpp4=\"$txpp4\" ";
				}
				if ($ddpp5 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp5=\"$ddpp5\" ";
				$httpString_tmp = $httpString_tmp . "dfpp5=\"$dfpp5\" ";
				$httpString_tmp = $httpString_tmp . "bbpp5=\"$bbpp5\" ";
				$httpString_tmp = $httpString_tmp . "bhpp5=\"$bhpp5\" ";
				$httpString_tmp = $httpString_tmp . "dmpp5=\"$dmpp5\" ";
				$httpString_tmp = $httpString_tmp . "tgpp5=\"$tgpp5\" ";
				$httpString_tmp = $httpString_tmp . "fbpp5=\"$fbpp5\" ";
				$httpString_tmp = $httpString_tmp . "tbpp5=\"$tbpp5\" ";
				$httpString_tmp = $httpString_tmp . "txpp5=\"$txpp5\" ";
				}
				if ($ddpp6 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp6=\"$ddpp6\" ";
				$httpString_tmp = $httpString_tmp . "dfpp6=\"$dfpp6\" ";
				$httpString_tmp = $httpString_tmp . "bbpp6=\"$bbpp6\" ";
				$httpString_tmp = $httpString_tmp . "bhpp6=\"$bhpp6\" ";
				$httpString_tmp = $httpString_tmp . "dmpp6=\"$dmpp6\" ";
				$httpString_tmp = $httpString_tmp . "tgpp6=\"$tgpp6\" ";
				$httpString_tmp = $httpString_tmp . "fbpp6=\"$fbpp6\" ";
				$httpString_tmp = $httpString_tmp . "tbpp6=\"$tbpp6\" ";
				$httpString_tmp = $httpString_tmp . "txpp6=\"$txpp6\" ";
				}
				if ($ddpp7 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp7=\"$ddpp7\" ";
				$httpString_tmp = $httpString_tmp . "dfpp7=\"$dfpp7\" ";
				$httpString_tmp = $httpString_tmp . "bbpp7=\"$bbpp7\" ";
				$httpString_tmp = $httpString_tmp . "bhpp7=\"$bhpp7\" ";
				$httpString_tmp = $httpString_tmp . "dmpp7=\"$dmpp7\" ";
				$httpString_tmp = $httpString_tmp . "tgpp7=\"$tgpp7\" ";
				$httpString_tmp = $httpString_tmp . "fbpp7=\"$fbpp7\" ";
				$httpString_tmp = $httpString_tmp . "tbpp7=\"$tbpp7\" ";
				$httpString_tmp = $httpString_tmp . "txpp7=\"$txpp7\" ";
				}
				if ($ddpp8 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp8=\"$ddpp8\" ";
				$httpString_tmp = $httpString_tmp . "dfpp8=\"$dfpp8\" ";
				$httpString_tmp = $httpString_tmp . "bbpp8=\"$bbpp8\" ";
				$httpString_tmp = $httpString_tmp . "bhpp8=\"$bhpp8\" ";
				$httpString_tmp = $httpString_tmp . "dmpp8=\"$dmpp8\" ";
				$httpString_tmp = $httpString_tmp . "tgpp8=\"$tgpp8\" ";
				$httpString_tmp = $httpString_tmp . "fbpp8=\"$fbpp8\" ";
				$httpString_tmp = $httpString_tmp . "tbpp8=\"$tbpp8\" ";
				$httpString_tmp = $httpString_tmp . "txpp8=\"$txpp8\" ";
				}
				if ($ddpp9 != "2099-12-31") {
				$httpString_tmp = $httpString_tmp . "ddpp9=\"$ddpp9\" ";
				$httpString_tmp = $httpString_tmp . "dfpp9=\"$dfpp9\" ";
				$httpString_tmp = $httpString_tmp . "bbpp9=\"$bbpp9\" ";
				$httpString_tmp = $httpString_tmp . "bhpp9=\"$bhpp9\" ";
				$httpString_tmp = $httpString_tmp . "dmpp9=\"$dmpp9\" ";
				$httpString_tmp = $httpString_tmp . "tgpp9=\"$tgpp9\" ";
				$httpString_tmp = $httpString_tmp . "fbpp9=\"$fbpp9\" ";
				$httpString_tmp = $httpString_tmp . "tbpp9=\"$tbpp9\" ";
				$httpString_tmp = $httpString_tmp . "txpp9=\"$txpp9\" ";
				}
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_diagnostics() {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	
	
	$sqlcmd = "SELECT t_diagnostics.oid, t_diagnostics.code, t_diagnostics.texte, 
		t_diagnostics.severite_fg11_code, 
		t_diagnostics.severite_fg12_code, 
		t_diagnostics.severite_fg13_code, 
		t_diagnostics.severite_fg1311d_code, 
		t_diagnostics.severite_fg1311e_code,
		t_diagnostics.severite_fg1311f_code,
		t_diagnostics.severite_fg1311g_code,
		t_diagnostics.severite_fg2016_code,
		t_diagnostics.severite_fg2017_code,
		t_diagnostics.severite_fg2018_code,";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_diagnostics  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rss_diagnostics.diagnostic_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss_diagnostics ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rss_diagnostics.diagnostic_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_diagnostics.oid = subview.diagnostic_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_diagnostics.oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY t_diagnostics.code";
	$result = $database->exec($sqlcmd);
	
	
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$sev11 = $record[3] + 0;
				$sev12 = $record[4] + 0;
				$sev13 = $record[5] + 0;
				$sev1311d = $record[6] + 0;
				$sev1311e = $record[7] + 0;
				$sev1311f = $record[8] + 0;
				$sev1311g = $record[9] + 0;
				$sev2016 = $record[10] + 0;
				$sev2017 = $record[11] + 0;
				$sev2018 = $record[12] + 0;
				$nbref = $record[13] + 0;
				
				if ($sev11 < 2) {
					$sev11 = "";
				}
				if ($sev12 < 2) {
					$sev12 = "";
				}
				if ($sev13 < 2) {
					$sev13 = "";
				}
				if ($sev1311d < 2) {
					$sev1311d = "";
				}
				if ($sev1311e < 2) {
					$sev1311e = "";
				}
				if ($sev1311f < 2) {
					$sev1311f = "";
				}
				if ($sev1311g < 2) {
					$sev1311g = "";
				}
				if ($sev2016 < 2) {
					$sev2016 = "";
				}
				if ($sev2017 < 2) {
					$sev2017 = "";
				}
				if ($sev2018 < 2) {
					$sev2018 = "";
				}

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "sev11=\"$sev11\" ";
				$httpString_tmp = $httpString_tmp . "sev12=\"$sev12\" ";
				$httpString_tmp = $httpString_tmp . "sev13=\"$sev13\" ";
				$httpString_tmp = $httpString_tmp . "sev1311d=\"$sev1311d\" ";
				$httpString_tmp = $httpString_tmp . "sev1311e=\"$sev1311e\" ";
				$httpString_tmp = $httpString_tmp . "sev1311f=\"$sev1311f\" ";
				$httpString_tmp = $httpString_tmp . "sev1311g=\"$sev1311g\" ";
				$httpString_tmp = $httpString_tmp . "sev2016=\"$sev2016\" ";
				$httpString_tmp = $httpString_tmp . "sev2017=\"$sev2017\" ";
				$httpString_tmp = $httpString_tmp . "sev2018=\"$sev2018\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_ccam_regroupements() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT oid, code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_ccam_regroupements ";
	$sqlcmd = $sqlcmd . "WHERE oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	
}

function getRecords_gestes_marqueurs() {

global $database;
global $getParam;

	$httpString = "";
	// rétro compatibilité avec l'ancienne méthode de requętage des gestes marqueurs
	if ($getParam == "") {
		$sqlcmd = "	SELECT 
						t_gestes_marqueurs.oid, 
						t_gestes_marqueurs.code, 
						t_gestes_marqueurs.texte, 
						t_gestes_marqueurs.texte_court, 
						subview.actes_codes 
					FROM 
						pmsi.t_gestes_marqueurs, 
						(SELECT 
							geste_marqueur_id, 
							base.cti_group_concat(code) as actes_codes 
						FROM 
							pmsi.t_actes 
						WHERE 
							geste_marqueur_id > 0 
						GROUP BY geste_marqueur_id) subview 
					WHERE 
						t_gestes_marqueurs.oid > 0
						and t_gestes_marqueurs.oid = subview.geste_marqueur_id 
					ORDER BY t_gestes_marqueurs.code ";
	}
	else {
		$sqlcmd = "	
		SELECT 
			t_classes_sections.oid, 
			t_classes_sections.code, 
			t_classes_sections.texte, 
			t_classes_sections.texte,
			base.cti_group_concat(t_actes.code)
		FROM pmsi.t_classes_sections 
		JOIN pmsi.t_classes ON t_classes.oid = t_classes_sections.classe_id
		JOIN pmsi.t_classes_sections_elements ON t_classes_sections_elements.section_id = t_classes_sections.oid
		JOIN pmsi.t_actes on t_actes.oid = t_classes_sections_elements.to_id
		WHERE t_classes.code = '$getParam'
		GROUP BY 1,2,3,4
		ORDER BY t_classes_sections.code
		";
	}
	$result = $database->exec($sqlcmd);
	
	if ($result != false) {
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$actes_codes = toHTML(trim($record[4]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "actes_codes=\"$actes_codes\" ";
				$httpString = $httpString . " />";
			}
		}
	}
	
	return $httpString;
}

function getRecords_actes() {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	
	
	$sqlcmd = "WITH w_gm AS (
			SELECT
				t_actes.oid as acte_id,
				t_classes_sections.code as gm_code
			FROM
				pmsi.t_actes
				LEFT JOIN pmsi.t_classes_sections_elements ON t_actes.oid = t_classes_sections_elements.to_id
				LEFT JOIN pmsi.t_classes_sections ON t_classes_sections.oid = t_classes_sections_elements.section_id
				LEFT JOIN pmsi.t_classes ON t_classes.oid = t_classes_sections.classe_id
			WHERE
				t_classes.code = 'CTI_GM_MSAP_2015'
		),
		subview as (
			SELECT 
				p_rss_actes.acte_id, count(*) as count 
			FROM 
				pmsi.p_rss_actes
			GROUP BY p_rss_actes.acte_id
		)
		SELECT 				
			t_actes.oid, 
			t_actes.code, 
			t_actes.texte,
			CASE WHEN classant = 'Y' THEN 'Classant' ELSE '' END as classant,
			icr_1, 
			icr_4,
			t_ccam_regroupements_1.code, 
			t_ccam_regroupements_4.code,
			COALESCE(w_gm.gm_code, ''::text) as gm_code,
			COALESCE(subview.count, 0)
		FROM 
			pmsi.t_actes
			JOIN pmsi.t_ccam_regroupements t_ccam_regroupements_1 ON ccam_regroupement_id_1 = t_ccam_regroupements_1.oid
			JOIN pmsi.t_ccam_regroupements t_ccam_regroupements_4 ON ccam_regroupement_id_4 = t_ccam_regroupements_4.oid
			LEFT JOIN w_gm ON w_gm.acte_id = t_actes.oid
			LEFT JOIN subview ON subview.acte_id = t_actes.oid
		WHERE 1=1
			AND t_actes.oid > 0
			AND nomenclature IN ('CCAM', 'CCAMDESC')
		ORDER BY t_actes.code";
	

	$result = $database->exec($sqlcmd);
	
	
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$classant = toHTML(trim($record[3]));
				$icr_1 = toHTML(trim($record[4]));
				$icr_4 = toHTML(trim($record[5]));
				$regroupement_1 = toHTML(trim($record[6]));
				$regroupement_4 = toHTML(trim($record[7]));
				$geste_marqueur = toHTML(trim($record[8]));
				$nbref = $record[9] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "classant=\"$classant\" ";
				$httpString_tmp = $httpString_tmp . "icr_1=\"+$icr_1\" ";
				$httpString_tmp = $httpString_tmp . "icr_4=\"+$icr_4\" ";
				$httpString_tmp = $httpString_tmp . "regroupement_1=\"$regroupement_1\" ";
				$httpString_tmp = $httpString_tmp . "regroupement_4=\"$regroupement_4\" ";
				$httpString_tmp = $httpString_tmp . "geste_marqueur=\"$geste_marqueur\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_prestations() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_prestations.oid, t_prestations.code, t_prestations.texte, t_prestations.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_prestations  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rsf_detail.prestation_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rsf_detail ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rsf_detail.prestation_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_prestations.oid = subview.prestation_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_prestations.oid > 0  ";
	//$sqlcmd = $sqlcmd . "AND compteur_rsf <> 9 ";
	//$sqlcmd = $sqlcmd . "AND compteur_rsf <> 10 ";
	//$sqlcmd = $sqlcmd . "AND compteur_rsf <> 11 ";
	//$sqlcmd = $sqlcmd . "AND compteur_rsf <> 12 ";
	//$sqlcmd = $sqlcmd . "AND compteur_rsf <> 14 ";
	$sqlcmd = $sqlcmd . "ORDER BY t_prestations.code";
	$result = $database->exec($sqlcmd);
	
	
	$httpString_tmp = "";
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_lpp() {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	
	$sqlcmd = "SELECT t_lpp.oid, t_lpp.code, t_lpp.texte, t_lpp.texte_court, t_lpp.code_fg11, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_lpp  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rss_lpp.lpp_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss_lpp ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rss_lpp.lpp_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_lpp.oid = subview.lpp_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_lpp.oid > 0 ";
	$sqlcmd = $sqlcmd . "ORDER BY t_lpp.code";
	$result = $database->exec($sqlcmd);
	
	
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$code_fg11 = toHTML(trim($record[4]));
				$code_fg11_label = "";
				if ($code_fg11 == "1") {
					$code_fg11_label = "OUI";
				}
				$nbref = $record[5] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "code_fg11=\"$code_fg11\" ";
				$httpString_tmp = $httpString_tmp . "code_fg11_label=\"$code_fg11_label\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_ucd() {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	
	
	$sqlcmd = "SELECT t_ucd.oid, t_ucd.code, t_ucd.texte, t_ucd.texte_court, t_ucd.laboratoire_texte, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_ucd  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rss_ucd.ucd_id, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss_ucd ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rss_ucd.ucd_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_ucd.oid = subview.ucd_id) ";
	$sqlcmd = $sqlcmd . "WHERE t_ucd.oid > 0  ";
	$sqlcmd = $sqlcmd . "ORDER BY t_ucd.code";
	$result = $database->exec($sqlcmd);
	
	
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$laboratoire_texte = toHTML(trim($record[4]));
				$nbref = $record[5] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "laboratoire_texte=\"$laboratoire_texte\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}
	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_comites_medicaux() {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";

	$sqlcmd = "SELECT t_comites_medicaux.oid, t_comites_medicaux.code, t_comites_medicaux.texte, 
			subview.count 
			FROM pmsi.t_comites_medicaux  
			LEFT JOIN  
			(SELECT p_rss.comite_medical_id, count(*) as count  
			FROM pmsi.p_rss 
			GROUP BY p_rss.comite_medical_id) subview  
			ON (t_comites_medicaux.oid = subview.comite_medical_id) 
			WHERE t_comites_medicaux.oid > 0 
			ORDER BY t_comites_medicaux.code";
	$result = $database->exec($sqlcmd);
	
	
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$nbref = $record[3] + 0;

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}
	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_types_autorisations() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_types_autorisations ";
	$sqlcmd = $sqlcmd . "WHERE code <> '' ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$code = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
				$texte_court = toHTML(trim($record[2]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_modes_entree() {

global $database;

	$httpString = "";
	
	$sqlcmd = "SELECT code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_modes_entree ";
	$sqlcmd = $sqlcmd . "WHERE code <> '' ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$code = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
				$texte_court = toHTML(trim($record[2]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}
	}
	
	return $httpString;
}

function getRecords_modes_sortie() {

global $database;

	$httpString = "";

	$sqlcmd = "SELECT code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_modes_sortie ";
	$sqlcmd = $sqlcmd . "WHERE code <> '' ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$code = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
				$texte_court = toHTML(trim($record[2]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}

	}
	
	return $httpString;
}

function getRecords_provenances_entree() {

global $database;

	$httpString = "";

	$sqlcmd = "SELECT code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_provenances_entree ";
	$sqlcmd = $sqlcmd . "WHERE code <> '' ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$code = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
				$texte_court = toHTML(trim($record[2]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}
	}
	
	return $httpString;
}

function getRecords_destinations_sortie() {

global $database;

	$httpString = "";
	
	$sqlcmd = "SELECT code, texte, texte_court ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_destinations_sortie ";
	$sqlcmd = $sqlcmd . "WHERE code <> '' ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$code = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
				$texte_court = toHTML(trim($record[2]));

				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . " />";

			}
		}
	}
	
	return $httpString;
}

function getCombo_departements() {

global $database;

	$httpString = "";

	
	$httpString = $httpString . "\r\n<COMBO_DEP>";

	$sqlcmd = "SELECT oid, code || ' ' || texte ";
	$sqlcmd = $sqlcmd . "FROM base.t_departements  ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
			
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . " />";

			}
		}

	}

	$httpString = $httpString . "\r\n</COMBO_DEP>";
	
	return $httpString;
	
	

}

function getRecords_departements() {

global $database;

	$httpString = "";

	

	$sqlcmd = "SELECT t_departements.oid, t_departements.code, t_departements.texte, t_departements.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM base.t_departements  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT t_codes_postaux.departement_id as departement_id, count(*) as count   ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, base.t_codes_postaux WHERE p_rss.code_postal_id = t_codes_postaux.oid ";
	$sqlcmd = $sqlcmd . "GROUP BY t_codes_postaux.departement_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_departements.oid = subview.departement_id) ";
	$sqlcmd = $sqlcmd . "WHERE oid > 0 ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$nbref = $record[4] + 0;
				
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_codes_geographiques_pmsi() {

global $database;

	
	
	// Liste
	$httpString = "";
	
	$httpString_tmp = "";


	$sqlcmd = "SELECT oid, code, texte, texte_court, population,  ";
	$sqlcmd = $sqlcmd . "subview.codes, subview2.count   ";
	$sqlcmd = $sqlcmd . "FROM base.t_codes_geographiques_pmsi    ";
	$sqlcmd = $sqlcmd . "LEFT JOIN    ";
	$sqlcmd = $sqlcmd . "(SELECT code_geographique_pmsi_id, base.cti_group_concat(code) as codes ";
	$sqlcmd = $sqlcmd . "FROM base.t_codes_postaux WHERE t_codes_postaux.oid > 0   ";
	$sqlcmd = $sqlcmd . "GROUP BY code_geographique_pmsi_id) subview    ";
	$sqlcmd = $sqlcmd . "ON (t_codes_geographiques_pmsi.oid = subview.code_geographique_pmsi_id) ";
	$sqlcmd = $sqlcmd . "LEFT JOIN    ";
	$sqlcmd = $sqlcmd . "(SELECT t_codes_postaux.code_geographique_pmsi_id as code_geographique_pmsi_id, count(*) as count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss, base.t_codes_postaux WHERE p_rss.code_postal_id = t_codes_postaux.oid  ";
	$sqlcmd = $sqlcmd . "GROUP BY t_codes_postaux.code_geographique_pmsi_id) subview2    ";
	$sqlcmd = $sqlcmd . "ON (t_codes_geographiques_pmsi.oid = subview2.code_geographique_pmsi_id)   ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
	
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$population = toHTML(trim($record[4]));
				$codes = toHTML($record[5]);
				$nbref = $record[6] + 0;
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "population=\"$population\" ";
				$httpString_tmp = $httpString_tmp . "codes=\"$codes\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_codes_postaux() {

global $database;

	$httpString = "";

	$httpString_tmp = "";

	$sqlcmd = "SELECT t_codes_postaux.oid, t_codes_postaux.code, t_codes_postaux.texte, t_codes_postaux.texte_court, ";
	$sqlcmd = $sqlcmd . "code_geographique_pmsi, population, ";
	$sqlcmd = $sqlcmd . "t_codes_postaux.departement_id, t_departements.code || ' ' || t_departements.texte_court, ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM base.t_departements, base.t_codes_postaux  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rss.code_postal as code_postal_code, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss  ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rss.code_postal) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_codes_postaux.code = subview.code_postal_code) ";
	$sqlcmd = $sqlcmd . "WHERE t_codes_postaux.oid > 0 AND t_codes_postaux.departement_id = t_departements.oid ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$code_geo_pmsi = toHTML(trim($record[4]));
				$population = toHTML(trim($record[5]));
				$departement_id = toHTML(trim($record[6]));
				$departement_texte = toHTML(trim($record[7]));
				$nbref = $record[8] + 0;
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "departement_id=\"$departement_id\" ";
				$httpString_tmp = $httpString_tmp . "departement=\"$departement_texte\" ";
				$httpString_tmp = $httpString_tmp . "code_geo_pmsi=\"$code_geo_pmsi\" ";
				$httpString_tmp = $httpString_tmp . "population=\"+$population\" ";
				$httpString_tmp = $httpString_tmp . "nbref=\"+$nbref\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getListe_codes_postaux() {
global $database;

	$httpString = "";

	$httpString_tmp = "";
	
	$httpString_tmp = $httpString_tmp . "\r\n<LIST_CPO>";

	$sqlcmd = "SELECT t_codes_postaux.oid, t_codes_postaux.code || ' ' || t_codes_postaux.texte_court || ' (' || t_secteurs_geographiques.code || ')', ";
	$sqlcmd = $sqlcmd . "subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_secteurs_geographiques, pmsi.t_secteurs_geographiques_codes_postaux, base.t_codes_postaux  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT p_rss.code_postal as code_postal_code, count(*) as count  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.p_rss  ";
	$sqlcmd = $sqlcmd . "GROUP BY p_rss.code_postal) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_codes_postaux.code = subview.code_postal_code) ";
	$sqlcmd = $sqlcmd . "WHERE t_codes_postaux.oid > 0 ";
	$sqlcmd = $sqlcmd . "AND t_secteurs_geographiques_codes_postaux.code_postal_id = t_codes_postaux.oid ";
	$sqlcmd = $sqlcmd . "AND t_secteurs_geographiques_codes_postaux.secteur_geographique_id = t_secteurs_geographiques.oid ";
	$sqlcmd = $sqlcmd . "ORDER BY t_codes_postaux.code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$texte = toHTML(trim($record[1]));
				$nbref = $record[2] + 0;
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString_tmp = $httpString_tmp . "\r\n</LIST_CPO>";
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

function getRecords_secteurs_geographiques() {

global $database;

	// Initialisation 
	$sqlcmd = "INSERT INTO pmsi.t_secteurs_geographiques_codes_postaux (secteur_geographique_id, code_postal_id) ";
	$sqlcmd = $sqlcmd . "SELECT 0, oid FROM base.t_codes_postaux WHERE oid NOT IN (SELECT code_postal_id FROM pmsi.t_secteurs_geographiques_codes_postaux)";
	$result = $database->exec($sqlcmd);
	
	// Liste
	$httpString = "";

	$httpString = $httpString . "\r\n<RECORD ";
	$httpString = $httpString . "oid=\"-1\" ";
	$httpString = $httpString . "code=\"\" ";
	$httpString = $httpString . "texte=\"Nouveau secteur\" ";
	$httpString = $httpString . "texte_court=\"\" ";
	$httpString = $httpString . "codes=\"\" ";
	$httpString = $httpString . "nbref=\"+0\" ";
	$httpString = $httpString . "/>";


	$sqlcmd = "SELECT oid, code, texte, texte_court, ";
	$sqlcmd = $sqlcmd . "subview.codes, subview.count ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_secteurs_geographiques  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN  ";
	$sqlcmd = $sqlcmd . "(SELECT secteur_geographique_id, count(*), base.cti_group_concat(' ' || code_postal_id::text || ' ') as codes  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_secteurs_geographiques_codes_postaux  WHERE code_postal_id > 0 ";
	$sqlcmd = $sqlcmd . "GROUP BY secteur_geographique_id) subview  ";
	$sqlcmd = $sqlcmd . "ON (t_secteurs_geographiques.oid = subview.secteur_geographique_id) ";
	$sqlcmd = $sqlcmd . "ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$codes = toHTML($record[4]);
				$nbref = $record[5] + 0;
				
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "texte_court=\"$texte_court\" ";
				$httpString = $httpString . "codes=\"$codes\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}

function getRecords_etude_1() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_etude_1.oid, t_etude_1.code, t_etude_1.texte, t_etude_1.texte_court, ";
	$sqlcmd = $sqlcmd . "taux_cible_2008, taux_cible_2009, taux_cible_2010, taux_cible_2011,  ";
	$sqlcmd = $sqlcmd . "t_ghm_1.code, t_ghm_1.code || ' ' || t_ghm_1.texte,  ";
	$sqlcmd = $sqlcmd . "t_ghm_2.code, t_ghm_2.code || ' ' || t_ghm_2.texte,  ";
	$sqlcmd = $sqlcmd . "t_ghm_3.code, t_ghm_3.code || ' ' || t_ghm_3.texte  ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_etude_1  ";
	$sqlcmd = $sqlcmd . "LEFT JOIN pmsi.t_ghm t_ghm_1 ON (t_ghm_1.oid = ghm_1_id AND ghm_1_id <> 0) ";
	$sqlcmd = $sqlcmd . "LEFT JOIN pmsi.t_ghm t_ghm_2 ON (t_ghm_2.oid = ghm_2_id AND ghm_2_id <> 0) ";
	$sqlcmd = $sqlcmd . "LEFT JOIN pmsi.t_ghm t_ghm_3 ON (t_ghm_3.oid = ghm_3_id AND ghm_3_id <> 0) ";
	$sqlcmd = $sqlcmd . "ORDER BY t_etude_1.code";
	$result = $database->exec($sqlcmd);
	
	
	$httpString_tmp = "";
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$taux_cible_2008 = toHTML(trim($record[4]));
				$taux_cible_2009 = toHTML(trim($record[5]));
				$taux_cible_2010 = toHTML(trim($record[6]));
				$taux_cible_2011 = toHTML(trim($record[7]));
				$ghm_1_code = toHTML(trim($record[8]));
				$ghm_1_texte = toHTML(trim($record[9]));
				$ghm_2_code = toHTML(trim($record[10]));
				$ghm_2_texte = toHTML(trim($record[11]));
				$ghm_3_code = toHTML(trim($record[12]));
				$ghm_3_texte = toHTML(trim($record[13]));

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "taux_cible_2008=\"$taux_cible_2008\" ";
				$httpString_tmp = $httpString_tmp . "taux_cible_2009=\"$taux_cible_2009\" ";
				$httpString_tmp = $httpString_tmp . "taux_cible_2010=\"$taux_cible_2010\" ";
				$httpString_tmp = $httpString_tmp . "taux_cible_2011=\"$taux_cible_2011\" ";
				$httpString_tmp = $httpString_tmp . "ghm_1_code=\"$ghm_1_code\" ";
				$httpString_tmp = $httpString_tmp . "ghm_1_texte=\"$ghm_1_texte\" ";
				$httpString_tmp = $httpString_tmp . "ghm_2_code=\"$ghm_2_code\" ";
				$httpString_tmp = $httpString_tmp . "ghm_2_texte=\"$ghm_2_texte\" ";
				$httpString_tmp = $httpString_tmp . "ghm_3_code=\"$ghm_3_code\" ";
				$httpString_tmp = $httpString_tmp . "ghm_3_texte=\"$ghm_3_texte\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

// déprécié et remplacé par getRecords_etude_6()
function getRecords_etude_2() {

global $database;

	$httpString = "";

	
	$sqlcmd = "SELECT t_etude_2.oid, t_etude_2.code, t_etude_2.texte, t_etude_2.texte_court, seuil_2008, seuil_2009, seuil_2010, seuil_2011 ";
	$sqlcmd = $sqlcmd . "FROM pmsi.t_etude_2  ";
	$sqlcmd = $sqlcmd . "ORDER BY t_etude_2.code";
	$result = $database->exec($sqlcmd);
	
	
	$httpString_tmp = "";
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$seuil_2008 = toHTML(trim($record[4]));
				$seuil_2009 = toHTML(trim($record[5]));
				$seuil_2010 = toHTML(trim($record[6]));
				$seuil_2011 = toHTML(trim($record[7]));

				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "texte_court=\"$texte_court\" ";
				$httpString_tmp = $httpString_tmp . "seuil_2008=\"$seuil_2008\" ";
				$httpString_tmp = $httpString_tmp . "seuil_2009=\"$seuil_2009\" ";
				$httpString_tmp = $httpString_tmp . "seuil_2010=\"$seuil_2010\" ";
				$httpString_tmp = $httpString_tmp . "seuil_2011=\"$seuil_2011\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}

/* deprecated
function getRecords_etude_4() {
	global $database;
	$httpString = "";
	$sqlcmd = "
		SELECT 
			oid, code, texte, texte_court, seuil_regional_2009, 
			seuil_regional_2010, seuil_regional_2011, seuil_regional_2012,
			seuil_national_2009, seuil_national_2010, seuil_national_2011,
			seuil_national_2012
		FROM pmsi.t_etude_4 
		WHERE oid > 0
		ORDER BY t_etude_4.code
	";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		// lignes 
		$ok = TRUE;
		while ($ok == TRUE) {
			$ok = FALSE;
			$record = $database->nextRecordAssoc();
			if ($record != FALSE) {
				$ok = TRUE;
				$httpString .= "\r\n<RECORD ";
				foreach ($record as $key => $value) {
					$httpString .= "$key=\"".toHTML(trim($value))."\" ";
				}
				$httpString .= " />";
			}
		}
	}
	return $httpString;
}
*/

function getRecords_etude_5() {

	global $database;
	global $getParam;
	
	$httpString = "";
	// rétro compatibilité avec l'ancienne version des seuils des gestes marqueurs
	if ($getParam == "") {
		$sqlcmd = "
			SELECT 
				oid, code, texte, texte_court, seuil_regional_2009, 
				seuil_regional_2010, seuil_regional_2011, seuil_regional_2012,
				seuil_national_2009, seuil_national_2010, seuil_national_2011,
				seuil_national_2012
			FROM pmsi.t_etude_4 
			WHERE oid > 0
			ORDER BY t_etude_4.code
		";

	}
	// nouvelle version
	else {
		$settings_file = simplexml_load_file(rootDir() . 'settings/settings.XML');
		$finess = getProperty($settings_file, 'ENVIRONMENT', 'FINESS');
		$sqlcmd = "
			SELECT
				t_etude_5.oid, 
				t_classes_sections.code, 
				t_classes_sections.texte, 
				t_classes.texte as liste,
				t_etude_5.taux_moyen_regional, 
				t_etude_5.taux_moyen_regional_prive, 
				t_etude_5.taux_moyen_regional_public, 
				t_etude_5.taux_moyen_tersante, 
				t_etude_5.taux_moyen_tersante_prive, 
				t_etude_5.taux_moyen_tersante_public, 
				t_etude_5.taux_cible_ets, 
				t_etude_5.taux_cible_ars, 
				t_etude_5.taux_moyen_national, 
				t_etude_5.taux_moyen_national_prive, 
				t_etude_5.taux_moyen_national_public 
			FROM 
				pmsi.t_listes_tables
				JOIN pmsi.t_classes ON pmsi.t_classes.table_id = pmsi.t_listes_tables.oid
				JOIN pmsi.t_classes_sections ON t_classes_sections.classe_id = t_classes.oid
				JOIN pmsi.t_etude_5 ON t_classes.sequence = t_etude_5.sequence AND t_classes_sections.code = t_etude_5.code
			WHERE 
				pmsi.t_listes_tables.code = 'ACTE'
				AND pmsi.t_classes.sequence = $getParam
				AND tersante_id = (SELECT territoire_sante_id FROM base.t_finess where code = '$finess') 
			ORDER BY code 
		";
	}
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		// lignes 
		$ok = TRUE;
		while ($ok == TRUE) {
			$ok = FALSE;
			$record = $database->nextRecordAssoc();
			if ($record != FALSE) {
				$ok = TRUE;
				$httpString .= "\r\n<RECORD ";
				foreach ($record as $key => $value) {
					$httpString .= "$key=\"".toHTML(trim($value))."\" ";
				}
				$httpString .= " />";
			}
		}
	}
	return $httpString;
}

// seuils de dégressivité tarifaire sur la table t_etude_7
function getRecords_etude_7() {

	global $database;
	global $getParam;
	
	$httpString = "";
	$sqlcmd = "
			SELECT
				oid
				,code
				,texte
				,annee
				,seuil_degressivite
				,taux_correction_avant_mars
				,taux_correction_apres_mars
			FROM
				pmsi.t_etude_7
			WHERE
				t_etude_7.annee = $getParam
			ORDER BY code
		";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		// lignes 
		$ok = TRUE;
		while ($ok == TRUE) {
			$ok = FALSE;
			$record = $database->nextRecordAssoc();
			if ($record != FALSE) {
				$ok = TRUE;
				$httpString .= "\r\n<RECORD ";
				foreach ($record as $key => $value) {
					$httpString .= "$key=\"".toHTML(trim($value))."\" ";
				}
				$httpString .= " />";
			}
		}
	}
	return $httpString;
}

function getRecords_etude_6() {

	global $database;
	global $getParam;
	
	// Si aucune année de cachier des charges passée en paramčtre, on va prendre la plus récente
	if ($getParam == '') {
		$sqlcmd = "
			SELECT
				max(annee)
			FROM 
				pmsi.t_etude_6 
		";
		$result = $database->exec($sqlcmd);
		if ($result != false) {
			$record = $database->nextRecord();
			if ($record != FALSE) {
				$getParam = intval($record[0]);
			}
			else {
				$getParam = 2011;
			}
		}
	}
	
	$httpString = "";
	$settings_file = simplexml_load_file(rootDir() . 'settings/settings.XML');
	$finess = getProperty($settings_file, 'ENVIRONMENT', 'FINESS');
	$sqlcmd = "
		SELECT
			t_etude_6.oid, 
			t_etude_6.code, 
			t_etude_6.texte, 
			t_etude_6.annee, 
			t_etude_6.seuil_ets, 
			t_etude_6.seuil_ars, 
			t_etude_6.moy_region, 
			t_etude_6.moy_nat 
		FROM 
			pmsi.t_etude_6 
		WHERE 
			t_etude_6.annee = $getParam
			AND tersante_id = (SELECT territoire_sante_id FROM base.t_finess where code = '$finess') 
		ORDER BY code 
	";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		// lignes 
		$ok = TRUE;
		while ($ok == TRUE) {
			$ok = FALSE;
			$record = $database->nextRecordAssoc();
			if ($record != FALSE) {
				$ok = TRUE;
				$httpString .= "\r\n<RECORD ";
				foreach ($record as $key => $value) {
					$httpString .= "$key=\"".toHTML(trim($value))."\" ";
				}
				$httpString .= " />";
			}
		}
	}
	return $httpString;
}

function getListe_ghm() {
global $database;

	$httpString = "";

	$httpString_tmp = "";
	
	$httpString_tmp = $httpString_tmp . "\r\n<LIST_GHM>";

	$sqlcmd = "SELECT t_ghm.oid, t_ghm.code, t_ghm.texte
			FROM pmsi.t_ghm  
			LEFT JOIN  
			(SELECT ghm_id, count(*) as count  
			FROM pmsi.p_rss  
			GROUP BY ghm_id) subview  
			ON (t_ghm.oid = subview.ghm_id)
			WHERE t_ghm.oid > 0 
			ORDER BY code";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD ";
				$httpString_tmp = $httpString_tmp . "oid=\"$oid\" ";
				$httpString_tmp = $httpString_tmp . "code=\"$code\" ";
				$httpString_tmp = $httpString_tmp . "texte=\"$texte\" ";
				$httpString_tmp = $httpString_tmp . "dms=\"+0\" ";
				$httpString_tmp = $httpString_tmp . " />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString_tmp = $httpString_tmp . "\r\n</LIST_GHM>";
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}


function getRecords_expert_controle() {

	global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	

	// Activation module EXPERT
	$sqlcmd = "
	INSERT INTO pmsi.t_divers (code, texte, valeur, description)
	SELECT
		'EXPERT_ACTIVE',
		'Module EXPERT activé',
		'0',
		'1=Activé'
	WHERE 'EXPERT_ACTIVE' NOT IN (SELECT code FROM pmsi.t_divers);
	INSERT INTO pmsi.t_divers (code, texte, valeur, description, valeur_date)
	SELECT
		'EXPERT_DATE_DEBUT',
		'Date séjours ŕ contrôler',
		'20130101',
		'Date de début des séjours ŕ contrôler',
		'20130101'
	WHERE 'EXPERT_DATE_DEBUT' NOT IN (SELECT code FROM pmsi.t_divers);
	INSERT INTO pmsi.t_divers (code, texte, valeur, description)
	SELECT
		'EXPERT_DATE_SELECT',
		'Mode de sélection de la période',
		'0',
		'0=année actuelle, 1=année précédente, 2=12 mois glissants, 3=Personnalisé'
	WHERE 'EXPERT_DATE_SELECT' NOT IN (SELECT code FROM pmsi.t_divers);";
	$result = $database->exec($sqlcmd);
	
	
	// Correction données antérieures
	$sqlcmd = "UPDATE pmsi.t_expert_controle_rule 
		SET numero = 1 
		WHERE numero NOT IN (1,2,3) OR numero IS NULL;
		UPDATE pmsi.t_expert_controle
		SET gravite_id = 5
		WHERE gravite_id NOT IN (0,5,9) OR gravite_id IS NULL";
	$result = $database->exec($sqlcmd);
	
	
	// Paramčtres généraux
	$EXPERT_ACTIVE = "0";
	$EXPERT_DATE_DEBUT = "2013-01-01";
	$EXPERT_DATE_SELECT = "0";
	$autorisation_neuro = "0";
	$autorisation_cardio = "0";
	$autorisation_rea = "0";
	$autorisation_rep = "0";
	$autorisation_nn = "0";
	$service_urgence = "0";
	$service_ssr = "0";
	$service_sld = "0";
	$service_psy = "0";
	
	$sqlcmd = "SELECT code, valeur, to_char(valeur_date,'DD/MM/YYYY')
			FROM pmsi.t_divers
			WHERE code LIKE 'EXPERT%'";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				switch(trim($record[0])) {
					case "EXPERT_ACTIVE" :
						$EXPERT_ACTIVE = trim($record[1]);
						break;
					case "EXPERT_DATE_DEBUT" :
						$EXPERT_DATE_DEBUT = trim($record[2]);
						break;
					case "EXPERT_DATE_SELECT" :
						$EXPERT_DATE_SELECT = trim($record[1]);
						break;
				}
			}
		}
	}
	
	$sqlcmd = "SELECT datim_autorisation_neuro, datim_autorisation_cardio, datim_service_urgence, datim_service_ssr, datim_service_sld, datim_service_psy, datim_autorisation_rea, datim_autorisation_rep, datim_autorisation_nn
		FROM base.t_finess
		WHERE secondaire = '0' AND
			code IN (SELECT finess FROM pmsi.p_rss WHERE date_sortie >= '20130101');";
	$result = $database->exec($sqlcmd);
	if ($result != false) {
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				if (trim($record[0]) == "1") {
					$autorisation_neuro = "1";
				}
				if (trim($record[1]) == "1") {
					$autorisation_cardio = "1";
				}
				if (trim($record[2]) == "1") {
					$service_urgence = "1";
				}
				if (trim($record[3]) == "1") {
					$service_ssr = "1";
				}
				if (trim($record[4]) == "1") {
					$service_sld = "1";
				}
				if (trim($record[5]) == "1") {
					$service_psy = "1";
				}
				if (trim($record[6]) == "1") {
					$autorisation_rea = "1";
				}
				if (trim($record[7]) == "1") {
					$autorisation_rep = "1";
				}
				if (trim($record[8]) == "1") {
					$autorisation_nn = "1";
				}
			}
		}
	}
	
	$httpString_tmp = "$httpString_tmp
				<GENERAL_SETTINGS 
				EXPERT_ACTIVE=\"$EXPERT_ACTIVE\" 
				EXPERT_DATE_SELECT=\"$EXPERT_DATE_SELECT\" 
				EXPERT_DATE_DEBUT=\"$EXPERT_DATE_DEBUT\" 
				autorisation_neuro=\"$autorisation_neuro\"
				autorisation_cardio=\"$autorisation_cardio\"
				autorisation_rea=\"$autorisation_rea\"
				autorisation_rep=\"$autorisation_rep\"
				autorisation_nn=\"$autorisation_nn\"
				service_urgence=\"$service_urgence\"
				service_ssr=\"$service_ssr\"
				service_sld=\"$service_sld\"
				service_psy=\"$service_psy\"
				/>";
	
	// Liste des controles
	$sqlcmd = "SELECT t_expert_controle.oid, 
				t_expert_controle.code, 
				t_expert_controle.texte, 
				COALESCE(t_expert_controle.texte_court,t_expert_controle.texte), 
				COALESCE(t_expert_controle.texte_court,t_expert_controle.texte,t_expert_controle.texte_abrege), 
				t_expert_controle.description,
				t_expert_controle.is_cti,
				t_expert_controle.is_datim, 
				t_expert_controle.is_hide,
				t_expert_controle.is_global,
				t_expert_controle.gravite_id,
				COALESCE(t_expert_controle_rule_1.oid,0),
				COALESCE(t_expert_controle_rule_1.sqlcmd_where),
				COALESCE(t_expert_controle_rule_1.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_1.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_1.last_execution_ok,''),
				COALESCE(t_expert_controle_rule_2.oid,0),
				COALESCE(t_expert_controle_rule_2.sqlcmd_where),
				COALESCE(t_expert_controle_rule_2.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_2.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_2.last_execution_ok,''),
				COALESCE(t_expert_controle_rule_3.oid,0),
				COALESCE(t_expert_controle_rule_3.sqlcmd_where),
				COALESCE(t_expert_controle_rule_3.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_3.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_3.last_execution_ok,''),
				COALESCE(TO_CHAR(GREATEST(
					t_expert_controle_rule_1.last_execution_date,
					t_expert_controle_rule_2.last_execution_date,
					t_expert_controle_rule_3.last_execution_date
					),'DD/MM/YYYY'),''),
				COALESCE(LEAST(
					t_expert_controle_rule_1.last_execution_ok,
					t_expert_controle_rule_2.last_execution_ok,
					t_expert_controle_rule_3.last_execution_ok
					),''),
				COALESCE(subview.nbref, 0),
				COALESCE(subview.nbref0, 0),
				t_expert_controle.alert_exp as is_alert
			FROM pmsi.t_expert_controle  
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_1 ON t_expert_controle_rule_1.controle_id = t_expert_controle.oid AND t_expert_controle_rule_1.numero = 1
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_2 ON t_expert_controle_rule_2.controle_id = t_expert_controle.oid AND t_expert_controle_rule_2.numero = 2
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_3 ON t_expert_controle_rule_3.controle_id = t_expert_controle.oid AND t_expert_controle_rule_3.numero = 3
				LEFT JOIN (SELECT controle_id, count(*) AS nbref, SUM(CASE WHEN etat = '' THEN 1 ELSE 0 END) AS nbref0 FROM pmsi.p_expert_rss_controle GROUP BY 1) subview ON t_expert_controle.oid = subview.controle_id
			WHERE t_expert_controle.oid > 0 AND is_global <> 1
			ORDER BY t_expert_controle.code";
	$result = $database->exec($sqlcmd);
	

				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$texte_abrege = toHTML(trim($record[4]));
				$description = toHTML(trim($record[5]));
				$is_cti = toHTML(trim($record[6]));
				$is_datim = toHTML(trim($record[7]));
				$is_hide = toHTML(trim($record[8]));
				$is_global = toHTML(trim($record[9]));
				$gravite_id = floatval(trim($record[10]));
				$rule_oid1 = floatval(trim($record[11]));
				$sqlcmd_where1 = toHTML(trim($record[12]));
				$sqlcmd_justificatif1 = toHTML(trim($record[13]));
				$last_execution_date1 = toHTML(trim($record[14]));
				$last_execution_ok1 = toHTML(trim($record[15]));
				$rule_oid2 = floatval(trim($record[16]));
				$sqlcmd_where2 = toHTML(trim($record[17]));
				$sqlcmd_justificatif2 = toHTML(trim($record[18]));
				$last_execution_date2 = toHTML(trim($record[19]));
				$last_execution_ok2 = toHTML(trim($record[20]));
				$rule_oid3 = floatval(trim($record[21]));
				$sqlcmd_where3 = toHTML(trim($record[22]));
				$sqlcmd_justificatif3 = toHTML(trim($record[23]));
				$last_execution_date3 = toHTML(trim($record[24]));
				$last_execution_ok3 = toHTML(trim($record[25]));
				$last_execution_date = toHTML(trim($record[26]));
				$last_execution_ok = toHTML(trim($record[27]));
				$nbref = floatval(trim($record[28]));
				$nbref0 = floatval(trim($record[29]));
				$is_alert = toHTML(trim($record[30]));

				
				if ($last_execution_date == "") {
					$last_execution_ok = "";
				}
				else {
					if ($last_execution_ok == "1") {
						$last_execution_ok = "OK";
					}
					if ($last_execution_ok == "0") {
						$last_execution_ok = "KO";
					}
					
				}

				
				$complement = "";
				if ($is_cti == "1") {
					$complement = "$complement CTI";
				}
				else {
					$is_cti = "0";
				}
				if ($is_datim == "1") {
					$complement = "$complement DATIM";
				}
				else {
					$is_datim = "0";
				}
				if ($is_hide == "1") {
					$complement = "$complement Masqué";
				}
				else {
					$is_hide = "0";
				}
				if ($is_global == "1") {
					$complement = "$complement Global";
				}
				else {
					$is_global = "0";
				}
				if ($gravite_id == 0) {
					$gravite_texte = "INFO";
				}
				else {
					if ($gravite_id == 9) {
						$gravite_texte = "ERREUR";
					}
					else {
						$gravite_texte = "ATT";
					}
				}
				if ($is_alert == "1") {
					$complement = "$complement Alerte";
				}
				else {
					$is_alert = "0";
				}
				$complement = trim($complement);
				
				
				$md5_def = refmd5("$code$texte$texte_court$texte_abrege$description$is_cti$is_datim$is_global");
				$md5_sql = refmd5("$code$sqlcmd_where1$sqlcmd_justificatif1$sqlcmd_where2$sqlcmd_justificatif2$sqlcmd_where3$sqlcmd_justificatif3");
				
				$httpString_tmp = "$httpString_tmp
				<RECORD 
				selected=\"0\" 
				oid=\"$oid\" 
				code=\"$code\" 
				texte=\"$texte\" 
				texte_court=\"$texte_court\" 
				texte_abrege=\"$texte_abrege\" 
				description=\"$description\" 
				is_cti=\"$is_cti\" 
				is_datim=\"$is_datim\" 
				is_hide=\"$is_hide\" 
				is_global=\"$is_global\" 
				gravite_id=\"$gravite_id\" 
				gravite_texte=\"$gravite_texte\" 
				complement=\"$complement\" 
				rule_oid1=\"$rule_oid1\" 
				sqlcmd_where1=\"$sqlcmd_where1\" 
				sqlcmd_justificatif1=\"$sqlcmd_justificatif1\" 
				last_execution_date1=\"$last_execution_date1\" 
				last_execution_ok1=\"$last_execution_ok1\" 
				rule_oid2=\"$rule_oid2\" 
				sqlcmd_where2=\"$sqlcmd_where2\" 
				sqlcmd_justificatif2=\"$sqlcmd_justificatif2\" 
				last_execution_date2=\"$last_execution_date2\" 
				last_execution_ok2=\"$last_execution_ok2\" 
				rule_oid3=\"$rule_oid3\" 
				sqlcmd_where3=\"$sqlcmd_where3\" 
				sqlcmd_justificatif3=\"$sqlcmd_justificatif3\" 
				last_execution_date3=\"$last_execution_date3\" 
				last_execution_ok3=\"$last_execution_ok3\" 
				last_execution_date=\"$last_execution_date\" 
				last_execution_ok=\"$last_execution_ok\" 
				nbref=\"$nbref\" 
				nbref0=\"$nbref0\" 
				md5_def=\"$md5_def\"
				md5_sql=\"$md5_sql\"
				is_alert=\"$is_alert\"
				 />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	
	
	// Référence
	$httpString = $httpString . getRefSettings("t_expert_controle", $httpString);
	
	return $httpString;
	
	

}


function getRecords_expert_controle_refsettings($refPrefix) {

global $database;

	$httpString = "";
	
	$httpString_tmp = "";
	

	
	// Liste des controles
	$sqlcmd = "SELECT t_expert_controle.oid, 
				t_expert_controle.code, 
				t_expert_controle.texte, 
				COALESCE(t_expert_controle.texte_court,t_expert_controle.texte), 
				COALESCE(t_expert_controle.texte_court,t_expert_controle.texte,t_expert_controle.texte_abrege),
				t_expert_controle.description,
				t_expert_controle.is_cti,
				t_expert_controle.is_datim, 
				t_expert_controle.is_hide,
				t_expert_controle.is_global,
				t_expert_controle.gravite_id,
				COALESCE(t_expert_controle_rule_1.oid,0),
				COALESCE(t_expert_controle_rule_1.sqlcmd_where),
				COALESCE(t_expert_controle_rule_1.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_1.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_1.last_execution_ok,''),
				COALESCE(t_expert_controle_rule_2.oid,0),
				COALESCE(t_expert_controle_rule_2.sqlcmd_where),
				COALESCE(t_expert_controle_rule_2.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_2.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_2.last_execution_ok,''),
				COALESCE(t_expert_controle_rule_3.oid,0),
				COALESCE(t_expert_controle_rule_3.sqlcmd_where),
				COALESCE(t_expert_controle_rule_3.sqlcmd_justificatif),
				COALESCE(TO_CHAR(t_expert_controle_rule_3.last_execution_date,'DD/MM/YYYY'),''),
				COALESCE(t_expert_controle_rule_3.last_execution_ok,''),
				COALESCE(TO_CHAR(GREATEST(
					t_expert_controle_rule_1.last_execution_date,
					t_expert_controle_rule_2.last_execution_date,
					t_expert_controle_rule_3.last_execution_date
					),'DD/MM/YYYY'),''),
				COALESCE(LEAST(
					t_expert_controle_rule_1.last_execution_ok,
					t_expert_controle_rule_2.last_execution_ok,
					t_expert_controle_rule_3.last_execution_ok
					),''),
				t_expert_controle.alert_exp as is_alert
			FROM pmsi.t_expert_controle  
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_1 ON t_expert_controle_rule_1.controle_id = t_expert_controle.oid AND t_expert_controle_rule_1.numero = 1
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_2 ON t_expert_controle_rule_2.controle_id = t_expert_controle.oid AND t_expert_controle_rule_2.numero = 2
				LEFT JOIN pmsi.t_expert_controle_rule t_expert_controle_rule_3 ON t_expert_controle_rule_3.controle_id = t_expert_controle.oid AND t_expert_controle_rule_3.numero = 3
			WHERE t_expert_controle.oid > 0 AND is_global <> 1 AND code ILIKE '$refPrefix%'
			ORDER BY t_expert_controle.code";
	$result = $database->exec($sqlcmd);
	

				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$texte_court = toHTML(trim($record[3]));
				$texte_abrege = toHTML(trim($record[4]));
				$description = toHTML(trim($record[5]));
				$is_cti = toHTML(trim($record[6]));
				$is_datim = toHTML(trim($record[7]));
				$is_hide = toHTML(trim($record[8]));
				$is_global = toHTML(trim($record[9]));
				$gravite_id = floatval(trim($record[10]));
				$rule_oid1 = floatval(trim($record[11]));
				$sqlcmd_where1 = toHTML(trim($record[12]));
				$sqlcmd_justificatif1 = toHTML(trim($record[13]));
				$last_execution_date1 = toHTML(trim($record[14]));
				$last_execution_ok1 = toHTML(trim($record[15]));
				$rule_oid2 = floatval(trim($record[16]));
				$sqlcmd_where2 = toHTML(trim($record[17]));
				$sqlcmd_justificatif2 = toHTML(trim($record[18]));
				$last_execution_date2 = toHTML(trim($record[19]));
				$last_execution_ok2 = toHTML(trim($record[20]));
				$rule_oid3 = floatval(trim($record[21]));
				$sqlcmd_where3 = toHTML(trim($record[22]));
				$sqlcmd_justificatif3 = toHTML(trim($record[23]));
				$last_execution_date3 = toHTML(trim($record[24]));
				$last_execution_ok3 = toHTML(trim($record[25]));
				$last_execution_date = toHTML(trim($record[26]));
				$last_execution_ok = toHTML(trim($record[27]));
				$is_alert = toHTML(trim($record[28]));
				
				if ($last_execution_date == "") {
					$last_execution_ok = "";
				}
				else {
					if ($last_execution_ok == "1") {
						$last_execution_ok = "OK";
					}
					if ($last_execution_ok == "0") {
						$last_execution_ok = "KO";
					}
					
				}

				
				$complement = "";
				if ($is_cti == "1") {
					$complement = "$complement CTI";
				}
				else {
					$is_cti = "0";
				}
				if ($is_datim == "1") {
					$complement = "$complement DATIM";
				}
				else {
					$is_datim = "0";
				}
				if ($is_hide == "1") {
					$complement = "$complement Masqué";
				}
				else {
					$is_hide = "0";
				}
				if ($is_global == "1") {
					$complement = "$complement Global";
				}
				else {
					$is_global = "0";
				}
				if ($gravite_id == 0) {
					$gravite_texte = "INFO";
				}
				else {
					if ($gravite_id == 9) {
						$gravite_texte = "ERREUR";
					}
					else {
						$gravite_texte = "ATT";
					}
				}
				$complement = trim($complement);
				
				
				$md5_def = refmd5("$code$texte$texte_court$texte_abrege$description$is_cti$is_datim$is_global");
				$md5_sql = refmd5("$code$sqlcmd_where1$sqlcmd_justificatif1$sqlcmd_where2$sqlcmd_justificatif2$sqlcmd_where3$sqlcmd_justificatif3");
				
				$httpString_tmp = "$httpString_tmp
				<RECORD 
				selected=\"0\" 
				oid=\"$oid\" 
				code=\"$code\" 
				texte=\"$texte\" 
				texte_court=\"$texte_court\" 
				texte_abrege=\"$texte_abrege\" 
				is_cti=\"$is_cti\" 
				is_datim=\"$is_datim\" 
				is_hide=\"$is_hide\" 
				is_global=\"$is_global\" 
				gravite_id=\"$gravite_id\" 
				gravite_texte=\"$gravite_texte\" 
				complement=\"$complement\"
				md5_def=\"$md5_def\"
				md5_sql=\"$md5_sql\"
				is_alert=\"$is_alert\"
				 />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}

			}
		}

	
	}
	
	$httpString = "$httpString$httpString_tmp";
	
	return $httpString;
	
	

}



function getRecords_datim_ccaminfo() {

global $database;

	$httpString = "";

	

	$sqlcmd = "
		SELECT 
			COALESCE(t_datim_ccaminfo.oid,0),
			t_actes.code,
			t_actes.texte,
			CASE WHEN t_datim_ccaminfo.acte IS NULL THEN 'Pas de donnée CCAMINFO, ' ELSE '' END ||
			CASE WHEN ffm = 1 THEN 'Acte FFM, ' ELSE '' END ||
			CASE WHEN se = 1 THEN 'Acte SE, ' ELSE '' END ||
			CASE WHEN fsd = 1 THEN 'Acte FSD, ' ELSE '' END ||
			CASE WHEN autre = 1 THEN 'Autre acte EXTERNE, ' ELSE '' END ||
			CASE WHEN unichir >= 99 THEN 'Acte réalisé UNE FOIS durant le séjour, ' ELSE '' END ||
			CASE WHEN gestcomp = 1 THEN 'Geste complémentaire danesthésie, ' ELSE '' END ||
			CASE WHEN reqz = 1 THEN 'Acte requérant un code spécifique Z en DP, ' ELSE '' END ||
			CASE WHEN dialyse = 1 THEN 'Acte DIALYSE, ' ELSE '' END ||
			CASE WHEN esthe = 1 THEN 'Acte chirurgie ESTHETIQUE, ' ELSE '' END ||
			CASE WHEN confort = 1 THEN 'Acte chirurgie de CONFORT, ' ELSE '' END ||
			CASE WHEN brule = 1 THEN 'Acte opératoire de brulure (CMD 22), ' ELSE '' END ||
			CASE WHEN neurochir = 1 THEN 'Acte relatif ŕ la neuro-chirurgie, ' ELSE '' END ||
			CASE WHEN ojatypique = 1 THEN 'Acte improbable en O jour, ' ELSE '' END       
			, 
			COALESCE(to_char(date_debut,'DD/MM/YYYY'),''), 
			COALESCE(to_char(date_fin,'DD/MM/YYYY'),''),
			subview.nbref
		FROM pmsi.t_actes
		LEFT JOIN pmsi.t_datim_ccaminfo ON t_datim_ccaminfo.acte_id = t_actes.oid
		JOIN (
			SELECT p_rss_actes.acte_id, count(*) as nbref
			FROM pmsi.p_rss_actes 
			JOIN pmsi.t_divers ON t_divers.code = 'EXPERT_DATE_DEBUT' AND p_rss_actes.date_acte >= valeur_date
			GROUP BY p_rss_actes.acte_id
			) subview ON t_actes.oid = subview.acte_id
		WHERE t_actes.nomenclature = 'CCAM' AND
			t_actes.texte NOT ILIKE '** SUP%'
		ORDER BY 2
	";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		$httpString_tmp = "";
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$datim = toHTML(trim($record[3]));
				$date_debut = toHTML(trim($record[4]));
				$date_fin = toHTML(trim($record[5]));
				$nbref = $record[6] + 0;
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD  oid=\"$oid\"  code=\"$code\"  texte=\"$texte\"  datim=\"$datim\"  date_debut=\"$date_debut\"  date_fin=\"$date_fin\"  nbref=\"+$nbref\"   />";

				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}
			}
		}
		
		$httpString = "$httpString$httpString_tmp";

	
	}
	
	return $httpString;
	
	

}


function getRecords_datim_diaginfo() {

global $database;

	$httpString = "";

	

	$sqlcmd = "
		SELECT 
			COALESCE(t_datim_diaginfo.oid,0),
			t_diagnostics.code,
			t_diagnostics.texte,
			CASE WHEN t_datim_diaginfo.diag IS NULL THEN 'Pas de donnée diaginfo, ' ELSE '' END ||
			CASE WHEN rare = 1 THEN 'Caractčre peu fréquent du diagnostic, ' ELSE '' END ||
			CASE WHEN dpchir > 0 THEN 'Diagnostic associé ŕ un acte opératoire (' || dpchir || '%), ' ELSE '' END || 
			CASE WHEN dague > 0 THEN 'Diagnostic dague nécessitant obligatoirement un code astérisque, ' ELSE '' END || 
			CASE WHEN sexed = 1 THEN 'Diagnostic uniquement chez l''homme, ' ELSE '' END || 
			CASE WHEN sexed = 2 THEN 'Diagnostic uniquement chez la femme, ' ELSE '' END || 
			CASE WHEN cl1v = 1 OR cl2v = 1 OR cl3v = 1 OR cl4v = 1 OR cl5v = 1 OR cl6v = 1 THEN
				'Diagnostic improbable pour un âge ' ||
				CASE WHEN cl1v = 1 THEN '<= 28 jours, ' ELSE '' END || 
				CASE WHEN cl2v = 1 THEN '> 28 jours et < 1 an, ' ELSE '' END || 
				CASE WHEN cl3v = 1 THEN 'compris 1 et 9 ans, ' ELSE '' END || 
				CASE WHEN cl4v = 1 THEN 'compris 10 et 19 ans, ' ELSE '' END || 
				CASE WHEN cl5v = 1 THEN '20 et 64 ans, ' ELSE '' END || 
				CASE WHEN cl6v = 1 THEN '>= 65 ans, ' ELSE '' END
			ELSE '' END ||
			CASE WHEN zinhab = 1 THEN 'Diagnostic Z inhabituel en DP, ' ELSE '' END ||
			CASE WHEN zinhab = 2 THEN 'Diagnostic Z inhabituel en DP (Limite), ' ELSE '' END ||
			CASE WHEN imprecis = 1 THEN 'Diagnostic imprécis, ' ELSE '' END ||
			CASE WHEN imprecis = 2 THEN 'Diagnostic trčs imprécis, ' ELSE '' END ||
			CASE WHEN zaffchr = 2 THEN 'Code Z généralement associé ŕ une affection chronique ou de longue durée, ' ELSE '' END ||
			CASE WHEN codext = 1 THEN 'Code Cim10 concerné par une extension (pčre), ' ELSE '' END ||
			CASE WHEN codext = 2 THEN 'Code Cim10 concerné par une extension (fils), ' ELSE '' END ||
			CASE WHEN codseq > 0 THEN 'Code représentant une séquelle, ' ELSE '' END ||
			CASE WHEN timprecis = 1 THEN 'Codes T (complication) imprécis ne devant pas ętre utilisé en DP, ' ELSE '' END ||
			CASE WHEN tintox = 1 THEN 'Code d''intoxication, ' ELSE '' END ||
			CASE WHEN cma = 2 THEN 'Code considérée comme une complication de niveau 2, ' ELSE '' END ||
			CASE WHEN cma = 3 THEN 'Code considérée comme une complication de niveau 3, ' ELSE '' END ||
			CASE WHEN cma = 4 THEN 'Code considérée comme une complication de niveau 4, ' ELSE '' END ||
			CASE WHEN dpacte > 0 THEN 'Diagnostic associé ŕ un acte (' || dpacte || '%) , ' ELSE '' END ||
			CASE WHEN dgcpt669 = 1 THEN 'Diagnostic compatible avec la racine 23C02, ' ELSE '' END ||
			CASE WHEN brulure = 1 THEN 'Diagnostic de brulure, ' ELSE '' END ||
			CASE WHEN esth = 1 THEN 'Diagnostic pouvant ętre associé ŕ un acte de chirurgie esthétique, ' ELSE '' END ||
			CASE WHEN brulure = 1 THEN 'Diagnostic dont le libellé mentionne le mot Ť aigue ť, ' ELSE '' END
			, 
			COALESCE(to_char(date_debut,'DD/MM/YYYY'),''), 
			COALESCE(to_char(date_fin,'DD/MM/YYYY'),''),
			subview.nbref
		FROM pmsi.t_diagnostics
		LEFT JOIN pmsi.t_datim_diaginfo ON t_datim_diaginfo.diagnostic_id = t_diagnostics.oid
		JOIN (
			SELECT p_rss_diagnostics.diagnostic_id, count(*) as nbref
			FROM pmsi.p_rss_diagnostics 
			JOIN pmsi.p_rss ON rss_id = p_rss.oid
			JOIN pmsi.t_divers ON t_divers.code = 'EXPERT_DATE_DEBUT' AND p_rss.date_sortie >= valeur_date
			GROUP BY p_rss_diagnostics.diagnostic_id
			) subview ON t_diagnostics.oid = subview.diagnostic_id
		WHERE t_diagnostics.code BETWEEN 'A' AND 'Z99999' 
		ORDER BY 2
	";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		$httpString_tmp = "";
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$datim = toHTML(trim($record[3]));
				$date_debut = toHTML(trim($record[4]));
				$date_fin = toHTML(trim($record[5]));
				$nbref = $record[6] + 0;
				
				if ($datim != "") {
					$datim = substr($datim,0,strlen($datim)-1);
				}
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD  oid=\"$oid\"  code=\"$code\"  texte=\"$texte\"  datim=\"$datim\"  date_debut=\"$date_debut\"  date_fin=\"$date_fin\"  nbref=\"+$nbref\"   />";

				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}
			}
		}
		
		$httpString = "$httpString$httpString_tmp";

	
	}
	
	return $httpString;
	
	

}



function getRecords_datim_ghminfo() {

global $database;

	$httpString = "";

	

	$sqlcmd = "
		SELECT 
			COALESCE(t_datim_ghminfo.oid,0),
			t_ghm.code,
			t_ghm.texte,
			CASE WHEN t_datim_ghminfo.ghm IS NULL THEN 'Pas de donnée ghminfo, ' ELSE '' END ||
			CASE WHEN tghm = 'C' THEN 'Type du GHM = Chirurgical, ' ELSE '' END ||
			CASE WHEN tghm = 'M' THEN 'Type du GHM = Médical, ' ELSE '' END ||
			CASE WHEN tghm = 'X' THEN 'Type du GHM = Autre, ' ELSE '' END
			, 
			COALESCE(to_char(date_debut,'DD/MM/YYYY'),''), 
			COALESCE(to_char(date_fin,'DD/MM/YYYY'),''),
			subview.nbref
		FROM pmsi.t_ghm
		LEFT JOIN pmsi.t_datim_ghminfo ON t_datim_ghminfo.ghm_id = t_ghm.oid
		JOIN (
			SELECT p_rss.ghm_id, count(*) as nbref
			FROM pmsi.p_rss
			JOIN pmsi.t_divers ON t_divers.code = 'EXPERT_DATE_DEBUT' AND p_rss.date_sortie >= valeur_date
			WHERE p_rss.ghm_id <> 0
			GROUP BY 1
			) subview ON t_ghm.oid = subview.ghm_id
		WHERE t_ghm.code BETWEEN '01' AND '91' 
		ORDER BY 2
	";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		$httpString_tmp = "";
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = $record[0];
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$datim = toHTML(trim($record[3]));
				$date_debut = toHTML(trim($record[4]));
				$date_fin = toHTML(trim($record[5]));
				$nbref = $record[6] + 0;
				
				if ($datim != "") {
					$datim = substr($datim,0,strlen($datim)-1);
				}
				
				$httpString_tmp = $httpString_tmp . "\r\n<RECORD  oid=\"$oid\"  code=\"$code\"  texte=\"$texte\"  datim=\"$datim\"  date_debut=\"$date_debut\"  date_fin=\"$date_fin\"  nbref=\"+$nbref\"   />";

				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}
			}
		}
		
		$httpString = "$httpString$httpString_tmp";

	
	}
	
	return $httpString;
	
	

}


function getRecords_divers() {

global $database;

	$httpString = "";


	$sqlcmd = "
        SELECT
            1::bigint AS oid,
            code,
            texte,
            valeur,
            description,
            CASE WHEN show_info_module THEN 1 ELSE 0 END AS show_info_module
		FROM pmsi.t_divers
		ORDER BY code ";
	$result = $database->exec($sqlcmd);
				
	if ($result != false) {
	
		
		// lignes 
		$ok = TRUE;

		while ($ok == TRUE) {
			$ok = FALSE;
		
			$record = $database->nextRecordInto();
										

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = 1;
				$code = toHTML(trim($record[1]));
				$texte = toHTML(trim($record[2]));
				$valeur = toHTML(trim($record[3]));
				$description = toHTML(trim($record[4]));
                $show_info_module = toHTML(trim($record[5]));
				$nbref = 1;
				
				$httpString = $httpString . "\r\n<RECORD ";
				$httpString = $httpString . "oid=\"$oid\" ";
				$httpString = $httpString . "code=\"$code\" ";
				$httpString = $httpString . "texte=\"$texte\" ";
				$httpString = $httpString . "valeur=\"$valeur\" ";
				$httpString = $httpString . "description=\"$description\" ";
                $httpString = $httpString . "show_info_module=\"$show_info_module\" ";
				$httpString = $httpString . "nbref=\"+$nbref\" ";
				$httpString = $httpString . " />";

			}
		}

	
	}
	
	return $httpString;
	
	

}


// recherche des listes de réference
function getRefSettings($tableName, $httpString_base) {

	global $getOption;
	
	$httpString = "";
	
	$SETTINGS_file = rootDir() . "settings/settings.XML";
	$SETTINGS_xml = simplexml_load_file($SETTINGS_file);
	$REFSETTINGS_URL = getProperty($SETTINGS_xml, "REFSETTINGS", 'URL');
	$REFSETTINGS_PREFIX = getProperty($SETTINGS_xml, "REFSETTINGS", 'PREFIX');
	

	if ($REFSETTINGS_URL != "" && extension_loaded('curl')) {
			
			// Recherche des indicateurs de l'environnement de référence
			$REFSETTINGS_table_url = "$REFSETTINGS_URL/modules/pmsi/php/PMSI_getTableRecords.php";
			
			// Recherche http pour indicateurs
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $REFSETTINGS_table_url);
			curl_setopt($ch, CURLOPT_POST, 2);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "tableName=$tableName&getOption=getRefSettings&refPrefix=$REFSETTINGS_PREFIX");
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
			$REFSETTINGS_data = @curl_exec($ch);
			curl_close($ch);
			
			
			
			if ($REFSETTINGS_data) {
			
				if (substr($REFSETTINGS_data, 0, 12) == "<CTICONTENT>") {
					$REFSETTINGS_data = substr($REFSETTINGS_data, 12, strlen($REFSETTINGS_data) - 25);
				}
				
				$REFSETTINGS_data = uncompress($REFSETTINGS_data);
				$REFSETTINGS_data = str_replace("<RECORD ","<REFRECORD ",$REFSETTINGS_data);
				$REFSETTINGS_data = str_replace("</RECORD>","</REFRECORD>",$REFSETTINGS_data);
				$REFSETTINGS_xml = simplexml_load_string($REFSETTINGS_data);
				if ($REFSETTINGS_xml) {
	
					foreach ($REFSETTINGS_xml->REFRECORD as $recordNode) {
						$md5_def = trim($recordNode["md5_def"]);
						$md5_sql = trim($recordNode["md5_sql"]);
						$recordNode["ok"] = "";
						if (stripos($httpString_base, $md5_def) === false) {
							$recordNode["ok"] = "Définition";
						}
						if (stripos($httpString_base, $md5_sql) === false) {
							$recordNode["ok"] = "Rčgles";
						}
						//if ($recordNode["ok"] != "") {
							$httpString = $httpString . $recordNode->asXML();
						//}
					}
					
				}
				
				
			}
	}
	
	
	return $httpString;
	
}

function refmd5($string) {
	$string = str_replace("\r","",$string);
	$string = str_replace("\n","",$string);
	$string = md5(trim($string));
	return $string;
}

/**
 * #CLEANME
 */
function getCombo_um() {

global $database;

	$httpString = "";
	$httpString = "$httpString\r\n<COMBO_UM>";
	$httpString_tmp = "";

	$sqlcmd = "	
				SELECT 
					t_unites_medicales.oid
					,t_unites_medicales.code || ' ' || t_unites_medicales.texte as codetexte
				FROM 
					pmsi.t_unites_medicales  
				WHERE 
					t_unites_medicales.oid > 0 
				ORDER BY 2";
	$result = $database->exec($sqlcmd);
	
	$httpString_tmp = "$httpString_tmp\r\n<RECORD oid=\"0\" codetexte=\"\" texte=\"\" />";
	
	if ($result != false) {
		$ok = TRUE;
		while ($ok == TRUE) {
			$ok = FALSE;
			$record = $database->nextRecordInto();

			if ($record != FALSE) {
				$ok = TRUE;

				$oid = toHTML(trim($record[0]));
				$texte = toHTML(trim($record[1]));
			
				$httpString_tmp = "$httpString_tmp\r\n<RECORD oid=\"$oid\" codetexte=\"$texte\" texte=\"$texte\"  />";
				
				if (strlen($httpString_tmp) > 64000) {
					$httpString = "$httpString$httpString_tmp";
					$httpString_tmp = "";
				}
			}
		}
	}
	
	$httpString = "$httpString$httpString_tmp\r\n</COMBO_UM>";
	return $httpString;
}
    
?>