Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit f7cda61

Browse files
SORMAS-Foundation#3674 - Added migration for empty travels/burials/gatherings
1 parent 04915c3 commit f7cda61

1 file changed

Lines changed: 73 additions & 10 deletions

File tree

sormas-backend/src/main/resources/sql/sormas_schema.sql

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5726,13 +5726,6 @@ FROM tl_map tl;
57265726

57275727
DROP TABLE IF EXISTS tl_map;
57285728

5729-
DROP TABLE epidataburial;
5730-
DROP TABLE epidatagathering;
5731-
DROP TABLE epidatatravel;
5732-
DROP TABLE epidataburial_history;
5733-
DROP TABLE epidatagathering_history;
5734-
DROP TABLE epidatatravel_history;
5735-
57365729
INSERT INTO schema_version (version_number, comment) VALUES (279, 'New exposure entity and migration #2948');
57375730

57385731
-- 2020-10-21 Epi data migration #2949
@@ -5845,15 +5838,78 @@ FROM last_exposure_map;
58455838
INSERT INTO exposures(id, uuid, changedate, creationdate, epidata_id, location_id, exposuretype, startdate, enddate, animalcondition, animalvaccinated, prophylaxis, prophylaxisdate, description)
58465839
SELECT exposure_id, exposure_uuid, now(), now(), epidata_id, location_id, 'ANIMAL_CONTACT', dateoflastexposure, dateoflastexposure, animalcondition,
58475840
CASE WHEN animalvaccinationstatus = 'VACCINATED' THEN 'YES' WHEN animalvaccinationstatus = 'UNVACCINATED' THEN 'NO' WHEN animalvaccinationstatus = 'UNKNOWN' THEN 'UNKNOWN' END,
5848-
prophylaxisstatus, dateofprophylaxis, 'Automatic epi data migration based on last exposure details; this exposure may be merged with another exposure with animal contact'
5841+
prophylaxisstatus, dateofprophylaxis, 'Automatic epi data migration based on last exposure details. This exposure may be merged with another exposure with the activity type Animal Contact.'
58495842
FROM last_exposure_map;
58505843

