Commit 2663aa57 authored by Julien Marchand's avatar Julien Marchand
Browse files

Update 01-vues-physalis-communes.sql

parent 4b38811f
Loading
Loading
Loading
Loading
Loading
+270 −90
Original line number Diff line number Diff line
@@ -613,98 +613,278 @@ WHERE A_COT.ASS_CODE = 'D_LAB_THESE'

--------------------------------------------------------------------------------

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_THESE" ("ID", "SOURCE_ID", "DOCTORANT_ID", "COD_DIS", "DAT_DEB_THS", "DAT_FIN_CFD_THS", "DAT_PREV_SOU", "DAT_SOU_THS", "ETA_THS", "LIB_INT1_DIS", "LIB_THS", "UNITE_RECH_ID", "ECOLE_DOCT_ID", "COD_NEG_TRE", "CORRECTION_POSSIBLE", "DAT_AUT_SOU_THS", "LIB_ETB_COT", "LIB_PAY", "TEM_AVENANT", "TEM_SOU_AUT_THS", "COD_LNG", "ETA_RPD_THS", "COD_ANU_PRM_IAE") AS 
  select ID,
        SOURCE_ID,
        DOCTORANT_ID,
        COD_DIS,
        DAT_DEB_THS,
        DAT_FIN_CFD_THS ,
        DAT_PREV_SOU,
        DAT_SOU_THS,
        ETA_THS,
        LIB_INT1_DIS,
        LIB_THS ,
        unite_rech_id,
        ecole_doct_id,
        COD_NEG_TRE,
        CORRECTION_POSSIBLE,
        DAT_AUT_SOU_THS,
        LIB_ETB_COT,
        LIB_PAY,
        TEM_AVENANT,
        TEM_SOU_AUT_THS,
        COD_LNG,
        ETA_RPD_THS,
        extract (YEAR from DAT_DEB_THS) as COD_ANU_PRM_IAE
        
FROM
 
 ( select th.ID_THESE as ID,
       h.hist_annee_scol,
       'physalis' as SOURCE_ID,
      d.NO_INDIVIDU ||1 as DOCTORANT_ID,
       gd.ID_SISE_DIPLOME as COD_DIS,
       av.avt_date_deb as DAT_DEB_THS,
       '' as DAT_FIN_CFD_THS ,
       th.DATE_PREV_SOUTENANCE as DAT_PREV_SOU,
       th.DATE_SOUTENANCE DAT_SOU_THS,
       case 
        when ins.res_code is null THEN 'E'
        when ins.res_code='W' THEN 'E'
        WHEN ins.res_code='A' THEN 'S'
        WHEN ins.res_code='D' THEN 'A'
        WHEN ins.res_code='4' THEN 'E'
       end as ETA_THS,
       
 --      case A_COT.ASS_CODE
 --      when 'D_LAB_THESE' THEN c_structure
       
       
       
   --    end as 
        dom.LIBELLE_DOMAINE as LIB_INT1_DIS,
        con.CON_OBJET as LIB_THS ,
         etab_cot2.c_structure AS unite_rech_id,
        etab_cot1.c_structure AS ecole_doct_id,
        '' AS COD_NEG_TRE,
     null AS CORRECTION_POSSIBLE,
        th.DATE_PREV_SOUTENANCE AS DAT_AUT_SOU_THS,
        cot.NOM_ETABLISSEMENT_COTUTELLE as LIB_ETB_COT,
        cot.PAYS_COTUTELLE AS LIB_PAY,
        '' AS TEM_AVENANT,
       '' as TEM_SOU_AUT_THS,
       '' as COD_LNG,
 null AS ETA_RPD_THS,
       row_number() over(partition by th.ID_THESE order by h.hist_annee_scol desc) as rn,
        null as COD_ANU_PRM_IAE
from RECHERCHE.DOCTORANT_THESE th left outer join  GRHUM.SISE_DOCTORAT_ETAB gd on th.ID_SISE_DOCTORAT_ETAB=gd.ID_SISE_DOCTORAT_ETAB
left outer join recherche.doctorant d on d.id_doctorant = th.id_doctorant
left outer join accords.avenant av on av.con_ordre = th.con_ordre
left outer join garnuche.historique h on h.etud_numero  = d.etud_numero
left outer join garnuche.insc_dipl ins on ins.hist_numero = h.hist_numero and ins.res_code <> 'Z'
left outer join accords.contrat  con on th.CON_ORDRE = con.con_ordre
left outer join recherche.these_domaine dom on dom.id_these_domaine = th.id_these_domaine
left outer join api_scolarite.co_tutelle cot on cot.id_doctorant = d.id_doctorant 
LEFT OUTER JOIN GRHUM.REPART_ASSOCIATION RA1 ON RA1.C_STRUCTURE = Con.CON_GROUPE_PARTENAIRE
LEFT OUTER JOIN GRHUM.ASSOCIATION A_COT1 ON A_COT1.ASS_ID = RA1.ASS_ID
LEFT OUTER JOIN grhum.structure_ulr etab_cot1 on etab_cot1.pers_id = ra1.pers_id
LEFT OUTER JOIN ACCORDS.contrat_partenaire cp1 on cp1.con_ordre = con.con_ordre and cp1.pers_id = ra1.pers_id
LEFT OUTER JOIN GRHUM.REPART_ASSOCIATION RA2 ON RA2.C_STRUCTURE = Con.CON_GROUPE_PARTENAIRE
LEFT OUTER JOIN GRHUM.ASSOCIATION A_COT2 ON A_COT2.ASS_ID = RA2.ASS_ID
LEFT OUTER JOIN grhum.structure_ulr etab_cot2 on etab_cot2.pers_id = ra2.pers_id
LEFT OUTER JOIN ACCORDS.contrat_partenaire cp2 on cp2.con_ordre = con.con_ordre and cp2.pers_id = ra2.pers_id

WHERE  A_COT1.ASS_CODE = 'D_ED_R' AND A_COT2.ASS_CODE = 'D_LAB_THESE' )
where rn = 1;

