Skip to content

Commit

Permalink
fixed problems with dates. Now the loader will not put in null end da…
Browse files Browse the repository at this point in the history
…tes or times, and instead substitutes the start_date / time. Add visit_source_value.

Updated the run script, removed more junk and removed date filters. Both person table and visit_occurrence tables are working.
  • Loading branch information
matthewjoss committed Jan 11, 2017
1 parent cb3dcce commit 58b46b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
10 changes: 5 additions & 5 deletions MSSQL/OMOPLoader.sql
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ begin

insert into visit_occurrence(person_id,visit_occurrence_id,visit_start_date,visit_start_time,
visit_end_date,visit_end_time,provider_id,
visit_concept_id ,care_site_id,visit_type_concept_id)
visit_concept_id ,care_site_id,visit_type_concept_id,visit_source_value)
select distinct v.patient_num, v.encounter_num,
start_Date,
substring(convert(varchar,start_Date,20),12,5),
(case when end_date is not null then end_date else '0' end) end_Date,
substring(convert(varchar, end_Date,20),12,5),
cast(start_Date as time),
(case when end_date is not null then end_date else start_date end) end_Date,
(case when end_date is not null then cast(end_Date as time) else cast(start_date as time) end),
'0',
(case when omop_enctype is not null then omop_enctype else '0' end) enc_type, '0', '44818518'
(case when omop_enctype is not null then omop_enctype else '0' end) enc_type, '0', '44818518',v.inout_cd
from i2b2visit v inner join person d on v.patient_num=d.person_id
left outer join
-- Encounter type. Note that this requires a full table scan on the ontology table, so it is not particularly efficient.
Expand Down
41 changes: 7 additions & 34 deletions MSSQL/run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GO
-- Make 100000000 number smaller for testing
select distinct top 100000000 f.patient_num into i2b2patient_list from i2b2fact f
inner join i2b2visit v on f.patient_num=v.patient_num
where f.start_date>='20100101' and v.start_date>='20100101'
-- where f.start_date>='20100101' and v.start_date>='20100101'
GO
-- Change to match your database names
drop synonym i2b2patient;
Expand All @@ -35,49 +35,22 @@ GO
drop view i2b2visit;
GO
-- Change to match your database name
create view i2b2visit as select * from PCORI_Mart..visit_dimension where start_date>='20100101' and (end_date is null or end_date<getdate());
create view i2b2visit as select * from PCORI_Mart..visit_dimension where (end_date is null or end_date<getdate());
GO

-- NEW! 7/28/16 Delete patients in the bottom 5% of fact count ("mini-loyalty") - these tend to have <5 facts and are not useful for research
-- Count total PCORI facts per patient
-- Note: you will need to have added the synonym in the latest transform: "create synonym i2b2concept for PCORI_Mart..concept_dimension "
drop table #miniloyalty_patient_facts
GO
select
o.patient_num, count(*) num_facts
into #miniloyalty_patient_facts
from i2b2fact o
inner join i2b2patient_list p on p.patient_num=o.patient_num
where concept_cd in (select concept_cd from i2b2concept where concept_path like '\P%') -- Change to '\PCORI%' if your paths are standard
and o.start_date>='1/1/2010'
group by o.patient_num
GO
alter table #miniloyalty_patient_facts add primary key (patient_num)
GO

-- Change "where k<6" to a different number to delete a different low fact %
delete from i2b2patient_list where patient_num in
(select patient_num from
(select patient_num, k, sum(f) f from
(select patient_num, ntile(100) over (partition by a, s order by f, patient_num) k,f
from (
select p.patient_num, floor(age_in_years_num/10) a, sex_cd s, isnull(f.num_facts,0) f
from i2b2patient p
left join #miniloyalty_patient_facts f
on p.patient_num = f.patient_num
) t
) t group by PATIENT_NUM,k) t where k<6)


--exec pcornetloader;
--GO
-- Now run each procedure individually to ease commenting/uncommenting
-- Also, deletes added for safety
exec pcornetclear
GO
delete from pmnharvest
GO
exec PCORNetHarvest
GO
--delete from pmnharvest
--GO
--exec PCORNetHarvest
--GO
delete from person
GO
exec OMOPdemographics
Expand Down

0 comments on commit 58b46b7

Please sign in to comment.