@@ -5,7 +5,12 @@ export class ClientValidationIssues {
5
5
generateVerificationClients ( params ) {
6
6
const that = this ;
7
7
return new Promise ( function ( resolve , reject ) {
8
- const sql = that . verificationClientsQuery ( params . locationUuid ) ;
8
+ const sql = that . verificationClientsQuery (
9
+ params . locationUuid ,
10
+ params . limit ,
11
+ params . offset
12
+ ) ;
13
+
9
14
const queryParts = {
10
15
sql : sql
11
16
} ;
@@ -15,62 +20,73 @@ export class ClientValidationIssues {
15
20
} ) ;
16
21
}
17
22
18
- verificationClientsQuery ( location ) {
19
- return `SELECT
20
- County,
21
- l.name AS 'Health Facility',
22
- mfl_code AS 'MFL Code',
23
- cc.identifier AS 'CCC NO',fh.person_id,
24
- nv.clientNumber as 'NUPI',
25
- nv.errorDescription as "Error description",
23
+ verificationClientsQuery ( location , limit , offset ) {
24
+ return (
25
+ `SELECT
26
+ county,
27
+ l.name AS 'health_facility',
28
+ mfl_code,
29
+ CONCAT(COALESCE(nv.clientNumber, ''),',',COALESCE(cc.identifier,'')) as 'identifiers',
30
+ pa.value as status,
31
+ fh.person_id,
32
+ fh.uuid as patient_uuid,
33
+ nv.errorDescription as "error_description",
26
34
CONCAT(COALESCE(person_name.given_name, ''),
27
35
' ',
28
36
COALESCE(person_name.middle_name, ''),
29
37
' ',
30
38
COALESCE(person_name.family_name, '')) AS 'person_name',
31
39
GROUP_CONCAT(DISTINCT contacts.value
32
40
SEPARATOR ',') AS 'phone_number',
33
- DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'Date of Birth ',
41
+ DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'date_of_birth ',
34
42
EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), pf.birthdate)))) AS age,
35
43
pf.gender
36
44
37
45
FROM
38
46
etl.flat_hiv_summary_v15b fh
39
47
LEFT JOIN
40
- amrs_migration .patient_identifier cc ON (fh.person_id = cc.patient_id
48
+ amrs .patient_identifier cc ON (fh.person_id = cc.patient_id
41
49
AND cc.identifier_type = 28
42
50
AND cc.voided = 0)
43
51
LEFT JOIN
44
- amrs_migration .person pf ON (fh.person_id = pf.person_id AND dead = 0
52
+ amrs .person pf ON (fh.person_id = pf.person_id AND dead = 0
45
53
AND pf.voided = 0)
46
54
LEFT JOIN
47
- amrs_migration .location l ON (l.location_id = fh.last_non_transit_location_id)
55
+ amrs .location l ON (l.location_id = fh.last_non_transit_location_id)
48
56
LEFT JOIN
49
57
ndwr.mfl_codes lx ON (l.location_id = lx.location_id)
50
58
LEFT JOIN
51
- amrs_migration .person_name person_name ON (fh.person_id = person_name.person_id
59
+ amrs .person_name person_name ON (fh.person_id = person_name.person_id
52
60
AND (person_name.voided IS NULL
53
61
|| person_name.voided = 0)
54
62
AND person_name.preferred = 1)
55
63
LEFT JOIN
56
- amrs_migration .person_attribute contacts ON (fh.person_id = contacts.person_id
64
+ amrs .person_attribute contacts ON (fh.person_id = contacts.person_id
57
65
AND (contacts.voided IS NULL
58
66
|| contacts.voided = 0)
59
67
AND contacts.person_attribute_type_id IN (10 , 48))
60
68
LEFT JOIN
61
- amrs_migration .patient_identifier id ON (id.patient_id = fh.person_id
69
+ amrs .patient_identifier id ON (id.patient_id = fh.person_id
62
70
AND id.identifier_type = 45
63
71
AND id.voided = 0)
64
72
LEFT JOIN
65
73
etl.hiv_monthly_report_dataset_v1_2 dd ON (dd.person_id = fh.person_id)
74
+ LEFT JOIN
75
+ amrs.person_attribute pa ON (pa.person_id = fh.person_id)
66
76
inner join etl.nupi_verification nv on nv.clientNumber=id.identifier
67
77
WHERE
68
- fh.location_id != 195
69
- AND fh.location_id = '${ location } '
78
+ fh.location_id != 195
79
+ AND pa.person_attribute_type_id = 74
80
+ AND l.uuid = '${ location } '
70
81
AND fh.next_clinical_datetime_hiv IS NULL
71
82
AND fh.is_clinical_encounter = 1
72
83
AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30)
73
84
AND fh.cur_arv_meds IS NOT NULL
74
- GROUP BY fh.person_id limit 10;` ;
85
+ GROUP BY fh.person_id limit ` +
86
+ limit +
87
+ ` offset ` +
88
+ offset +
89
+ `;`
90
+ ) ;
75
91
}
76
92
}
0 commit comments