Changeset 1955


Ignore:
Timestamp:
Apr 24, 2013, 1:47:20 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

Script for anonymizing data update to create fake PersonalNumbers based on the randomly generated DateOfBith annotation. To ensure that no real personal number is generated, the last digit is replaced with an 'X'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/testdata/cleanup_dev_clone.sql

    r1830 r1955  
    1616 
    1717  * Replace the ROOT account login and password with 'root'/'root'
    18   * Replace the PersonalNumber for all patients with '201212121212'
    1918  * Replace the DateOfBirth with a random date for all patients
     19  * Replace the PersonalNumber for all patients with a random based on the 'DateOfBith' annotation
    2020  * Replace the AllFirstNames and FamilyName with other values
    2121*/
     
    2828where id = (select u.id from `Users` u where u.system_id='net.sf.basedb.core.User.ROOT');
    2929
    30 /* Replace PersonalNumber with '201212121212' for all patients */
    31 update `StringValues` set value='201212121212'
    32 where id in
    33   (select a.value_id from `Annotations` a inner join `AnnotationTypes` at on at.id=a.annotationtype_id
    34    where at.name='PersonalNumber');
    35 
    3630/* Replace DateOfBirth with random values for all patients */
    3731update `DateValues` set value=makedate(1900+floor(100*rand()), ceil(365*rand()))
     
    4034   where at.name='DateOfBirth');
    4135
     36/* Replace PersonalNumber with '201212121212' for all patients */
     37/*
     38update `StringValues` set value='201212121212'
     39where id in
     40  (select a.value_id from `Annotations` a inner join `AnnotationTypes` at on at.id=a.annotationtype_id
     41   where at.name='PersonalNumber');
     42*/
     43
     44/* Replace PersonalNumber with value generated from corresponding DateOfBirth
     45 * padded with 'X' and a random 3-digit number. Patients with no BirthOfDate will
     46 * get '201212121212' as PersonalNumber. If this query doesn't work, use the one
     47 * above instead which set all PersonalNumber's to '201212121212'.
     48 */
     49update `StringValues` pnr set pnr.value=coalesce(concat(date_format(
     50  (
     51    select dofb.value from `DateValues` dofb
     52    inner join `Annotations` a1 on dofb.id=a1.value_id
     53    inner join `AnnotationTypes` at1 on at1.id=a1.annotationtype_id and at1.name='DateOfBirth'
     54    inner join `Annotations` a2 on a1.annotationset_id=a2.annotationset_id
     55    inner join `AnnotationTypes` at2 on at2.id=a2.annotationtype_id and at2.name='PersonalNumber'
     56    where a2.value_id=pnr.id
     57  ),
     58  '%Y%m%d'), 100+floor(900*rand()), 'X'), '201212121212')
     59where pnr.id in
     60  (select a.value_id from `Annotations` a inner join `AnnotationTypes` at on at.id=a.annotationtype_id
     61   where at.name='PersonalNumber');
     62   
    4263/* Replace AllFirstNames with 'Blue', 'Red', 'Green', 'Yellow' or 'White' for all patients */
    4364update `StringValues` set value=
Note: See TracChangeset for help on using the changeset viewer.