Skip to content

Commit

Permalink
Split hospitalization indicators by projects
Browse files Browse the repository at this point in the history
Add project reference in service
Update the indicator report by splitting hospitalization by projects
  • Loading branch information
mbayopanda committed Jun 3, 2019
1 parent 995a746 commit 18d659b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PORT=8080
DB_HOST='localhost'
DB_USER='bhima'
DB_PASS='HISCongo2013'
DB_NAME='imck'
DB_NAME='bhima_test'

# session variables
SESS_SECRET='XopEn BlowFISH'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function IndicatorsReportController($sce, Notify, SavedReports, AppCache, report
.catch(Notify.handleError);
};

vm.onSelectService = service => {
vm.reportDetails.service_id = service.id;
};

vm.clear = (key) => {
delete vm.reportDetails[key];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3 class="text-capitalize" translate>REPORT.REPORT_INDICATORS.TITLE</h3>
<!-- indicator type selection -->
<div class="form-group" ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.type.$invalid }">
<label class="control-label">
<i class="fa fa-briefcase"></i> <span translate> FORM.SELECT.INDICATOR_TYPE</span>
<span translate> FORM.SELECT.INDICATOR_TYPE</span>
</label>
<bh-clear on-clear="ReportConfigCtrl.clear('type')"></bh-clear>
<select
Expand All @@ -45,7 +45,13 @@ <h3 class="text-capitalize" translate>REPORT.REPORT_INDICATORS.TITLE</h3>
ng-options="type.id as (type.label | translate) for type in ReportConfigCtrl.indicatorTypes">
<option value="" disabled>{{ "FORM.SELECT.INDICATOR_TYPE" | translate }}<option>
</select>
</div>
</div>

<bh-service-select
service-id="ReportConfigCtrl.reportDetails.service_id"
on-select-callback="ReportConfigCtrl.onSelectService(service)">
<bh-clear on-clear="ReportConfigCtrl.clear('service_id')"></bh-clear>
</bh-service-select>
</bh-hidden-field>

<bh-loading-button loading-state="ConfigForm.$loading">
Expand Down
1 change: 1 addition & 0 deletions server/controllers/admin/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,4 @@ exports.update = update;
exports.remove = remove;
exports.detail = detail;
exports.countServiceByProject = countServiceByProject;
exports.lookupService = lookupService;
10 changes: 10 additions & 0 deletions server/controllers/finance/indicator/dashboard/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const FilterParser = require('../../../../lib/filter');
module.exports.hospitalization = hospitalization;
module.exports.finances = finances;
module.exports.staff = staff;
module.exports.getProjects = getProjects;

function getDaysOfPeriods(options) {
const query = `SELECT DATEDIFF(DATE(?), DATE(?)) + 1 AS nb_days;`;
return db.one(query, [options.dateTo, options.dateFrom]);
}

function getProjects() {
return db.exec('SELECT id, abbr FROM project;');
}

