Syneos Health clinical data reviewers need to identify recurring diagnostic patterns across patient visits. A diagnostic sequence is the ordered list of non-null diagnosis codes recorded during one completed visit.
Write a PostgreSQL query to find the three most frequent diagnostic sequences for completed visits in 2025.
diagnosis_order and concatenating codes with >.RANK() window function to rank sequences by frequency, including ties.| Column | Type | Description |
|---|---|---|
| visit_idPK | INT | Unique visit identifier |
| patient_id | INT | Patient identifier |
| visit_date | DATE | Date of the patient visit |
| visit_status | VARCHAR(20) | Visit status such as completed or canceled |
| Column | Type | Description |
|---|---|---|
| diagnosis_idPK | INT | Unique diagnosis record identifier |
| visit_id | INT | Visit associated with the diagnosis |
| diagnosis_code | VARCHAR(20) | ICD diagnosis code |
| diagnosis_order | INT | Position of the diagnosis within the visit |