1
+ BEGIN ;
2
+
3
+ -- Drop view using the OrganismTypology enum
4
+ -- available_certification
5
+ -- used by candidate app to view available certification
6
+ CREATE
7
+ OR REPLACE VIEW available_certification_based_on_formacode AS
8
+ -- expert filiere and expertBrancheEtFiliere filiere part
9
+ SELECT DISTINCT
10
+ cer .id as certification_id,
11
+ cer .searchable_text as certification_searchable_text
12
+ FROM
13
+ certification cer,
14
+ organism org
15
+ LEFT JOIN maison_mere_aap mma ON org .maison_mere_aap_id = mma .id ,
16
+ formacode code,
17
+ organism_on_formacode org_code,
18
+ certification_on_formacode cer_code,
19
+ organism_on_degree org_degree,
20
+ degree degree
21
+ WHERE
22
+ (
23
+ org .typology = ' expertFiliere'
24
+ or org .typology = ' expertBrancheEtFiliere' -- "expertBrancheEtFiliere" is both "expertBranche" and "expertFiliere"
25
+ )
26
+ AND code .type = ' SUB_DOMAIN'
27
+ AND mma .is_active = true
28
+ AND org .ferme_pour_absence_ou_conges = false
29
+ AND cer .visible = true
30
+ AND org_code .organism_id = org .id
31
+ AND org_code .formacode_id = code .id
32
+ AND cer_code .certification_id = cer .id
33
+ AND cer_code .formacode_id = code .id
34
+ AND org_degree .organism_id = org .id
35
+ AND org_degree .degree_id = degree .id
36
+ AND degree .level = cer .level
37
+ AND NOT EXISTS (
38
+ select
39
+ certification_on_ccn .certification_id
40
+ from
41
+ certification_on_ccn
42
+ where
43
+ certification_on_ccn .certification_id = cer .id
44
+ )
45
+ UNION DISTINCT --
46
+ -- expert branche and expertBrancheEtFiliere branche part
47
+ SELECT DISTINCT
48
+ cer .id as certification_id,
49
+ cer .searchable_text as certification_searchable_text
50
+ FROM
51
+ certification cer,
52
+ organism org
53
+ LEFT JOIN maison_mere_aap mma ON org .maison_mere_aap_id = mma .id ,
54
+ convention_collective ccn,
55
+ organism_on_ccn org_ccn,
56
+ certification_on_ccn cer_ccn,
57
+ organism_on_degree org_degree,
58
+ degree degree
59
+ WHERE
60
+ (
61
+ org .typology = ' expertBranche'
62
+ or org .typology = ' expertBrancheEtFiliere' -- "expertBrancheEtFiliere" is both "expertBranche" and "expertFiliere"
63
+ )
64
+ AND mma .is_active = true
65
+ AND org .ferme_pour_absence_ou_conges = false
66
+ AND cer .visible = true
67
+ AND org_ccn .organism_id = org .id
68
+ AND org_ccn .ccn_id = ccn .id
69
+ AND cer_ccn .certification_id = cer .id
70
+ AND cer_ccn .ccn_id = ccn .id
71
+ AND org_degree .organism_id = org .id
72
+ AND org_degree .degree_id = degree .id
73
+ AND degree .level = cer .level ;
74
+
75
+ -- active_organism_by_available_certification
76
+ -- used by candidate app to view active organisms for a given certificate
77
+ CREATE
78
+ OR REPLACE VIEW active_organism_by_available_certification_based_on_formacode AS
79
+ -- expert filiere and expertBrancheEtFiliere filiere part
80
+ SELECT DISTINCT
81
+ org .id as organism_id,
82
+ cer .id as certification_id,
83
+ cer .searchable_text as certification_searchable_text
84
+ FROM
85
+ certification cer,
86
+ organism org
87
+ LEFT JOIN maison_mere_aap mma ON org .maison_mere_aap_id = mma .id ,
88
+ formacode code,
89
+ organism_on_formacode org_code,
90
+ certification_on_formacode cer_code,
91
+ organism_on_degree org_degree,
92
+ degree degree
93
+ WHERE
94
+ (
95
+ org .typology = ' expertFiliere'
96
+ or org .typology = ' expertBrancheEtFiliere' -- "expertBrancheEtFiliere" is both "expertBranche" and "expertFiliere"
97
+ )
98
+ AND code .type = ' SUB_DOMAIN'
99
+ AND mma .is_active = true
100
+ AND org .ferme_pour_absence_ou_conges = false
101
+ AND cer .visible = true
102
+ AND org_code .organism_id = org .id
103
+ AND org_code .formacode_id = code .id
104
+ AND cer_code .certification_id = cer .id
105
+ AND cer_code .formacode_id = code .id
106
+ AND org_degree .organism_id = org .id
107
+ AND org_degree .degree_id = degree .id
108
+ AND degree .level = cer .level
109
+ AND NOT EXISTS (
110
+ select
111
+ certification_on_ccn .certification_id
112
+ from
113
+ certification_on_ccn
114
+ where
115
+ certification_on_ccn .certification_id = cer .id
116
+ )
117
+ UNION DISTINCT --
118
+ -- expert branche and expertBrancheEtFiliere branche part
119
+ SELECT DISTINCT
120
+ org .id as organisme_id,
121
+ cer .id as certification_id,
122
+ cer .searchable_text as certification_searchable_text
123
+ FROM
124
+ certification cer,
125
+ organism org
126
+ LEFT JOIN maison_mere_aap mma ON org .maison_mere_aap_id = mma .id ,
127
+ convention_collective ccn,
128
+ organism_on_ccn org_ccn,
129
+ certification_on_ccn cer_ccn,
130
+ organism_on_degree org_degree,
131
+ degree degree
132
+ WHERE
133
+ (
134
+ org .typology = ' expertBranche'
135
+ or org .typology = ' expertBrancheEtFiliere' -- "expertBrancheEtFiliere" is both "expertBranche" and "expertFiliere"
136
+ )
137
+ AND mma .is_active = true
138
+ AND org .ferme_pour_absence_ou_conges = false
139
+ AND cer .visible = true
140
+ AND org_ccn .organism_id = org .id
141
+ AND org_ccn .ccn_id = ccn .id
142
+ AND cer_ccn .certification_id = cer .id
143
+ AND cer_ccn .ccn_id = ccn .id
144
+ AND org_degree .organism_id = org .id
145
+ AND org_degree .degree_id = degree .id
146
+ AND degree .level = cer .level ;
147
+
148
+ COMMIT ;
0 commit comments