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

BAH-2763 | sharing prescriptions via sms feature #522

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
20 changes: 18 additions & 2 deletions ui/app/clinical/common/services/treatmentService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('bahmni.clinical')
.factory('treatmentService', ['$http', '$q', 'appService', '$rootScope', function ($http, $q, appService, $rootScope) {
.factory('treatmentService', ['$http', '$q', 'appService', '$rootScope', '$translate', function ($http, $q, appService, $rootScope, $translate) {
var createDrugOrder = function (drugOrder) {
return Bahmni.Clinical.DrugOrder.create(drugOrder);
};
Expand Down Expand Up @@ -125,6 +125,21 @@ angular.module('bahmni.clinical')
return deferred.promise;
};

var sendPrescriptionSMS = function (visitUuid) {
var deferred = $q.defer();
var locale = $translate.instant(appService.getAppDescriptor().getConfigValue("smsLanguage") || Bahmni.Clinical.Constants.smsLanguage);
kavitha-sundararajan marked this conversation as resolved.
Show resolved Hide resolved
$http.post(Bahmni.Common.Constants.bahmniDrugOrderUrl + "/sendPrescriptionSMS", {"visitUuid": visitUuid, "locale": locale}, {
withCredentials: true,
headers: {"Content-Type": "application/json"}
}).success(function (response) {
if (response.status != 200) {
response.error = true;
}
deferred.resolve(response);
});
return deferred.promise;
};

var voidDrugOrder = function (drugOrder) {
var deferred = $q.defer();

Expand All @@ -142,6 +157,7 @@ angular.module('bahmni.clinical')
getPrescribedAndActiveDrugOrders: getPrescribedAndActiveDrugOrders,
getNonCodedDrugConcept: getNonCodedDrugConcept,
getAllDrugOrdersFor: getAllDrugOrdersFor,
voidDrugOrder: voidDrugOrder
voidDrugOrder: voidDrugOrder,
sendPrescriptionSMS: sendPrescriptionSMS
};
}]);
3 changes: 2 additions & 1 deletion ui/app/clinical/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Bahmni.Clinical.Constants = (function () {
globalPropertyToFetchActivePatients: 'emrapi.sqlSearch.activePatients',
adtPrivilege: "app:adt",
adtForwardUrl: "../adt/#/patient/{{patientUuid}}/visit/{{visitUuid}}/",
certificateHeader: "Certificate Header"
certificateHeader: "Certificate Header",
smsLanguage: "SMS_LANGUAGE"
};
})();

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ angular.module('bahmni.clinical')
function ($scope, ngDialog, visitActionsService) {
var treatmentConfigParams = $scope.dashboard.getSectionByType("treatment") || {};
$scope.isEmailPresent = $scope.patient.email ? true : false;
var patientParams = {"patientUuid": $scope.patient.uuid, "isEmailPresent": $scope.isEmailPresent};
$scope.isPhoneNumberPresent = $scope.patient.phoneNumber ? true : false;
var patientParams = {"patientUuid": $scope.patient.uuid, "isEmailPresent": $scope.isEmailPresent, "isPhoneNumberPresent": $scope.isPhoneNumberPresent};

$scope.dashboardConfig = {};
$scope.expandedViewConfig = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

angular.module('bahmni.clinical')
.directive('treatmentTable', function () {
var controller = function ($scope, $rootScope) {
var controller = function ($scope, $rootScope, treatmentService, messagingService) {
$scope.prescriptionEmailToggle = $rootScope.prescriptionEmailToggle;
$scope.prescriptionSMSToggle = $rootScope.prescriptionSMSToggle;
kavitha-sundararajan marked this conversation as resolved.
Show resolved Hide resolved
$scope.isOtherActiveSection = function (dateString) {
return dateString === Bahmni.Clinical.Constants.otherActiveDrugOrders;
};
Expand All @@ -17,6 +19,16 @@ angular.module('bahmni.clinical')
$scope.downloadPrescription = function (visitStartDate, visitUuid) {
$rootScope.$broadcast("event:downloadPrescriptionFromDashboard", visitStartDate, visitUuid);
};

$scope.sendSMSForPrescription = function (visitUuid) {
treatmentService.sendPrescriptionSMS(visitUuid).then(function (data) {
if (data.error) {
messagingService.showMessage("error", "MESSAGE_SENDING_SMS_FAILURE");
} else {
messagingService.showMessage("info", "MESSAGE_SENDING_SMS_SUCCESS");
}
});
};
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ <h2 ng-if="::params.translationKey" class="section-title">{{::params | titleTran
<i class="fa fa-share-alt" bm-pop-over-trigger>
</i>
<div class="share-popup" bm-pop-over-target>
<i class="fa fa-envelope" ng-class="{'disable-icon' : !params.isEmailPresent}"></i>
<i class="fa fa-envelope" ng-if="::prescriptionEmailToggle == 'true'" ng-class="{'disable-icon' : !params.isEmailPresent}"></i>
<i class="fa fa-comment" ng-if="::prescriptionSMSToggle == 'true'" ng-class="{'disable-icon' : !params.isPhoneNumberPresent}" ng-click="sendSMSForPrescription(drugOrderSection.drugOrders[0].visit.uuid)"></i>
<i class="fa fa-download" ng-click="downloadPrescription(drugOrderSection.visitDate, drugOrderSection.drugOrders[0].visit.uuid)"></i>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/app/clinical/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ <h3 class="close" ng-click="closeTeleConsultation()">
<script src="common/services/clinicalAppConfigService.js"></script>
<script src="common/directives/visitPaginator.js"></script>

<script src="../common/services/smsService.js"></script>
<script src="../common/services/init.js"></script>
<script src="../common/services/drugService.js"></script>

Expand Down
6 changes: 5 additions & 1 deletion ui/app/clinical/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ angular.module('bahmni.clinical').factory('initialization',
'stoppedOrderReasonConfig',
'genderMap',
'relationshipTypeMap',
'defaultEncounterType'
'defaultEncounterType',
'prescriptionSMSToggle',
'prescriptionEmailToggle'
]).then(function () {
$rootScope.genderMap = configurations.genderMap();
$rootScope.relationshipTypeMap = configurations.relationshipTypeMap();
$rootScope.diagnosisStatus = (appService.getAppDescriptor().getConfig("diagnosisStatus") && appService.getAppDescriptor().getConfig("diagnosisStatus").value || "RULED OUT");
$rootScope.prescriptionSMSToggle = configurations.prescriptionSMSToggle();
$rootScope.prescriptionEmailToggle = configurations.prescriptionEmailToggle();
});
};

Expand Down
8 changes: 8 additions & 0 deletions ui/app/common/config/services/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ angular.module('bahmni.common.config')
this.helpDeskNumber = function () {
return this.configs.helpDeskNumber;
};

this.prescriptionSMSToggle = function () {
return this.configs.prescriptionSMSToggle;
};

this.prescriptionEmailToggle = function () {
return this.configs.prescriptionEmailToggle;
};
}]);
24 changes: 24 additions & 0 deletions ui/app/common/domain/services/configurationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,30 @@ angular.module('bahmni.common.domain')
});
};

