From 94051ba94a53a3ac6bce364271be99e975936543 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 8 Feb 2023 08:48:20 +0300 Subject: [PATCH 1/3] End point to expose Patients with validation issues --- app/routes/client-validation-issues.js | 29 ++++++++++ service/client-validation-service.js | 75 ++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 app/routes/client-validation-issues.js create mode 100644 service/client-validation-service.js diff --git a/app/routes/client-validation-issues.js b/app/routes/client-validation-issues.js new file mode 100644 index 000000000..4be947930 --- /dev/null +++ b/app/routes/client-validation-issues.js @@ -0,0 +1,29 @@ +import { ClientValidationIssues } from '../../service/client-validation-service'; +const routes = [ + { + method: 'GET', + path: '/etl/client_validation', + config: { + handler: function (request, reply) { + let service = new ClientValidationIssues(); + service + .generateAggregates() + .then((res) => reply(res)) + .catch((err) => { + console.log('ERROR l13', err); + reply(err); + }); + }, + description: 'Get all verification aggregates ', + notes: 'Returns all verification aggregates', + tags: ['api'], + validate: { + options: { + allowUnknown: true + }, + params: {} + } + } + } +]; +exports.routes = (server) => server.route(routes); diff --git a/service/client-validation-service.js b/service/client-validation-service.js new file mode 100644 index 000000000..90b39f0f3 --- /dev/null +++ b/service/client-validation-service.js @@ -0,0 +1,75 @@ +var db = require('../etl-db'); +const Promise = require('bluebird'); + +export class ClientValidationIssues { + generateAggregates() { + const that = this; + return new Promise(function (resolve, reject) { + const sql = that.aggregateQuery(); + const queryParts = { + sql: sql + }; + return db.queryServer(queryParts, function (result) { + resolve(result); + }); + }); + } + + aggregateQuery() { + return `SELECT + County, + l.name AS 'Health Facility', + mfl_code AS 'MFL Code', + cc.identifier AS 'CCC NO',fh.person_id, + nv.clientNumber as 'NUPI', + nv.errorDescription as "Error description", + CONCAT(COALESCE(person_name.given_name, ''), + ' ', + COALESCE(person_name.middle_name, ''), + ' ', + COALESCE(person_name.family_name, '')) AS 'person_name', + GROUP_CONCAT(DISTINCT contacts.value + SEPARATOR ',') AS 'phone_number', + DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'Date of Birth', + EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), pf.birthdate)))) AS age, + pf.gender + +FROM + etl.flat_hiv_summary_v15b fh + LEFT JOIN + amrs_migration.patient_identifier cc ON (fh.person_id = cc.patient_id + AND cc.identifier_type = 28 + AND cc.voided = 0) + LEFT JOIN + amrs_migration.person pf ON (fh.person_id = pf.person_id AND dead = 0 + AND pf.voided = 0) + LEFT JOIN + amrs_migration.location l ON (l.location_id = fh.last_non_transit_location_id) + LEFT JOIN + ndwr.mfl_codes lx ON (l.location_id = lx.location_id) + LEFT JOIN + amrs_migration.person_name person_name ON (fh.person_id = person_name.person_id + AND (person_name.voided IS NULL + || person_name.voided = 0) + AND person_name.preferred = 1) + LEFT JOIN + amrs_migration.person_attribute contacts ON (fh.person_id = contacts.person_id + AND (contacts.voided IS NULL + || contacts.voided = 0) + AND contacts.person_attribute_type_id IN (10 , 48)) + LEFT JOIN + amrs_migration.patient_identifier id ON (id.patient_id = fh.person_id + AND id.identifier_type = 45 + AND id.voided = 0) + LEFT JOIN + etl.hiv_monthly_report_dataset_v1_2 dd ON (dd.person_id = fh.person_id) + inner join etl.nupi_verification nv on nv.clientNumber=id.identifier +WHERE + fh.location_id != 195 + AND fh.next_clinical_datetime_hiv IS NULL + AND fh.is_clinical_encounter = 1 + AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30) + AND fh.cur_arv_meds IS NOT NULL +GROUP BY fh.person_id limit 10;`; + } +} From bd1c883295947c914399d8dd23c4ea33df3a31e9 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 8 Feb 2023 12:51:23 +0300 Subject: [PATCH 2/3] POC-130: End point to expose Patients with validation issues --- app/routes/client-validation-issues.js | 2 +- service/client-validation-service.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/routes/client-validation-issues.js b/app/routes/client-validation-issues.js index 4be947930..022819822 100644 --- a/app/routes/client-validation-issues.js +++ b/app/routes/client-validation-issues.js @@ -7,7 +7,7 @@ const routes = [ handler: function (request, reply) { let service = new ClientValidationIssues(); service - .generateAggregates() + .generateVerificationClients(request.query) .then((res) => reply(res)) .catch((err) => { console.log('ERROR l13', err); diff --git a/service/client-validation-service.js b/service/client-validation-service.js index 90b39f0f3..008a13f0d 100644 --- a/service/client-validation-service.js +++ b/service/client-validation-service.js @@ -2,10 +2,10 @@ var db = require('../etl-db'); const Promise = require('bluebird'); export class ClientValidationIssues { - generateAggregates() { + generateVerificationClients(params) { const that = this; return new Promise(function (resolve, reject) { - const sql = that.aggregateQuery(); + const sql = that.verificationClientsQuery(params.locationUuid); const queryParts = { sql: sql }; @@ -15,7 +15,7 @@ export class ClientValidationIssues { }); } - aggregateQuery() { + verificationClientsQuery(location) { return `SELECT County, l.name AS 'Health Facility', @@ -66,6 +66,7 @@ FROM inner join etl.nupi_verification nv on nv.clientNumber=id.identifier WHERE fh.location_id != 195 + AND fh.location_id = '${location}' AND fh.next_clinical_datetime_hiv IS NULL AND fh.is_clinical_encounter = 1 AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30) From 45d3fabd014a6d75de0b61bfdcb6066b1cb25ca4 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 8 Feb 2023 12:54:25 +0300 Subject: [PATCH 3/3] POC-130: End point to expose Patients with validation issues --- app/routes/client-validation-issues.js | 5 +-- service/client-validation-service.js | 56 +++++++++++++++++--------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/routes/client-validation-issues.js b/app/routes/client-validation-issues.js index 022819822..358ca5505 100644 --- a/app/routes/client-validation-issues.js +++ b/app/routes/client-validation-issues.js @@ -10,12 +10,11 @@ const routes = [ .generateVerificationClients(request.query) .then((res) => reply(res)) .catch((err) => { - console.log('ERROR l13', err); reply(err); }); }, - description: 'Get all verification aggregates ', - notes: 'Returns all verification aggregates', + description: 'Get all Clients with validation issues', + notes: 'Returns all clients with validation issues', tags: ['api'], validate: { options: { diff --git a/service/client-validation-service.js b/service/client-validation-service.js index 008a13f0d..0b4739613 100644 --- a/service/client-validation-service.js +++ b/service/client-validation-service.js @@ -1,11 +1,16 @@ -var db = require('../etl-db'); +const db = require('../etl-db'); const Promise = require('bluebird'); export class ClientValidationIssues { generateVerificationClients(params) { const that = this; return new Promise(function (resolve, reject) { - const sql = that.verificationClientsQuery(params.locationUuid); + const sql = that.verificationClientsQuery( + params.locationUuid, + params.limit, + params.offset + ); + const queryParts = { sql: sql }; @@ -15,14 +20,17 @@ export class ClientValidationIssues { }); } - verificationClientsQuery(location) { - return `SELECT - County, - l.name AS 'Health Facility', - mfl_code AS 'MFL Code', - cc.identifier AS 'CCC NO',fh.person_id, - nv.clientNumber as 'NUPI', - nv.errorDescription as "Error description", + verificationClientsQuery(location, limit, offset) { + return ( + `SELECT + county, + l.name AS 'health_facility', + mfl_code, + CONCAT(COALESCE(nv.clientNumber, ''),',',COALESCE(cc.identifier,'')) as 'identifiers', + pa.value as status, + fh.person_id, + fh.uuid as patient_uuid, + nv.errorDescription as "error_description", CONCAT(COALESCE(person_name.given_name, ''), ' ', COALESCE(person_name.middle_name, ''), @@ -30,47 +38,55 @@ export class ClientValidationIssues { COALESCE(person_name.family_name, '')) AS 'person_name', GROUP_CONCAT(DISTINCT contacts.value SEPARATOR ',') AS 'phone_number', - DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'Date of Birth', + DATE_FORMAT(pf.birthdate, '%Y-%m-%d') AS 'date_of_birth', EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), pf.birthdate)))) AS age, pf.gender FROM etl.flat_hiv_summary_v15b fh LEFT JOIN - amrs_migration.patient_identifier cc ON (fh.person_id = cc.patient_id + amrs.patient_identifier cc ON (fh.person_id = cc.patient_id AND cc.identifier_type = 28 AND cc.voided = 0) LEFT JOIN - amrs_migration.person pf ON (fh.person_id = pf.person_id AND dead = 0 + amrs.person pf ON (fh.person_id = pf.person_id AND dead = 0 AND pf.voided = 0) LEFT JOIN - amrs_migration.location l ON (l.location_id = fh.last_non_transit_location_id) + amrs.location l ON (l.location_id = fh.last_non_transit_location_id) LEFT JOIN ndwr.mfl_codes lx ON (l.location_id = lx.location_id) LEFT JOIN - amrs_migration.person_name person_name ON (fh.person_id = person_name.person_id + amrs.person_name person_name ON (fh.person_id = person_name.person_id AND (person_name.voided IS NULL || person_name.voided = 0) AND person_name.preferred = 1) LEFT JOIN - amrs_migration.person_attribute contacts ON (fh.person_id = contacts.person_id + amrs.person_attribute contacts ON (fh.person_id = contacts.person_id AND (contacts.voided IS NULL || contacts.voided = 0) AND contacts.person_attribute_type_id IN (10 , 48)) LEFT JOIN - amrs_migration.patient_identifier id ON (id.patient_id = fh.person_id + amrs.patient_identifier id ON (id.patient_id = fh.person_id AND id.identifier_type = 45 AND id.voided = 0) LEFT JOIN etl.hiv_monthly_report_dataset_v1_2 dd ON (dd.person_id = fh.person_id) + LEFT JOIN + amrs.person_attribute pa ON (pa.person_id = fh.person_id) inner join etl.nupi_verification nv on nv.clientNumber=id.identifier WHERE - fh.location_id != 195 - AND fh.location_id = '${location}' + fh.location_id != 195 + AND pa.person_attribute_type_id = 74 + AND l.uuid = '${location}' AND fh.next_clinical_datetime_hiv IS NULL AND fh.is_clinical_encounter = 1 AND (TIMESTAMPDIFF(DAY, fh.rtc_date, CURDATE()) < 30) AND fh.cur_arv_meds IS NOT NULL -GROUP BY fh.person_id limit 10;`; +GROUP BY fh.person_id limit ` + + limit + + ` offset ` + + offset + + `;` + ); } }