-
Notifications
You must be signed in to change notification settings - Fork 1
/
COST.sql
111 lines (104 loc) · 3.47 KB
/
COST.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
-- Insert data from Device_exposure
select
cost_id,
b.person_id,
cost_event_id,
case when cost_domain_id='device' then device_concept_id
end as cost_event_field_concept_id,
NULL as cost_concept_id,
cost_type_concept_id,
NULL as cost_source_concept_id,
NULL as cost_source_value,
currency_concept_id,
total_cost as cost,
case when cost_domain_id='device' then device_exposure_start_date
end as incurred_date,
NULL as billed_date,
NULL as paid_date,
revenue_code_concept_id,
drg_concept_id,
a.payer_plan_period_id
into @DatabaseSchemaCDMVersion6.dbo.cost
from @DatabaseSchemaCDMVersion5.COST a, @DatabaseSchemaCDMVersion5.PAYER_PLAN_PERIOD b, @DatabaseSchemaCDMVersion5.DEVICE_EXPOSURE c
where a.payer_plan_period_id=b.payer_plan_period_id
and b.person_id=c.person_id
and a.cost_id=c.device_exposure_id
and cost_domain_id='device'
--Insert data from Drug_exposure
Insert into @DatabaseSchemaCDMVersion6.dbo.cost
select
cost_id,
b.person_id,
cost_event_id,
case when cost_domain_id='drug' then drug_concept_id
end as cost_event_field_concept_id,
NULL as cost_concept_id,
cost_type_concept_id,
NULL as cost_source_concept_id,
NULL as cost_source_value,
currency_concept_id,
total_cost as cost,
case when cost_domain_id='drug' then drug_exposure_start_date
end as incurred_date,
NULL as billed_date,
NULL as paid_date,
revenue_code_concept_id,
drg_concept_id,
a.payer_plan_period_id
from @DatabaseSchemaCDMVersion5.COST a, @DatabaseSchemaCDMVersion5.PAYER_PLAN_PERIOD b, @DatabaseSchemaCDMVersion5.DRUG_EXPOSURE c
where a.payer_plan_period_id=b.payer_plan_period_id
and b.person_id=c.person_id
and a.cost_id=c.drug_exposure_id
and cost_domain_id='drug'
--Insert data from Procedure_occurrence
Insert into @DatabaseSchemaCDMVersion6.dbo.cost
select
cost_id,
b.person_id,
cost_event_id,
case when cost_domain_id='procedure' then procedure_concept_id
end as cost_event_field_concept_id,
NULL as cost_concept_id,
cost_type_concept_id,
NULL as cost_source_concept_id,
NULL as cost_source_value,
currency_concept_id,
total_cost as cost,
case when cost_domain_id='procedure' then procedure_date
end as incurred_date,
NULL as billed_date,
NULL as paid_date,
revenue_code_concept_id,
drg_concept_id,
a.payer_plan_period_id
from @DatabaseSchemaCDMVersion5.COST a, @DatabaseSchemaCDMVersion5.PAYER_PLAN_PERIOD b, @DatabaseSchemaCDMVersion5.PROCEDURE_OCCURRENCE c
where a.payer_plan_period_id=b.payer_plan_period_id
and b.person_id=c.person_id
and a.cost_id=c.procedure_occurrence_id
and cost_domain_id='procedure'
--Insert data from Visit_occurrence
Insert into @DatabaseSchemaCDMVersion6.cost
select
cost_id,
b.person_id,
cost_event_id,
case when cost_domain_id='visit' then visit_concept_id
end as cost_event_field_concept_id, -- 이건 뭐하는 변수인걸까..
NULL as cost_concept_id, -- concept table 에 있는 cost concept_id 들 넣어줘야함
cost_type_concept_id,
NULL as cost_source_concept_id,
NULL as cost_source_value,
currency_concept_id,
total_cost as cost,
case when cost_domain_id='visit' then visit_start_date
end as incurred_date,
NULL as billed_date,
NULL as paid_date,
revenue_code_concept_id,
drg_concept_id,
a.payer_plan_period_id
from @DatabaseSchemaCDMVersion5.COST a, @DatabaseSchemaCDMVersion5.PAYER_PLAN_PERIOD b, @DatabaseSchemaCDMVersion5.VISIT_OCCURRENCE c
where a.payer_plan_period_id=b.payer_plan_period_id
and b.person_id=c.person_id
and a.cost_id=c.visit_occurrence_id
and cost_domain_id='visit'