2864 |
28 Oct 14 |
nicklas |
1 |
/* |
2864 |
28 Oct 14 |
nicklas |
Use this SQL file to remove sensitive personal information from |
2864 |
28 Oct 14 |
nicklas |
a development copy of the production server database. |
2864 |
28 Oct 14 |
nicklas |
4 |
|
2864 |
28 Oct 14 |
nicklas |
5 |
!!!!! *********************************** !!!!! |
2864 |
28 Oct 14 |
nicklas |
!!!!! DO NOT USE ON THE PRODUCTION SERVER !!!!! |
2864 |
28 Oct 14 |
nicklas |
7 |
!!!!! *********************************** !!!!! |
2864 |
28 Oct 14 |
nicklas |
8 |
|
2864 |
28 Oct 14 |
nicklas |
For certain functions in Reggie, eg. generating statistics, it is |
2864 |
28 Oct 14 |
nicklas |
more or less required to use real data. It is not really possible |
2864 |
28 Oct 14 |
nicklas |
to autogenerate the required amount of fake data that is needed and |
2864 |
28 Oct 14 |
nicklas |
the statistical functions also need to be compared for correctness |
2864 |
28 Oct 14 |
nicklas |
against the current statistics produces by other means. |
2864 |
28 Oct 14 |
nicklas |
14 |
|
2864 |
28 Oct 14 |
nicklas |
This script works with PostgreSQL and will: |
2864 |
28 Oct 14 |
nicklas |
16 |
|
2864 |
28 Oct 14 |
nicklas |
* Replace the ROOT account login and password with 'root'/'root' |
2864 |
28 Oct 14 |
nicklas |
* Replace the DateOfBirth with a random date for all patients |
2864 |
28 Oct 14 |
nicklas |
* Replace the PersonalNumber for all patients with a random based on the 'DateOfBith' annotation |
2864 |
28 Oct 14 |
nicklas |
* Replace the AllFirstNames and FamilyName with other values |
2864 |
28 Oct 14 |
nicklas |
* Replace PAD with 'PAD-' + hex value derived from internal id |
2864 |
28 Oct 14 |
nicklas |
22 |
*/ |
2864 |
28 Oct 14 |
nicklas |
23 |
|
2864 |
28 Oct 14 |
nicklas |
/* Change ROOT login to 'root' */ |
2864 |
28 Oct 14 |
nicklas |
update "Users" set login='root' where system_id='net.sf.basedb.core.User.ROOT'; |
2864 |
28 Oct 14 |
nicklas |
26 |
|
2864 |
28 Oct 14 |
nicklas |
/* Change ROOT password to 'root' */ |
2864 |
28 Oct 14 |
nicklas |
update "Passwords" set crypted_password = '$2a$10$yBj1SdJy7K.998hx7XKGauME6fUpIC1yOqzp.TKvoBQmW7bm0ZlFW' |
2864 |
28 Oct 14 |
nicklas |
where id = (select u.id from "Users" u where u.system_id='net.sf.basedb.core.User.ROOT'); |
2864 |
28 Oct 14 |
nicklas |
30 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace DateOfBirth with random values for all patients */ |
2864 |
28 Oct 14 |
nicklas |
update "DateValues" set value=to_date(concat(1900+floor(100*random()), ' ', ceil(365*random())), 'YYYY DDD') |
2864 |
28 Oct 14 |
nicklas |
where id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='DateOfBirth'); |
2864 |
28 Oct 14 |
nicklas |
36 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace PersonalNumber with '201212121212' for all patients */ |
2864 |
28 Oct 14 |
nicklas |
38 |
/* |
2864 |
28 Oct 14 |
nicklas |
update "StringValues" set value='201212121212' |
2864 |
28 Oct 14 |
nicklas |
where id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='PersonalNumber'); |
2864 |
28 Oct 14 |
nicklas |
43 |
*/ |
2864 |
28 Oct 14 |
nicklas |
44 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace PersonalNumber with value generated from corresponding DateOfBirth |
2864 |
28 Oct 14 |
nicklas |
* padded with 'X' and a random 3-digit number. Patients with no BirthOfDate will |
2864 |
28 Oct 14 |
nicklas |
* get '201212121212' as PersonalNumber. If this query doesn't work, use the one |
2864 |
28 Oct 14 |
nicklas |
* above instead which set all PersonalNumber's to '201212121212'. |
2864 |
28 Oct 14 |
nicklas |
49 |
*/ |
2864 |
28 Oct 14 |
nicklas |
update "StringValues" pnr set value=coalesce(concat(to_char( |
2864 |
28 Oct 14 |
nicklas |
51 |
( |
2864 |
28 Oct 14 |
nicklas |
select dofb.value from "DateValues" dofb |
2864 |
28 Oct 14 |
nicklas |
inner join "Annotations" a1 on dofb.id=a1.value_id |
2864 |
28 Oct 14 |
nicklas |
inner join "AnnotationTypes" at1 on at1.id=a1.annotationtype_id and at1.name='DateOfBirth' |
2864 |
28 Oct 14 |
nicklas |
inner join "Annotations" a2 on a1.annotationset_id=a2.annotationset_id |
2864 |
28 Oct 14 |
nicklas |
inner join "AnnotationTypes" at2 on at2.id=a2.annotationtype_id and at2.name='PersonalNumber' |
2864 |
28 Oct 14 |
nicklas |
where a2.value_id=pnr.id |
2864 |
28 Oct 14 |
nicklas |
58 |
), |
2864 |
28 Oct 14 |
nicklas |
'YYYYMMDD'), 100+floor(900*random()), 'X'), '201212121212') |
2864 |
28 Oct 14 |
nicklas |
where pnr.id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='PersonalNumber'); |
2864 |
28 Oct 14 |
nicklas |
63 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace AllFirstNames with 'Blue', 'Red', 'Green', 'Yellow' or 'White' for all patients */ |
2864 |
28 Oct 14 |
nicklas |
update "StringValues" set value= |
2864 |
28 Oct 14 |
nicklas |
case id % 5 |
2864 |
28 Oct 14 |
nicklas |
when 0 then 'Blue' |
2864 |
28 Oct 14 |
nicklas |
when 1 then 'Red' |
2864 |
28 Oct 14 |
nicklas |
when 2 then 'Green' |
2864 |
28 Oct 14 |
nicklas |
when 3 then 'Yellow' |
2864 |
28 Oct 14 |
nicklas |
else 'White' |
2864 |
28 Oct 14 |
nicklas |
end |
2864 |
28 Oct 14 |
nicklas |
where id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='AllFirstNames'); |
2864 |
28 Oct 14 |
nicklas |
76 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace FamilyName with 'Winter', 'Spring', 'Summer' or 'Autumn' for all patients */ |
2864 |
28 Oct 14 |
nicklas |
update "StringValues" set value= |
2864 |
28 Oct 14 |
nicklas |
case id % 4 |
2864 |
28 Oct 14 |
nicklas |
when 0 then 'Winter' |
2864 |
28 Oct 14 |
nicklas |
when 1 then 'Spring' |
2864 |
28 Oct 14 |
nicklas |
when 2 then 'Summer' |
2864 |
28 Oct 14 |
nicklas |
else 'Autumn' |
2864 |
28 Oct 14 |
nicklas |
end |
2864 |
28 Oct 14 |
nicklas |
where id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='FamilyName'); |
2864 |
28 Oct 14 |
nicklas |
88 |
|
2864 |
28 Oct 14 |
nicklas |
89 |
|
2864 |
28 Oct 14 |
nicklas |
/* Replace PAD with PAD-HEX(<id>) values for all specimen */ |
2864 |
28 Oct 14 |
nicklas |
update "StringValues" set value=upper(concat('PAD-', to_hex(id))) |
2864 |
28 Oct 14 |
nicklas |
where id in |
2864 |
28 Oct 14 |
nicklas |
(select a.value_id from "Annotations" a inner join "AnnotationTypes" at on at.id=a.annotationtype_id |
2864 |
28 Oct 14 |
nicklas |
where at.name='PAD'); |