Skip to content

Commit

Permalink
refactor(Bhima Data Collector)
Browse files Browse the repository at this point in the history
- Improved form selection component, added disable option when viewing
  patient data
- Reformated the research params by the using of components bh-filters
- Improved data display module, removal of entangled requests in the
  controller
-
  • Loading branch information
lomamech committed Sep 20, 2019
1 parent 18bc8cf commit eb0bf63
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 120 deletions.
10 changes: 10 additions & 0 deletions client/src/js/components/bhSurveyFormSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ angular.module('bhima.components')
form : '<?',
onSelectCallback : '&',
required : '<?',
disabled : '<?',
label : '@?',
},
});
Expand Down Expand Up @@ -37,6 +38,15 @@ function SurveyFormSelectController(DataCollectorManagement, Notify) {
.catch(Notify.handleError);
};

$ctrl.$onChanges = (changes) => {
if (changes.form.currentValue) {
$ctrl.form = parseInt(changes.form.currentValue, 10);
}
};

// fires the onSelectCallback bound to the component
$ctrl.handleChange = form => $ctrl.onChange({ form });

// fires the onSelectCallback bound to the component boundary
$ctrl.onSelect = surveyForm => {
$ctrl.onSelectCallback({ surveyForm });
Expand Down
29 changes: 10 additions & 19 deletions client/src/modules/display_metadata/display_metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,18 @@

<!-- main content -->
<div class="flex-util" style="overflow: auto" ng-if="DisplayMetadataCtrl.collector">
<span data="filter">
<span class="label" style="text-shadow: {{ DisplayMetadataCtrl.collector.color }} 5px 3px 8px; font-size: 15px; color: black">
{{ DisplayMetadataCtrl.collector.label }}
<div class="flex-util bh-filter-bar">
<span ng-if="DisplayMetadataCtrl.hasPatientData" data="filter">
<span class="label" style="font-size: 15px; color: black; text-shadow: gray 4px 1px 10px;">
<span> <i translate>FORM.LABELS.PATIENT_NAME </i> :{{ DisplayMetadataCtrl.patient.display_name }}/{{ DisplayMetadataCtrl.patient.reference}}</span>
</span>
</span>
</span>

<span ng-if="DisplayMetadataCtrl.filterElements" data="filter">
<span class="label label-primary label-emphasize">
<i class="fa fa-filter"></i>
{{ DisplayMetadataCtrl.filterElements }}
<a href ng-click="DisplayMetadataCtrl.onRemove()" class="filter-text-link">
<i class="fa fa-close"></i>
</a>
</span>
</span>

<span ng-if="DisplayMetadataCtrl.hasPatientData" data="filter">
<span class="label" style="font-size: 15px; color: black; text-shadow: gray 4px 1px 10px;">
<span>:{{ DisplayMetadataCtrl.patient.display_name }}/{{ DisplayMetadataCtrl.patient.reference}}</span>
</span>
</span>
<bh-filters
filters="DisplayMetadataCtrl.filterElements"
on-remove-filter="DisplayMetadataCtrl.onRemoveFilter(filter)">
</bh-filters>
</div>
</div>

<div class="flex-content" ng-if="DisplayMetadataCtrl.collector">
Expand Down
109 changes: 81 additions & 28 deletions client/src/modules/display_metadata/display_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
vm.search = search;
vm.collector = {};
vm.changes = {};
vm.onRemove = onRemove;
vm.displayData = displayData;
vm.patient = {};
vm.options = {};
vm.onRemoveFilter = onRemoveFilter;

vm.filterElements = {
defaultFilters : [],
customFilters : [],
};

vm.filterElements.defaultFilters = [];

vm.downloadPDF = function downloadPDF() {
vm.options.renderer = 'pdf';

return DisplayMetadata.download(vm.options);
};

Expand Down Expand Up @@ -103,6 +109,17 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
});
}

// remove a filter with from the filter object, save the filters and reload
function onRemoveFilter(key) {

vm.changes = DisplayMetadata.removeFilters(key, vm.changes);
vm.filterElements.defaultFilters = [];
vm.filterElements.customFilters = [];

cache.changes = vm.changes;
loadGrid();
}

