@@ -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,69 @@ 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
+ fh.person_id,
31
+ fh.uuid as patient_uuid,
32
+ nv.errorDescription as "error_description",
26
33
CONCAT(COALESCE(person_name.given_name, ''),
27
34
' ',
28
35
COALESCE(person_name.middle_name, ''),
29
36
' ',
30
37
COALESCE(person_name.family_name, '')) AS 'person_name',
31
38
GROUP_CONCAT(DISTINCT contacts.value
32
39
SEPARATOR ',') AS 'phone_number',
33
- DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'Date of Birth ',
40
+ DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'date_of_birth ',
34
41
EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), pf.birthdate)))) AS age,
35
42
pf.gender
36
43
37
44
FROM
38
45
etl.flat_hiv_summary_v15b fh
39
46
LEFT JOIN
40
- amrs_migration .patient_identifier cc ON (fh.person_id = cc.patient_id
47
+ amrs .patient_identifier cc ON (fh.person_id = cc.patient_id
41
48
AND cc.identifier_type = 28
42
49
AND cc.voided = 0)
43
50
LEFT JOIN
44
- amrs_migration .person pf ON (fh.person_id = pf.person_id AND dead = 0
51
+ amrs .person pf ON (fh.person_id = pf.person_id AND dead = 0
45
52
AND pf.voided = 0)
46
53
LEFT JOIN
47
- amrs_migration .location l ON (l.location_id = fh.last_non_transit_location_id)
54
+ amrs .location l ON (l.location_id = fh.last_non_transit_location_id)
48
55
LEFT JOIN
49
56
ndwr.mfl_codes lx ON (l.location_id = lx.location_id)
50
57
LEFT JOIN
51
- amrs_migration .person_name person_name ON (fh.person_id = person_name.person_id
58
+ amrs .person_name person_name ON (fh.person_id = person_name.person_id
52
59
AND (person_name.voided IS NULL
53
60
|| person_name.voided = 0)
54
61
AND person_name.preferred = 1)
55
62
LEFT JOIN
56
- amrs_migration .person_attribute contacts ON (fh.person_id = contacts.person_id
63
+ amrs .person_attribute contacts ON (fh.person_id = contacts.person_id
57
64
AND (contacts.voided IS NULL
58
65
|| contacts.voided = 0)
59
66
AND contacts.person_attribute_type_id IN (10 , 48))
60
67
LEFT JOIN
61
- amrs_migration .patient_identifier id ON (id.patient_id = fh.person_id
68
+ amrs .patient_identifier id ON (id.patient_id = fh.person_id
62
69
AND id.identifier_type = 45
63
70
AND id.voided = 0)
64
71
LEFT JOIN
65
72
etl.hiv_monthly_report_dataset_v1_2 dd ON (dd.person_id = fh.person_id)
66
73
inner join etl.nupi_verification nv on nv.clientNumber=id.identifier
67
74
WHERE
68
- fh.location_id != 195
69
- AND fh.location_id = '${ location } '
75
+ fh.location_id != 195
76
+ AND l.uuid = '${ location } '
70
77
AND fh.next_clinical_datetime_hiv IS NULL
71
78
AND fh.is_clinical_encounter = 1
72
79
AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30)
73
80
AND fh.cur_arv_meds IS NOT NULL
74
- GROUP BY fh.person_id limit 10;` ;
81
+ GROUP BY fh.person_id limit ` +
82
+ limit +
83
+ ` offset ` +
84
+ offset +
85
+ `;`
86
+ ) ;
75
87
}
76
88
}
0 commit comments