Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaulter tracing register endpoint #1413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions etl-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { Covid19MonthlyReport } from './service/covid-19/covid-19-monthly-report
import { MlWeeklyPredictionsService } from './service/ml-weekly-predictions.service';
import { getPatientPredictedScore } from './service/predictions/ml-prediction-service';
import { CohortModuleService } from './app/otz/cohort-module.service';
import { getDefaulterTracingData } from './service/moh-registers/defaulter-tracing.js';

module.exports = (function () {
var routes = [
Expand Down Expand Up @@ -6360,6 +6361,31 @@ module.exports = (function () {
notes: 'Api endpoint that returns AMRS ID in string format',
tags: ['api']
}
},
{
method: 'GET',
path: '/etl/registers/defaulter-tracing',
config: {
auth: 'simple',
plugins: {},
handler: function (request, reply) {
if (request.query.locationUuid) {
const locationUuids = request.query.locationUuid;
getDefaulterTracingData(locationUuids)
.then((results) => {
reply(results);
})
.catch((error) => {
reply(Boom.internal('An error occured', error));
});
} else {
reply(Boom.internal('Request misssing location uuid'));
}
},
description: 'Get defaulter tracing data',
notes: 'Returns the defaulter tracing data',
tags: ['api']
}
}
];

Expand Down
69 changes: 69 additions & 0 deletions service/moh-registers/defaulter-tracing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const db = require('../../etl-db');

const getDefaulterTracingSummary = (locationUuid) => {
return new Promise((resolve, reject) => {
const sql = `
select
e.patient_id 'client_id_No',
d.identifier nupi,
pn.given_name as first_name,
pn.middle_name as middle,
pn.family_name as last_name,
pa.city_village as village,
pt.value as 'Telephone number',
max(if(o.concept_id=1592,(o.value_datetime),null)) as date_of_missed_appointment,
max(if(o.concept_id=9082,(case o.value_coded
when 159 then "Dead"
when 12296 then "Return to care"
when 10652 then "Transferred"
when 1679 then "Stopped"
when 9580 then "Follow Up"
else "" end),null)) as defaulter_tracing_outcomes,
max(o.obs_datetime) as 'date of outcomes',
max(if(o.concept_id=9467,(o.value_text),null)) as outcomes
from
etl.flat_obs fo
INNER JOIN amrs.encounter e ON fo.encounter_id = e.encounter_id
inner join amrs.location l on l.location_id=e.location_id
inner join amrs.person p on p.person_id=e.patient_id and p.voided=0
inner join amrs.patient_identifier d on d.patient_id=p.person_id
inner join amrs.person_name pn on pn.person_id = d.patient_id
inner join amrs.person_address pa on pn.person_id = pa.person_id
left join amrs.person_attribute pt on pt.person_id = pa.person_id and person_attribute_type_id = 10 and pt.voided =0
inner join amrs.form f on f.form_id = e.form_id and f.uuid = "f3ba9242-9bbb-4284-a0c0-56ac6f0cec65"
left join amrs.obs o on o.encounter_id = e.encounter_id
and o.concept_id in (1592, 9082, 9467)
and o.voided=0
where e.voided=0
and l.uuid in ('${locationUuid}')
group by e.encounter_id

`;

const queryParts = {
sql: sql
};
db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result);
});
});
};

export const getDefaulterTracingData = (locationUuids) => {
return new Promise((resolve, reject) => {
getDefaulterTracingSummary(locationUuids)
.then((results) => {
const defaulterTracingData = {
result: {}
};
if (results.size) {
defaulterTracingData.result = results.result || [];
}
resolve(defaulterTracingData);
})
.catch((error) => {
reject(error);
});
});
};
Loading