return: text
lang: plpgsql
src: |
  DECLARE	
  	result TEXT;
  BEGIN	
  
  
  		-- Médecins
  		
  		INSERT INTO base.t_specialites_medecin (oid, code, texte) 
  		SELECT 0, chr(127) || '**', 'Non saisie'
  		WHERE 0 NOT IN (SELECT oid FROM base.t_specialites_medecin);
  		
  		INSERT INTO base.t_medecins (oid, code, nom, specialite_id) 
  		SELECT 0, chr(127) || '******', 'Non saisi', 0
  		WHERE 0 NOT IN (SELECT oid FROM base.t_medecins);
  		
  		-- Secteurs géographiques
  		INSERT INTO pmsi.t_secteurs_geographiques(oid, code, texte, texte_court)
  		SELECT 0, chr(127) || '******', 'Non renseigné', 'Non renseigné'
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_secteurs_geographiques);
  		
  		-- Unités médicales
  		INSERT INTO pmsi.t_unites_medicales(oid, code, texte, type_autorisation)
  		SELECT 0, chr(127) || '***', 'Non saisie', '' 
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_unites_medicales);
  
  
  		-- Unités fonctionnelles
  		INSERT INTO pmsi.t_unites_fonctionnelles(oid, code, texte)
  		SELECT 0, chr(127) || '**', 'Non renseigné'
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_unites_fonctionnelles);
  		
  		-- Médecins
  		
  		INSERT INTO pmsi.t_specialites_medecin(oid, code, texte, type)
  		SELECT 0, chr(127) || '**', 'Non saisie', '' 
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_specialites_medecin);
  		
  		INSERT INTO pmsi.t_specialites_internes_medecin(oid, code, texte)
  		SELECT 0, chr(127) || '**', 'Non saisie' 
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_specialites_internes_medecin);
  		
  		INSERT INTO pmsi.t_medecins(oid, code, nom, prenom, specialite_id, no_adeli, statut, medecin_reference_id, specialite_interne_id)
  		SELECT 0, chr(127) || '******', 'Non saisi', '', 0, '', '', 0, 0 
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_medecins);
  	  
  		UPDATE pmsi.t_comites_medicaux SET code = chr(127) || '***', texte = 'Non renseigné' WHERE oid = 0;
  		INSERT INTO pmsi.t_comites_medicaux(oid, code, texte)
  		SELECT 0, chr(127) || '****', 'Non renseigné' 
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_comites_medicaux);
    		
  		-- Pole          
  		INSERT INTO pmsi.t_pole (oid, code, texte, texte_court)
  		SELECT 0, '**', 'Non renseigné', 'Non renseigné'
  		WHERE 0 NOT IN (SELECT oid FROM pmsi.t_pole);
          
  	RETURN 'OK';
  END;