Skip to content

Commit

Permalink
Family history reporting indicators numbers not tallying fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jecihjoy committed Feb 1, 2022
1 parent 9bcc95a commit 74e3553
Showing 1 changed file with 64 additions and 12 deletions.
76 changes: 64 additions & 12 deletions app/family-history/family-history.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,9 @@ export class FamilyTestingService {
}

if (params.elicited_clients == 0) {
where = `${where} group by tx.person_id`;
sql =
sql +
' tx.*, extract(year from (from_days(datediff(now(),tx.birthdate)))) as age, tx.gender as index_gender ' +
from +
where;
sql = this.allReviewedClientsQuery(params, sql, from);
} else if (params.elicited_clients < 0) {
where = `${where} and obs_group_id is null `;
sql =
sql +
' tx.*, extract(year from (from_days(datediff(now(),tx.birthdate)))) as age, tx.gender as index_gender ' +
from +
where;
sql = this.clientsWithoutContactsQuery(params, sql, from);
} else if (params.elicited_clients > 0) {
where = `${where} and tx.person_id in (select patient_id from etl.flat_family_testing where location_uuid = '${params.locationUuid}' ) group by tx.person_id`;
sql =
Expand Down Expand Up @@ -368,4 +358,66 @@ export class FamilyTestingService {
});
});
};

allReviewedClientsQuery(params, sql, from) {
let w = ` WHERE tx.location_uuid = '${params.locationUuid}' `;
if (params.start_date != null && params.end_date != null) {
w =
w +
` AND ((DATE(t1.date_elicited) BETWEEN date('${params.start_date}') and date('${params.end_date}') AND obs_group_id IS NOT NULL)
OR (DATE(tx.encounter_datetime) BETWEEN date('${params.start_date}') and date('${params.end_date}') and obs_group_id IS NULL))`;
} else if (params.end_date != null) {
w =
w +
` and (date(t1.date_elicited) <= date('${params.end_date}') or (date(tx.encounter_datetime) <= date('${params.end_date}') and obs_group_id IS NULL)) `;
}

switch (params.child_status) {
case '1':
w = w + ` and tx.child_status_reason = 11890`;
break;
case '0':
w = w + ` and tx.child_status_reason = 11891`;
break;
}

sql =
sql +
' tx.*, extract(year from (from_days(datediff(now(),tx.birthdate)))) as age, tx.gender as index_gender ' +
from +
w +
' group by tx.person_id';

return sql;
}

clientsWithoutContactsQuery(params, sql, from) {
let w = ` WHERE tx.location_uuid = '${params.locationUuid}' `;
if (params.start_date != null && params.end_date != null) {
w =
w +
` and date(tx.encounter_datetime) between date('${params.start_date}') and date('${params.end_date}')`;
} else if (params.end_date != null) {
w =
w + ` and date(tx.encounter_datetime) <= date('${params.end_date}') `;
}

switch (params.child_status) {
case '1':
w = w + ` and tx.child_status_reason = 11890`;
break;
case '0':
w = w + ` and tx.child_status_reason = 11891`;
break;
}

sql =
sql +
' tx.*, extract(year from (from_days(datediff(now(),tx.birthdate)))) as age, tx.gender as index_gender ' +
from +
w +
' and obs_group_id is null';

return sql;
}
}

0 comments on commit 74e3553

Please sign in to comment.