async function hospitalization(options) {
try {

Expand Down Expand Up @@ -53,6 +58,11 @@ async function hospitalization(options) {
filters1 = defaultFilters(filters1);
filters2 = defaultFilters(filters2);

if (options.project_id) {
filters1.equals('project_id', 'project_id', 's');
filters2.equals('project_id', 'project_id', 's');
}

// group by periods
if (options.groupByPeriod) {
filters1.setGroup('GROUP BY p.id');
Expand Down
37 changes: 36 additions & 1 deletion server/controllers/finance/indicator/dashboard/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,26 @@ async function processIndicators(options) {

try {

// hospitalization indicators
if (options.distinctProject) {
const projects = await collect.getProjects();
const hospitalizationByProject = {};
const hospitalizationByProjectDependencies = {};
indicators.hospitalizationByProject = {};

projects.forEach(async p => {
options.project_id = p.id;
hospitalizationByProject[p.abbr] = await collect.hospitalization(options);
hospitalizationByProjectDependencies[p.abbr] = mergeIndicatorsByPeriod(hospitalizationByProject[p.abbr]);

_.keys(hospitalizationByProjectDependencies[p.abbr]).forEach(period => {
const periodicDependencies = hospitalizationByProjectDependencies[p.abbr][period];
indicators.hospitalizationByProject[p.abbr] = getHospitalizationIndicators(
periodicDependencies, hospitalizationByProject[p.abbr].totalDaysOfPeriods.nb_days
);
});
});
}

const hospitalizationCollection = await collect.hospitalization(options);
const staffCollection = await collect.staff(options);
const financeCollection = await collect.finances(options);
Expand Down Expand Up @@ -201,6 +220,22 @@ function getHospitalizationIndicators(dependencies, nbDays = 356, period) {

// format the result for having indicators and dependencies
const indicators = {
totalBeds : {
value : dependencies.total_beds,
},

totalDayRealized : {
value : dependencies.total_day_realized,
},

totalHospitalizedPatient : {
value : dependencies.total_hospitalized_patient,
},

totalDeath : {
value : dependencies.total_death,
},

bedOccupationRate : {
value : bedOccupationRate,
dependencies : [
Expand Down
85 changes: 59 additions & 26 deletions server/controllers/finance/indicator/dashboard/report.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,65 @@
<div class="row">
<div class="col-xs-12">
<br/>
{{#if display.hospitalization}}
<h5><u>{{translate 'TREE.DASHBOARDS.HOSPITALIZATION'}}</u></h5>
<table class="table table-condensed table-bordered table-report">
<thead>
<th style="width: 350px !important">{{translate 'FORM.LABELS.INDICATOR'}}</th>
<th>{{translate 'FORM.LABELS.VALUE'}}</th>
</thead>
<tbody>
<tr>
<td>{{translate 'DASHBOARD.BEDS_OCCUPATION_RATE'}}</td>
<td>{{ ignoreNan indicators.hospitalization.bedOccupationRate.value '%'}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.HOSP_DAYS'}}</td>
<td>{{ ignoreNan indicators.hospitalization.averageHospitalizationDays.value ''}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.HOSP_BY_DAY'}}</td>
<td>{{ ignoreNan indicators.hospitalization.dailyHospitalization.value ''}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.DEATH_RATE'}}</td>
<td>{{ ignoreNan indicators.hospitalization.deathRate.value '%'}}</td>
</tr>
</tbody>
</table>
{{#if display.hospitalization}}
<h5>
<u>{{translate 'TREE.DASHBOARDS.HOSPITALIZATION'}}</u>
{{#if serviceName}}<b>: {{ serviceName }}</b>{{/if}}
</h5>

{{#each indicators.hospitalizationByProject as |value key|}}
<strong>{{key}}</strong>
<table class="table table-condensed table-bordered table-report">
<thead>
<th style="width: 350px !important">{{translate 'FORM.LABELS.INDICATOR'}}</th>
<th style="width: 200px !important">{{translate 'FORM.LABELS.VALUE'}}</th>
<th>{{translate 'DASHBOARD.NORM'}}</th>
</thead>
<tbody>
<tr>
<td>{{translate 'DASHBOARD.INDICATORS_FILES.TOTAL_BED'}}</td>
<td>{{ ignoreNan value.totalBeds.value ''}}</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.HOSP_DAYS'}}</td>
<td>{{ ignoreNan value.totalDayRealized.value ''}}</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.INDICATORS_FILES.TOTAL_HOSPI_PATIENT'}}</td>
<td>{{ ignoreNan value.totalHospitalizedPatient.value ''}}</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.INDICATORS_FILES.TOTAL_DEATH'}}</td>
<td>{{ ignoreNan value.totalDeath.value ''}}</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.BEDS_OCCUPATION_RATE'}}</td>
<td>{{ ignoreNan value.bedOccupationRate.value '%'}}</td>
<td>{{translate 'DASHBOARD.BEDS_OCCUPATION_RATE_NORM'}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.HOSP_DAYS'}}</td>
<td>{{ ignoreNan value.averageHospitalizationDays.value ''}}</td>
<td>{{translate 'DASHBOARD.HOSP_DAYS_NORM'}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.HOSP_BY_DAY'}}</td>
<td>{{ ignoreNan value.dailyHospitalization.value ''}}</td>
<td>{{translate 'DASHBOARD.HOSP_BY_DAY_NORM'}}</td>
</tr>
<tr>
<td>{{translate 'DASHBOARD.DEATH_RATE'}}</td>
<td>{{ ignoreNan value.deathRate.value '%'}}</td>
<td>{{translate 'DASHBOARD.DEATH_RATE_NORM'}}</td>
</tr>
</tbody>
</table>
<br>
{{/each}}
{{/if}}
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions server/controllers/finance/indicator/dashboard/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const _ = require('lodash');
const moment = require('moment');
const process = require('./process');
const ReportManager = require('../../../../lib/ReportManager');
const service = require('../../../admin/services');

const REPORT_TEMPLATE = './server/controllers/finance/indicator/dashboard/report.handlebars';

Expand Down Expand Up @@ -47,6 +48,8 @@ function report(req, res, next) {
return;
}

options.distinctProject = true;

lookupIndicators(options)
.then(result => {
if (options.type) { // a specific indicator type is defined
Expand All @@ -65,6 +68,10 @@ function report(req, res, next) {
data.dateFrom = options.dateFrom;
data.dateTo = options.dateTo;

return options.service_id ? service.lookupService(options.service_id) : {};
})
.then(serviceObject => {
data.serviceName = serviceObject.name;
return reportInstance.render(data);
})
.then(result => {
Expand Down

0 comments on commit 18d659b

Please sign in to comment.