--------------------------------------------------------------------------------


  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_THESE_ANNEE_UNIV" ("SOURCE_ID", "ID", "THESE_ID", "ANNEE_UNIV") AS 
  select
  'physalis' as SOURCE_ID     ,
  th.ID_THESE||so.fann_key as ID,

/*
create view SYGAL_INDIVIDU as
  ...
*/

/*
create view SYGAL_DOCTORANT as
  ...
*/

/*
create view SYGAL_THESE as
  ...
*/

/*
create view SYGAL_STRUCTURE as
  ...
*/

/*
create view SYGAL_ECOLE_DOCT as
  ...
*/

/*
create view SYGAL_UNITE_RECH as
  ...
*/

/*
create view SYGAL_ETABLISSEMENT as
  ...
*/

/*
create view SYGAL_ACTEUR as
  ...
*/

/*
create view SYGAL_FINANCEMENT as
  ...
*/

create view SYGAL_ROLE(source_id, COD_ROJ, LIC_ROJ, LIB_ROJ) as
  select 'physalis', 'A', 'Absent',     'Membre absent'         from dual union
  select 'physalis', 'B', 'Co-encadr',  'Co-encadrant'          from dual union
  select 'physalis', 'C', 'Chef Labo',  'Chef de laboratoire'   from dual union
  select 'physalis', 'D', 'Directeur',  'Directeur de thèse'    from dual union
  select 'physalis', 'K', 'Co-direct',  'Co-directeur de thèse' from dual union
  select 'physalis', 'M', 'Membre',     'Membre du jury'        from dual union
  select 'physalis', 'P', 'Président',  'Président du jury'     from dual union
  select 'physalis', 'R', 'Rapporteur', 'Rapporteur du jury'    from dual
/
 th.ID_THESE as THESE_ID,
  so.fann_key as annee_univ

