Skip to content

Commit 45d3fab

Browse files
committed
POC-130: End point to expose Patients with validation issues
1 parent bd1c883 commit 45d3fab

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

app/routes/client-validation-issues.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ const routes = [
1010
.generateVerificationClients(request.query)
1111
.then((res) => reply(res))
1212
.catch((err) => {
13-
console.log('ERROR l13', err);
1413
reply(err);
1514
});
1615
},
17-
description: 'Get all verification aggregates ',
18-
notes: 'Returns all verification aggregates',
16+
description: 'Get all Clients with validation issues',
17+
notes: 'Returns all clients with validation issues',
1918
tags: ['api'],
2019
validate: {
2120
options: {

service/client-validation-service.js

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
var db = require('../etl-db');
1+
const db = require('../etl-db');
22
const Promise = require('bluebird');
33

44
export class ClientValidationIssues {
55
generateVerificationClients(params) {
66
const that = this;
77
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+
914
const queryParts = {
1015
sql: sql
1116
};
@@ -15,62 +20,73 @@ export class ClientValidationIssues {
1520
});
1621
}
1722

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",
2634
CONCAT(COALESCE(person_name.given_name, ''),
2735
' ',
2836
COALESCE(person_name.middle_name, ''),
2937
' ',
3038
COALESCE(person_name.family_name, '')) AS 'person_name',
3139
GROUP_CONCAT(DISTINCT contacts.value
3240
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',
3442
EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), pf.birthdate)))) AS age,
3543
pf.gender
3644
3745
FROM
3846
etl.flat_hiv_summary_v15b fh
3947
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
4149
AND cc.identifier_type = 28
4250
AND cc.voided = 0)
4351
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
4553
AND pf.voided = 0)
4654
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)
4856
LEFT JOIN
4957
ndwr.mfl_codes lx ON (l.location_id = lx.location_id)
5058
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
5260
AND (person_name.voided IS NULL
5361
|| person_name.voided = 0)
5462
AND person_name.preferred = 1)
5563
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
5765
AND (contacts.voided IS NULL
5866
|| contacts.voided = 0)
5967
AND contacts.person_attribute_type_id IN (10 , 48))
6068
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
6270
AND id.identifier_type = 45
6371
AND id.voided = 0)
6472
LEFT JOIN
6573
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)
6676
inner join etl.nupi_verification nv on nv.clientNumber=id.identifier
6777
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}'
7081
AND fh.next_clinical_datetime_hiv IS NULL
7182
AND fh.is_clinical_encounter = 1
7283
AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30)
7384
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+
);
7591
}
7692
}

0 commit comments

Comments
 (0)