8 | | 1. Check that the patient has one of the required statuses in the civicrm_case.status_id column. (Define what these are ~ recruited, completed, etc) |
| 8 | 1. Check that the patient has one of the required statuses in the civicrm_case.status_id column. These are: 6: Available for cohort, 10: Completed, 1: Open, 5: Recruited. |
| 9 | |
| 10 | === Query |
| 11 | |
| 12 | As usual the queries are different for test and for live. Hurray! |
| 13 | |
| 14 | ==== Test |
| 15 | |
| 16 | {{{ |
| 17 | #!sql |
| 18 | |
| 19 | SELECT |
| 20 | recruit.id civiCRM_contact_id |
| 21 | , cids.nhs_number_1 nhs_number |
| 22 | , cids.uhl_s_number_2 uhl_s_number |
| 23 | , grd.genvasc_id_10 genvasc_id |
| 24 | , grd.genvasc_consent_q1_11 consent_1 |
| 25 | , grd.genvasc_consent_q2_12 consent_2 |
| 26 | , grd.genvasc_consent_q3_13 consent_3 |
| 27 | , grd.genvasc_consent_q4_14 consent_4 |
| 28 | , grd.genvasc_consent_q5_15 consent_5 |
| 29 | , grd.genvasc_consent_q6_16 consent_6 |
| 30 | , grd.genvasc_consent_q7_17 consent_7 |
| 31 | , recruit.birth_date |
| 32 | , enrollment.start_date enrollment_date |
| 33 | , CASE |
| 34 | WHEN (wstatus.withdrawal_status_24 = 'A') THEN enrollment.end_date |
| 35 | END withdrawal_date |
| 36 | FROM civicrm_contact recruit |
| 37 | JOIN civicrm_case_contact enrollcontact ON enrollcontact.contact_id = recruit.id |
| 38 | JOIN civicrm_case enrollment ON enrollment.id = enrollcontact.case_id |
| 39 | AND enrollment.start_date < DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) |
| 40 | AND enrollment.status_id NOT IN (699 /* declined */, 701 /* excluded */) |
| 41 | AND enrollment.case_type_id = "3" /* GENVASC */ |
| 42 | AND enrollment.is_deleted = 0 |
| 43 | JOIN civicrm_value_contact_ids_2 cids ON cids.entity_id = recruit.id |
| 44 | JOIN civicrm_value_genvasc_recruitment_data_6 grd ON grd.entity_id = enrollment.id |
| 45 | LEFT JOIN civicrm_value_genvasc_withdrawal_status_9 wstatus ON wstatus.entity_id = enrollment.id |
| 46 | WHERE recruit.is_deleted = 0 |
| 47 | AND COALESCE(wstatus.withdrawal_status_24, '') <> 'B' |
| 48 | AND EXISTS ( SELECT 1 |
| 49 | FROM civicrm_relationship rel |
| 50 | WHERE rel.contact_id_a = recruit.id |
| 51 | AND rel.relationship_type_id = 15 /* with GP surgery */ |
| 52 | ) |
| 53 | ; |
| 54 | |
| 55 | }}} |