Skip to content

Commit cb41fba

Browse files
committed
Committing CDM_BUILDER source.
1 parent 1205615 commit cb41fba

File tree

257 files changed

+9972
-2103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+9972
-2103
lines changed

source/APSClient/APSClient.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
</PropertyGroup>
3636
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
3737
<DebugSymbols>true</DebugSymbols>
38-
<OutputPath>bin\x64\Debug\</OutputPath>
38+
<OutputPath>..\build\</OutputPath>
39+
<IntermediateOutputPath>..\obj\</IntermediateOutputPath>
3940
<DefineConstants>DEBUG;TRACE</DefineConstants>
4041
<DebugType>full</DebugType>
4142
<PlatformTarget>x64</PlatformTarget>
@@ -44,7 +45,8 @@
4445
<Prefer32Bit>false</Prefer32Bit>
4546
</PropertyGroup>
4647
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
47-
<OutputPath>bin\x64\Release\</OutputPath>
48+
<OutputPath>..\build\</OutputPath>
49+
<IntermediateOutputPath>..\obj\</IntermediateOutputPath>
4850
<DefineConstants>TRACE</DefineConstants>
4951
<Optimize>true</Optimize>
5052
<DebugType>pdbonly</DebugType>

source/BuilderDb Tables Creation.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ CREATE NONCLUSTERED INDEX [IDX_BuildingId] ON [dbo].[Chunk]
5151
[BuilderId] ASC
5252
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
5353
GO
54+
55+
56+
CREATE TABLE [SubChunk](
57+
[ChunkId] [int] NOT NULL,
58+
[Index] [int] NOT NULL,
59+
[MinPersonId] [bigint] NOT NULL,
60+
[MaxPersonId] [bigint] NOT NULL,
61+
[PersonCount] [int] NOT NULL,
62+
[Saved] [tinyint] NOT NULL,
63+
CONSTRAINT [PK_SubChunk] PRIMARY KEY CLUSTERED
64+
(
65+
[ChunkId] ASC,
66+
[Index] ASC
67+
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
68+
) ON [PRIMARY]
69+
70+
GO
71+
72+
ALTER TABLE [SubChunk] ADD CONSTRAINT [DF_SubChunk_Saved] DEFAULT ((0)) FOR [Saved]
73+
GO
74+
75+
ALTER TABLE [SubChunk] WITH CHECK ADD CONSTRAINT [FK_SubChunk_Chunk] FOREIGN KEY([ChunkId])
76+
REFERENCES [Chunk] ([Id])
77+
ON DELETE CASCADE
78+
GO
79+
80+
ALTER TABLE [SubChunk] CHECK CONSTRAINT [FK_SubChunk_Chunk]
81+
GO
82+
83+
84+
5485
/****** Object: Table [dbo].[BuildingSettings] Script Date: 07/04/2016 11:16:14 ******/
5586
SET ANSI_NULLS ON
5687
GO
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
SELECT DISTINCT {0} patid, patid FROM {sc}.Patient
2-
WHERE accept = 1 and yob + 1800 > 1899
2+
WHERE accept = 1 and yob + 1800 > 1899
3+
order by patid

source/Builders/org.ohdsi.cdm.builders.cprd_v5/CPRDV5/CdmSource.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
INSERT INTO {sc}.CDM_SOURCE
1+
truncate table {sc}.CDM_SOURCE;
2+
truncate table {sc}.CDM_DOMAIN_META;
3+
4+
INSERT INTO {sc}.CDM_SOURCE
25
(CDM_SOURCE_NAME
36
,CDM_SOURCE_ABBREVIATION
47
,CDM_HOLDER

source/Builders/org.ohdsi.cdm.builders.cprd_v5/CPRDV5/Definitions/Additional.xml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,9 @@
201201
a.patid,
202202
a.observation_source_value,
203203
a.value_as_string,
204-
case when ISNUMERIC(a.value_as_string) = 1 then cast(a.value_as_string as float) else null end as value_as_number,
205204
b.eventdate,
206205
b.staffid,
207-
(a.patid*100000000)+(year(b.eventdate)*10000)+(month(b.eventdate)*100)+day(b.eventdate) as visit_occurrence_id,
206+
(a.patid*100000000)+(DATEPART(year,b.eventdate)*10000)+(DATEPART(month,b.eventdate)*100)+DATEPART(day,b.eventdate) as visit_occurrence_id,
208207
case when value_as_string = 'Not examined' then 4301433
209208
when value_as_string ='Potential Abnormal' then 40567538
210209
when value_as_string = 'Present' then 4181412
@@ -232,8 +231,11 @@
232231
<StartDate>eventdate</StartDate>
233232
<ProviderId>staffid</ProviderId>
234233
<ValueSourceValue>value_as_string</ValueSourceValue>
235-
<ValueAsNumber>value_as_number</ValueAsNumber>
234+
<!--<ValueAsNumber>value_as_number</ValueAsNumber>-->
236235
<ValueAsConceptId>value_as_concept_id</ValueAsConceptId>
236+
<AdditionalFields>
237+
<string>value_as_string</string>
238+
</AdditionalFields>
237239
<Concepts>
238240
<Concept>
239241
<IdRequired>true</IdRequired>
@@ -264,8 +266,11 @@
264266
<VisitOccurrenceId>visit_occurrence_id</VisitOccurrenceId>
265267
<StartDate>eventdate</StartDate>
266268
<ProviderId>staffid</ProviderId>
267-
<ValueAsNumber>value_as_number</ValueAsNumber>
269+
<!--<ValueAsNumber>value_as_number</ValueAsNumber>-->
268270
<ValueSourceValue>value_as_string</ValueSourceValue>
271+
<AdditionalFields>
272+
<string>value_as_string</string>
273+
</AdditionalFields>
269274
<Concepts>
270275
<Concept>
271276
<IdRequired>true</IdRequired>
@@ -292,10 +297,13 @@
292297
<ValuesAsString>
293298
<string>value_as_string</string>
294299
</ValuesAsString>
295-
<ValuesAsNumber>
300+
<!--<ValuesAsNumber>
296301
<string>value_as_number</string>
297-
</ValuesAsNumber>
302+
</ValuesAsNumber>-->
298303
<ValueAsConceptId>value_as_concept_id</ValueAsConceptId>
304+
<AdditionalFields>
305+
<string>value_as_string</string>
306+
</AdditionalFields>
299307
<Concepts>
300308
<Concept>
301309
<!--<IdRequired>true</IdRequired>-->
@@ -327,9 +335,12 @@
327335
<StartDate>eventdate</StartDate>
328336
<ProviderId>staffid</ProviderId>
329337
<VisitOccurrenceId>visit_occurrence_id</VisitOccurrenceId>
330-
<ValuesAsNumber>
338+
<!--<ValuesAsNumber>
331339
<string>value_as_number</string>
332-
</ValuesAsNumber>
340+
</ValuesAsNumber>-->
341+
<AdditionalFields>
342+
<string>value_as_string</string>
343+
</AdditionalFields>
333344
<Concepts>
334345
<Concept>
335346
<ConceptIdMappers>

source/Builders/org.ohdsi.cdm.builders.cprd_v5/CPRDV5/Definitions/Clinical.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
a.eventdate,
66
a.patid,
77
a.staffid,
8-
cast((cast(a.patid as bigint)*100000000)+(year(a.eventdate) *10000)+
9-
(month(a.eventdate)*100)+
10-
day(a.eventdate) as bigint)
8+
cast((cast(a.patid as bigint)*100000000)+(DATEPART(year, a.eventdate) *10000)+
9+
(DATEPART(month, a.eventdate)*100)+
10+
DATEPART(day,a.eventdate) as bigint)
1111
as visit_occurrence_id,
1212
right(a.patid,3) as care_site_id,
1313
null endDate,

source/Builders/org.ohdsi.cdm.builders.cprd_v5/CPRDV5/Definitions/Consultation.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
cast(a.patid as varchar) + ':' + cast(eventdate as varchar) VISIT_SOURCE_VALUE,
77
consid place_of_service_source_value,
88
right(a.patid,3) as care_site_id,
9-
cast((cast(a.patid as bigint)*100000000)+(year(a.eventdate) *10000)+
10-
(month(a.eventdate)*100)+
11-
day(a.eventdate) as bigint)
9+
cast((cast(a.patid as bigint)*100000000)+(DATEPART(year,a.eventdate) *10000)+
10+
(DATEPART(month,a.eventdate)*100)+
11+
DATEPART(day,a.eventdate) as bigint)
1212
as visit_occurrence_id,
1313
staffid
1414
from {sc}.consultation a

source/Builders/org.ohdsi.cdm.builders.cprd_v5/CPRDV5/Definitions/HES_acp.xml

Lines changed: 100 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
<QueryDefinition>
22
<Query>
3-
if not exists (select * from sys.types where name = 'HessAcpNullType')
4-
create type HessAcpNullType as table (fieldname varchar(50) NOT NULL, isnullable bit not null)
5-
6-
if not exists (select * from sys.types where name = 'HessAcpLookupTableType')
7-
create type HessAcpLookupTableType as table (id varchar(50) NOT NULL, fieldname varchar(50) NOT NULL, fieldquery varchar(250) NOT NULL, observation_source_value varchar(50) NOT NULL, fieldid int null)
8-
go;
9-
10-
declare @hessNull HessAcpNullType
11-
12-
insert into @hessNull
13-
select 'delmeth',1 union select 'delonset',1 union select 'delinten',1 union select 'delchang',1
14-
union select 'delpren',1 union select 'delposn',1 union select 'anagest',1 union select 'matage',1
15-
union select 'neodur',1 union select 'antedur',1 union select 'postdur',1 union select 'intdays',1
16-
union select 'acpspef',1 union select 'elecdate',1 union select 'elecdur',1
17-
18-
declare @lookup HessAcpLookupTableType;
19-
20-
INSERT INTO @lookup
21-
select a.id, a.fieldname, 'isnull(cast(' + a.id + ' as nvarchar(50)), ''9999999'') ' + a.id, '1-'+cast(row_number() OVER(Order By a.fieldname) as varchar(256)) as observation_source_value, b.fieldid
3+
WITH nullFields as
4+
(
5+
select 'delmeth' as fieldName, 1 as isNullField
6+
union
7+
select 'delonset'as fieldName, 1 as isNullField
8+
union
9+
select 'delinten'as fieldName, 1 as isNullField
10+
union
11+
select 'delchang'as fieldName, 1 as isNullField
12+
union
13+
select 'delpren'as fieldName, 1 as isNullField
14+
union
15+
select 'delposn'as fieldName, 1 as isNullField
16+
union
17+
select 'anagest'as fieldName, 1 as isNullField
18+
union
19+
select 'matage'as fieldName, 1 as isNullField
20+
union
21+
select 'neodur'as fieldName, 1 as isNullField
22+
union
23+
select 'antedur'as fieldName, 1 as isNullField
24+
union
25+
select 'postdur'as fieldName, 1 as isNullField
26+
union
27+
select 'intdays'as fieldName, 1 as isNullField
28+
union
29+
select 'acpspef'as fieldName, 1 as isNullField
30+
union
31+
select 'elecdate'as fieldName, 1 as isNullField
32+
union
33+
select 'elecdur'as fieldName, 1 as isNullField
34+
),
35+
acpLookup as
36+
(
37+
select a.id, a.fieldname, '1-'+cast(row_number() OVER(Order By a.fieldname) as varchar(256)) as observation_source_value, b.fieldid
2238
from
2339
(
2440
select 'acpdur' id ,'acpdur' fieldname union
@@ -33,63 +49,83 @@
3349
select 'orgsup' id ,'orgsup' fieldname
3450
) as a
3551
left join {sc}.hes_fielddefinitions b on a.fieldname = b.fieldname and b.class = 'Augmented/critical care period'
36-
37-
38-
declare @cols nvarchar(max);
39-
declare @cols1 nvarchar(max);
40-
declare @query nvarchar(max);
41-
42-
select @cols = coalesce(@cols+N',', N'') + fieldquery, @cols1 = coalesce(@cols1+N',', N'') + Id from @lookup
43-
44-
set @query = N'
45-
with mappings as
52+
),
53+
mappings as
4654
(
47-
SELECT distinct FieldId, Value, Description
55+
SELECT distinct
56+
FieldId,
57+
REPLACE(Value, '0', '') Value,
58+
Description
4859
FROM {sc}.hes_fieldmappings
49-
UNION
50-
SELECT distinct FieldId, CASE WHEN ISNUMERIC([Value]) = 1 THEN CAST(CAST([Value] as int) as varchar) ELSE [Value] END as [Value], Description
60+
where Value like '0%' and len(Value) = 2
61+
union
62+
SELECT DISTINCT
63+
FieldId,
64+
Value,
65+
Description
5166
FROM {sc}.hes_fieldmappings
52-
WHERE LEFT([Value], 1) = ''0''
5367
),
54-
a as
68+
hesacp as
5569
(
56-
select patid, spno, acpstar, l.observation_source_value,
57-
case when description is null then case when ISNUMERIC(var_code) = 1 then var_code else null end
58-
else null end as value_as_number,
59-
case when description is not null then description
60-
when description is null and var_code is not null then var_code
61-
else null end as value_as_string
62-
from
63-
(
64-
select patid, spno, acpstar, ' + @cols + '
65-
from {sc}.hes_acp
70+
SELECT
71+
patid,
72+
spno,
73+
acpstar,
74+
ISNULL(CAST(acpdisp AS nvarchar(50)), '9999999') acpdisp,
75+
ISNULL(CAST(acpdur AS nvarchar(50)), '9999999') acpdur,
76+
ISNULL(CAST(acploc AS nvarchar(50)), '9999999') acploc,
77+
ISNULL(CAST(acpout AS nvarchar(50)), '9999999') acpout,
78+
ISNULL(CAST(acpplan AS nvarchar(50)), '9999999') acpplan,
79+
ISNULL(CAST(acpsour AS nvarchar(50)), '9999999') acpsour,
80+
ISNULL(CAST(acpspef AS nvarchar(50)), '9999999') acpspef,
81+
ISNULL(CAST(depdays AS nvarchar(50)), '9999999') depdays,
82+
ISNULL(CAST(intdays AS nvarchar(50)), '9999999') intdays,
83+
ISNULL(CAST(orgsup AS nvarchar(50)), '9999999') orgsup
84+
FROM {sc}.hes_acp
6685
JOIN {sc}._chunks ch ON ch.ChunkId = {0} AND patid = ch.PERSON_ID
67-
where acpstar is not null
68-
) p
69-
UNPIVOT
70-
(var_code for field in ('+@cols1+')) as up
71-
join @tblLookup l on l.id = field
72-
left join @tblLookupNull n on l.fieldname = n.fieldname
73-
left join mappings m on l.fieldid = m.fieldid and ((var_code = ''9999999'' and m.value = ''null'') or (var_code = m.value))
74-
where var_code != '''' and (var_code != ''9999999'' or (isnullable = 1 and var_code = ''9999999''))
86+
WHERE acpstar IS NOT NULL
87+
),
88+
acp_unp as
89+
(
90+
SELECT patid, spno, acpstar, 'acpdisp' as fieldname, acpdisp as var_code from hesacp union
91+
SELECT patid, spno, acpstar, 'acpdur' as fieldname , acpdur as var_code from hesacp union
92+
SELECT patid, spno, acpstar, 'acploc' as fieldname , acploc as var_code from hesacp union
93+
SELECT patid, spno, acpstar, 'acpout' as fieldname , acpout as var_code from hesacp union
94+
SELECT patid, spno, acpstar, 'acpplan' as fieldname, acpplan as var_code from hesacp union
95+
SELECT patid, spno, acpstar, 'acpsour' as fieldname, acpsour as var_code from hesacp union
96+
SELECT patid, spno, acpstar, 'acpspef' as fieldname, acpspef as var_code from hesacp union
97+
SELECT patid, spno, acpstar, 'depdays' as fieldname, depdays as var_code from hesacp union
98+
SELECT patid, spno, acpstar, 'intdays' as fieldname, intdays as var_code from hesacp union
99+
SELECT patid, spno, acpstar, 'orgsup' as fieldname , orgsup as var_code from hesacp
75100
)
76101

77-
78-
select *, case when value_as_number is not null then 900000006
79-
else 900000007 end as observation_type_concept_id
80-
from a
81-
order by a.patid
82-
'
83-
84-
exec sp_executesql @query, N'@tblLookup HessAcpLookupTableType readonly, @tblLookupNull HessAcpNullType readonly', @lookup, @hessNull
102+
select patid,
103+
spno,
104+
acpstar,
105+
l.observation_source_value,
106+
900000007 as observation_type_concept_id,
107+
CASE
108+
WHEN description IS NOT NULL THEN description
109+
WHEN description IS NULL AND
110+
var_code IS NOT NULL THEN var_code
111+
ELSE NULL
112+
END AS value_as_string
113+
from acp_unp
114+
JOIN acpLookup l ON l.id = acp_unp.fieldname
115+
LEFT JOIN nullFields n ON l.fieldname = n.fieldname
116+
LEFT JOIN mappings m ON l.fieldid = m.fieldid AND ((var_code = '9999999' AND m.value = 'null') OR (var_code = m.value))
117+
WHERE var_code != '' AND (var_code != '9999999' OR (isNullField = 1 AND var_code = '9999999'))
118+
order by patid
85119
</Query>
86120
<Measurement>
87121
<MeasurementDefinition>
88122
<PersonId>patid</PersonId>
89123
<StartDate>acpstar</StartDate>
90124
<VisitOccurrenceId>spno</VisitOccurrenceId>
91-
<ValueAsNumber>value_as_number</ValueAsNumber>
92125
<ValueSourceValue>value_as_string</ValueSourceValue>
126+
<AdditionalFields>
127+
<string>value_as_string</string>
128+
</AdditionalFields>
93129
<Concepts>
94130
<Concept>
95131
<IdRequired>true</IdRequired>
@@ -113,9 +149,9 @@
113149
<ValuesAsString>
114150
<string>value_as_string</string>
115151
</ValuesAsString>
116-
<ValuesAsNumber>
117-
<string>value_as_number</string>
118-
</ValuesAsNumber>
152+
<AdditionalFields>
153+
<string>value_as_string</string>
154+
</AdditionalFields>
119155
<Concepts>
120156
<Concept>
121157
<!--<IdRequired>true</IdRequired>-->

0 commit comments

Comments
 (0)