@xdev-asia/xdev-knowledge-mcp 1.0.56 → 1.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/01-phan-1-tong-quan-nen-tang/lessons/bai-1-omop-cdm-la-gi-tai-sao-can-chuan-hoa-du-lieu-y-te.md +339 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/01-phan-1-tong-quan-nen-tang/lessons/bai-2-kien-truc-tong-the-omop-cdm-5-4-nhom-bang-nguyen-ly-thiet-ke.md +440 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/01-phan-1-tong-quan-nen-tang/lessons/bai-3-hieu-concept-trai-tim-cua-omop-cdm.md +441 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/02-phan-2-person-visit-nen-tang/lessons/bai-4-bang-person-quan-ly-danh-tinh-benh-nhan.md +323 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/02-phan-2-person-visit-nen-tang/lessons/bai-5-observation-period-khoang-thoi-gian-theo-doi-benh-nhan.md +308 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/02-phan-2-person-visit-nen-tang/lessons/bai-6-visit-occurrence-visit-detail-luot-kham-chi-tiet.md +353 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/03-phan-3-su-kien-lam-sang-chinh/lessons/bai-10-measurement-xet-nghiem-do-luong.md +409 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/03-phan-3-su-kien-lam-sang-chinh/lessons/bai-7-condition-occurrence-chan-doan-benh-ly.md +285 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/03-phan-3-su-kien-lam-sang-chinh/lessons/bai-8-drug-exposure-thuoc-dieu-tri.md +354 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/03-phan-3-su-kien-lam-sang-chinh/lessons/bai-9-procedure-occurrence-thu-thuat-phau-thuat.md +291 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/04-phan-4-bang-lam-sang-mo-rong/lessons/bai-11-observation-su-kien-lam-sang-tong-hop.md +289 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/04-phan-4-bang-lam-sang-mo-rong/lessons/bai-12-device-exposure-specimen-note.md +313 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/04-phan-4-bang-lam-sang-mo-rong/lessons/bai-13-death-episode-episode-event.md +346 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/05-phan-5-standardized-vocabularies/lessons/bai-14-concept-vocabulary-nen-tang-tu-dien-chuan.md +298 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/05-phan-5-standardized-vocabularies/lessons/bai-15-concept-relationship-concept-ancestor.md +336 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/05-phan-5-standardized-vocabularies/lessons/bai-16-drug-strength-cac-bang-vocabulary-con-lai.md +295 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/06-phan-6-health-system-economics-derived/lessons/bai-17-location-care-site-provider.md +334 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/06-phan-6-health-system-economics-derived/lessons/bai-18-payer-plan-period-cost.md +343 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/06-phan-6-health-system-economics-derived/lessons/bai-19-condition-era-drug-era-dose-era.md +418 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/chapters/07-phan-7-metadata-cohort-tong-ket/lessons/bai-20-cdm-source-metadata-cohort-tong-ket.md +517 -0
- package/content/series/architecture/omop-cdm-5-4-cho-nguoi-moi-bat-dau/index.md +385 -0
- package/package.json +1 -1
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 019f1a00-a119-7b01-e001-omopcdm54019
|
|
3
|
+
title: "Bài 19: CONDITION_ERA, DRUG_ERA & DOSE_ERA — Bảng tổng hợp tự động"
|
|
4
|
+
slug: bai-19-condition-era-drug-era-dose-era
|
|
5
|
+
description: >-
|
|
6
|
+
Ba bảng Derived Elements: CONDITION_ERA gộp chẩn đoán liên tiếp,
|
|
7
|
+
DRUG_ERA gộp đợt dùng thuốc, DOSE_ERA theo dõi liều lượng.
|
|
8
|
+
Thuật toán tạo ERA và ứng dụng phân tích.
|
|
9
|
+
duration_minutes: 50
|
|
10
|
+
is_free: true
|
|
11
|
+
video_url: null
|
|
12
|
+
sort_order: 19
|
|
13
|
+
section_title: "Phần 6: Health System, Economics & Derived Elements"
|
|
14
|
+
course:
|
|
15
|
+
id: 019f1a00-a100-7b01-e001-omopcdm54001
|
|
16
|
+
title: "OMOP CDM 5.4 cho Người mới — Hiểu từ A đến Z"
|
|
17
|
+
slug: omop-cdm-5-4-cho-nguoi-moi-bat-dau
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 340" style="max-width: 100%; height: auto; border-radius: 12px; margin-bottom: 1.5rem;">
|
|
21
|
+
<defs>
|
|
22
|
+
<linearGradient id="bg-omop19" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
23
|
+
<stop offset="0%" style="stop-color:#0c1222"/>
|
|
24
|
+
<stop offset="100%" style="stop-color:#1e293b"/>
|
|
25
|
+
</linearGradient>
|
|
26
|
+
</defs>
|
|
27
|
+
<rect width="1200" height="340" rx="12" fill="url(#bg-omop19)"/>
|
|
28
|
+
<g>
|
|
29
|
+
<circle cx="730" cy="85" r="20" fill="#818cf8" opacity="0.12"/>
|
|
30
|
+
<circle cx="830" cy="115" r="24" fill="#818cf8" opacity="0.08"/>
|
|
31
|
+
<circle cx="910" cy="80" r="16" fill="#818cf8" opacity="0.07"/>
|
|
32
|
+
<line x1="660" y1="130" x2="1100" y2="250" stroke="#818cf8" stroke-width="0.5" opacity="0.1"/>
|
|
33
|
+
</g>
|
|
34
|
+
<rect x="60" y="50" width="4" height="60" rx="2" fill="#818cf8"/>
|
|
35
|
+
<rect x="80" y="50" width="130" height="28" rx="14" fill="#818cf8" opacity="0.15"/>
|
|
36
|
+
<text x="92" y="69" font-family="system-ui,-apple-system,sans-serif" font-size="13" font-weight="600" fill="#818cf8">🏗️ Kiến trúc — Bài 19</text>
|
|
37
|
+
<text x="60" y="140" font-family="system-ui,-apple-system,sans-serif" font-size="34" font-weight="700" fill="#f1f5f9">
|
|
38
|
+
<tspan x="60" dy="0">CONDITION_ERA, DRUG_ERA</tspan>
|
|
39
|
+
<tspan x="60" dy="42">& DOSE_ERA — Bảng tổng hợp</tspan>
|
|
40
|
+
</text>
|
|
41
|
+
<text x="60" y="244" font-family="system-ui,-apple-system,sans-serif" font-size="15" fill="#94a3b8" opacity="0.8">OMOP CDM 5.4 cho Người mới — Hiểu từ A đến Z</text>
|
|
42
|
+
<text x="60" y="268" font-family="system-ui,-apple-system,sans-serif" font-size="13" fill="#64748b" opacity="0.6">Phần 6: Health System, Economics & Derived Elements</text>
|
|
43
|
+
<text x="1140" y="320" font-family="system-ui,-apple-system,sans-serif" font-size="12" fill="#475569" text-anchor="end" opacity="0.4">xdev.asia</text>
|
|
44
|
+
</svg>
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
## Giới thiệu
|
|
49
|
+
|
|
50
|
+
Ba bảng **Derived Elements** không được nhập trực tiếp từ dữ liệu nguồn mà **tính toán tự động** từ bảng lâm sàng. Chúng gộp nhiều records liên tiếp thành 1 "era" (đợt) — rất hữu ích cho phân tích dịch tễ và nghiên cứu lâm sàng.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 1. Khái niệm ERA
|
|
55
|
+
|
|
56
|
+
### 1.1. ERA là gì?
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
Dữ liệu nguồn (nhiều records):
|
|
60
|
+
───────────────────────────────────────────────
|
|
61
|
+
Record 1: Tiểu đường 01/01 ─── 15/01
|
|
62
|
+
Record 2: Tiểu đường 20/01 ─── 28/01 (gap = 5 ngày < 30)
|
|
63
|
+
Record 3: Tiểu đường 10/03 ─── 20/03 (gap = 41 ngày > 30)
|
|
64
|
+
───────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
Sau khi tính ERA (persistence window = 30 ngày):
|
|
67
|
+
───────────────────────────────────────────────
|
|
68
|
+
ERA 1: Tiểu đường 01/01 ─── 28/01 (gộp record 1+2)
|
|
69
|
+
ERA 2: Tiểu đường 10/03 ─── 20/03 (record 3 riêng)
|
|
70
|
+
───────────────────────────────────────────────
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- **Persistence window**: khoảng cách tối đa giữa 2 records để gộp
|
|
74
|
+
- CONDITION_ERA: 30 ngày
|
|
75
|
+
- DRUG_ERA: 30 ngày
|
|
76
|
+
- DOSE_ERA: 0 ngày (chỉ gộp liên tiếp)
|
|
77
|
+
|
|
78
|
+
### 1.2. Tại sao cần ERA?
|
|
79
|
+
|
|
80
|
+
| Vấn đề | Giải quyết |
|
|
81
|
+
|--------|-----------|
|
|
82
|
+
| 1 BN có 20 lần khám Tiểu đường → 20 records | 1-2 CONDITION_ERA |
|
|
83
|
+
| BN uống Metformin 12 tháng → 12 đơn thuốc | 1 DRUG_ERA |
|
|
84
|
+
| Cần tính "thời gian mắc bệnh" | ERA end - ERA start |
|
|
85
|
+
| Cần tính "thời gian điều trị" | drug_era_end - drug_era_start |
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 2. CONDITION_ERA
|
|
90
|
+
|
|
91
|
+
### 2.1. Cấu trúc bảng
|
|
92
|
+
|
|
93
|
+
| Cột | Kiểu | Bắt buộc | Mô tả |
|
|
94
|
+
|-----|------|----------|-------|
|
|
95
|
+
| `condition_era_id` | INTEGER | ✅ PK | ID duy nhất |
|
|
96
|
+
| `person_id` | INTEGER | ✅ | FK → PERSON |
|
|
97
|
+
| `condition_concept_id` | INTEGER | ✅ | Standard Concept (Ingredient level cho Drug) |
|
|
98
|
+
| `condition_era_start_date` | DATE | ✅ | Ngày bắt đầu đợt |
|
|
99
|
+
| `condition_era_end_date` | DATE | ✅ | Ngày kết thúc đợt |
|
|
100
|
+
| `condition_occurrence_count` | INTEGER | | Số records gộp |
|
|
101
|
+
|
|
102
|
+
### 2.2. Đặc điểm quan trọng
|
|
103
|
+
|
|
104
|
+
- `condition_concept_id` luôn là **Standard Concept** (SNOMED)
|
|
105
|
+
- Persistence window = **30 ngày** (mặc định, có thể tùy chỉnh)
|
|
106
|
+
- Gộp cả condition_occurrence từ nhiều visit khác nhau
|
|
107
|
+
|
|
108
|
+
### 2.3. Thuật toán tạo CONDITION_ERA
|
|
109
|
+
|
|
110
|
+
```sql
|
|
111
|
+
-- Simplified logic (actual implementation dùng CTE phức tạp hơn)
|
|
112
|
+
-- Bước 1: Map tất cả condition → Standard + thêm end_date
|
|
113
|
+
-- Bước 2: Xác định gap giữa records liên tiếp
|
|
114
|
+
-- Bước 3: Nếu gap <= 30 ngày → gộp vào cùng ERA
|
|
115
|
+
|
|
116
|
+
WITH condition_dates AS (
|
|
117
|
+
SELECT
|
|
118
|
+
person_id,
|
|
119
|
+
condition_concept_id,
|
|
120
|
+
condition_start_date,
|
|
121
|
+
COALESCE(
|
|
122
|
+
condition_end_date,
|
|
123
|
+
condition_start_date + INTERVAL '1 day' -- Default 1 ngày
|
|
124
|
+
) AS condition_end_date
|
|
125
|
+
FROM condition_occurrence
|
|
126
|
+
WHERE condition_concept_id != 0
|
|
127
|
+
),
|
|
128
|
+
-- Xác định ERA groups bằng cách tìm gaps > 30 ngày
|
|
129
|
+
era_groups AS (
|
|
130
|
+
SELECT *,
|
|
131
|
+
SUM(new_era_flag) OVER (
|
|
132
|
+
PARTITION BY person_id, condition_concept_id
|
|
133
|
+
ORDER BY condition_start_date
|
|
134
|
+
) AS era_group
|
|
135
|
+
FROM (
|
|
136
|
+
SELECT *,
|
|
137
|
+
CASE
|
|
138
|
+
WHEN condition_start_date - LAG(condition_end_date)
|
|
139
|
+
OVER (PARTITION BY person_id, condition_concept_id
|
|
140
|
+
ORDER BY condition_start_date)
|
|
141
|
+
> 30
|
|
142
|
+
THEN 1
|
|
143
|
+
ELSE 0
|
|
144
|
+
END AS new_era_flag
|
|
145
|
+
FROM condition_dates
|
|
146
|
+
) t
|
|
147
|
+
)
|
|
148
|
+
SELECT
|
|
149
|
+
ROW_NUMBER() OVER () AS condition_era_id,
|
|
150
|
+
person_id,
|
|
151
|
+
condition_concept_id,
|
|
152
|
+
MIN(condition_start_date) AS condition_era_start_date,
|
|
153
|
+
MAX(condition_end_date) AS condition_era_end_date,
|
|
154
|
+
COUNT(*) AS condition_occurrence_count
|
|
155
|
+
FROM era_groups
|
|
156
|
+
GROUP BY person_id, condition_concept_id, era_group;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 2.4. Truy vấn ứng dụng
|
|
160
|
+
|
|
161
|
+
```sql
|
|
162
|
+
-- Top 10 bệnh mạn tính (ERA > 365 ngày)
|
|
163
|
+
SELECT
|
|
164
|
+
c.concept_name AS condition_name,
|
|
165
|
+
COUNT(DISTINCT ce.person_id) AS patient_count,
|
|
166
|
+
ROUND(AVG(
|
|
167
|
+
ce.condition_era_end_date - ce.condition_era_start_date
|
|
168
|
+
), 0) AS avg_duration_days,
|
|
169
|
+
AVG(ce.condition_occurrence_count) AS avg_visits
|
|
170
|
+
FROM condition_era ce
|
|
171
|
+
JOIN concept c ON ce.condition_concept_id = c.concept_id
|
|
172
|
+
WHERE ce.condition_era_end_date - ce.condition_era_start_date > 365
|
|
173
|
+
GROUP BY c.concept_name
|
|
174
|
+
ORDER BY patient_count DESC
|
|
175
|
+
LIMIT 10;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 3. DRUG_ERA
|
|
181
|
+
|
|
182
|
+
### 3.1. Cấu trúc bảng
|
|
183
|
+
|
|
184
|
+
| Cột | Kiểu | Bắt buộc | Mô tả |
|
|
185
|
+
|-----|------|----------|-------|
|
|
186
|
+
| `drug_era_id` | INTEGER | ✅ PK | ID duy nhất |
|
|
187
|
+
| `person_id` | INTEGER | ✅ | FK → PERSON |
|
|
188
|
+
| `drug_concept_id` | INTEGER | ✅ | Standard Concept (**Ingredient**) |
|
|
189
|
+
| `drug_era_start_date` | DATE | ✅ | Ngày bắt đầu đợt |
|
|
190
|
+
| `drug_era_end_date` | DATE | ✅ | Ngày kết thúc đợt |
|
|
191
|
+
| `drug_exposure_count` | INTEGER | | Số đơn thuốc gộp |
|
|
192
|
+
| `gap_days` | INTEGER | | Tổng ngày gap giữa prescriptions |
|
|
193
|
+
|
|
194
|
+
### 3.2. Đặc điểm quan trọng
|
|
195
|
+
|
|
196
|
+
- `drug_concept_id` luôn ở mức **Ingredient** (không phải Clinical Drug)
|
|
197
|
+
- Tất cả dạng bào chế Metformin → gộp vào 1 Metformin ERA
|
|
198
|
+
- `gap_days`: tổng số ngày BN không dùng thuốc giữa các đơn
|
|
199
|
+
|
|
200
|
+
### 3.3. Ví dụ trực quan
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
drug_exposure records (BN 100001, Metformin):
|
|
204
|
+
──────────────────────────────────────────────
|
|
205
|
+
Đơn 1: Metformin 500mg Tab 01/01 → 30/01 (30 ngày)
|
|
206
|
+
Đơn 2: Metformin 850mg Tab 05/02 → 06/03 (30 ngày) gap=6
|
|
207
|
+
Đơn 3: Metformin 500mg Tab 10/03 → 08/04 (30 ngày) gap=4
|
|
208
|
+
[GAP 45 ngày — > 30 → NEW ERA]
|
|
209
|
+
Đơn 4: Metformin 1000mg Tab 23/05 → 21/06 (30 ngày)
|
|
210
|
+
──────────────────────────────────────────────
|
|
211
|
+
|
|
212
|
+
drug_era kết quả:
|
|
213
|
+
──────────────────────────────────────────────
|
|
214
|
+
ERA 1: Metformin (Ingredient)
|
|
215
|
+
01/01 → 08/04 (98 ngày)
|
|
216
|
+
drug_exposure_count = 3
|
|
217
|
+
gap_days = 10 (6 + 4)
|
|
218
|
+
|
|
219
|
+
ERA 2: Metformin (Ingredient)
|
|
220
|
+
23/05 → 21/06 (30 ngày)
|
|
221
|
+
drug_exposure_count = 1
|
|
222
|
+
gap_days = 0
|
|
223
|
+
──────────────────────────────────────────────
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 3.4. Truy vấn: Tuân thủ điều trị
|
|
227
|
+
|
|
228
|
+
```sql
|
|
229
|
+
-- Tính adherence = (ERA days - gap_days) / ERA days
|
|
230
|
+
SELECT
|
|
231
|
+
c.concept_name AS drug,
|
|
232
|
+
de.person_id,
|
|
233
|
+
de.drug_era_start_date,
|
|
234
|
+
de.drug_era_end_date,
|
|
235
|
+
de.drug_era_end_date - de.drug_era_start_date AS era_days,
|
|
236
|
+
de.gap_days,
|
|
237
|
+
de.drug_exposure_count,
|
|
238
|
+
ROUND(
|
|
239
|
+
(de.drug_era_end_date - de.drug_era_start_date - de.gap_days)
|
|
240
|
+
* 100.0
|
|
241
|
+
/ NULLIF(de.drug_era_end_date - de.drug_era_start_date, 0),
|
|
242
|
+
1
|
|
243
|
+
) AS adherence_pct
|
|
244
|
+
FROM drug_era de
|
|
245
|
+
JOIN concept c ON de.drug_concept_id = c.concept_id
|
|
246
|
+
WHERE de.person_id = 100001
|
|
247
|
+
ORDER BY de.drug_era_start_date;
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 3.5. Top thuốc sử dụng lâu nhất
|
|
251
|
+
|
|
252
|
+
```sql
|
|
253
|
+
SELECT
|
|
254
|
+
c.concept_name AS ingredient,
|
|
255
|
+
COUNT(DISTINCT de.person_id) AS patient_count,
|
|
256
|
+
ROUND(AVG(
|
|
257
|
+
de.drug_era_end_date - de.drug_era_start_date
|
|
258
|
+
), 0) AS avg_era_days,
|
|
259
|
+
ROUND(AVG(de.drug_exposure_count), 1) AS avg_prescriptions,
|
|
260
|
+
ROUND(AVG(de.gap_days), 0) AS avg_gap_days
|
|
261
|
+
FROM drug_era de
|
|
262
|
+
JOIN concept c ON de.drug_concept_id = c.concept_id
|
|
263
|
+
GROUP BY c.concept_name
|
|
264
|
+
HAVING COUNT(DISTINCT de.person_id) >= 100
|
|
265
|
+
ORDER BY avg_era_days DESC
|
|
266
|
+
LIMIT 15;
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## 4. DOSE_ERA
|
|
272
|
+
|
|
273
|
+
### 4.1. Cấu trúc bảng
|
|
274
|
+
|
|
275
|
+
| Cột | Kiểu | Bắt buộc | Mô tả |
|
|
276
|
+
|-----|------|----------|-------|
|
|
277
|
+
| `dose_era_id` | INTEGER | ✅ PK | ID duy nhất |
|
|
278
|
+
| `person_id` | INTEGER | ✅ | FK → PERSON |
|
|
279
|
+
| `drug_concept_id` | INTEGER | ✅ | Standard Concept (Ingredient) |
|
|
280
|
+
| `unit_concept_id` | INTEGER | ✅ | Đơn vị liều (mg, g) |
|
|
281
|
+
| `dose_value` | FLOAT | ✅ | Liều lượng |
|
|
282
|
+
| `dose_era_start_date` | DATE | ✅ | Ngày bắt đầu |
|
|
283
|
+
| `dose_era_end_date` | DATE | ✅ | Ngày kết thúc |
|
|
284
|
+
|
|
285
|
+
### 4.2. DOSE_ERA vs DRUG_ERA
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
DRUG_ERA: Gộp theo Ingredient, bỏ qua liều
|
|
289
|
+
──────────────────────────────────────────────
|
|
290
|
+
Metformin ERA: 01/01 → 08/04
|
|
291
|
+
|
|
292
|
+
DOSE_ERA: Gộp theo Ingredient + Liều cụ thể
|
|
293
|
+
──────────────────────────────────────────────
|
|
294
|
+
Metformin 500mg: 01/01 → 30/01
|
|
295
|
+
Metformin 850mg: 05/02 → 06/03 ← tăng liều
|
|
296
|
+
Metformin 500mg: 10/03 → 08/04 ← giảm liều
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
- DOSE_ERA **persistence window = 0**: chỉ gộp khi liên tiếp cùng liều
|
|
300
|
+
- Dùng DRUG_STRENGTH để tính dose_value từ drug_concept_id
|
|
301
|
+
|
|
302
|
+
### 4.3. Truy vấn: Theo dõi thay đổi liều
|
|
303
|
+
|
|
304
|
+
```sql
|
|
305
|
+
-- Lịch sử thay đổi liều Metformin
|
|
306
|
+
SELECT
|
|
307
|
+
de.person_id,
|
|
308
|
+
c.concept_name AS ingredient,
|
|
309
|
+
de.dose_value,
|
|
310
|
+
cu.concept_name AS unit,
|
|
311
|
+
de.dose_era_start_date,
|
|
312
|
+
de.dose_era_end_date,
|
|
313
|
+
de.dose_era_end_date - de.dose_era_start_date AS days_on_dose
|
|
314
|
+
FROM dose_era de
|
|
315
|
+
JOIN concept c ON de.drug_concept_id = c.concept_id
|
|
316
|
+
JOIN concept cu ON de.unit_concept_id = cu.concept_id
|
|
317
|
+
WHERE de.person_id = 100001
|
|
318
|
+
AND de.drug_concept_id = 1503297 -- Metformin
|
|
319
|
+
ORDER BY de.dose_era_start_date;
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### 4.4. Phân tích dose escalation
|
|
323
|
+
|
|
324
|
+
```sql
|
|
325
|
+
-- Tìm BN có dose escalation (tăng liều theo thời gian)
|
|
326
|
+
WITH dose_changes AS (
|
|
327
|
+
SELECT
|
|
328
|
+
de.person_id,
|
|
329
|
+
de.drug_concept_id,
|
|
330
|
+
de.dose_value,
|
|
331
|
+
de.dose_era_start_date,
|
|
332
|
+
LAG(de.dose_value) OVER (
|
|
333
|
+
PARTITION BY de.person_id, de.drug_concept_id
|
|
334
|
+
ORDER BY de.dose_era_start_date
|
|
335
|
+
) AS prev_dose
|
|
336
|
+
FROM dose_era de
|
|
337
|
+
)
|
|
338
|
+
SELECT
|
|
339
|
+
c.concept_name AS drug,
|
|
340
|
+
dc.person_id,
|
|
341
|
+
dc.prev_dose AS from_dose,
|
|
342
|
+
dc.dose_value AS to_dose,
|
|
343
|
+
dc.dose_era_start_date AS escalation_date
|
|
344
|
+
FROM dose_changes dc
|
|
345
|
+
JOIN concept c ON dc.drug_concept_id = c.concept_id
|
|
346
|
+
WHERE dc.dose_value > dc.prev_dose -- Liều tăng
|
|
347
|
+
ORDER BY dc.person_id, c.concept_name, dc.dose_era_start_date;
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 5. So sánh 3 bảng ERA
|
|
353
|
+
|
|
354
|
+
| Đặc điểm | CONDITION_ERA | DRUG_ERA | DOSE_ERA |
|
|
355
|
+
|-----------|--------------|----------|----------|
|
|
356
|
+
| **Nguồn** | condition_occurrence | drug_exposure | drug_exposure + drug_strength |
|
|
357
|
+
| **Concept level** | Standard (SNOMED) | Ingredient | Ingredient |
|
|
358
|
+
| **Persistence window** | 30 ngày | 30 ngày | 0 ngày |
|
|
359
|
+
| **Gộp theo** | person + condition | person + ingredient | person + ingredient + dose |
|
|
360
|
+
| **Đếm records** | condition_occurrence_count | drug_exposure_count | (không có) |
|
|
361
|
+
| **Gap info** | (không có) | gap_days | (không có) |
|
|
362
|
+
| **Dose info** | (không có) | (không có) | dose_value, unit |
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## 6. Pipeline tạo ERA tables
|
|
367
|
+
|
|
368
|
+
```
|
|
369
|
+
Bước 1: ETL source → CDM tables
|
|
370
|
+
┌────────────────────┐ ┌─────────────────────┐
|
|
371
|
+
│ HIS / EMR │───→│ condition_occurrence │
|
|
372
|
+
│ (dữ liệu nguồn) │───→│ drug_exposure │
|
|
373
|
+
└────────────────────┘ └──────────┬────────────┘
|
|
374
|
+
│
|
|
375
|
+
Bước 2: Tạo ERA tables │
|
|
376
|
+
↓
|
|
377
|
+
┌────────────────────────────────────────────────┐
|
|
378
|
+
│ ERA Builder Script │
|
|
379
|
+
│ │
|
|
380
|
+
│ 1. condition_occurrence → CONDITION_ERA │
|
|
381
|
+
│ (SNOMED rollup + 30-day window) │
|
|
382
|
+
│ │
|
|
383
|
+
│ 2. drug_exposure + drug_strength → DRUG_ERA │
|
|
384
|
+
│ (Ingredient rollup + 30-day window) │
|
|
385
|
+
│ │
|
|
386
|
+
│ 3. drug_exposure + drug_strength → DOSE_ERA │
|
|
387
|
+
│ (Ingredient + dose + 0-day window) │
|
|
388
|
+
└────────────────────────────────────────────────┘
|
|
389
|
+
|
|
390
|
+
Bước 3: Validate
|
|
391
|
+
┌────────────────────────────────────┐
|
|
392
|
+
│ - Mỗi ERA có start <= end │
|
|
393
|
+
│ - occurrence_count >= 1 │
|
|
394
|
+
│ - gap_days >= 0 │
|
|
395
|
+
│ - Không khoảng trống logic │
|
|
396
|
+
└────────────────────────────────────┘
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## Tổng kết
|
|
402
|
+
|
|
403
|
+
1. **ERA** = gộp nhiều records liên tiếp thành 1 đợt duy nhất
|
|
404
|
+
2. **CONDITION_ERA**: 30 ngày window, SNOMED standard concept
|
|
405
|
+
3. **DRUG_ERA**: 30 ngày window, Ingredient level, có `gap_days` tính adherence
|
|
406
|
+
4. **DOSE_ERA**: 0 ngày window, theo dõi thay đổi liều theo thời gian
|
|
407
|
+
5. ERA tables được **tạo tự động** sau ETL, không nhập trực tiếp
|
|
408
|
+
|
|
409
|
+
**Bài tiếp theo:** CDM_SOURCE, METADATA, COHORT & Tổng kết series.
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Tài liệu tham khảo
|
|
414
|
+
|
|
415
|
+
- [OMOP CDM 5.4 — CONDITION_ERA](https://ohdsi.github.io/CommonDataModel/cdm54.html#CONDITION_ERA)
|
|
416
|
+
- [OMOP CDM 5.4 — DRUG_ERA](https://ohdsi.github.io/CommonDataModel/cdm54.html#DRUG_ERA)
|
|
417
|
+
- [OMOP CDM 5.4 — DOSE_ERA](https://ohdsi.github.io/CommonDataModel/cdm54.html#DOSE_ERA)
|
|
418
|
+
- [Book of OHDSI — ch. 6: Standardized Derived Elements](https://ohdsi.github.io/TheBookOfOhdsi/)
|