return: text
lang: plpgsql
src: |
  DECLARE	
  	result TEXT;
  BEGIN
      TRUNCATE activite.t_ghmgme_c
      ;
  INSERT INTO activite.t_ghmgme_c
      ( ghmgme_id, ghmgme_code, ghmgme_texte,cm_id, cm_code, cm_texte, gn_id, gn_code, gn_texte,rgme_id,rgme_code,rgme_texte, gme_id, gme_code, gme_texte,ghm_id,ghm_code,ghm_texte, cmd_id, cmd_code, cmd_texte,ghm5_id,ghm5_code, ghm5_texte, type_pmsi)
  VALUES
      (0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 0, 'Non renseigné', 'Non renseigné', 'MCO/SSR');
  
  /*
      Insertion GHM sauf 99
  */
  INSERT INTO activite.t_ghmgme_c
      (
      ghmgme_id,
      ghmgme_code,
      ghmgme_texte,
  
      ghm_id,
      ghm_code,
      ghm_texte,
  
      cmd_id,
      cmd_code,
      cmd_texte,
  
      ghm5_id,
      ghm5_code,
      ghm5_texte,
  
      type_pmsi)
  SELECT
      ghm_id,
      ghm_code,
      'MCO: ' || ghm_texte,
  
      ghm_id,
      ghm_code,
      'MCO: ' || ghm_texte,
  
      cmd_id,
      cmd_code,
      'MCO: ' || cmd_texte,
  
      ghm5_id,
      ghm5_code,
      'MCO: ' || ghm5_texte,
      '1'
  FROM activite.t_ghm_c
  where ghm_id > 0 AND length(ghm_code) > 5
  order by ghm_id
  ;
  
  /*
      Insertion GME sauf 99
  */
  
  INSERT INTO activite.t_ghmgme_c
      (
      ghmgme_id,
      ghmgme_code,
      ghmgme_texte,
  
      cm_id,
      cm_code,
      cm_texte,
  
      gn_id,
      gn_code,
      gn_texte,
  
      rgme_id,
      rgme_code,
      rgme_texte,
  
      gme_id,
      gme_code,
      gme_texte,
  
      type_pmsi)
  
  SELECT
      gme_id + 10000,
      gme_code,
      'SSR: ' || gme_texte,
  
      cm_id,
      cm_code,
      'SSR: ' || cm_texte,
  
      gn_id,
      gn_code,
      'SSR: ' || gn_texte,
  
      rgme_id,
      rgme_code,
      'SSR: ' || rgme_texte,
  
      gme_id,
      gme_code,
      'SSR: ' || gme_texte,
      '2'
  FROM activite.t_gme_c
  WHERE gme_id > 0 AND length(gme_code) > 5
  ;
  
  INSERT INTO activite.t_ghmgme_c
      (
      ghmgme_id,
      ghmgme_code,
      ghmgme_texte,
      type_pmsi )
      SELECT -9991 AS oid, '99_SE1' AS code, 'Hors GHM-GME. Forfaits SE1' AS texte, '12'
  UNION
      SELECT -9992 AS oid, '99_SE2' AS code, 'Hors GHM-GME. Forfaits SE2' AS texte, '12'
  UNION
      SELECT -9993 AS oid, '99_SE3' AS code, 'Hors GHM-GME. Forfaits SE3' AS texte, '12'
  UNION
      SELECT -9994 AS oid, '99_SE4' AS code, 'Hors GHM-GME. Forfaits SE4' AS texte, '12'
  UNION
      SELECT -9995 AS oid, '99_ATU' AS code, 'Hors GHM-GME. Forfaits ATU' AS texte, '12'
  UNION
      SELECT -9996 AS oid, '99_FFM' AS code, 'Hors GHM-GME. Forfaits FFM' AS texte, '12'
  UNION
      SELECT -9990 AS oid, '99_ZZZ' AS code, 'Hors GHM-GME. Divers' AS texte, '12'
  UNION
      SELECT -9980 AS oid, '98_P' AS code, 'Champ GHM-GME. Présents' AS texte, '12'
  UNION
      SELECT -9981 AS oid, '98_NG' AS code, 'Champ GHM-GME. Sortis non groupés' AS texte, '12';
  
  /*PERFORM base.cti_update_classes
  ('activite', 't_ghmgme_c', 'GHMGME','ghmgme_section');*/
  
  RETURN 'OK';
  END;