Compare commits
No commits in common. "cadcddddb5b2c15a2d7013a13ba445d9ae2baf68" and "0c7ea76178057ba5d6c762d1e9795ef61e00c492" have entirely different histories.
cadcddddb5
...
0c7ea76178
@ -209,32 +209,19 @@ UPDATE import.periodes SET acp_scopes1=json_build_object('fr', trim(acp_scopes))
|
|||||||
ALTER TABLE import.periodes ADD COLUMN intensity1 text;
|
ALTER TABLE import.periodes ADD COLUMN intensity1 text;
|
||||||
UPDATE import.periodes SET intensity1='occasional'; UPDATE import.periodes SET intensity1='regular' WHERE intensity='regular';
|
UPDATE import.periodes SET intensity1='occasional'; UPDATE import.periodes SET intensity1='regular' WHERE intensity='regular';
|
||||||
|
|
||||||
-- 33-34. Format phones numbers
|
|
||||||
ALTER TABLE import.personnes ADD column mobilenumber1 text;
|
|
||||||
ALTER TABLE import.personnes ADD column phonenumber1 text;
|
|
||||||
DO $$
|
|
||||||
DECLARE
|
|
||||||
intl text := 32;
|
|
||||||
BEGIN
|
|
||||||
-- 33. Format mobile numbers
|
-- 33. Format mobile numbers
|
||||||
|
ALTER TABLE import.personnes ADD column mobilenumber1 text;
|
||||||
UPDATE import.personnes SET mobilenumber1=NULLIF(regexp_replace(mobilenumber, '[^0-9]', '', 'g'), ''); -- remove all NaN chars
|
UPDATE import.personnes SET mobilenumber1=NULLIF(regexp_replace(mobilenumber, '[^0-9]', '', 'g'), ''); -- remove all NaN chars
|
||||||
UPDATE import.personnes SET mobilenumber1 = CASE -- remove intl prefix
|
UPDATE import.personnes SET mobilenumber1=regexp_replace(mobilenumber1, '^0', '') WHERE mobilenumber1 like '0%'; -- remove first 0 prefix
|
||||||
WHEN LEFT(mobilenumber1, 2) = '00' THEN substr(mobilenumber1, 5, length(mobilenumber1) - 4)
|
UPDATE import.personnes SET mobilenumber1=regexp_replace(mobilenumber1, '(.*)', '+32\1'); -- add belgium intl prefix
|
||||||
WHEN LEFT(mobilenumber1, 2) = intl THEN substr(mobilenumber1, 3, length(mobilenumber1) - 2)
|
|
||||||
ELSE regexp_replace(mobilenumber1, '^0', '') -- remove first 0 prefix
|
|
||||||
END;
|
|
||||||
UPDATE import.personnes SET mobilenumber1=regexp_replace(mobilenumber1, '(.*)', '+' || intl || '\1'); -- add intl prefix
|
|
||||||
|
|
||||||
-- 34. Format phone numbers
|
-- 34. Format phone numbers
|
||||||
|
ALTER TABLE import.personnes ADD column phonenumber1 text;
|
||||||
UPDATE import.personnes SET phonenumber1=NULLIF(regexp_replace(phonenumber, '[^0-9]', '', 'g'), ''); -- remove all NaN chars
|
UPDATE import.personnes SET phonenumber1=NULLIF(regexp_replace(phonenumber, '[^0-9]', '', 'g'), ''); -- remove all NaN chars
|
||||||
UPDATE import.personnes SET phonenumber1 = CASE -- remove intl prefix
|
UPDATE import.personnes SET phonenumber1=regexp_replace(phonenumber1, '^0', '') WHERE phonenumber1 like '0%'; -- remove first 0 prefix
|
||||||
WHEN LEFT(phonenumber1, 2) = '00' THEN substr(phonenumber1, 5, length(phonenumber1) - 4)
|
UPDATE import.personnes SET phonenumber1=regexp_replace(phonenumber1, '(.*)', '+32\1'); -- add belgium intl prefix
|
||||||
WHEN LEFT(phonenumber1, 2) = intl THEN substr(phonenumber1, 3, length(phonenumber1) - 2)
|
-- SELECT mobilenumber, mobilenumber1, phonenumber, phonenumber1 FROM import.personnes;
|
||||||
ELSE regexp_replace(phonenumber1, '^0', '') -- remove first 0 prefix
|
|
||||||
END;
|
|
||||||
UPDATE import.personnes SET phonenumber1=regexp_replace(phonenumber1, '(.*)', '+' || intl || '\1'); -- add intl prefix
|
|
||||||
--SELECT mobilenumber, mobilenumber1, phonenumber, phonenumber1 FROM import.personnes ORDER BY id;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
-- 35. Prepare required default dates
|
-- 35. Prepare required default dates
|
||||||
-- address_validfrom1 | household_startdate1
|
-- address_validfrom1 | household_startdate1
|
||||||
@ -254,10 +241,10 @@ INSERT INTO chill_person_person (
|
|||||||
, firstname, lastname, birthdate, place_of_birth, memo, email, contactinfo, phonenumber, mobilenumber, numberofchildren, gender, deathdate, proxyaccompanyingperiodopenstate
|
, firstname, lastname, birthdate, place_of_birth, memo, email, contactinfo, phonenumber, mobilenumber, numberofchildren, gender, deathdate, proxyaccompanyingperiodopenstate
|
||||||
, createdat, updatedat, createdby_id, updatedby_id
|
, createdat, updatedat, createdby_id, updatedby_id
|
||||||
, center_id
|
, center_id
|
||||||
, gendercomment_comment, gendercomment_userid, gendercomment_date
|
|
||||||
/*
|
/*
|
||||||
, maritalstatusdate
|
, maritalstatusdate
|
||||||
, maritalstatuscomment_comment, maritalstatuscomment_userid, maritalstatuscomment_date
|
, maritalstatuscomment_comment, maritalstatuscomment_userid, maritalstatuscomment_date
|
||||||
|
, gendercomment_comment, gendercomment_userid, gendercomment_date
|
||||||
, acceptsms, acceptemail
|
, acceptsms, acceptemail
|
||||||
*/
|
*/
|
||||||
) SELECT
|
) SELECT
|
||||||
@ -267,13 +254,13 @@ INSERT INTO chill_person_person (
|
|||||||
, (SELECT c.id FROM chill_main_civility c WHERE c.name::jsonb->>'fr' = ip.civility1::jsonb->>'fr' AND ip.civility1 IS NOT NULL ) -- civility_id
|
, (SELECT c.id FROM chill_main_civility c WHERE c.name::jsonb->>'fr' = ip.civility1::jsonb->>'fr' AND ip.civility1 IS NOT NULL ) -- civility_id
|
||||||
, (SELECT ms.id FROM chill_person_marital_status ms WHERE ms.name::jsonb->>'fr' = ip.maritalstatus1::jsonb->>'fr' AND ip.maritalstatus1 IS NOT NULL ) -- maritalstatus_id,
|
, (SELECT ms.id FROM chill_person_marital_status ms WHERE ms.name::jsonb->>'fr' = ip.maritalstatus1::jsonb->>'fr' AND ip.maritalstatus1 IS NOT NULL ) -- maritalstatus_id,
|
||||||
, TRIM(firstname), UPPER(TRIM(lastname)), birthdate1, TRIM(place_of_birth), TRIM(memo), TRIM(email), TRIM(contactinfo), phonenumber1, mobilenumber1, numberofchildren1, gender1, deathdate1, false
|
, TRIM(firstname), UPPER(TRIM(lastname)), birthdate1, TRIM(place_of_birth), TRIM(memo), TRIM(email), TRIM(contactinfo), phonenumber1, mobilenumber1, numberofchildren1, gender1, deathdate1, false
|
||||||
, CURRENT_DATE, CURRENT_DATE -- createdat, updatedat (= import date)
|
, CURRENT_DATE, CURRENT_DATE -- createdat, updatedat
|
||||||
, (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users) -- createdby_id, updatedby_id
|
, (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users) -- createdby_id, updatedby_id
|
||||||
, (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM centers) -- center_id
|
, (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM centers) -- center_id
|
||||||
, TRIM(gendercomment), (SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM users), date(date_trunc('year', CURRENT_DATE)) --gendercomment_<comment|userid|date>
|
|
||||||
/*
|
/*
|
||||||
, -- maritalstatusdate
|
, -- maritalstatusdate
|
||||||
, -- maritalstatuscomment_comment, maritalstatuscomment_userid, maritalstatuscomment_date
|
, -- maritalstatuscomment_comment, maritalstatuscomment_userid, maritalstatuscomment_date
|
||||||
|
, -- gendercomment_comment, gendercomment_userid, gendercomment_date
|
||||||
, -- acceptsms, acceptemail
|
, -- acceptsms, acceptemail
|
||||||
*/
|
*/
|
||||||
FROM import.personnes ip;
|
FROM import.personnes ip;
|
||||||
@ -282,7 +269,7 @@ FROM import.personnes ip;
|
|||||||
INSERT INTO chill_person_person_center_history (id, person_id, center_id, startdate) SELECT
|
INSERT INTO chill_person_person_center_history (id, person_id, center_id, startdate) SELECT
|
||||||
nextval('chill_person_person_center_history_id_seq'), person_id,
|
nextval('chill_person_person_center_history_id_seq'), person_id,
|
||||||
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM centers) , -- center_id
|
(SELECT distinct(first_value(id) OVER(ORDER BY id)) FROM centers) , -- center_id
|
||||||
date(date_trunc('year', CURRENT_DATE))
|
CURRENT_DATE
|
||||||
FROM import.personnes ip;
|
FROM import.personnes ip;
|
||||||
-- SELECT ip.id, ip.lastname, ip.firstname, ip.person_id, hist.id, hist.person_id, hist.center_id, hist.startdate, p.id, p.fullnamecanonical, p.email FROM chill_person_person p RIGHT JOIN import.personnes ip ON ip.person_id = p.id FULL JOIN chill_person_person_center_history hist on p.id = hist.person_id ORDER BY ip.person_id;
|
-- SELECT ip.id, ip.lastname, ip.firstname, ip.person_id, hist.id, hist.person_id, hist.center_id, hist.startdate, p.id, p.fullnamecanonical, p.email FROM chill_person_person p RIGHT JOIN import.personnes ip ON ip.person_id = p.id FULL JOIN chill_person_person_center_history hist on p.id = hist.person_id ORDER BY ip.person_id;
|
||||||
|
|
||||||
@ -292,7 +279,7 @@ UPDATE import.personnes SET address_id = nextval('chill_main_address_id_seq');
|
|||||||
ALTER TABLE import.personnes ADD column postcode_id BIGINT;
|
ALTER TABLE import.personnes ADD column postcode_id BIGINT;
|
||||||
UPDATE import.personnes SET postcode_id = cmpc.id FROM chill_main_postal_code cmpc WHERE cmpc.code = postcode AND cmpc.origin = 0;
|
UPDATE import.personnes SET postcode_id = cmpc.id FROM chill_main_postal_code cmpc WHERE cmpc.code = postcode AND cmpc.origin = 0;
|
||||||
INSERT INTO chill_main_address (id, postcode_id, street, streetnumber, extra, validFrom) SELECT
|
INSERT INTO chill_main_address (id, postcode_id, street, streetnumber, extra, validFrom) SELECT
|
||||||
address_id, postcode_id, street, streetnumber, extra, COALESCE(validfrom1 , date(date_trunc('year', CURRENT_DATE)))
|
address_id, postcode_id, street, streetnumber, extra, CURRENT_DATE
|
||||||
FROM import.personnes WHERE postcode_id IS NOT NULL;
|
FROM import.personnes WHERE postcode_id IS NOT NULL;
|
||||||
SELECT ip.person_id, ip.address_id FROM import.personnes ip ;
|
SELECT ip.person_id, ip.address_id FROM import.personnes ip ;
|
||||||
-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, addr.* FROM chill_main_address addr RIGHT JOIN import.personnes ip ON addr.id = ip.address_id ORDER BY ip.id;
|
-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, addr.* FROM chill_main_address addr RIGHT JOIN import.personnes ip ON addr.id = ip.address_id ORDER BY ip.id;
|
||||||
@ -301,7 +288,7 @@ SELECT ip.person_id, ip.address_id FROM import.personnes ip ;
|
|||||||
INSERT INTO chill_person_household (id) SELECT person_id from import.personnes;
|
INSERT INTO chill_person_household (id) SELECT person_id from import.personnes;
|
||||||
SELECT setval('chill_person_household_id_seq', (SELECT max(id) FROM chill_person_household));
|
SELECT setval('chill_person_household_id_seq', (SELECT max(id) FROM chill_person_household));
|
||||||
INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, sharedhousehold, position_id, holder) SELECT
|
INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, sharedhousehold, position_id, holder) SELECT
|
||||||
nextval('chill_person_household_members_id_seq'), person_id, person_id, COALESCE(household_startdate1, date(date_trunc('year', CURRENT_DATE))),
|
nextval('chill_person_household_members_id_seq'), person_id, person_id, COALESCE(household_startdate1, CURRENT_DATE),
|
||||||
true, (SELECT id FROM chill_person_household_position pos WHERE household_position1::jsonb->>'fr' = pos.label::jsonb->>'fr'), false
|
true, (SELECT id FROM chill_person_household_position pos WHERE household_position1::jsonb->>'fr' = pos.label::jsonb->>'fr'), false
|
||||||
FROM import.personnes;
|
FROM import.personnes;
|
||||||
-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, hh.* FROM chill_person_household hh FULL JOIN import.personnes ip ON hh.id = ip.person_id ORDER BY hh.id;
|
-- SELECT ip.id, ip.person_id, ip.firstname, ip.lastname, hh.* FROM chill_person_household hh FULL JOIN import.personnes ip ON hh.id = ip.person_id ORDER BY hh.id;
|
||||||
|
Loading…
Reference in New Issue
Block a user