create view SYGAL_ORIGINE_FINANCEMENT as
  select '10', 'apogee', '10', 'SALARIE',     'Etudiant salarié'                         from dual union all
  select '11', 'apogee', '11', 'SANS FIN',    'Sans financement'                         from dual union all
  select '13', 'apogee', '13', 'DOT EPSCP',   'Dotation des EPSCP'                       from dual union all
  select '14', 'apogee', '14', 'DOT EPST',    'Dotation des EPST'                        from dual union all
  select '15', 'apogee', '15', 'POLYTECH',    'Programmes Spé. Normaliens, Polytechnici' from dual union all
  select '16', 'apogee', '16', 'HANDICAP',    'Programme Spécifique Handicap'            from dual union all
  select '17', 'apogee', '17', 'DEFENSE',     'Ministère de la Défense (dont DGA)'       from dual union all
  select '18', 'apogee', '18', 'AGRICULTUR',  'Ministère de l''Agriculture'              from dual union all
  select '19', 'apogee', '19', 'AFF ETRANG',  'Ministère des Affaires Etrangères'        from dual union all
  select '20', 'apogee', '20', 'SANTE',       'Ministère de la Santé'                    from dual union all
  select '21', 'apogee', '21', 'AUTRES MIN',  'Autres Ministères'                        from dual union all
  select '22', 'apogee', '22', 'DOT EPIC',    'Dotation des EPIC'                        from dual union all
  select '23', 'apogee', '23', 'DOT EPA',     'Dotation des EPA'                         from dual union all
  select '24', 'apogee', '24', 'NORMANDIE',   'Région Normandie'                         from dual union all
  select '25', 'apogee', '25', 'AUT COLLEC',  'Autre Collectivité Territoriale'          from dual union all
  select '26', 'apogee', '26', 'ANR',         'ANR'                                      from dual union all
  select '27', 'apogee', '27', 'IDEX',        'IDEX'                                     from dual union all
  select '28', 'apogee', '28', 'PIA',         'Autres dispositifs du PIA (dont LABEX)'   from dual union all
  select '29', 'apogee', '29', 'AUT AFFPR',   'Autres Finan. Pub. d''Agences Françaises' from dual union all
  select '30', 'apogee', '30', 'FI PUB PRV',  'Financements Mixtes Public Privé'         from dual union all
  select '31', 'apogee', '31', 'CIFRE',       'Conventions CIFRE'                        from dual union all
  select '32', 'apogee', '32', 'PART RECH',   'Partenariat de Recherche'                 from dual union all
  select '33', 'apogee', '33', 'MECENAT',     'Mécénat y compris Fondations et Asso.'    from dual union all
  select '34', 'apogee', '34', 'ERC',         'ERC'                                      from dual union all
  select '35', 'apogee', '35', 'MARIE CURI',  'Actions Marie Sklodowska Curie'           from dual union all
  select '36', 'apogee', '36', 'ERASMUS',     'ERASMUS'                                  from dual union all
  select '37', 'apogee', '37', 'AUT PRO EU',  'Autre Programme Européen'                 from dual union all
  select '38', 'apogee', '38', 'GOUV EUROP',  'Gouvernement Etranger Européen'           from dual union all
  select '39', 'apogee', '39', 'GOUV NON E',  'Gouvernement Etranger Hors Europe'        from dual union all
  select '40', 'apogee', '40', 'AUT FI ETR',  'Autres Financements Etrangers'            from dual union all
  select '41', 'apogee', '41', 'ENT ETR',     'Entreprise Etrangère'                     from dual union all
  select '42', 'apogee', '42', 'ORG FC',      'Financements Organismes FC'               from dual union all
  select '43', 'apogee', '43', 'ORG INTER',   'Organismes Internationaux'                from dual
/
    
from RECHERCHE.DOCTORANT_THESE th left outer join recherche.doctorant d on d.id_doctorant = th.id_doctorant
--left outer join garnuche.historique h on h.etud_numero  = d.etud_numero
--left outer join garnuche.insc_dipl ins on ins.hist_numero = h.hist_numero 
left outer join scolarite.scol_inscription_etudiant so on so.etud_numero = d.etud_numero
and ( so.FGRA_CODE='D' )
--and (so.res_code <> 'Z'  )

-- or so.FGRA_CODE is not null
order  by id asc



--where rn = 1;
;

--------------------------------------------------------------------------------

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_TITRE_ACCES" ("SOURCE_ID", "ID", "THESE_ID", "TYPE_ETB_TITRE_ACCES", "TITRE_ACCES_INTERNE_EXTERNE", "LIBELLE_TITRE_ACCES", "CODE_DEPT_TITRE_ACCES", "LIBELLE_ETB_TITRE_ACCES", "CODE_PAYS_TITRE_ACCES") AS 
  select 'physalis' as source_id  ,
ID,
these_id,
type_etb_titre_acces,
titre_acces_interne_externe,
libelle_titre_acces,
code_dept_titre_acces,
libelle_etb_titre_acces,
code_pays_titre_acces
from
(
select 
 
th.ID_THESE as ID,
  --   p.ll_pays,
     th.ID_THESE as these_id ,
     
     type_etab.TETAB_LIBELLE as  type_etb_titre_acces,
     
     case  h.ETAB_CODE_DER_DIPL
     when '0760165S' THEN 'I'
     else  'E' 
      end   titre_acces_interne_externe ,
      
     h.hist_libelle_der_dipl as libelle_titre_acces,
     etab.CODE_POSTAL as  code_dept_titre_acces,
     etab.LL_RNE as libelle_etb_titre_acces,
     h.PAYS_CODE_DER_DIPL as code_pays_titre_acces,
    row_number() over(partition by h.etud_numero order by h.hist_annee_scol desc) as rn
from RECHERCHE.DOCTORANT e left outer join  garnuche.historique h on  e.etud_numero = h.etud_numero
                           left outer join  recherche.doctorant_these th on e.id_doctorant=  th.id_doctorant
                           left outer join  grhum.rne etab on etab.C_RNE = h.ETAB_CODE_DER_DIPL
                           left outer join  grhum.type_etablissement_ulr type_etab on type_etab.TETAB_CODE = etab.TETAB_CODE
                           
    )
