Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ BEGIN
EXECUTE 'create table ' || tempPatientMappingTableName || ' (
ENCOUNTER_MAP_ID varchar(200) NOT NULL,
ENCOUNTER_MAP_ID_SOURCE varchar(50) NOT NULL,
PROJECT_ID VARCHAR(50) NOT NULL,
PATIENT_MAP_ID varchar(200),
PATIENT_MAP_ID varchar(200),
PATIENT_MAP_ID_SOURCE varchar(50),
ENCOUNTER_ID varchar(200) NOT NULL,
ENCOUNTER_ID_SOURCE varchar(50) ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ BEGIN
EXECUTE 'create table ' || tempTableName || ' (
encounter_id varchar(200) not null,
encounter_id_source varchar(50) not null,
project_id varchar(50) not null,
patient_id varchar(200) not null,
patient_id_source varchar(50) not null,
encounter_num numeric(38,0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ and coalesce(encounter_mapping.update_date,to_date(''01-JAN-1900'',''DD-MON-YYYY

-- insert new mapping records i.e flagged P
EXECUTE ' insert into encounter_mapping (encounter_ide,encounter_ide_source,encounter_ide_status,encounter_num,patient_ide,patient_ide_source,update_date,download_date,import_date,sourcesystem_cd,upload_id,project_id)
SELECT encounter_map_id,encounter_map_id_source,encounter_map_id_status,encounter_num,patient_map_id,patient_map_id_source,update_date,download_date,Now(),sourcesystem_cd,' || upload_id || ' , project_id
SELECT encounter_map_id,encounter_map_id_source,encounter_map_id_status,encounter_num,patient_map_id,patient_map_id_source,update_date,download_date,Now(),sourcesystem_cd,' || upload_id || ' , ''@'' project_id
FROM ' || tempEidTableName || '
WHERE process_status_flag = ''P'' ' ;
EXCEPTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ BEGIN
, distinctTemp.patient_id_source
, ''A''
, '|| upload_id ||'
, distinctTemp.project_id
, ''@'' project_id
FROM
(SELECT
distinct encounter_id
, encounter_id_source
, patient_id
, patient_id_source
, project_id
FROM ' || tempTableName || ' temp
WHERE
NOT EXISTS (SELECT encounter_ide
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
CREATE OR REPLACE FUNCTION insert_pid_map_fromtemp (tempPidTableName IN text, upload_id IN bigint,
errorMsg OUT text)
CREATE OR REPLACE FUNCTION insert_pid_map_fromtemp (tempPidTableName IN text, upload_id IN bigint,
errorMsg OUT text)
RETURNS text AS $body$
DECLARE
existingPatientNum varchar(32);
maxPatientNum bigint;
distinctPidCur REFCURSOR;
disPatientId varchar(100);
disPatientId varchar(100);
disPatientIdSource varchar(100);
BEGIN
--delete the doublons
EXECUTE ' delete from ' || tempPidTableName || ' t1 where
oid > (select min(oid) from ' || tempPidTableName || ' t2
EXECUTE ' delete from ' || tempPidTableName || ' t1 where
oid > (select min(oid) from ' || tempPidTableName || ' t2
where t1.patient_map_id = t2.patient_map_id
and t1.patient_map_id_source = t2.patient_map_id_source) ';
LOCK TABLE patient_mapping IN EXCLUSIVE MODE NOWAIT;
select max(patient_num) into STRICT maxPatientNum from patient_mapping ;
select max(patient_num) into STRICT maxPatientNum from patient_mapping ;
-- set max patient num to zero of the value is null
if coalesce(maxPatientNum::text, '') = '' then
if coalesce(maxPatientNum::text, '') = '' then
maxPatientNum := 0;
end if;
open distinctPidCur for EXECUTE 'SELECT distinct patient_id,patient_id_source from ' || tempPidTableName || '' ;
loop
FETCH distinctPidCur INTO disPatientId, disPatientIdSource;
IF NOT FOUND THEN EXIT;
IF NOT FOUND THEN EXIT;
END IF; -- apply on distinctPidCur
-- dbms_output.put_line(disPatientId);
if disPatientIdSource = 'HIVE' THEN
if disPatientIdSource = 'HIVE' THEN
begin
--check if hive number exist, if so assign that number to reset of map_id's within that pid
select patient_num into existingPatientNum from patient_mapping where patient_num = CAST(disPatientId AS numeric) and patient_ide_source = 'HIVE';
EXCEPTION when NO_DATA_FOUND THEN
existingPatientNum := null;
end;
if (existingPatientNum IS NOT NULL AND existingPatientNum::text <> '') then
if (existingPatientNum IS NOT NULL AND existingPatientNum::text <> '') then
EXECUTE ' update ' || tempPidTableName ||' set patient_num = CAST(patient_id AS numeric), process_status_flag = ''P''
where patient_id = $1 and not exists (select 1 from patient_mapping pm where pm.patient_ide = patient_map_id
and pm.patient_ide_source = patient_map_id_source)' using disPatientId;
else
-- generate new patient_num i.e. take max(patient_num) + 1
if maxPatientNum < CAST(disPatientId AS numeric) then
else
-- generate new patient_num i.e. take max(patient_num) + 1
if maxPatientNum < CAST(disPatientId AS numeric) then
maxPatientNum := disPatientId;
end if ;
EXECUTE ' update ' || tempPidTableName ||' set patient_num = CAST(patient_id AS numeric), process_status_flag = ''P'' where
EXECUTE ' update ' || tempPidTableName ||' set patient_num = CAST(patient_id AS numeric), process_status_flag = ''P'' where
patient_id = $1 and patient_id_source = ''HIVE'' and not exists (select 1 from patient_mapping pm where pm.patient_ide = patient_map_id
and pm.patient_ide_source = patient_map_id_source)' using disPatientId;
end if;
end if;
-- test if record fectched
-- dbms_output.put_line(' HIVE ');
else
else
begin
select patient_num into STRICT existingPatientNum from patient_mapping where patient_ide = disPatientId and
patient_ide_source = disPatientIdSource ;
-- test if record fetched.
select patient_num into STRICT existingPatientNum from patient_mapping where patient_ide = disPatientId and
patient_ide_source = disPatientIdSource ;
-- test if record fetched.
EXCEPTION
WHEN NO_DATA_FOUND THEN
existingPatientNum := null;
end;
if (existingPatientNum IS NOT NULL AND existingPatientNum::text <> '') then
if (existingPatientNum IS NOT NULL AND existingPatientNum::text <> '') then
EXECUTE ' update ' || tempPidTableName ||' set patient_num = CAST($1 AS numeric) , process_status_flag = ''P''
where patient_id = $2 and not exists (select 1 from patient_mapping pm where pm.patient_ide = patient_map_id
and pm.patient_ide_source = patient_map_id_source)' using existingPatientNum,disPatientId;
else
maxPatientNum := maxPatientNum + 1 ;
else
maxPatientNum := maxPatientNum + 1 ;
EXECUTE 'insert into ' || tempPidTableName ||' (
patient_map_id
,patient_map_id_source
Expand All @@ -74,7 +74,7 @@ BEGIN
,download_date
,import_date
,sourcesystem_cd
,project_id)
,project_id)
values(
$1
,''HIVE''
Expand All @@ -88,19 +88,19 @@ BEGIN
,Now()
,''edu.harvard.i2b2.crc''
,''HIVE''
)' using maxPatientNum,maxPatientNum,maxPatientNum;
EXECUTE 'update ' || tempPidTableName ||' set patient_num = $1 , process_status_flag = ''P''
where patient_id = $2 and not exists (select 1 from
)' using maxPatientNum,maxPatientNum,maxPatientNum;
EXECUTE 'update ' || tempPidTableName ||' set patient_num = $1 , process_status_flag = ''P''
where patient_id = $2 and not exists (select 1 from
patient_mapping pm where pm.patient_ide = patient_map_id
and pm.patient_ide_source = patient_map_id_source)' using maxPatientNum, disPatientId ;
end if ;
-- dbms_output.put_line(' NOT HIVE ');
end if;
end if;
END LOOP;
close distinctPidCur ;
-- do the mapping update if the update date is old
EXECUTE ' UPDATE patient_mapping
SET
SET
patient_num = CAST(temp.patient_id AS numeric)
,patient_ide_status = temp.patient_map_id_status
,update_date = temp.update_date
Expand All @@ -109,17 +109,17 @@ patient_num = CAST(temp.patient_id AS numeric)
,sourcesystem_cd = temp.sourcesystem_cd
,upload_id = ' || upload_id ||'
FROM '|| tempPidTableName || ' temp
WHERE
temp.patient_map_id = patient_mapping.patient_ide
WHERE
temp.patient_map_id = patient_mapping.patient_ide
and temp.patient_map_id_source = patient_mapping.patient_ide_source
and temp.patient_id_source = ''HIVE''
and coalesce(temp.process_status_flag::text, '''') = ''''
and coalesce(temp.process_status_flag::text, '''') = ''''
and coalesce(patient_mapping.update_date,to_date(''01-JAN-1900'',''DD-MON-YYYY'')) <= coalesce(temp.update_date,to_date(''01-JAN-1900'',''DD-MON-YYYY''))
';
-- insert new mapping records i.e flagged P
EXECUTE ' insert into patient_mapping (patient_ide,patient_ide_source,patient_ide_status,patient_num,update_date,download_date,import_date,sourcesystem_cd,upload_id,project_id)
SELECT patient_map_id,patient_map_id_source,patient_map_id_status,patient_num,update_date,download_date,Now(),sourcesystem_cd,' || upload_id ||', project_id from '|| tempPidTableName || '
where process_status_flag = ''P'' ' ;
SELECT patient_map_id,patient_map_id_source,patient_map_id_status,patient_num,update_date,download_date,Now(),sourcesystem_cd,' || upload_id ||', ''@'' project_id from '|| tempPidTableName || '
where process_status_flag = ''P'' ' ;
EXCEPTION WHEN OTHERS THEN
RAISE EXCEPTION 'An error was encountered - % -ERROR- %',SQLSTATE,SQLERRM;
END;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INSERT INTO CRC_DB_LOOKUP(c_domain_id, c_project_path, c_owner_id, c_db_fullschema, c_db_datasource, c_db_servertype, c_db_nicename, c_db_tooltip, c_comment, c_entry_date, c_change_date, c_status_cd)
VALUES('i2b2demo', '/Demo/', '@', 'public', 'java:/QueryToolDemoDS', 'POSTGRESQL', 'Demo', NULL, NULL, NULL, NULL, NULL);
VALUES('i2b2demo', '/Demo/', '@', 'i2b2demodata', 'java:/QueryToolDemoDS', 'POSTGRESQL', 'Demo', NULL, NULL, NULL, NULL, NULL);


Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO IM_DB_LOOKUP(c_domain_id, c_project_path, c_owner_id, c_db_fullschema, c_db_datasource, c_db_servertype, c_db_nicename, c_db_tooltip, c_comment, c_entry_date, c_change_date, c_status_cd)
VALUES('i2b2demo', 'Demo/', '@', 'public', 'java:/IMDemoDS', 'POSTGRESQL', 'IM', NULL, NULL, NULL, NULL, NULL);
VALUES('i2b2demo', 'Demo/', '@', 'i2b2imdata', 'java:/IMDemoDS', 'POSTGRESQL', 'IM', NULL, NULL, NULL, NULL, NULL);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO ONT_DB_LOOKUP(c_domain_id, c_project_path, c_owner_id, c_db_fullschema, c_db_datasource, c_db_servertype, c_db_nicename, c_db_tooltip, c_comment, c_entry_date, c_change_date, c_status_cd)
VALUES('i2b2demo', 'Demo/', '@', 'public', 'java:/OntologyDemoDS', 'POSTGRESQL', 'Metadata', NULL, NULL, NULL, NULL, NULL);
VALUES('i2b2demo', 'Demo/', '@', 'i2b2metadata', 'java:/OntologyDemoDS', 'POSTGRESQL', 'Metadata', NULL, NULL, NULL, NULL, NULL);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO WORK_DB_LOOKUP(c_domain_id, c_project_path, c_owner_id, c_db_fullschema, c_db_datasource, c_db_servertype, c_db_nicename, c_db_tooltip, c_comment, c_entry_date, c_change_date, c_status_cd)
VALUES('i2b2demo', 'Demo/', '@', 'public', 'java:/WorkplaceDemoDS', 'POSTGRESQL', 'Workplace', NULL, NULL, NULL, NULL, NULL);
VALUES('i2b2demo', 'Demo/', '@', 'i2b2workdata', 'java:/WorkplaceDemoDS', 'POSTGRESQL', 'Workplace', NULL, NULL, NULL, NULL, NULL);