|
|
-- 1/3 : Création de la table temporaire
|
|
|
DROP TABLE IF EXISTS w_dbsetup
|
|
|
;
|
|
|
|
|
|
CREATE TEMP TABLE w_dbsetup AS
|
|
|
SELECT
|
|
|
t_indicateur_theme.oid,
|
|
|
t_indicateur_theme.code,
|
|
|
t_indicateur_theme.texte,
|
|
|
t_indicateur_theme.level,
|
|
|
COALESCE(t_indicateur_parent_theme.code,'') AS parent_code
|
|
|
FROM eco.t_indicateur_theme
|
|
|
LEFT JOIN eco.t_indicateur_theme t_indicateur_parent_theme ON t_indicateur_theme.parent_id = t_indicateur_parent_theme.oid
|
|
|
ORDER BY 2 LIMIT 0
|
|
|
;
|
|
|
|
|
|
-- 2/3 : Peuplement de la table temporaire
|
|
|
INSERT INTO w_dbsetup(
|
|
|
oid,
|
|
|
code,
|
|
|
texte,
|
|
|
level,
|
|
|
parent_code
|
|
|
)
|
|
|
VALUES
|
|
|
(1, '--0', 'Source', 1, ''),
|
|
|
(1, '--1', 'Thèmes principaux', 1, ''),
|
|
|
(1, '--2', 'Période', 1, ''),
|
|
|
(1, '--3', 'Rapports', 1, ''),
|
|
|
(1, '--4', 'Type de donnée', 1, ''),
|
|
|
(1, '--DDATE', 'Date date', 2, '--2'),
|
|
|
(1, '--DDATE_COMMANDE', 'Date date_commande', 2, '--2'),
|
|
|
(1, '--DDATE_ENGAGEMENT', 'Date date_engagement', 2, '--2'),
|
|
|
(1, '--DDATE_FIN', 'Date date_fin', 2, '--2'),
|
|
|
(1, '--R1', 'Rapports CTI', 2, '--3'),
|
|
|
(1, '--R10002', 'Essentiels CTI', 3, '--R1'),
|
|
|
(1, '--R10003', 'Dispositifs Médicaux', 3, '--R1'),
|
|
|
(1, '--R10004', 'Dispostifs Médicaux Implantables', 3, '--R1'),
|
|
|
(1, '--R10005', 'Médicaments', 3, '--R1'),
|
|
|
(1, '--R10006', 'Parapharmacie', 3, '--R1'),
|
|
|
(1, '--R10007', 'Economat', 3, '--R1'),
|
|
|
(1, '--R10008', 'Cuisine', 3, '--R1'),
|
|
|
(1, '--R10009', 'Lingerie', 3, '--R1'),
|
|
|
(1, '--R10010', 'Atelier', 3, '--R1'),
|
|
|
(1, '--R3', 'Rapports Etablissement', 2, '--3'),
|
|
|
(1, '--R30011', 'CTI Portfolio ', 3, '--R3'),
|
|
|
(1, '--S1', 'Indicateurs CTI', 2, '--0'),
|
|
|
(1, '--S2', 'Indicateurs Groupe', 2, '--0'),
|
|
|
(1, '--S3', 'Indicateurs spécifiques Etablissement', 2, '--0'),
|
|
|
(1, '--T0010', 'Mouvements', 2, '--1'),
|
|
|
(1, '--T0020', 'Commandes', 2, '--1'),
|
|
|
(1, '--T0030', 'Stocks mensuels', 2, '--1'),
|
|
|
(1, '1QTE', 'Quantité', 2, '--4'),
|
|
|
(1, '2MNT', 'Montants', 2, '--4'),
|
|
|
(1, '3DUR', 'Durées', 2, '--4'),
|
|
|
(1, '4TAUX', 'Taux', 2, '--4'),
|
|
|
(1, '5STOCK', 'Stocks', 2, '--4')
|
|
|
;
|
|
|
|
|
|
-- 3/3 : Màj de la table iCTI
|
|
|
INSERT INTO eco.t_indicateur_theme (code, texte, level)
|
|
|
SELECT code, texte, level
|
|
|
FROM w_dbsetup
|
|
|
WHERE code NOT IN (SELECT code FROM eco.t_indicateur_theme WHERE t_indicateur_theme.code IS NOT NULL)
|
|
|
;
|
|
|
|
|
|
UPDATE eco.t_indicateur_theme SET
|
|
|
texte = w_dbsetup.texte,
|
|
|
level = w_dbsetup.level,
|
|
|
parent_id = COALESCE(t_indicateur_parent_theme.oid,0)
|
|
|
FROM w_dbsetup
|
|
|
LEFT JOIN eco.t_indicateur_theme t_indicateur_parent_theme ON w_dbsetup.parent_code = t_indicateur_parent_theme.code
|
|
|
WHERE t_indicateur_theme.code = w_dbsetup.code AND
|
|
|
(
|
|
|
t_indicateur_theme.texte IS DISTINCT FROM w_dbsetup.texte OR
|
|
|
t_indicateur_theme.level IS DISTINCT FROM w_dbsetup.level OR
|
|
|
t_indicateur_theme.parent_id IS DISTINCT FROM COALESCE(t_indicateur_parent_theme.oid,0)
|
|
|
)
|
|
|
;
|
|
|
|
|
|
|
|
|
SELECT base.cti_reorganize_indicateur_theme('eco')
|
|
|
;
|