pour déploiement auto v2 via gitlab
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.2 KiB

-- 1/3 : Création de la table temporaire
DROP TABLE IF EXISTS w_dbsetup
;
CREATE TEMP TABLE w_dbsetup AS
SELECT
t_modes_hospitalisation.oid as keepoid,
t_modes_hospitalisation.code,
t_modes_hospitalisation.texte
FROM
pmsi.t_modes_hospitalisation
WHERE
t_modes_hospitalisation.code <> t_modes_hospitalisation.texte
ORDER BY code LIMIT 0
;
-- 2/3 : Peuplement de la table temporaire
INSERT INTO w_dbsetup(
keepoid,
code,
texte
)
VALUES
(1, 'HC', 'Hospitalisation Complete'),
(3, 'HM', 'Hospitalisation Mixte'),
(2, 'HP', 'Hospitalisation Partielle'),
(0, '**', 'Non renseigné')
;
-- 3/3 : Màj de la table iCTI
UPDATE pmsi.t_modes_hospitalisation
SET
code = w_dbsetup.code,
texte = w_dbsetup.texte
FROM w_dbsetup
WHERE
t_modes_hospitalisation.oid = w_dbsetup.keepoid
AND (1 != 1
OR t_modes_hospitalisation.texte IS DISTINCT FROM w_dbsetup.texte
OR t_modes_hospitalisation.code IS DISTINCT FROM w_dbsetup.code
)
;
INSERT INTO pmsi.t_modes_hospitalisation (oid,code,texte)
SELECT
w_dbsetup.keepoid,
w_dbsetup.code,
w_dbsetup.texte
FROM
w_dbsetup
LEFT JOIN pmsi.t_modes_hospitalisation ON t_modes_hospitalisation.oid = w_dbsetup.keepoid
WHERE
t_modes_hospitalisation.oid IS NULL
;