Skip to content

Commit

Permalink
Merge pull request #127 from OpenLMIS-Angola/OAM-205
Browse files Browse the repository at this point in the history
OAM-205
  • Loading branch information
olewandowski1 authored Jun 17, 2024
2 parents d3bcc4b + 1cc7ef0 commit 22e09f7
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
var userId = authorizationService.getUser().user_id;

return $q.all([
facilityService.getAllMinimalWithoutWards(),
facilityService.getFacilitiesWithoutWards(),
programService.getUserPrograms(userId),
permissionService.load(userId),
currentUserService.getUserInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('facilityProgramCacheService', function() {

spyOn(this.authorizationService, 'getUser').andReturn(this.user);
spyOn(this.programService, 'getUserPrograms').andReturn(this.$q.when(this.programs));
spyOn(this.facilityService, 'getAllMinimalWithoutWards').andReturn(this.$q.when(this.facilities));
spyOn(this.facilityService, 'getFacilitiesWithoutWards').andReturn(this.$q.when(this.facilities));
spyOn(this.permissionService, 'load').andReturn(this.$q.when(permissions));
spyOn(this.currentUserService, 'getUserInfo').andReturn(this.$q.when(this.referencedataUser));

Expand All @@ -91,7 +91,7 @@ describe('facilityProgramCacheService', function() {
});

it('should call facilityService', function() {
expect(this.facilityService.getAllMinimalWithoutWards).toHaveBeenCalled();
expect(this.facilityService.getFacilitiesWithoutWards).toHaveBeenCalled();
});

it('should call authorizationService', function() {
Expand Down
12 changes: 12 additions & 0 deletions src/openlmis-facility-program-select/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"openlmisFacilityProgramSelect.facility": "Facility",
"openlmisFacilityProgramSelect.facilityType": "Facility Type",
"openlmisFacilityProgramSelect.myFacility": "My Facility",
"openlmisFacilityProgramSelect.program": "Program",
"openlmisFacilityProgramSelect.supervisedFacility": "Supervised Facility",
"openlmisFacilityProgramSelect.selectFacility": "Select Facility",
"openlmisFacilityProgramSelect.selectProgram": "Select Program",
"openlmisFacilityProgramSelect.type": "Type",
"openlmisFacilityProgramSelect.selectWard": "Select Ward",
"openlmisFacilityProgramSelect.ward": "Ward"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

(function() {

'use strict';

/**
* @ngdoc service
* @name openlmis-facility-program-select.component:openlmisFacilityProgramSelect
*
* @description
* Component responsible for selecting facility, facility type and program. This component will
* look for supervised, facility and program parameters in the state parameters to set the
* initial values, module parameter is for recognizing module where this component is used.
* @example
* ```
* <openlmis-facility-program-select
* is-supervised="vm.supervisedFlag"
* program="vm.programObject"
* facility="vm.facilityObject"
* module="'openlmis-some-module-name'">
* </openlmis-facility-program-select>
* ```
*/
angular
.module('openlmis-facility-program-select')
.component('openlmisFacilityProgramSelect', {
bindings: {
isSupervised: '=',
program: '=',
facility: '=',
module: '=?',
selectedWard: '=?'
},
controller: 'OpenlmisFacilityProgramSelectController',
controllerAs: 'vm',
templateUrl: 'openlmis-facility-program-select/openlmis-facility-program-select.html'
});

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

(function() {

'use strict';

/**
* @ngdoc controller
* @name openlmis-facility-program-select.controller:OpenlmisFacilityProgramSelectController
*
* @description
* Controller responsible for facilities and programs for the openlmis-facility-program-select
* component.
*/
angular
.module('openlmis-facility-program-select')
.controller('OpenlmisFacilityProgramSelectController', controller);

controller.$inject = ['$q', '$stateParams', '$filter', 'facilityProgramCacheService', 'wardService',
'WARDS_CONSTANTS'];

function controller($q, $stateParams, $filter, facilityProgramCacheService, wardService, WARDS_CONSTANTS) {

var vm = this;

vm.$onInit = onInit;
vm.updateForm = updateForm;
vm.updateFacilities = updateFacilities;
vm.homeFacilityWards = [];

/**
* @ngdoc method
* @methodOf openlmis-facility-program-select.controller:OpenlmisFacilityProgramSelectController
* @name $onInit
*
* @description
* Initialization method of the controller.
*/
function onInit() {
facilityProgramCacheService.loadData(vm.module)
.then(function() {
vm.homeFacility = facilityProgramCacheService.getUserHomeFacility();
vm.supervisedPrograms = facilityProgramCacheService.getUserPrograms(true);
vm.isSupervised = $stateParams.supervised === 'true' || !vm.homeFacility;
vm.programs = facilityProgramCacheService.getUserPrograms(vm.isSupervised);

if ($stateParams.program) {
vm.program = $filter('filter')(vm.programs,
{
id: $stateParams.program
})[0];
}

vm.updateFacilities();

return getHomeFacilityWards(vm.homeFacility).then(function(wards) {
vm.homeFacilityWards = wards ? wards : [];
});
});
}

function getHomeFacilityWards(facility) {
var searchParams = {
zoneId: facility.geographicZone.id,
sort: 'code,asc',
type: WARDS_CONSTANTS.WARD_TYPE_CODE

};

return wardService.getWardsByFacility(searchParams)
.then(function(response) {
return response.content;
});
}

/**
* @ngdoc method
* @methodOf openlmis-facility-program-select.controller:OpenlmisFacilityProgramSelectController
* @name updateForm
*
* @description
* Updates the form by clearing program and facility selection and setting appropriate
* lists.
*/
function updateForm() {
vm.program = undefined;
vm.programs = facilityProgramCacheService.getUserPrograms(vm.isSupervised);
vm.updateFacilities();
}

/**
* @ngdoc method
* @methodOf openlmis-facility-program-select.controller:OpenlmisFacilityProgramSelectController
* @name updateFacilities
*
* @description
* Updates the facility list by clearing the facility selection and setting appropriate
* facility list.
*/
function updateFacilities() {
vm.facility = undefined;

if (!vm.isSupervised) {
vm.facilities = [vm.homeFacility];
vm.facility = vm.facilities[0];
} else if (vm.program) {
vm.facilities = facilityProgramCacheService.getSupervisedFacilities(vm.program.id);
if ($stateParams.facility) {
vm.facility = $filter('filter')(vm.facilities,
{
id: $stateParams.facility
})[0];
}
} else {
vm.facilities = [];
}
}
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<fieldset class="form-group">

<legend>{{'openlmisFacilityProgramSelect.facilityType' | message}}</legend>

<label class="radio">
<input type="radio"
ng-model="vm.isSupervised"
ng-disabled="!vm.homeFacility"
ng-value="false"
ng-change="vm.updateForm()"/>
{{'openlmisFacilityProgramSelect.myFacility' | message}}
</label>

<label class="radio">
<input type="radio"
ng-model="vm.isSupervised"
ng-disabled="vm.supervisedPrograms.length == 0"
ng-value="true"
ng-change="vm.updateForm()"/>
{{'openlmisFacilityProgramSelect.supervisedFacility' | message}}
</label>

</fieldset>
<fieldset class="form-group" ng-if="!vm.isSupervised">

<label for="facilityName">{{'openlmisFacilityProgramSelect.facility' | message}}</label>
<select id="facilityName"
ng-model="vm.facility"
ng-options="facility as facility.name for facility in vm.facilities"
placeholder="{{'openlmisFacilityProgramSelect.selectFacility' | message}}"
disabled
required></select>

<label for="myFacilityWard">{{'openlmisFacilityProgramSelect.ward' | message}}</label>
<select id="myFacilityWard"
ng-model="vm.selectedWard"
ng-options="ward as ward.name for ward in vm.homeFacilityWards track by ward.id"
placeholder="{{'openlmisFacilityProgramSelect.selectWard' | message}}"></select>

<label for="programListMyFacility">{{'openlmisFacilityProgramSelect.program' | message}}</label>
<select id="programListMyFacility"
ng-model="vm.program"
ng-options="program as program.name for program in vm.programs | orderBy:'name' track by program.id"
placeholder="{{'openlmisFacilityProgramSelect.selectProgram' | message}}"
required></select>

</fieldset>
<fieldset class="form-group" ng-if="vm.isSupervised">

<label for="programListSupervisedFacility">{{'openlmisFacilityProgramSelect.program' | message}}</label>
<select id="programListSupervisedFacility"
ng-model="vm.program"
ng-options="program as program.name for program in vm.programs | orderBy:'name' track by program.id"
ng-change="vm.updateFacilities()"
placeholder="{{'openlmisFacilityProgramSelect.selectProgram' | message}}"
required></select>

<label for="supervisedFacilityName">{{'openlmisFacilityProgramSelect.facility' | message}}</label>
<select id="supervisedFacilityName"
ng-model="vm.facility"
ng-options="facility as facility.name for facility in vm.facilities | unique:'id' | orderBy:'name' track by facility.id"
placeholder="{{'openlmisFacilityProgramSelect.selectFacility' | message}}"
required></select>

</fieldset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

(function() {

'use strict';

/**
* @module openlmis-facility-program-select
*
* @description
* Proved openlmis-facility-program-select component for selecting facility and program.
*/
angular.module('openlmis-facility-program-select', [
'referencedata-facility',
'referencedata-program',
'referencedata-user',
'openlmis-auth',
'openlmis-permissions',
'referencedata-user',
'admin-facility-view'
]);

})();
2 changes: 1 addition & 1 deletion src/referencedata-facility/facility.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
* @ngdoc method
* @methodOf referencedata-facility.facilityService
* @name getAllMinimalWithoutWards
*
*
* @description
* Retrieves all facilities with id and name fields that are not wards.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/stock-card-summary-list/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"stockCardSummaryList.packs": "Packs",
"stockCardSummaryList.doses": "Doses",
"stockCardSummaryList.unit": "Unit",
"stockCardSummaryList.packsQuantity": "Packs quantity"
"stockCardSummaryList.packsQuantity": "Packs quantity",
"stockCardSummaryList.titleWithWard": "Stock on Hand - ${facility} - ${ward} - ${program}"
}
Loading

0 comments on commit 22e09f7

Please sign in to comment.