where rn = 1



--grant select on grhum.type_etablissement_ulr  to api_scolarite
;



--------------------------------------------------------------------------------


  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_UNITE_RECH" ("STRUCTURE_ID", "SOURCE_ID", "ID") AS 
  SELECT 
distinct
etab_cot.c_structure   AS STRUCTURE_ID,
'physalis' as source_id,
etab_cot.c_structure as   ID


FROM  GRHUM.REPART_ASSOCIATION RA 
LEFT OUTER JOIN GRHUM.ASSOCIATION A_COT ON A_COT.ASS_ID = RA.ASS_ID
LEFT OUTER JOIN grhum.structure_ulr etab_cot on etab_cot.pers_id = ra.pers_id


-- adresse de l etablissement de cotutelle
LEFT OUTER JOIN GRHUM.REPART_PERSONNE_ADRESSE RPA_COT ON RPA_COT.PERS_ID = etab_cot.PERS_ID AND RPA_COT.RPA_PRINCIPAL = 'O'
LEFT OUTER JOIN GRHUM.ADRESSE AD_cot ON RPA_COT.ADR_ORDRE = AD_cot.ADR_ORDRE
LEFT OUTER JOIN GRHUM.PAYS P_cot ON P_cot.C_PAYS = AD_cot.C_PAYS

WHERE  A_COT.ASS_CODE = 'D_LAB_THESE'
 ;


--------------------------------------------------------------------------------


  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_VARIABLE" ("SOURCE_ID", "ID", "COD_VAP", "LIB_VAP", "PAR_VAP", "DATE_DEB_VALIDITE", "DATE_FIN_VALIDITE") AS 
  select
    'physalis' as source_id,
    'ETB_LIB' as id,
    'ETB_LIB' as cod_vap,
    'Nom de l''établissement de référence' as lib_vap,
    'INSA Rouen Normandie' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'ETB_LIB_NOM_RESP' as id,
    'ETB_LIB_NOM_RESP' as cod_vap,
    'Nom du responsable de l''établissement' as lib_vap,
    'M. Mourad BOUKHALFA' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'ETB_LIB_TIT_RESP' as id,
    'ETB_LIB_TIT_RESP' as cod_vap,
    'Titre du responsable de l''établissement' as lib_vap,
    'Directeur' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'ETB_ART_ETB_LIB' as id,
    'ETB_ART_ETB_LIB' as cod_vap,
    'Article du nom de l''etb de référence' as lib_vap,
    'Le' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'EMAIL_ASSISTANCE' as id,
    'EMAIL_ASSISTANCE' as cod_vap,
    'Adresse mail de l''assistance utilisateur' as lib_vap,
    'assistance-sygal@insa-rouen.fr' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'EMAIL_BU' as id,
    'EMAIL_BU' as cod_vap,
    'Adresse mail de contact de la BU' as lib_vap,
    'scd.theses@insa-rouen.fr' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
  union all
  select
    'physalis' as source_id,
    'EMAIL_BDD' as id,
    'EMAIL_BDD' as cod_vap,
    'Adresse mail de contact du bureau des doctorats' as lib_vap,
    'recherche.doctorat@insa-rouen.fr' as par_vap,
    to_date('2017-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
    to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
  from dual
 ;


--------------------------------------------------------------------------------


  CREATE OR REPLACE FORCE EDITIONABLE VIEW "API_SCOLARITE"."V_SYGAL_VARIABLE_MANU" ("SOURCE_ID", "ID", "COD_VAP", "LIB_VAP", "PAR_VAP", "DATE_DEB_VALIDITE", "DATE_FIN_VALIDITE") AS 
  select
        'physalis' as source_id,
        'TRIBUNAL_COMPETENT' as id,
        'TRIBUNAL_COMPETENT' as cod_vap,
        'Tribunal compétent' as lib_vap,
        'Le Tribunal Administratif de Caen' as par_vap, --< à adapter
        to_date('1900-01-01', 'YYYY-MM-DD') as DATE_DEB_VALIDITE,
        to_date('9999-12-31', 'YYYY-MM-DD') as DATE_FIN_VALIDITE
    from dual;

 No newline at end of file