function handleError(error) {
vm.hasError = true;
Notify.handleError(error);
Expand Down Expand Up @@ -135,16 +152,18 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem

SurveyForm.read(null, { data_collector_management_id : vm.collectorId })
.then((survey) => {
vm.filterElements = DisplayMetadata.displayFilters(survey, vm.changes);
vm.filterElements.customFilters = DisplayMetadata.displayFilters(survey, vm.changes);

vm.options = {
changes : vm.changes,
data_collector_management_id : vm.collectorId,
filterClient : vm.filterElements,
filterClient : vm.filterElements.customFilters,
};

return DisplayMetadata.read(null, vm.params);
})
.catch(handleError)
.finally(toggleLoadingIndicator);

DisplayMetadata.read(null, vm.params)
.then((data) => {
data.columns.forEach(item => {
if (item.field === 'dateSurvey') {
Expand All @@ -155,13 +174,27 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem

vm.gridOptions.columnDefs = data.columns;
vm.gridOptions.data = data.surveyData;

return DataCollectorManagement.read(vm.collectorId);
})
.catch(handleError)
.finally(toggleLoadingIndicator);

DataCollectorManagement.read(vm.collectorId)
.then((collector) => {
cache.collector = collector;
cache.changes = vm.changes;
vm.collector = collector;

vm.filterElements.defaultFilters.push(
{
_key : 'form_name',
_label : 'FORM.LABELS.FORM',
_displayValue : vm.collector.label,
_isCacheable : true,
_isDefault : true,
displayValue : vm.collector.label,
comparitorLabel : ':',
}
);
})
.catch(handleError)
.finally(toggleLoadingIndicator);
Expand All @@ -185,35 +218,52 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem
item.aggregationHideLabel = true;
}
});

vm.gridOptions.columnDefs = data.columns;
vm.gridOptions.data = data.surveyData;
})
.catch(handleError)
.finally(toggleLoadingIndicator);

return Patients.read($state.params.patient);
DataCollectorManagement.read($state.params.id)
.then((collector) => {
vm.collector = collector;
vm.filterElements.defaultFilters.push(
{
_key : 'form_name',
_label : 'FORM.LABELS.FORM',
_displayValue : vm.collector.label,
_isCacheable : true,
_isDefault : true,
displayValue : vm.collector.label,
comparitorLabel : ':',
}
);
})
.catch(handleError)
.finally(toggleLoadingIndicator);

Patients.read($state.params.patient)
.then((patient) => {
vm.patient = patient;
return DataCollectorManagement.read($state.params.id);
})
.then((collector) => {
vm.collector = collector;
return SurveyForm.read(null, { data_collector_management_id : vm.collectorId });
})
.then((survey) => {
vm.filterElements = DisplayMetadata.displayFilters(survey, vm.changes);
.catch(handleError)
.finally(toggleLoadingIndicator);

SurveyForm.read(null, { data_collector_management_id : vm.collectorId })
.then((survey) => {
vm.filterElements.customFilters = DisplayMetadata.displayFilters(survey, vm.changes);
vm.options = {
changes : vm.changes,
data_collector_management_id : vm.collectorId,
filterClient : vm.filterElements,
patient_uuid : vm.patient.uuid,
patient : vm.patient,
};

})
.catch(handleError)
.finally(toggleLoadingIndicator);
}

}

function toggleLoadingIndicator() {
Expand All @@ -222,21 +272,24 @@ function DisplayMetadataController($state, DisplayMetadata, DataCollectorManagem

// search Metadata of survey
function search() {
DisplayMetadata.openSearchModal()
// Prevent the changement of form when hasPatientData is true
const params = {
data_collector_management_id : vm.collectorId,
hasPatientData : vm.hasPatientData,
};

DisplayMetadata.openSearchModal(params)
.then((changes) => {
vm.collectorId = changes.collectorId;
vm.changes = changes;
if (changes) {
vm.collectorId = changes.collectorId;
vm.changes = changes;
}

vm.filterElements.defaultFilters = [];
loadGrid();
});
}

// On Remove all filter;
function onRemove() {
vm.changes = {};
cache.changes = {};
loadGrid();
}

function displayData(dataUuid) {
Receipts.displayData(dataUuid, vm.patient, true);
}
Expand Down
Loading

0 comments on commit eb0bf63

Please sign in to comment.