configurationFunctions.prescriptionSMSToggle = function () {
return $http.get(Bahmni.Common.Constants.globalPropertyUrl, {
params: {
property: 'bahmni.enableSMSPrescriptionOption'
},
withCredentials: true,
transformResponse: [function (data) {
return data;
}]
});
};

configurationFunctions.prescriptionEmailToggle = function () {
return $http.get(Bahmni.Common.Constants.globalPropertyUrl, {
params: {
property: 'bahmni.enableEmailPrescriptionOption'
},
withCredentials: true,
transformResponse: [function (data) {
return data;
}]
});
};

configurationFunctions.helpDeskNumber = function () {
return $http.get(Bahmni.Common.Constants.globalPropertyUrl, {
params: {
Expand Down
5 changes: 4 additions & 1 deletion ui/app/i18n/clinical/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,8 @@
"CHIEF_COMPLAINT_DATA_CONCEPT_NAME_KEY": "Chief Complaint Data",
"CHIEF_COMPLAINT_DATA_OTHER_CONCEPT_KEY": "Other generic",
"CHIEF_COMPLAINT_DATA_OTHER_CONCEPT_TEMPLATE_KEY": "{{chiefComplaint}} ({{chiefComplaintText}}) since {{duration}} {{unit}}",
"CHIEF_COMPLAINT_DATA_WITHOUT_OTHER_CONCEPT_TEMPLATE_KEY": "{{chiefComplaint}} since {{duration}} {{unit}}"
"CHIEF_COMPLAINT_DATA_WITHOUT_OTHER_CONCEPT_TEMPLATE_KEY": "{{chiefComplaint}} since {{duration}} {{unit}}",
"SMS_LANGUAGE": "en",
"MESSAGE_SENDING_SMS_SUCCESS" : "SMS sent successfully",
"MESSAGE_SENDING_SMS_FAILURE" : "Failed to send SMS . Please check SMS configuration settings"
}
7 changes: 7 additions & 0 deletions ui/app/registration/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ angular.module('bahmni.registration').factory('initialization',
});
};

var visitLocation = function () {
return locationService.getAllByTag("Visit Location").then(function (response) {
$rootScope.visitLocation = response.data.results[0];
});
};

var mergeFormConditions = function () {
var formConditions = Bahmni.ConceptSet.FormConditions;
if (formConditions) {
Expand All @@ -80,6 +86,7 @@ angular.module('bahmni.registration').factory('initialization',
.then(initAppConfigs)
.then(mapRelationsTypeWithSearch)
.then(loggedInLocation)
.then(visitLocation)
.then(loadValidators(appService.configBaseUrl(), "registration"))
.then(mergeFormConditions)
);
Expand Down
4 changes: 2 additions & 2 deletions ui/app/registration/services/patientService.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ angular.module('bahmni.registration')
};

var getRegistrationMessage = function (patientId, name, age, gender) {
var clinicName = $rootScope.loggedInLocation.name;
var locationName = $rootScope.visitLocation.name;
var message = $translate.instant(appService.getAppDescriptor().getConfigValue("registrationMessage") || Bahmni.Registration.Constants.registrationMessage);
message = message.replace("#clinicName", clinicName);
message = message.replace("#locationName", locationName);
message = message.replace("#patientId", patientId);
message = message.replace("#name", name);
message = message.replace("#age", age);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ describe("TreamentService", function () {
var appDescriptor = jasmine.createSpyObj('appDescriptor', ['getConfigValue']);
appDescriptor.getConfigValue.and.returnValue({showDetailsWithinDateRange: false});
appService.getAppDescriptor.and.returnValue(appDescriptor);
var $translate = jasmine.createSpyObj('$translate', ['instant']);
$provide.value('$http', _$http);
$provide.value('$q', Q);
$provide.value('appService',appService);
$provide.value('appService', appService);
$provide.value('$translate', $translate);
}));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ describe("PatientDashboardTreatmentController", function () {
describe("Should fetch configuration", function () {
it("should fetch dashboard params", function () {
var expected = {};
_.extend(expected, treatmentConfigParams.dashboardConfig || {}, {patientUuid: "patient uuid", isEmailPresent: false});
_.extend(expected, treatmentConfigParams.dashboardConfig || {}, {patientUuid: "patient uuid", isEmailPresent: false, isPhoneNumberPresent: false});
expect(expected).toEqual(scope.dashboardConfig);
});

it("should fetch summary page params", function () {
var expected = {};
_.extend(expected, treatmentConfigParams.expandedViewConfig || {}, {patientUuid: "patient uuid", isEmailPresent: false});
_.extend(expected, treatmentConfigParams.expandedViewConfig || {}, {patientUuid: "patient uuid", isEmailPresent: false, isPhoneNumberPresent: false});
expect(expected).toEqual(scope.expandedViewConfig);
});
});
Expand Down
16 changes: 16 additions & 0 deletions ui/test/unit/clinical/displaycontrols/treatmentTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Treatment Table DisplayControl', function () {
compile,
mockBackend,
rootScope,
treatmentService,
params,
simpleHtml = '<treatment-table drug-order-sections="treatmentSections" params="params"></treatment-table>';

Expand All @@ -23,12 +24,27 @@ describe('Treatment Table DisplayControl', function () {

beforeEach(module('bahmni.clinical'));

beforeEach(module(function ($provide) {
treatmentService = jasmine.createSpyObj('treatmentService', ['sendPrescriptionSMS']);
$provide.value('treatmentService', treatmentService);
}));

beforeEach(inject(['$compile', '$httpBackend', '$rootScope', function ($compile, $httpBackend, $rootScope) {
compile = $compile;
mockBackend = $httpBackend;
rootScope = $rootScope;
}]));

var mockTreatmentService = function (data) {
treatmentService.sendPrescriptionSMS.and.callFake(function () {
return {
then: function (callback) {
return callback(data)
}
}
});
};

it("should return true if the section is other active drug orders", function () {
var scope = rootScope.$new();

Expand Down