58515844
DROP TABLE IF EXISTS last_exposure_map;
5845+
CREATE TEMP TABLE empty_travels_map AS
5846+
SELECT id as epidata_id,
5847+
nextval('entity_seq') as location_id,
5848+
nextval('entity_seq') as exposure_id,
5849+
overlay(overlay(overlay(
5850+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5851+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as location_uuid,
5852+
overlay(overlay(overlay(
5853+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5854+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as exposure_uuid
5855+
FROM epidata WHERE traveled = 'YES' AND epidata.id NOT IN (SELECT epidatatravel.epidata_id FROM epidatatravel);
5856+
5857+
INSERT INTO location (id, uuid, changedate, creationdate)
5858+
SELECT location_id, location_uuid, now(), now()
5859+
FROM empty_travels_map;
5860+
5861+
INSERT INTO exposures(id, uuid, changedate, creationdate, epidata_id, location_id, exposuretype)
5862+
SELECT exposure_id, exposure_uuid, now(), now(), epidata_id, location_id, 'TRAVEL'
5863+
FROM empty_travels_map;
5864+
5865+
DROP TABLE IF EXISTS empty_travels_map;
5866+
CREATE TEMP TABLE empty_gatherings_map AS
5867+
SELECT id as epidata_id,
5868+
nextval('entity_seq') as location_id,
5869+
nextval('entity_seq') as exposure_id,
5870+
overlay(overlay(overlay(
5871+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5872+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as location_uuid,
5873+
overlay(overlay(overlay(
5874+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5875+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as exposure_uuid
5876+
FROM epidata WHERE gatheringattended = 'YES' AND epidata.id NOT IN (SELECT epidatagathering.epidata_id FROM epidatagathering);
5877+
5878+
INSERT INTO location (id, uuid, changedate, creationdate)
5879+
SELECT location_id, location_uuid, now(), now()
5880+
FROM empty_gatherings_map;
5881+
5882+
INSERT INTO exposures(id, uuid, changedate, creationdate, epidata_id, location_id, exposuretype)
5883+
SELECT exposure_id, exposure_uuid, now(), now(), epidata_id, location_id, 'GATHERING'
5884+
FROM empty_gatherings_map;
5885+
5886+
DROP TABLE IF EXISTS empty_gatherings_map;
5887+
CREATE TEMP TABLE empty_burials_map AS
5888+
SELECT id as epidata_id,
5889+
nextval('entity_seq') as location_id,
5890+
nextval('entity_seq') as exposure_id,
5891+
overlay(overlay(overlay(
5892+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5893+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as location_uuid,
5894+
overlay(overlay(overlay(
5895+
substring(upper(REPLACE(CAST(CAST(md5(CAST(random() AS text) || CAST(clock_timestamp() AS text)) AS uuid) AS text), '-', '')), 0, 30)
5896+
placing '-' from 7) placing '-' from 14) placing '-' from 21) as exposure_uuid
5897+
FROM epidata WHERE burialattended = 'YES' AND epidata.id NOT IN (SELECT epidataburial.epidata_id FROM epidataburial);
5898+
5899+
INSERT INTO location (id, uuid, changedate, creationdate)
5900+
SELECT location_id, location_uuid, now(), now()
5901+
FROM empty_burials_map;
5902+
5903+
INSERT INTO exposures(id, uuid, changedate, creationdate, epidata_id, location_id, exposuretype)
5904+
SELECT exposure_id, exposure_uuid, now(), now(), epidata_id, location_id, 'BURIAL'
5905+
FROM empty_burials_map;
5906+
5907+
DROP TABLE IF EXISTS empty_burials_map;
58525908

58535909
UPDATE exposures SET typeofanimaldetails = otheranimalsdetails FROM epidata WHERE epidata.id = epidata_id AND typeofanimal = 'OTHER';
58545910
UPDATE exposures SET animalcontacttypedetails = kindofexposuredetails FROM epidata WHERE epidata.id = epidata_id AND animalcontacttype = 'OTHER';
58555911
UPDATE exposures SET watersource = epidata.watersource, watersourcedetails = epidata.watersourceother FROM epidata WHERE epidata.id = epidata_id AND bodyofwater = 'YES';
5856-
UPDATE exposures SET description = 'Automatic epi data migration based on selected kinds of exposure; this exposure may be merged with another exposure with animal contact' WHERE exposuretype = 'ANIMAL_CONTACT' AND typeofanimal IS NULL;
5912+
UPDATE exposures SET description = 'Automatic epi data migration based on selected kinds of exposure. This exposure may be merged with another exposure of the activity type Animal Contact.' WHERE exposuretype = 'ANIMAL_CONTACT' AND typeofanimal IS NULL;
58575913

58585914
UPDATE epidata SET contactwithsourcecaseknown = 'YES' WHERE directcontactconfirmedcase = 'YES' OR directcontactprobablecase = 'YES' OR closecontactprobablecase = 'YES' OR contactwithsourcerespiratorycase = 'YES';
58595915

@@ -5875,7 +5931,14 @@ UPDATE epidata SET contactwithsourcecaseknown = 'YES' WHERE directcontactconfirm
58755931
DROP COLUMN directcontactdeadunsafe, DROP COLUMN processingsuspectedcasesampleunsafe, DROP COLUMN eatingrawanimalsininfectedarea, DROP COLUMN eatingrawanimalsdetails,
58765932
DROP COLUMN kindofexposurebite, DROP COLUMN kindofexposuretouch, DROP COLUMN kindofexposurescratch, DROP COLUMN kindofexposurelick, DROP COLUMN kindofexposureother,
58775933
DROP COLUMN kindofexposuredetails, DROP COLUMN animalvaccinationstatus, DROP COLUMN dogs, DROP COLUMN cats, DROP COLUMN canidae, DROP COLUMN rabbits, DROP COLUMN prophylaxisstatus,
5878-
DROP COLUMN dateofprophylaxis, DROP COLUMN visitedhealthfacility, DROP COLUMN contactwithsourcerespiratorycase, DROP COLUMN visitedanimalmarket, DROP COLUMN camels, DROP COLUMN snakes;*/
5934+
DROP COLUMN dateofprophylaxis, DROP COLUMN visitedhealthfacility, DROP COLUMN contactwithsourcerespiratorycase, DROP COLUMN visitedanimalmarket, DROP COLUMN camels, DROP COLUMN snakes;
5935+
5936+
DROP TABLE epidataburial;
5937+
DROP TABLE epidatagathering;
5938+
DROP TABLE epidatatravel;
5939+
DROP TABLE epidataburial_history;
5940+
DROP TABLE epidatagathering_history;
5941+
DROP TABLE epidatatravel_history;*/
58795942

58805943
UPDATE epidata SET exposuredetailsknown = 'YES' FROM exposures WHERE (exposuredetailsknown IS NULL OR exposuredetailsknown != 'YES') AND exposures.epidata_id = epidata.id;
58815944

0 commit comments

Comments
 (0)